Search in sources :

Example 36 with ITypeBinding

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

the class StubUtility2 method getOverridableMethods.

public static IMethodBinding[] getOverridableMethods(AST ast, ITypeBinding typeBinding, boolean isSubType) {
    List<IMethodBinding> allMethods = new ArrayList<IMethodBinding>();
    IMethodBinding[] typeMethods = typeBinding.getDeclaredMethods();
    for (int index = 0; index < typeMethods.length; index++) {
        final int modifiers = typeMethods[index].getModifiers();
        if (!typeMethods[index].isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers))
            allMethods.add(typeMethods[index]);
    }
    ITypeBinding clazz = typeBinding.getSuperclass();
    while (clazz != null) {
        IMethodBinding[] methods = clazz.getDeclaredMethods();
        for (int offset = 0; offset < methods.length; offset++) {
            final int modifiers = methods[offset].getModifiers();
            if (!methods[offset].isConstructor() && !Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) {
                if (findOverridingMethod(methods[offset], allMethods) == null)
                    allMethods.add(methods[offset]);
            }
        }
        clazz = clazz.getSuperclass();
    }
    clazz = typeBinding;
    while (clazz != null) {
        ITypeBinding[] superInterfaces = clazz.getInterfaces();
        for (int index = 0; index < superInterfaces.length; index++) {
            getOverridableMethods(ast, superInterfaces[index], allMethods);
        }
        clazz = clazz.getSuperclass();
    }
    if (typeBinding.isInterface())
        //$NON-NLS-1$
        getOverridableMethods(ast, ast.resolveWellKnownType("java.lang.Object"), allMethods);
    if (!isSubType)
        allMethods.removeAll(Arrays.asList(typeMethods));
    int modifiers = 0;
    if (!typeBinding.isInterface()) {
        for (int index = allMethods.size() - 1; index >= 0; index--) {
            IMethodBinding method = allMethods.get(index);
            modifiers = method.getModifiers();
            if (Modifier.isFinal(modifiers))
                allMethods.remove(index);
        }
    }
    return allMethods.toArray(new IMethodBinding[allMethods.size()]);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ArrayList(java.util.ArrayList)

Example 37 with ITypeBinding

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

the class StubUtility2 method getVisibleConstructors.

public static IMethodBinding[] getVisibleConstructors(ITypeBinding binding, boolean accountExisting, boolean proposeDefault) {
    List<IMethodBinding> constructorMethods = new ArrayList<IMethodBinding>();
    List<IMethodBinding> existingConstructors = null;
    ITypeBinding superType = binding.getSuperclass();
    if (superType == null)
        return new IMethodBinding[0];
    if (accountExisting) {
        IMethodBinding[] methods = binding.getDeclaredMethods();
        existingConstructors = new ArrayList<IMethodBinding>(methods.length);
        for (int index = 0; index < methods.length; index++) {
            IMethodBinding method = methods[index];
            if (method.isConstructor() && !method.isDefaultConstructor())
                existingConstructors.add(method);
        }
    }
    if (existingConstructors != null)
        constructorMethods.addAll(existingConstructors);
    IMethodBinding[] methods = binding.getDeclaredMethods();
    IMethodBinding[] superMethods = superType.getDeclaredMethods();
    for (int index = 0; index < superMethods.length; index++) {
        IMethodBinding method = superMethods[index];
        if (method.isConstructor()) {
            if (Bindings.isVisibleInHierarchy(method, binding.getPackage()) && (!accountExisting || !Bindings.containsSignatureEquivalentConstructor(methods, method)))
                constructorMethods.add(method);
        }
    }
    if (existingConstructors != null)
        constructorMethods.removeAll(existingConstructors);
    if (constructorMethods.isEmpty()) {
        superType = binding;
        while (superType.getSuperclass() != null) superType = superType.getSuperclass();
        //$NON-NLS-1$
        IMethodBinding method = Bindings.findMethodInType(superType, "Object", new ITypeBinding[0]);
        if (method != null) {
            if ((proposeDefault || !accountExisting || existingConstructors == null || existingConstructors.isEmpty()) && (!accountExisting || !Bindings.containsSignatureEquivalentConstructor(methods, method)))
                constructorMethods.add(method);
        }
    }
    return constructorMethods.toArray(new IMethodBinding[constructorMethods.size()]);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ArrayList(java.util.ArrayList)

Example 38 with ITypeBinding

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

the class Bindings method sameParameters.

//---- Helper methods to convert a method ---------------------------------------------
private static boolean sameParameters(IMethodBinding method, IMethod candidate) throws JavaModelException {
    ITypeBinding[] methodParamters = method.getParameterTypes();
    String[] candidateParameters = candidate.getParameterTypes();
    if (methodParamters.length != candidateParameters.length)
        return false;
    IType scope = candidate.getDeclaringType();
    for (int i = 0; i < methodParamters.length; i++) {
        ITypeBinding methodParameter = methodParamters[i];
        String candidateParameter = candidateParameters[i];
        if (!sameParameter(methodParameter, candidateParameter, scope))
            return false;
    }
    return true;
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) IType(org.eclipse.jdt.core.IType)

Example 39 with ITypeBinding

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

the class Bindings method isVisibleInHierarchy.

public static boolean isVisibleInHierarchy(IMethodBinding member, IPackageBinding pack) {
    int otherflags = member.getModifiers();
    ITypeBinding declaringType = member.getDeclaringClass();
    if (Modifier.isPublic(otherflags) || Modifier.isProtected(otherflags) || (declaringType != null && declaringType.isInterface())) {
        return true;
    } else if (Modifier.isPrivate(otherflags)) {
        return false;
    }
    return declaringType != null && pack == declaringType.getPackage();
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 40 with ITypeBinding

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

the class Bindings method normalizeForDeclarationUse.

/**
     * Normalizes the binding so that it can be used as a type inside a declaration (e.g. variable
     * declaration, method return type, parameter type, ...).
     * For null bindings, java.lang.Object is returned.
     * For void bindings, <code>null</code> is returned.
     *
     * @param binding binding to normalize
     * @param ast current AST
     * @return the normalized type to be used in declarations, or <code>null</code>
     */
public static ITypeBinding normalizeForDeclarationUse(ITypeBinding binding, AST ast) {
    if (binding.isNullType())
        //$NON-NLS-1$
        return ast.resolveWellKnownType("java.lang.Object");
    if (binding.isPrimitive())
        return binding;
    binding = normalizeTypeBinding(binding);
    if (binding == null || !binding.isWildcardType())
        return binding;
    ITypeBinding bound = binding.getBound();
    if (bound == null || !binding.isUpperbound()) {
        ITypeBinding[] typeBounds = binding.getTypeBounds();
        if (typeBounds.length > 0) {
            return typeBounds[0];
        } else {
            return binding.getErasure();
        }
    } else {
        return bound;
    }
}
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