Search in sources :

Example 41 with ParameterizedType

use of org.eclipse.jdt.core.dom.ParameterizedType 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)

Example 42 with ParameterizedType

use of org.eclipse.jdt.core.dom.ParameterizedType in project whole by wholeplatform.

the class CompilationUnitBuilder method newParameterizedType.

public ParameterizedType newParameterizedType(String type, String type1, String type2) {
    ParameterizedType ptype = newParameterizedType(type);
    ptype.typeArguments().add(newType(type1));
    ptype.typeArguments().add(newType(type2));
    return ptype;
}
Also used : ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType)

Example 43 with ParameterizedType

use of org.eclipse.jdt.core.dom.ParameterizedType in project generator by mybatis.

the class TypeStringifier method visit.

@SuppressWarnings("unchecked")
@Override
public boolean visit(ParameterizedType node) {
    node.getType().accept(this);
    buffer.append('<');
    for (Iterator<Type> it = node.typeArguments().iterator(); it.hasNext(); ) {
        Type t = it.next();
        t.accept(this);
        if (it.hasNext()) {
            buffer.append(',');
        }
    }
    buffer.append('>');
    return false;
}
Also used : NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType) IntersectionType(org.eclipse.jdt.core.dom.IntersectionType) WildcardType(org.eclipse.jdt.core.dom.WildcardType) SimpleType(org.eclipse.jdt.core.dom.SimpleType) Type(org.eclipse.jdt.core.dom.Type) UnionType(org.eclipse.jdt.core.dom.UnionType) QualifiedType(org.eclipse.jdt.core.dom.QualifiedType) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType)

Example 44 with ParameterizedType

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

the class ASTResolving method internalGetPossibleTypeKinds.

private static int internalGetPossibleTypeKinds(ASTNode node) {
    int kind = SimilarElementsRequestor.ALL_TYPES;
    int mask = SimilarElementsRequestor.ALL_TYPES | SimilarElementsRequestor.VOIDTYPE;
    ASTNode parent = node.getParent();
    while (parent instanceof QualifiedName) {
        if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) {
            return SimilarElementsRequestor.REF_TYPES;
        }
        node = parent;
        parent = parent.getParent();
        mask = SimilarElementsRequestor.REF_TYPES;
    }
    while (parent instanceof Type) {
        if (parent instanceof QualifiedType) {
            if (node.getLocationInParent() == QualifiedType.QUALIFIER_PROPERTY) {
                return mask & (SimilarElementsRequestor.REF_TYPES);
            }
            mask &= SimilarElementsRequestor.REF_TYPES;
        } else if (parent instanceof NameQualifiedType) {
            if (node.getLocationInParent() == NameQualifiedType.QUALIFIER_PROPERTY) {
                return mask & (SimilarElementsRequestor.REF_TYPES);
            }
            mask &= SimilarElementsRequestor.REF_TYPES;
        } else if (parent instanceof ParameterizedType) {
            if (node.getLocationInParent() == ParameterizedType.TYPE_ARGUMENTS_PROPERTY) {
                return mask & SimilarElementsRequestor.REF_TYPES_AND_VAR;
            }
            mask &= SimilarElementsRequestor.CLASSES | SimilarElementsRequestor.INTERFACES;
        } else if (parent instanceof WildcardType) {
            if (node.getLocationInParent() == WildcardType.BOUND_PROPERTY) {
                return mask & SimilarElementsRequestor.REF_TYPES_AND_VAR;
            }
        }
        node = parent;
        parent = parent.getParent();
    }
    switch(parent.getNodeType()) {
        case ASTNode.TYPE_DECLARATION:
            if (node.getLocationInParent() == TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY) {
                kind = SimilarElementsRequestor.INTERFACES;
            } else if (node.getLocationInParent() == TypeDeclaration.SUPERCLASS_TYPE_PROPERTY) {
                kind = SimilarElementsRequestor.CLASSES;
            }
            break;
        case ASTNode.ENUM_DECLARATION:
            kind = SimilarElementsRequestor.INTERFACES;
            break;
        case ASTNode.METHOD_DECLARATION:
            if (node.getLocationInParent() == MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) {
                kind = SimilarElementsRequestor.CLASSES;
            } else if (node.getLocationInParent() == MethodDeclaration.RETURN_TYPE2_PROPERTY) {
                kind = SimilarElementsRequestor.ALL_TYPES | SimilarElementsRequestor.VOIDTYPE;
            }
            break;
        case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
            kind = SimilarElementsRequestor.PRIMITIVETYPES | SimilarElementsRequestor.ANNOTATIONS | SimilarElementsRequestor.ENUMS;
            break;
        case ASTNode.INSTANCEOF_EXPRESSION:
            kind = SimilarElementsRequestor.REF_TYPES;
            break;
        case ASTNode.THROW_STATEMENT:
            kind = SimilarElementsRequestor.CLASSES;
            break;
        case ASTNode.CLASS_INSTANCE_CREATION:
            if (((ClassInstanceCreation) parent).getAnonymousClassDeclaration() == null) {
                kind = SimilarElementsRequestor.CLASSES;
            } else {
                kind = SimilarElementsRequestor.CLASSES | SimilarElementsRequestor.INTERFACES;
            }
            break;
        case ASTNode.SINGLE_VARIABLE_DECLARATION:
            int superParent = parent.getParent().getNodeType();
            if (superParent == ASTNode.CATCH_CLAUSE) {
                kind = SimilarElementsRequestor.CLASSES;
            } else if (superParent == ASTNode.ENHANCED_FOR_STATEMENT) {
                kind = SimilarElementsRequestor.REF_TYPES;
            }
            break;
        case ASTNode.TAG_ELEMENT:
            kind = SimilarElementsRequestor.REF_TYPES;
            break;
        case ASTNode.MARKER_ANNOTATION:
        case ASTNode.SINGLE_MEMBER_ANNOTATION:
        case ASTNode.NORMAL_ANNOTATION:
            kind = SimilarElementsRequestor.ANNOTATIONS;
            break;
        case ASTNode.TYPE_PARAMETER:
            if (((TypeParameter) parent).typeBounds().indexOf(node) > 0) {
                kind = SimilarElementsRequestor.INTERFACES;
            } else {
                kind = SimilarElementsRequestor.REF_TYPES_AND_VAR;
            }
            break;
        case ASTNode.TYPE_LITERAL:
            kind = SimilarElementsRequestor.REF_TYPES;
            break;
        default:
    }
    return kind & mask;
}
Also used : ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) SimpleType(org.eclipse.jdt.core.dom.SimpleType) Type(org.eclipse.jdt.core.dom.Type) WildcardType(org.eclipse.jdt.core.dom.WildcardType) QualifiedType(org.eclipse.jdt.core.dom.QualifiedType) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) WildcardType(org.eclipse.jdt.core.dom.WildcardType) TypeParameter(org.eclipse.jdt.core.dom.TypeParameter) NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType) QualifiedType(org.eclipse.jdt.core.dom.QualifiedType) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) ASTNode(org.eclipse.jdt.core.dom.ASTNode) NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType)

Example 45 with ParameterizedType

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

the class ASTNodes method getQualifiedTypeName.

/**
 * Returns the (potentially qualified) name of a type, followed by array dimensions.
 * Skips type arguments and type annotations.
 *
 * @param type a type that has a name
 * @return the name, followed by array dimensions
 * @since 3.10
 */
public static String getQualifiedTypeName(Type type) {
    final StringBuffer buffer = new StringBuffer();
    ASTVisitor visitor = new ASTVisitor() {

        @Override
        public boolean visit(SimpleType node) {
            buffer.append(node.getName().getFullyQualifiedName());
            return false;
        }

        @Override
        public boolean visit(QualifiedType node) {
            node.getQualifier().accept(this);
            buffer.append('.');
            buffer.append(node.getName().getIdentifier());
            return false;
        }

        @Override
        public boolean visit(NameQualifiedType node) {
            buffer.append(node.getQualifier().getFullyQualifiedName());
            buffer.append('.');
            buffer.append(node.getName().getIdentifier());
            return false;
        }

        @Override
        public boolean visit(ParameterizedType node) {
            node.getType().accept(this);
            return false;
        }

        @Override
        public void endVisit(ArrayType node) {
            for (int i = 0; i < node.dimensions().size(); i++) {
                // $NON-NLS-1$
                buffer.append("[]");
            }
        }
    };
    type.accept(visitor);
    return buffer.toString();
}
Also used : ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) SimpleType(org.eclipse.jdt.core.dom.SimpleType) NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType) QualifiedType(org.eclipse.jdt.core.dom.QualifiedType) NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor)

Aggregations

ParameterizedType (org.eclipse.jdt.core.dom.ParameterizedType)63 Type (org.eclipse.jdt.core.dom.Type)42 SimpleType (org.eclipse.jdt.core.dom.SimpleType)26 ArrayType (org.eclipse.jdt.core.dom.ArrayType)24 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)21 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)19 ASTNode (org.eclipse.jdt.core.dom.ASTNode)15 ClassInstanceCreation (org.eclipse.jdt.core.dom.ClassInstanceCreation)14 NameQualifiedType (org.eclipse.jdt.core.dom.NameQualifiedType)13 QualifiedType (org.eclipse.jdt.core.dom.QualifiedType)13 IType (org.eclipse.jdt.core.IType)12 SimpleName (org.eclipse.jdt.core.dom.SimpleName)12 Name (org.eclipse.jdt.core.dom.Name)10 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)9 WildcardType (java.lang.reflect.WildcardType)8 org.eclipse.jdt.core.dom (org.eclipse.jdt.core.dom)8 AST (org.eclipse.jdt.core.dom.AST)8 Expression (org.eclipse.jdt.core.dom.Expression)8 UnionType (org.eclipse.jdt.core.dom.UnionType)8 WildcardType (org.eclipse.jdt.core.dom.WildcardType)8