public final class JavaParserUtils extends Object
This class is for internal use by the Java Parser module and should NOT be used by other code.
| Modifier and Type | Method and Description |
|---|---|
static com.github.antlrjavaparser.api.type.ClassOrInterfaceType |
getClassOrInterfaceType(com.github.antlrjavaparser.api.expr.NameExpr nameExpr)
Converts the indicated
NameExpr into a
ClassOrInterfaceType. |
static com.github.antlrjavaparser.api.type.ClassOrInterfaceType |
getClassOrInterfaceType(com.github.antlrjavaparser.api.type.Type type)
Returns the final
ClassOrInterfaceType from a Type |
static int |
getJavaParserModifier(int modifiers)
Converts a JDK
Modifier integer into the equivalent Java Parser
modifier. |
static org.springframework.roo.model.JavaType |
getJavaType(CompilationUnitServices compilationUnitServices,
com.github.antlrjavaparser.api.expr.NameExpr nameToFind,
Set<org.springframework.roo.model.JavaSymbolName> typeParameters)
Resolves the effective
JavaType a NameExpr represents. |
static org.springframework.roo.model.JavaType |
getJavaType(CompilationUnitServices compilationUnitServices,
com.github.antlrjavaparser.api.body.TypeDeclaration typeDeclaration)
Resolves the effective
JavaType a
ClassOrInterfaceDeclaration represents, including any type
parameters. |
static org.springframework.roo.model.JavaType |
getJavaType(CompilationUnitServices compilationUnitServices,
com.github.antlrjavaparser.api.type.Type type,
Set<org.springframework.roo.model.JavaSymbolName> typeParameters)
Resolves the effective
JavaType a Type represents. |
static org.springframework.roo.model.JavaType |
getJavaTypeNow(CompilationUnitServices compilationUnitServices,
com.github.antlrjavaparser.api.type.ClassOrInterfaceType cit,
Set<org.springframework.roo.model.JavaSymbolName> typeParameters)
Resolves the effective
JavaType a ClassOrInterfaceType
represents, including any type arguments. |
static int |
getJdkModifier(int modifiers)
Converts a Java Parser modifier integer into a JDK
Modifier
integer. |
static com.github.antlrjavaparser.api.expr.NameExpr |
getNameExpr(com.github.antlrjavaparser.api.expr.AnnotationExpr annotationExpr)
Obtains the name expression (
NameExpr) for the passed
AnnotationExpr, which is the annotation's type. |
static com.github.antlrjavaparser.api.expr.NameExpr |
getNameExpr(String className)
Converts the presented class name into a name expression (either a
NameExpr or QualifiedNameExpr depending on whether a
package was presented). |
static com.github.antlrjavaparser.api.type.ReferenceType |
getReferenceType(com.github.antlrjavaparser.api.expr.NameExpr nameExpr)
Converts the indicated
JavaType into a ReferenceType. |
static com.github.antlrjavaparser.api.type.ClassOrInterfaceType |
getResolvedName(org.springframework.roo.model.JavaType target,
org.springframework.roo.model.JavaType current,
com.github.antlrjavaparser.api.CompilationUnit compilationUnit) |
static com.github.antlrjavaparser.api.type.Type |
getResolvedName(org.springframework.roo.model.JavaType target,
org.springframework.roo.model.JavaType current,
CompilationUnitServices compilationUnit) |
static com.github.antlrjavaparser.api.type.Type |
getType(org.springframework.roo.model.JavaType javaType)
Given a primitive type, computes the corresponding Java Parser type.
|
static com.github.antlrjavaparser.api.expr.Expression |
importExpressionIfRequired(org.springframework.roo.model.JavaType targetType,
List<com.github.antlrjavaparser.api.ImportDeclaration> imports,
com.github.antlrjavaparser.api.expr.Expression value)
Recognises
Expressions of type FieldAccessExpr and
ClassExpr and automatically imports them if required, returning
the correct Expression that should subsequently be used. |
static com.github.antlrjavaparser.api.type.ReferenceType |
importParametersForType(org.springframework.roo.model.JavaType targetType,
List<com.github.antlrjavaparser.api.ImportDeclaration> imports,
org.springframework.roo.model.JavaType typeToImport) |
static com.github.antlrjavaparser.api.expr.NameExpr |
importTypeIfRequired(org.springframework.roo.model.JavaType targetType,
List<com.github.antlrjavaparser.api.ImportDeclaration> imports,
org.springframework.roo.model.JavaType typeToImport)
Attempts to import the presented
JavaType. |
static com.github.antlrjavaparser.api.body.TypeDeclaration |
locateTypeDeclaration(com.github.antlrjavaparser.api.CompilationUnit compilationUnit,
org.springframework.roo.model.JavaType javaType)
Searches a compilation unit and locates the declaration with the given
type's simple name.
|
public static com.github.antlrjavaparser.api.type.ClassOrInterfaceType getClassOrInterfaceType(com.github.antlrjavaparser.api.expr.NameExpr nameExpr)
NameExpr into a
ClassOrInterfaceType.
Note that no effort is made to manage imports etc.
nameExpr - to convert (required)ClassOrInterfaceType (never null)public static int getJavaParserModifier(int modifiers)
Modifier integer into the equivalent Java Parser
modifier.modifiers - the JDK intpublic static org.springframework.roo.model.JavaType getJavaType(CompilationUnitServices compilationUnitServices, com.github.antlrjavaparser.api.expr.NameExpr nameToFind, Set<org.springframework.roo.model.JavaSymbolName> typeParameters)
JavaType a NameExpr represents.
You should use getJavaType(CompilationUnitServices, Type, Set)
where possible so that type arguments are preserved (a NameExpr
does not contain type arguments).
A name expression can be either qualified or unqualified.
If a name expression is qualified and the qualification starts with a lowercase letter, that represents the fully-qualified name. If the qualification starts with an uppercase letter, the package name is prepended to the qualifier.
If a name expression is unqualified, the imports are scanned. If the unqualified name expression is found in the imports, that import declaration represents the fully-qualified name. If the unqualified name expression is not found in the imports, it indicates the name to find is either in the same package as the qualified name expression, or the type relates to a member of java.lang. If part of java.lang, the fully qualified name is treated as part of java.lang. Otherwise the compilation unit package plus unqualified name expression represents the fully qualified name expression.
compilationUnitServices - for package management (required)nameToFind - to locate (required)typeParameters - names to consider type parameters (can be null if
there are none)public static org.springframework.roo.model.JavaType getJavaType(CompilationUnitServices compilationUnitServices, com.github.antlrjavaparser.api.type.Type type, Set<org.springframework.roo.model.JavaSymbolName> typeParameters)
JavaType a Type represents. A
Type includes low-level types such as void, arrays and
primitives.compilationUnitServices - to use for package resolution (required)type - to locate (required)typeParameters - names to consider type parameters (can be null if
there are none)JavaType, with proper indication of primitive and
array status (never null)public static org.springframework.roo.model.JavaType getJavaType(CompilationUnitServices compilationUnitServices, com.github.antlrjavaparser.api.body.TypeDeclaration typeDeclaration)
JavaType a
ClassOrInterfaceDeclaration represents, including any type
parameters.compilationUnitServices - for package management (required)typeDeclaration - the type declaration to resolve (required)public static org.springframework.roo.model.JavaType getJavaTypeNow(CompilationUnitServices compilationUnitServices, com.github.antlrjavaparser.api.type.ClassOrInterfaceType cit, Set<org.springframework.roo.model.JavaSymbolName> typeParameters)
JavaType a ClassOrInterfaceType
represents, including any type arguments.compilationUnitServices - for package management (required)cit - the class or interface type to resolve (required)public static int getJdkModifier(int modifiers)
Modifier
integer.modifiers - the Java Parser intpublic static com.github.antlrjavaparser.api.expr.NameExpr getNameExpr(com.github.antlrjavaparser.api.expr.AnnotationExpr annotationExpr)
NameExpr) for the passed
AnnotationExpr, which is the annotation's type.annotationExpr - to retrieve the type name from (required)public static com.github.antlrjavaparser.api.expr.NameExpr getNameExpr(String className)
NameExpr or QualifiedNameExpr depending on whether a
package was presented).className - to convert (required; can be fully qualified or simple
name only)public static com.github.antlrjavaparser.api.type.ReferenceType getReferenceType(com.github.antlrjavaparser.api.expr.NameExpr nameExpr)
JavaType into a ReferenceType.
Note that no effort is made to manage imports etc.
nameExpr - to convert (required)ReferenceType (never null)public static com.github.antlrjavaparser.api.type.ClassOrInterfaceType getResolvedName(org.springframework.roo.model.JavaType target,
org.springframework.roo.model.JavaType current,
com.github.antlrjavaparser.api.CompilationUnit compilationUnit)
public static com.github.antlrjavaparser.api.type.Type getResolvedName(org.springframework.roo.model.JavaType target,
org.springframework.roo.model.JavaType current,
CompilationUnitServices compilationUnit)
public static com.github.antlrjavaparser.api.type.Type getType(org.springframework.roo.model.JavaType javaType)
Presenting a non-primitive type to this method will throw an exception.
If you have a non-primitive type, use
importTypeIfRequired(JavaType, List, JavaType) and then present
the NameExpr it returns to
getClassOrInterfaceType(NameExpr).
javaType - a primitive type (required, and must be primitive)Typepublic static com.github.antlrjavaparser.api.expr.Expression importExpressionIfRequired(org.springframework.roo.model.JavaType targetType,
List<com.github.antlrjavaparser.api.ImportDeclaration> imports,
com.github.antlrjavaparser.api.expr.Expression value)
Expressions of type FieldAccessExpr and
ClassExpr and automatically imports them if required, returning
the correct Expression that should subsequently be used.
Even if an Expression is not resolved by this method into a type
and/or imported, the method guarantees to always return an
Expression that the caller can subsequently use in place of the
passed Expression. In practical terms, the Expression
passed to this method will be returned unless the type was already
imported, just imported, or represented a java.lang type.
targetType - the compilation unit target type (required)imports - the existing imports (required)value - that expression, which need not necessarily be resolvable to
a type (required)public static com.github.antlrjavaparser.api.type.ReferenceType importParametersForType(org.springframework.roo.model.JavaType targetType,
List<com.github.antlrjavaparser.api.ImportDeclaration> imports,
org.springframework.roo.model.JavaType typeToImport)
public static com.github.antlrjavaparser.api.expr.NameExpr importTypeIfRequired(org.springframework.roo.model.JavaType targetType,
List<com.github.antlrjavaparser.api.ImportDeclaration> imports,
org.springframework.roo.model.JavaType typeToImport)
JavaType.
Whether imported or not, the method returns a NameExpr suitable
for subsequent use when referring to that type.
If an attempt is made to import a java.lang type, it is ignored.
If an attempt is made to import a type without a package, it is ignored.
We import every type usage even if the type usage is within the same package and would theoretically not require an import. This is undertaken so that there is no requirement to separately parse every unqualified type usage within the compilation unit so as to refrain from importing subsequently conflicting types.
targetType - the compilation unit target type (required)imports - the compilation unit's imports (required)typeToImport - the type to be imported (required)public static com.github.antlrjavaparser.api.body.TypeDeclaration locateTypeDeclaration(com.github.antlrjavaparser.api.CompilationUnit compilationUnit,
org.springframework.roo.model.JavaType javaType)
compilationUnit - to scan (required)javaType - the target to locate (required)public static com.github.antlrjavaparser.api.type.ClassOrInterfaceType getClassOrInterfaceType(com.github.antlrjavaparser.api.type.Type type)
ClassOrInterfaceType from a TypeinitType - ClassOrInterfaceType or null if no
ClassOrInterfaceType foundCopyright © 2009–2017 Pivotal Software, Inc.. All rights reserved.