Search in sources :

Example 16 with NameExpr

use of com.github.antlrjavaparser.api.expr.NameExpr in project spring-roo by spring-projects.

the class JavaParserUtils method getJavaTypeNow.

/**
 * Resolves the effective {@link JavaType} a {@link ClassOrInterfaceType}
 * represents, including any type arguments.
 *
 * @param compilationUnitServices for package management (required)
 * @param cit the class or interface type to resolve (required)
 * @return the effective Java type (never null)
 */
public static JavaType getJavaTypeNow(final CompilationUnitServices compilationUnitServices, final ClassOrInterfaceType cit, final Set<JavaSymbolName> typeParameters) {
    Validate.notNull(compilationUnitServices, "Compilation unit services required");
    Validate.notNull(cit, "ClassOrInterfaceType required");
    final JavaPackage compilationUnitPackage = compilationUnitServices.getCompilationUnitPackage();
    Validate.notNull(compilationUnitPackage, "Compilation unit package required");
    String typeName = cit.getName();
    ClassOrInterfaceType scope = cit.getScope();
    while (scope != null) {
        typeName = scope.getName() + "." + typeName;
        scope = scope.getScope();
    }
    final NameExpr nameExpr = getNameExpr(typeName);
    final JavaType effectiveType = getJavaType(compilationUnitServices, nameExpr, typeParameters);
    // Handle any type arguments
    final List<JavaType> parameterTypes = new ArrayList<JavaType>();
    if (cit.getTypeArgs() != null) {
        for (final Type ta : cit.getTypeArgs()) {
            parameterTypes.add(getJavaType(compilationUnitServices, ta, typeParameters));
        }
    }
    return new JavaType(effectiveType.getFullyQualifiedTypeName(), effectiveType.getArray(), effectiveType.getDataType(), null, parameterTypes);
}
Also used : JdkJavaType(org.springframework.roo.model.JdkJavaType) JavaType(org.springframework.roo.model.JavaType) WildcardType(com.github.antlrjavaparser.api.type.WildcardType) ClassOrInterfaceType(com.github.antlrjavaparser.api.type.ClassOrInterfaceType) DataType(org.springframework.roo.model.DataType) JdkJavaType(org.springframework.roo.model.JdkJavaType) VoidType(com.github.antlrjavaparser.api.type.VoidType) JavaType(org.springframework.roo.model.JavaType) PrimitiveType(com.github.antlrjavaparser.api.type.PrimitiveType) ReferenceType(com.github.antlrjavaparser.api.type.ReferenceType) Type(com.github.antlrjavaparser.api.type.Type) NameExpr(com.github.antlrjavaparser.api.expr.NameExpr) QualifiedNameExpr(com.github.antlrjavaparser.api.expr.QualifiedNameExpr) ArrayList(java.util.ArrayList) ClassOrInterfaceType(com.github.antlrjavaparser.api.type.ClassOrInterfaceType) JavaPackage(org.springframework.roo.model.JavaPackage)

Aggregations

NameExpr (com.github.antlrjavaparser.api.expr.NameExpr)16 QualifiedNameExpr (com.github.antlrjavaparser.api.expr.QualifiedNameExpr)11 JavaType (org.springframework.roo.model.JavaType)11 ClassOrInterfaceType (com.github.antlrjavaparser.api.type.ClassOrInterfaceType)8 ArrayList (java.util.ArrayList)8 Type (com.github.antlrjavaparser.api.type.Type)7 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)7 AnnotationExpr (com.github.antlrjavaparser.api.expr.AnnotationExpr)6 JdkJavaType (org.springframework.roo.model.JdkJavaType)6 Expression (com.github.antlrjavaparser.api.expr.Expression)5 NormalAnnotationExpr (com.github.antlrjavaparser.api.expr.NormalAnnotationExpr)5 ReferenceType (com.github.antlrjavaparser.api.type.ReferenceType)5 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)5 ImportDeclaration (com.github.antlrjavaparser.api.ImportDeclaration)4 TypeDeclaration (com.github.antlrjavaparser.api.body.TypeDeclaration)4 MarkerAnnotationExpr (com.github.antlrjavaparser.api.expr.MarkerAnnotationExpr)4 SingleMemberAnnotationExpr (com.github.antlrjavaparser.api.expr.SingleMemberAnnotationExpr)4 TypeParameter (com.github.antlrjavaparser.api.TypeParameter)3 BodyDeclaration (com.github.antlrjavaparser.api.body.BodyDeclaration)3 ArrayInitializerExpr (com.github.antlrjavaparser.api.expr.ArrayInitializerExpr)3