use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class CallInliner method crossCheckArguments.
/**
* Checks whether arguments are passed to the method which do some assignments
* inside the expression. If so these arguments can't be inlined into the
* calling method since the assignments might be reorder. An example is:
* <code>
* add((field=args).length,field.hashCode());
* </code>
* Field might not be initialized when the arguments are reorder in the called
* method.
* @param arguments the arguments
* @return all arguments that cannot be inlined
*/
private Set<Expression> crossCheckArguments(List<Expression> arguments) {
final Set<IBinding> assigned = new HashSet<IBinding>();
final Set<Expression> result = new HashSet<Expression>();
for (Iterator<Expression> iter = arguments.iterator(); iter.hasNext(); ) {
final Expression expression = iter.next();
expression.accept(new ASTVisitor() {
@Override
public boolean visit(Assignment node) {
Expression lhs = node.getLeftHandSide();
if (lhs instanceof Name) {
IBinding binding = ((Name) lhs).resolveBinding();
if (binding instanceof IVariableBinding) {
assigned.add(binding);
result.add(expression);
}
}
return true;
}
});
}
for (Iterator<Expression> iter = arguments.iterator(); iter.hasNext(); ) {
final Expression expression = iter.next();
if (!result.contains(expression)) {
expression.accept(new HierarchicalASTVisitor() {
@Override
public boolean visit(Name node) {
IBinding binding = node.resolveBinding();
if (binding != null && assigned.contains(binding))
result.add(expression);
return false;
}
});
}
}
return result;
}
use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class ConvertAnonymousToNestedRefactoring method getAllAccessedFields.
private List<IBinding> getAllAccessedFields() {
final List<IBinding> accessedFields = new ArrayList<IBinding>();
ASTVisitor visitor = new ASTVisitor() {
@Override
public boolean visit(FieldAccess node) {
final IVariableBinding binding = node.resolveFieldBinding();
if (binding != null && !binding.isEnumConstant())
accessedFields.add(binding);
return super.visit(node);
}
@Override
public boolean visit(QualifiedName node) {
final IBinding binding = node.resolveBinding();
if (binding != null && binding instanceof IVariableBinding) {
IVariableBinding variable = (IVariableBinding) binding;
if (!variable.isEnumConstant() && variable.isField())
accessedFields.add(binding);
}
return super.visit(node);
}
@Override
public boolean visit(SimpleName node) {
final IBinding binding = node.resolveBinding();
if (binding != null && binding instanceof IVariableBinding) {
IVariableBinding variable = (IVariableBinding) binding;
if (!variable.isEnumConstant() && variable.isField())
accessedFields.add(binding);
}
return super.visit(node);
}
@Override
public boolean visit(SuperFieldAccess node) {
final IVariableBinding binding = node.resolveFieldBinding();
if (binding != null && !binding.isEnumConstant())
accessedFields.add(binding);
return super.visit(node);
}
};
fAnonymousInnerClassNode.accept(visitor);
return accessedFields;
}
use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class ConvertAnonymousToNestedRefactoring method areLocalsUsedIn.
private boolean areLocalsUsedIn(Expression fieldInitializer, List<VariableDeclarationFragment> fieldsToInitialize) {
Set<IBinding> localsUsed = new HashSet<IBinding>(0);
collectRefrencedVariables(fieldInitializer, localsUsed);
ITypeBinding anonType = fAnonymousInnerClassNode.resolveBinding();
for (Iterator<IBinding> iterator = localsUsed.iterator(); iterator.hasNext(); ) {
IVariableBinding curr = (IVariableBinding) iterator.next();
if (isBindingToTemp(curr)) {
// reference a local from outside
return true;
} else if (curr.isField() && (curr.getDeclaringClass() == anonType) && fieldsToInitialize.contains(fCompilationUnitNode.findDeclaringNode(curr))) {
// references a field that references a local from outside
return true;
}
}
return false;
}
use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class FullConstraintCreator method create.
/* (non-Javadoc)
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.FieldAccess)
*/
@Override
public ITypeConstraint[] create(FieldAccess access) {
Expression expression = access.getExpression();
SimpleName name = access.getName();
IBinding binding = name.resolveBinding();
if (!(binding instanceof IVariableBinding))
return new ITypeConstraint[0];
IVariableBinding vb = (IVariableBinding) binding;
return createConstraintsForAccessToField(vb, expression, access);
}
use of org.eclipse.jdt.core.dom.IBinding in project che by eclipse.
the class FullConstraintCreator method create.
/* (non-Javadoc)
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.QualifiedName)
*/
@Override
public ITypeConstraint[] create(QualifiedName qualifiedName) {
SimpleName name = qualifiedName.getName();
Name qualifier = qualifiedName.getQualifier();
IBinding nameBinding = name.resolveBinding();
if (nameBinding instanceof IVariableBinding) {
IVariableBinding vb = (IVariableBinding) nameBinding;
if (vb.isField())
return createConstraintsForAccessToField(vb, qualifier, qualifiedName);
}
//TODO other bindings
return new ITypeConstraint[0];
}
Aggregations