Search in sources :

Example 1 with AnnotatableType

use of org.eclipse.jdt.core.dom.AnnotatableType in project eclipse.jdt.ls by eclipse.

the class ASTNodeFactory method newCreationType.

/**
 * Create a Type suitable as the creationType in a ClassInstanceCreation expression.
 * @param ast The AST to create the nodes for.
 * @param typeBinding binding representing the given class type
 * @param importRewrite the import rewrite to use
 * @param importContext the import context used to determine which (null) annotations to consider
 * @return a Type suitable as the creationType in a ClassInstanceCreation expression.
 */
public static Type newCreationType(AST ast, ITypeBinding typeBinding, ImportRewrite importRewrite, ImportRewriteContext importContext) {
    if (typeBinding.isParameterizedType()) {
        Type baseType = newCreationType(ast, typeBinding.getTypeDeclaration(), importRewrite, importContext);
        IAnnotationBinding[] typeAnnotations = importContext.removeRedundantTypeAnnotations(typeBinding.getTypeAnnotations(), TypeLocation.NEW, typeBinding);
        for (IAnnotationBinding typeAnnotation : typeAnnotations) {
            ((AnnotatableType) baseType).annotations().add(importRewrite.addAnnotation(typeAnnotation, ast, importContext));
        }
        ParameterizedType parameterizedType = ast.newParameterizedType(baseType);
        for (ITypeBinding typeArgument : typeBinding.getTypeArguments()) {
            typeArgument = StubUtility2.replaceWildcardsAndCaptures(typeArgument);
            parameterizedType.typeArguments().add(importRewrite.addImport(typeArgument, ast, importContext, TypeLocation.TYPE_ARGUMENT));
        }
        return parameterizedType;
    } else {
        return importRewrite.addImport(typeBinding, ast, importContext, TypeLocation.NEW);
    }
}
Also used : ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) Type(org.eclipse.jdt.core.dom.Type) AnnotatableType(org.eclipse.jdt.core.dom.AnnotatableType) UnionType(org.eclipse.jdt.core.dom.UnionType) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) IAnnotationBinding(org.eclipse.jdt.core.dom.IAnnotationBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Aggregations

AnnotatableType (org.eclipse.jdt.core.dom.AnnotatableType)1 ArrayType (org.eclipse.jdt.core.dom.ArrayType)1 IAnnotationBinding (org.eclipse.jdt.core.dom.IAnnotationBinding)1 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)1 ParameterizedType (org.eclipse.jdt.core.dom.ParameterizedType)1 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)1 Type (org.eclipse.jdt.core.dom.Type)1 UnionType (org.eclipse.jdt.core.dom.UnionType)1