Java Code Examples for org.eclipse.jdt.core.dom.VariableDeclarationStatement#getType()

The following examples show how to use org.eclipse.jdt.core.dom.VariableDeclarationStatement#getType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeUtils.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
public boolean visit(VariableDeclarationStatement node) {
	ASTNode parent = node.getParent();
	while(parent != null){
		if(parent instanceof Block){
			break;
		}
		parent = parent.getParent();
	}
	if(parent != null) {
		int start = _unit.getLineNumber(node.getStartPosition());
		int end = _unit.getLineNumber(parent.getStartPosition() + parent.getLength());
		for (Object o : node.fragments()) {
			VariableDeclarationFragment vdf = (VariableDeclarationFragment) o;
			Pair<String, Type> pair = new Pair<String, Type>(vdf.getName().getFullyQualifiedName(), node.getType());
			Pair<Integer, Integer> range = new Pair<Integer, Integer>(start, end);
			_tmpVars.put(pair, range);
		}
	}
	return true;
}
 
Example 2
Source File: VariableDeclaration.java    From RefactoringMiner with MIT License 6 votes vote down vote up
private static Type extractType(org.eclipse.jdt.core.dom.VariableDeclaration variableDeclaration) {
	Type returnedVariableType = null;
	if(variableDeclaration instanceof SingleVariableDeclaration) {
		SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration)variableDeclaration;
		returnedVariableType = singleVariableDeclaration.getType();
	}
	else if(variableDeclaration instanceof VariableDeclarationFragment) {
		VariableDeclarationFragment fragment = (VariableDeclarationFragment)variableDeclaration;
		if(fragment.getParent() instanceof VariableDeclarationStatement) {
			VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement)fragment.getParent();
			returnedVariableType = variableDeclarationStatement.getType();
		}
		else if(fragment.getParent() instanceof VariableDeclarationExpression) {
			VariableDeclarationExpression variableDeclarationExpression = (VariableDeclarationExpression)fragment.getParent();
			returnedVariableType = variableDeclarationExpression.getType();
		}
		else if(fragment.getParent() instanceof FieldDeclaration) {
			FieldDeclaration fieldDeclaration = (FieldDeclaration)fragment.getParent();
			returnedVariableType = fieldDeclaration.getType();
		}
	}
	return returnedVariableType;
}
 
Example 3
Source File: PromoteTempToFieldRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkTempTypeForLocalTypeUsage(){
  	VariableDeclarationStatement vds= getTempDeclarationStatement();
  	if (vds == null)
  		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_cannot_promote);
  	Type type= 	vds.getType();
  	ITypeBinding binding= type.resolveBinding();
  	if (binding == null)
  		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_cannot_promote);

IMethodBinding declaringMethodBinding= getMethodDeclaration().resolveBinding();
ITypeBinding[] methodTypeParameters= declaringMethodBinding == null ? new ITypeBinding[0] : declaringMethodBinding.getTypeParameters();
LocalTypeAndVariableUsageAnalyzer analyzer= new LocalTypeAndVariableUsageAnalyzer(methodTypeParameters);
type.accept(analyzer);
boolean usesLocalTypes= ! analyzer.getUsageOfEnclosingNodes().isEmpty();
fTempTypeUsesClassTypeVariables= analyzer.getClassTypeVariablesUsed();
if (usesLocalTypes)
	return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_uses_type_declared_locally);
return null;
  }
 
Example 4
Source File: RefactoringUtility.java    From JDeodorant with MIT License 6 votes vote down vote up
private static Type extractType(VariableDeclaration variableDeclaration) {
	Type returnedVariableType = null;
	if(variableDeclaration instanceof SingleVariableDeclaration) {
		SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration)variableDeclaration;
		returnedVariableType = singleVariableDeclaration.getType();
	}
	else if(variableDeclaration instanceof VariableDeclarationFragment) {
		VariableDeclarationFragment fragment = (VariableDeclarationFragment)variableDeclaration;
		if(fragment.getParent() instanceof VariableDeclarationStatement) {
			VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement)fragment.getParent();
			returnedVariableType = variableDeclarationStatement.getType();
		}
		else if(fragment.getParent() instanceof VariableDeclarationExpression) {
			VariableDeclarationExpression variableDeclarationExpression = (VariableDeclarationExpression)fragment.getParent();
			returnedVariableType = variableDeclarationExpression.getType();
		}
		else if(fragment.getParent() instanceof FieldDeclaration) {
			FieldDeclaration fieldDeclaration = (FieldDeclaration)fragment.getParent();
			returnedVariableType = fieldDeclaration.getType();
		}
	}
	return returnedVariableType;
}
 
Example 5
Source File: TypeParseVisitor.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
public boolean visit(VariableDeclarationStatement node) {
	if(isAnonymousClass(node)){
		return true;
	}
	for (Object o : node.fragments()) {
		VariableDeclarationFragment vdf = (VariableDeclarationFragment) o;
		Type type = node.getType();
		if(vdf.getExtraDimensions() > 0){
			AST ast = AST.newAST(AST.JLS8);
			type = ast.newArrayType((Type) ASTNode.copySubtree(ast, type), vdf.getExtraDimensions());
		}
		map.put(vdf.getName().toString(), type);
	}
	return true;
}