Search in sources :

Example 31 with ITypeBinding

use of org.eclipse.jdt.core.dom.ITypeBinding in project che 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, ITypeBinding[] 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 32 with ITypeBinding

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

the class Bindings method collectSuperTypes.

private static void collectSuperTypes(ITypeBinding curr, Set<ITypeBinding> collection) {
    if (collection.add(curr)) {
        ITypeBinding[] interfaces = curr.getInterfaces();
        for (int i = 0; i < interfaces.length; i++) {
            collectSuperTypes(interfaces[i], collection);
        }
        ITypeBinding superClass = curr.getSuperclass();
        if (superClass != null) {
            collectSuperTypes(superClass, collection);
        }
    }
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 33 with ITypeBinding

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

the class StubUtility method getParameterTypeNamesForSeeTag.

/*
	 * Returns the parameters type names used in see tags. Currently, these are always fully qualified.
	 */
public static String[] getParameterTypeNamesForSeeTag(IMethodBinding binding) {
    ITypeBinding[] typeBindings = binding.getParameterTypes();
    String[] result = new String[typeBindings.length];
    for (int i = 0; i < result.length; i++) {
        ITypeBinding curr = typeBindings[i];
        // Javadoc references use erased type
        curr = curr.getErasure();
        result[i] = curr.getQualifiedName();
    }
    return result;
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 34 with ITypeBinding

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

the class StubUtility2 method createThrownExceptions.

private static void createThrownExceptions(MethodDeclaration decl, IMethodBinding method, ImportRewrite imports, ImportRewriteContext context, AST ast) {
    ITypeBinding[] excTypes = method.getExceptionTypes();
    if (ast.apiLevel() >= AST.JLS8) {
        List<Type> thrownExceptions = decl.thrownExceptionTypes();
        for (int i = 0; i < excTypes.length; i++) {
            Type excType = imports.addImport(excTypes[i], ast, context);
            thrownExceptions.add(excType);
        }
    } else {
        List<Name> thrownExceptions = getThrownExceptions(decl);
        for (int i = 0; i < excTypes.length; i++) {
            String excTypeName = imports.addImport(excTypes[i], context);
            thrownExceptions.add(ASTNodeFactory.newName(ast, excTypeName));
        }
    }
}
Also used : ArrayType(org.eclipse.jdt.core.dom.ArrayType) Type(org.eclipse.jdt.core.dom.Type) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) Name(org.eclipse.jdt.core.dom.Name)

Example 35 with ITypeBinding

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

the class StubUtility2 method getDelegateCandidates.

//	public static DelegateEntry[] getDelegatableMethods(ITypeBinding binding) {
//		final List<DelegateEntry> tuples= new ArrayList<DelegateEntry>();
//		final List<IMethodBinding> declared= new ArrayList<IMethodBinding>();
//		IMethodBinding[] typeMethods= binding.getDeclaredMethods();
//		for (int index= 0; index < typeMethods.length; index++)
//			declared.add(typeMethods[index]);
//		IVariableBinding[] typeFields= binding.getDeclaredFields();
//		for (int index= 0; index < typeFields.length; index++) {
//			IVariableBinding fieldBinding= typeFields[index];
//			if (fieldBinding.isField() && !fieldBinding.isEnumConstant() && !fieldBinding.isSynthetic())
//				getDelegatableMethods(new ArrayList<IMethodBinding>(declared), fieldBinding, fieldBinding.getType(), binding, tuples);
//		}
//		// list of tuple<IVariableBinding, IMethodBinding>
//		return tuples.toArray(new DelegateEntry[tuples.size()]);
//	}
//
//	private static void getDelegatableMethods(List<IMethodBinding> methods, IVariableBinding fieldBinding, ITypeBinding typeBinding, ITypeBinding binding, List<DelegateEntry> result) {
//		boolean match= false;
//		if (typeBinding.isTypeVariable()) {
//			ITypeBinding[] typeBounds= typeBinding.getTypeBounds();
//			if (typeBounds.length > 0) {
//				for (int i= 0; i < typeBounds.length; i++) {
//					getDelegatableMethods(methods, fieldBinding, typeBounds[i], binding, result);
//				}
//			} else {
//				ITypeBinding objectBinding= Bindings.findTypeInHierarchy(binding, "java.lang.Object"); //$NON-NLS-1$
//				if (objectBinding != null) {
//					getDelegatableMethods(methods, fieldBinding, objectBinding, binding, result);
//				}
//			}
//		} else {
//			IMethodBinding[] candidates= getDelegateCandidates(typeBinding, binding);
//			for (int index= 0; index < candidates.length; index++) {
//				match= false;
//				final IMethodBinding methodBinding= candidates[index];
//				for (int offset= 0; offset < methods.size() && !match; offset++) {
//					if (Bindings.areOverriddenMethods(methods.get(offset), methodBinding))
//						match= true;
//				}
//				if (!match) {
//					result.add(new DelegateEntry(methodBinding, fieldBinding));
//					methods.add(methodBinding);
//				}
//			}
//			final ITypeBinding superclass= typeBinding.getSuperclass();
//			if (superclass != null)
//				getDelegatableMethods(methods, fieldBinding, superclass, binding, result);
//			ITypeBinding[] superInterfaces= typeBinding.getInterfaces();
//			for (int offset= 0; offset < superInterfaces.length; offset++)
//				getDelegatableMethods(methods, fieldBinding, superInterfaces[offset], binding, result);
//		}
//	}
private static IMethodBinding[] getDelegateCandidates(ITypeBinding binding, ITypeBinding hierarchy) {
    List<IMethodBinding> allMethods = new ArrayList<IMethodBinding>();
    boolean isInterface = binding.isInterface();
    IMethodBinding[] typeMethods = binding.getDeclaredMethods();
    for (int index = 0; index < typeMethods.length; index++) {
        final int modifiers = typeMethods[index].getModifiers();
        if (!typeMethods[index].isConstructor() && !Modifier.isStatic(modifiers) && (isInterface || Modifier.isPublic(modifiers))) {
            IMethodBinding result = Bindings.findOverriddenMethodInHierarchy(hierarchy, typeMethods[index]);
            if (result != null && Flags.isFinal(result.getModifiers()))
                continue;
            ITypeBinding[] parameterBindings = typeMethods[index].getParameterTypes();
            boolean upper = false;
            for (int offset = 0; offset < parameterBindings.length; offset++) {
                if (parameterBindings[offset].isWildcardType() && parameterBindings[offset].isUpperbound())
                    upper = true;
            }
            if (!upper)
                allMethods.add(typeMethods[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)

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