Search in sources :

Example 81 with ITypeBinding

use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.

the class ScopeAnalyzer method isDeclaredInScope.

public boolean isDeclaredInScope(IBinding declaration, SimpleName selector, int flags) {
    try {
        // special case for switch on enum
        if (selector.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) {
            ITypeBinding binding = ((SwitchStatement) selector.getParent().getParent()).getExpression().resolveTypeBinding();
            if (binding != null && binding.isEnum()) {
                return hasEnumContants(declaration, binding.getTypeDeclaration());
            }
        }
        ITypeBinding parentTypeBinding = Bindings.getBindingOfParentTypeContext(selector);
        if (parentTypeBinding != null) {
            ITypeBinding binding = getQualifier(selector);
            SearchRequestor requestor = new SearchRequestor(declaration, parentTypeBinding, flags);
            if (binding == null) {
                addLocalDeclarations(selector, flags, requestor);
                if (requestor.found())
                    return requestor.isVisible();
                addTypeDeclarations(parentTypeBinding, flags, requestor);
                if (requestor.found())
                    return requestor.isVisible();
            } else {
                addInherited(binding, flags, requestor);
                if (requestor.found())
                    return requestor.isVisible();
            }
        }
        return false;
    } finally {
        clearLists();
    }
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 82 with ITypeBinding

use of org.eclipse.jdt.core.dom.ITypeBinding in project flux 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 83 with ITypeBinding

use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.

the class ScopeAnalyzer method getDeclarationsInScope.

public IBinding[] getDeclarationsInScope(SimpleName selector, int flags) {
    try {
        // special case for switch on enum
        if (selector.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) {
            ITypeBinding binding = ((SwitchStatement) selector.getParent().getParent()).getExpression().resolveTypeBinding();
            if (binding != null && binding.isEnum()) {
                return getEnumContants(binding);
            }
        }
        ITypeBinding parentTypeBinding = Bindings.getBindingOfParentType(selector);
        if (parentTypeBinding != null) {
            ITypeBinding binding = getQualifier(selector);
            DefaultBindingRequestor requestor = new DefaultBindingRequestor(parentTypeBinding, flags);
            if (binding == null) {
                addLocalDeclarations(selector, flags, requestor);
                addTypeDeclarations(parentTypeBinding, flags, requestor);
            } else {
                addInherited(binding, flags, requestor);
            }
            List<IBinding> result = requestor.getResult();
            return result.toArray(new IBinding[result.size()]);
        }
        return NO_BINDING;
    } finally {
        clearLists();
    }
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) IBinding(org.eclipse.jdt.core.dom.IBinding)

Example 84 with ITypeBinding

use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.

the class ASTResolving method isVariableDefinedInContext.

private static boolean isVariableDefinedInContext(IBinding binding, ITypeBinding typeVariable) {
    if (binding.getKind() == IBinding.VARIABLE) {
        IVariableBinding var = (IVariableBinding) binding;
        binding = var.getDeclaringMethod();
        if (binding == null) {
            binding = var.getDeclaringClass();
        }
    }
    if (binding instanceof IMethodBinding) {
        if (binding == typeVariable.getDeclaringMethod()) {
            return true;
        }
        binding = ((IMethodBinding) binding).getDeclaringClass();
    }
    while (binding instanceof ITypeBinding) {
        if (binding == typeVariable.getDeclaringClass()) {
            return true;
        }
        if (Modifier.isStatic(binding.getModifiers())) {
            break;
        }
        binding = ((ITypeBinding) binding).getDeclaringClass();
    }
    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 85 with ITypeBinding

use of org.eclipse.jdt.core.dom.ITypeBinding in project flux by eclipse.

the class Bindings method asString.

private static String asString(IMethodBinding method) {
    StringBuffer result = new StringBuffer();
    result.append(method.getDeclaringClass().getName());
    result.append(':');
    result.append(method.getName());
    result.append('(');
    ITypeBinding[] parameters = method.getParameterTypes();
    int lastComma = parameters.length - 1;
    for (int i = 0; i < parameters.length; i++) {
        ITypeBinding parameter = parameters[i];
        result.append(parameter.getName());
        if (i < lastComma)
            //$NON-NLS-1$
            result.append(", ");
    }
    result.append(')');
    return result.toString();
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Aggregations

ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)388 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)110 ASTNode (org.eclipse.jdt.core.dom.ASTNode)72 Expression (org.eclipse.jdt.core.dom.Expression)69 Type (org.eclipse.jdt.core.dom.Type)55 SimpleName (org.eclipse.jdt.core.dom.SimpleName)52 ArrayList (java.util.ArrayList)50 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)49 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)49 AST (org.eclipse.jdt.core.dom.AST)43 IBinding (org.eclipse.jdt.core.dom.IBinding)41 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)40 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)36 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)35 CastExpression (org.eclipse.jdt.core.dom.CastExpression)33 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)32 Name (org.eclipse.jdt.core.dom.Name)31 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)29 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)29 ContextSensitiveImportRewriteContext (org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext)26