Java Code Examples for org.eclipse.jdt.core.dom.VariableDeclarationExpression#fragments()

The following examples show how to use org.eclipse.jdt.core.dom.VariableDeclarationExpression#fragments() . 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(VariableDeclarationExpression node) {
	ASTNode parent = node.getParent();
	while(parent != null){
		if(parent instanceof Block || parent instanceof ForStatement){
			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: CodeBlock.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
private VarDeclarationExpr visit(VariableDeclarationExpression node) {
	int startLine = _cunit.getLineNumber(node.getStartPosition());
	int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
	VarDeclarationExpr varDeclarationExpr = new VarDeclarationExpr(startLine, endLine, node);
	
	varDeclarationExpr.setDeclType(node.getType());
	
	List<Vdf> vdfs = new ArrayList<>();
	for(Object object : node.fragments()){
		Vdf vdf = (Vdf) process((ASTNode) object);
		vdf.setParent(varDeclarationExpr);
		vdfs.add(vdf);
	}
	varDeclarationExpr.setVarDeclFrags(vdfs);
	
	return varDeclarationExpr;
}
 
Example 3
Source File: InferTypeArgumentsConstraintCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void endVisit(VariableDeclarationExpression node) {
	// Constrain the types of the child VariableDeclarationFragments to be equal to one
	// another, since the initializers in a 'for' statement can only have one type.
	// Pairwise constraints between adjacent variables is enough.
	Type type= node.getType();
	ConstraintVariable2 typeCv= getConstraintVariable(type);
	if (typeCv == null)
		return;

	setConstraintVariable(node, typeCv);

	List<VariableDeclarationFragment> fragments= node.fragments();
	for (Iterator<VariableDeclarationFragment> iter= fragments.iterator(); iter.hasNext();) {
		VariableDeclarationFragment fragment= iter.next();
		ConstraintVariable2 fragmentCv= getConstraintVariable(fragment);
		fTCModel.createElementEqualsConstraints(typeCv, fragmentCv);
	}
}
 
Example 4
Source File: TypeParseVisitor.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
public boolean visit(VariableDeclarationExpression 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;
}
 
Example 5
Source File: TypeResolver.java    From KodeBeagle with Apache License 2.0 5 votes vote down vote up
/**
 * Looks for variables declared in for loops.
 */
@Override
public boolean visit(final VariableDeclarationExpression node) {
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		addBinding(node, frag.getName(), node.getType());
	}
	return true;
}
 
Example 6
Source File: VariableScopeExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean visit(final VariableDeclarationExpression node) {
	final ASTNode parent = node.getParent();
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		variableScopes.put(parent, new Variable(frag.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}
 
Example 7
Source File: JavaApproximateVariableBindingExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Looks for variables declared in for loops.
 */
@Override
public boolean visit(final VariableDeclarationExpression node) {
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		addBinding(node, frag.getName().getIdentifier());
	}
	return true;
}
 
Example 8
Source File: JavaApproximateTypeInferencer.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Looks for variables declared in for loops.
 */
@Override
public boolean visit(final VariableDeclarationExpression node) {
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		addBinding(node, frag.getName().getIdentifier(), node.getType());
	}
	return true;
}
 
Example 9
Source File: IdentifierInformationScanner.java    From naturalize with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final VariableDeclarationExpression node) {
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment vdf = (VariableDeclarationFragment) fragment;
		final IdentifierInformation vd = new IdentifierInformation(SHA,
				file, vdf.getName().getIdentifier(), node.getType()
						.toString(), getLineNumber(vdf),
				getAstParentString(vdf));
		identifiers.add(vd);
	}
	return super.visit(node);
}
 
Example 10
Source File: VariableScopeExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final VariableDeclarationExpression node) {
	final ASTNode parent = node.getParent();
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		variableScopes.put(parent, new Variable(frag.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}
 
Example 11
Source File: JavaApproximateVariableBindingExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Looks for variables declared in for loops.
 */
@Override
public boolean visit(final VariableDeclarationExpression node) {
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		addBinding(node, frag.getName().getIdentifier());
	}
	return true;
}
 
Example 12
Source File: ConvertIterableLoopOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IStatus checkIteratorCondition() {

		List<Expression> initializers= getForStatement().initializers();
		if (initializers.size() != 1)
			return SEMANTIC_CHANGE_WARNING_STATUS;

		Expression expression= initializers.get(0);
		if (!(expression instanceof VariableDeclarationExpression))
			return SEMANTIC_CHANGE_WARNING_STATUS;

		VariableDeclarationExpression declaration= (VariableDeclarationExpression)expression;
		List<VariableDeclarationFragment> variableDeclarationFragments= declaration.fragments();
		if (variableDeclarationFragments.size() != 1)
			return SEMANTIC_CHANGE_WARNING_STATUS;

		VariableDeclarationFragment declarationFragment= variableDeclarationFragments.get(0);

		Expression initializer= declarationFragment.getInitializer();
		if (!(initializer instanceof MethodInvocation))
			return SEMANTIC_CHANGE_WARNING_STATUS;

		MethodInvocation methodInvocation= (MethodInvocation)initializer;
		String methodName= methodInvocation.getName().getIdentifier();
		if (!"iterator".equals(methodName) || methodInvocation.arguments().size() != 0) //$NON-NLS-1$
			return SEMANTIC_CHANGE_WARNING_STATUS;

		return StatusInfo.OK_STATUS;
	}
 
Example 13
Source File: ExceptionOccurrencesFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void handleResourceDeclarations(TryStatement tryStatement) {
	List<VariableDeclarationExpression> resources= tryStatement.resources();
	for (Iterator<VariableDeclarationExpression> iterator= resources.iterator(); iterator.hasNext();) {
		iterator.next().accept(this);
	}

	//check if the exception is thrown as a result of resource#close()
	boolean exitMarked= false;
	for (VariableDeclarationExpression variable : resources) {
		Type type= variable.getType();
		IMethodBinding methodBinding= Bindings.findMethodInHierarchy(type.resolveBinding(), "close", new ITypeBinding[0]); //$NON-NLS-1$
		if (methodBinding != null) {
			ITypeBinding[] exceptionTypes= methodBinding.getExceptionTypes();
			for (int j= 0; j < exceptionTypes.length; j++) {
				if (matches(exceptionTypes[j])) { // a close() throws the caught exception
					// mark name of resource
					for (VariableDeclarationFragment fragment : (List<VariableDeclarationFragment>) variable.fragments()) {
						SimpleName name= fragment.getName();
						fResult.add(new OccurrenceLocation(name.getStartPosition(), name.getLength(), 0, fDescription));
					}
					if (!exitMarked) {
						// mark exit position
						exitMarked= true;
						Block body= tryStatement.getBody();
						int offset= body.getStartPosition() + body.getLength() - 1; // closing bracket of try block
						fResult.add(new OccurrenceLocation(offset, 1, 0, Messages.format(SearchMessages.ExceptionOccurrencesFinder_occurrence_implicit_close_description,
								BasicElementLabels.getJavaElementName(fException.getName()))));
					}
				}
			}
		}
	}
}
 
Example 14
Source File: BindingSignatureVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(VariableDeclarationExpression expr) {
	List modifiers = expr.modifiers();
	for (int i = 0; i < modifiers.size(); i++) {
		visit((Modifier) modifiers.get(i));
	}
	// Append Type
	handleType(expr.getType());
	// Visit Fragments
	List fragments = expr.fragments();
	for (int i = 0; i < fragments.size(); i++) {
		visit((VariableDeclarationFragment) fragments.get(i));
	}
	return false;
}
 
Example 15
Source File: VariableScopeExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final VariableDeclarationExpression node) {
	final ASTNode parent = node.getParent();
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		variableScopes.put(parent, new Variable(frag.getName()
				.getIdentifier(), node.getType().toString(),
				ScopeType.SCOPE_LOCAL));
	}
	return false;
}
 
Example 16
Source File: JavaApproximateVariableBindingExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Looks for variables declared in for loops.
 */
@Override
public boolean visit(final VariableDeclarationExpression node) {
	for (final Object fragment : node.fragments()) {
		final VariableDeclarationFragment frag = (VariableDeclarationFragment) fragment;
		addBinding(node, frag.getName().getIdentifier());
	}
	return true;
}