use of org.eclipse.jdt.core.dom.IVariableBinding in project che by eclipse.
the class ConvertForLoopOperation method validateLengthFragment.
/*
* [lengthBinding]= [arrayBinding].length
*/
private boolean validateLengthFragment(VariableDeclarationFragment fragment) {
Expression initializer = fragment.getInitializer();
if (initializer == null)
return false;
if (!validateLengthQuery(initializer))
return false;
IVariableBinding lengthBinding = (IVariableBinding) fragment.getName().resolveBinding();
if (lengthBinding == null)
return false;
fLengthBinding = lengthBinding;
return true;
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project che by eclipse.
the class ConvertForLoopOperation method validateExpression.
/*
* Must be one of:
* <ul>
* <li>[indexBinding] < [result].length;</li>
* <li>[result].length > [indexBinding];</li>
* <li>[indexBinding] < [lengthBinding];</li>
* <li>[lengthBinding] > [indexBinding];</li>
* </ul>
*/
private boolean validateExpression(ForStatement statement) {
Expression expression = statement.getExpression();
if (!(expression instanceof InfixExpression))
return false;
InfixExpression infix = (InfixExpression) expression;
Expression left = infix.getLeftOperand();
Expression right = infix.getRightOperand();
if (left instanceof SimpleName && right instanceof SimpleName) {
IVariableBinding lengthBinding = fLengthBinding;
if (lengthBinding == null)
return false;
IBinding leftBinding = ((SimpleName) left).resolveBinding();
IBinding righBinding = ((SimpleName) right).resolveBinding();
if (fIndexBinding.equals(leftBinding)) {
return lengthBinding.equals(righBinding);
} else if (fIndexBinding.equals(righBinding)) {
return lengthBinding.equals(leftBinding);
}
return false;
} else if (left instanceof SimpleName) {
if (!fIndexBinding.equals(((SimpleName) left).resolveBinding()))
return false;
if (!Operator.LESS.equals(infix.getOperator()))
return false;
return validateLengthQuery(right);
} else if (right instanceof SimpleName) {
if (!fIndexBinding.equals(((SimpleName) right).resolveBinding()))
return false;
if (!Operator.GREATER.equals(infix.getOperator()))
return false;
return validateLengthQuery(left);
}
return false;
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project che by eclipse.
the class ScopeAnalyzer method addInherited.
/**
* Collects all elements available in a type and its hierarchy
* @param binding The type binding
* @param flags Flags defining the elements to report
* @param requestor the requestor to which all results are reported
* @return return <code>true</code> if the requestor has reported the binding as found and no further results are required
*/
private boolean addInherited(ITypeBinding binding, int flags, IBindingRequestor requestor) {
if (!fTypesVisited.add(binding)) {
return false;
}
if (hasFlag(VARIABLES, flags)) {
IVariableBinding[] variableBindings = binding.getDeclaredFields();
for (int i = 0; i < variableBindings.length; i++) {
if (requestor.acceptBinding(variableBindings[i]))
return true;
}
}
if (hasFlag(METHODS, flags)) {
IMethodBinding[] methodBindings = binding.getDeclaredMethods();
for (int i = 0; i < methodBindings.length; i++) {
IMethodBinding curr = methodBindings[i];
if (!curr.isSynthetic() && !curr.isConstructor()) {
if (requestor.acceptBinding(curr))
return true;
}
}
}
if (hasFlag(TYPES, flags)) {
ITypeBinding[] typeBindings = binding.getDeclaredTypes();
for (int i = 0; i < typeBindings.length; i++) {
ITypeBinding curr = typeBindings[i];
if (requestor.acceptBinding(curr))
return true;
}
}
ITypeBinding superClass = binding.getSuperclass();
if (superClass != null) {
if (// recursive
addInherited(superClass, flags, requestor))
return true;
} else if (binding.isArray()) {
if (//$NON-NLS-1$
addInherited(fRoot.getAST().resolveWellKnownType("java.lang.Object"), flags, requestor))
return true;
}
// includes looking for methods: abstract, unimplemented methods
ITypeBinding[] interfaces = binding.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
if (// recursive
addInherited(interfaces[i], flags, requestor))
return true;
}
return false;
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project che by eclipse.
the class ScopeAnalyzer method getEnumContants.
private IVariableBinding[] getEnumContants(ITypeBinding binding) {
IVariableBinding[] declaredFields = binding.getDeclaredFields();
ArrayList<IVariableBinding> res = new ArrayList<IVariableBinding>(declaredFields.length);
for (int i = 0; i < declaredFields.length; i++) {
IVariableBinding curr = declaredFields[i];
if (curr.isEnumConstant()) {
res.add(curr);
}
}
return res.toArray(new IVariableBinding[res.size()]);
}
use of org.eclipse.jdt.core.dom.IVariableBinding in project che by eclipse.
the class Bindings method findFieldInHierarchy.
/**
* Finds the field specified by <code>fieldName</code> in
* the type hierarchy denoted by the given type. Returns <code>null</code> if no such field
* exists. If the field is defined in more than one super type only the first match is
* returned. First the super class is examined and then the implemented interfaces.
* @param type The type to search the field in
* @param fieldName The name of the field to find
* @return the variable binding representing the field
*/
public static IVariableBinding findFieldInHierarchy(ITypeBinding type, String fieldName) {
IVariableBinding field = findFieldInType(type, fieldName);
if (field != null)
return field;
ITypeBinding superClass = type.getSuperclass();
if (superClass != null) {
field = findFieldInHierarchy(superClass, fieldName);
if (field != null)
return field;
}
ITypeBinding[] interfaces = type.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
field = findFieldInHierarchy(interfaces[i], fieldName);
if (// no private fields in interfaces
field != null)
return field;
}
return null;
}
Aggregations