Search in sources :

Example 86 with ITypeBinding

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

the class Bindings method getTopLevelType.

public static ITypeBinding getTopLevelType(ITypeBinding type) {
    ITypeBinding parent = type.getDeclaringClass();
    while (parent != null) {
        type = parent;
        parent = type.getDeclaringClass();
    }
    return type;
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 87 with ITypeBinding

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

the class Bindings method isSubsignature.

/**
	 * @param overriding overriding method (m1)
	 * @param overridden overridden method (m2)
	 * @return <code>true</code> iff the method <code>m1</code> is a subsignature of the method <code>m2</code>.
	 * 		This is one of the requirements for m1 to override m2.
	 * 		Accessibility and return types are not taken into account.
	 * 		Note that subsignature is <em>not</em> symmetric!
	 */
public static boolean isSubsignature(IMethodBinding overriding, IMethodBinding overridden) {
    //TODO: use IMethodBinding#isSubsignature(..) once it is tested and fixed (only erasure of m1's parameter types, considering type variable counts, doing type variable substitution
    if (!overriding.getName().equals(overridden.getName()))
        return false;
    ITypeBinding[] m1Params = overriding.getParameterTypes();
    ITypeBinding[] m2Params = overridden.getParameterTypes();
    if (m1Params.length != m2Params.length)
        return false;
    ITypeBinding[] m1TypeParams = overriding.getTypeParameters();
    ITypeBinding[] m2TypeParams = overridden.getTypeParameters();
    if (m1TypeParams.length != m2TypeParams.length && //non-generic m1 can override a generic m2
    m1TypeParams.length != 0)
        return false;
    //m1TypeParameters.length == (m2TypeParameters.length || 0)
    if (m2TypeParams.length != 0) {
        //Compare type parameter bounds:
        for (int i = 0; i < m1TypeParams.length; i++) {
            // loop over m1TypeParams, which is either empty, or equally long as m2TypeParams
            Set<ITypeBinding> m1Bounds = getTypeBoundsForSubsignature(m1TypeParams[i]);
            Set<ITypeBinding> m2Bounds = getTypeBoundsForSubsignature(m2TypeParams[i]);
            if (!m1Bounds.equals(m2Bounds))
                return false;
        }
        //Compare parameter types:
        if (equals(m2Params, m1Params))
            return true;
        for (int i = 0; i < m1Params.length; i++) {
            ITypeBinding m1Param = m1Params[i];
            ITypeBinding m2Param = m2Params[i];
            if (containsTypeVariables(m1Param) || m1Param.isRawType())
                // try to achieve effect of "rename type variables"
                m1Param = m1Param.getErasure();
            if (!(equals(m1Param, m2Param) || equals(m1Param, m2Param.getErasure())))
                return false;
        }
        return true;
    } else {
        // m1TypeParams.length == m2TypeParams.length == 0
        if (equals(m1Params, m2Params))
            return true;
        for (int i = 0; i < m1Params.length; i++) {
            ITypeBinding m1Param = m1Params[i];
            ITypeBinding m2Param = m2Params[i];
            if (m1Param.isRawType())
                m1Param = m1Param.getTypeDeclaration();
            if (!(equals(m1Param, m2Param) || equals(m1Param, m2Param.getErasure())))
                return false;
        }
        return true;
    }
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 88 with ITypeBinding

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

the class Bindings method findMethodInHierarchy.

/**
	 * Finds the method specified by <code>methodName</code> and <code>parameters</code> in
	 * the type hierarchy denoted by the given type. Returns <code>null</code> if no such method
	 * exists. If the method 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 method in
	 * @param methodName The name of the method to find
	 * @param parameters The parameter types of the method to find. If <code>null</code> is passed, only the name is matched and parameters are ignored.
	 * @return the method binding representing the method
	 */
public static IMethodBinding findMethodInHierarchy(ITypeBinding type, String methodName, String[] parameters) {
    IMethodBinding method = findMethodInType(type, methodName, parameters);
    if (method != null)
        return method;
    ITypeBinding superClass = type.getSuperclass();
    if (superClass != null) {
        method = findMethodInHierarchy(superClass, methodName, parameters);
        if (method != null)
            return method;
    }
    ITypeBinding[] interfaces = type.getInterfaces();
    for (int i = 0; i < interfaces.length; i++) {
        method = findMethodInHierarchy(interfaces[i], methodName, parameters);
        if (method != null)
            return method;
    }
    return null;
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 89 with ITypeBinding

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

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