Search in sources :

Example 71 with IVariableBinding

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;
}
Also used : PostfixExpression(org.eclipse.jdt.core.dom.PostfixExpression) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) PrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding)

Example 72 with IVariableBinding

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;
}
Also used : PostfixExpression(org.eclipse.jdt.core.dom.PostfixExpression) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) PrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression) SimpleName(org.eclipse.jdt.core.dom.SimpleName) IBinding(org.eclipse.jdt.core.dom.IBinding) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding)

Example 73 with IVariableBinding

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;
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding)

Example 74 with IVariableBinding

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()]);
}
Also used : ArrayList(java.util.ArrayList) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding)

Example 75 with IVariableBinding

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;
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding)

Aggregations

IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)106 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)49 IBinding (org.eclipse.jdt.core.dom.IBinding)48 SimpleName (org.eclipse.jdt.core.dom.SimpleName)43 ASTNode (org.eclipse.jdt.core.dom.ASTNode)30 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)29 Expression (org.eclipse.jdt.core.dom.Expression)24 ArrayList (java.util.ArrayList)22 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)16 Name (org.eclipse.jdt.core.dom.Name)13 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)13 Assignment (org.eclipse.jdt.core.dom.Assignment)12 CastExpression (org.eclipse.jdt.core.dom.CastExpression)12 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)12 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)12 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)12 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)12 FieldAccess (org.eclipse.jdt.core.dom.FieldAccess)11 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)11 PrefixExpression (org.eclipse.jdt.core.dom.PrefixExpression)11