Search in sources :

Example 6 with ITypeBinding

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

the class ASTNodeFactory method newType.

private static Type newType(LambdaExpression lambdaExpression, VariableDeclarationFragment declaration, AST ast, ImportRewrite importRewrite, ImportRewriteContext context) {
    IMethodBinding method = lambdaExpression.resolveMethodBinding();
    if (method != null) {
        ITypeBinding[] parameterTypes = method.getParameterTypes();
        int index = lambdaExpression.parameters().indexOf(declaration);
        ITypeBinding typeBinding = parameterTypes[index];
        if (importRewrite != null) {
            return importRewrite.addImport(typeBinding, ast, context);
        } else {
            String qualifiedName = typeBinding.getQualifiedName();
            if (qualifiedName.length() > 0) {
                return newType(ast, qualifiedName);
            }
        }
    }
    //$NON-NLS-1$
    return ast.newSimpleType(ast.newSimpleName("Object"));
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 7 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 8 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 9 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 10 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)

Aggregations

ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)359 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)103 ASTNode (org.eclipse.jdt.core.dom.ASTNode)73 Expression (org.eclipse.jdt.core.dom.Expression)63 SimpleName (org.eclipse.jdt.core.dom.SimpleName)51 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)49 Type (org.eclipse.jdt.core.dom.Type)49 ArrayList (java.util.ArrayList)48 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)48 AST (org.eclipse.jdt.core.dom.AST)43 IBinding (org.eclipse.jdt.core.dom.IBinding)40 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)40 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)34 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)34 CastExpression (org.eclipse.jdt.core.dom.CastExpression)32 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)30 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)29 Name (org.eclipse.jdt.core.dom.Name)28 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)28 ContextSensitiveImportRewriteContext (org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext)26