|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.roo.classpath.javaparser.JavaParserUtils
public class JavaParserUtils
Assists with the usage of Java Parser.
This class is for internal use by the Java Parser module and should NOT be used by other code.
Constructor Summary | |
---|---|
JavaParserUtils()
|
Method Summary | |
---|---|
static japa.parser.ast.type.ClassOrInterfaceType |
getClassOrInterfaceType(japa.parser.ast.expr.NameExpr nameExpr)
Converts the indicated NameExpr into a ClassOrInterfaceType . |
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,
japa.parser.ast.body.ClassOrInterfaceDeclaration cid)
Resolves the effective JavaType a ClassOrInterfaceDeclaration represents, including any
type parameters. |
static org.springframework.roo.model.JavaType |
getJavaType(CompilationUnitServices compilationUnitServices,
japa.parser.ast.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,
japa.parser.ast.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,
japa.parser.ast.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 japa.parser.ast.expr.NameExpr |
getNameExpr(japa.parser.ast.expr.AnnotationExpr annotationExpr)
Obtains the name expression ( NameExpr ) for the passed AnnotationExpr ,
which is the annotation's type. |
static japa.parser.ast.expr.NameExpr |
getNameExpr(String className)
Converts the presented class name into a name expression (either a NamedExpr or
QualifiedNameExpr depending on whether a package was presented). |
static japa.parser.ast.type.ReferenceType |
getReferenceType(japa.parser.ast.expr.NameExpr nameExpr)
Converts the indicated JavaType into a ReferenceType . |
static japa.parser.ast.type.Type |
getType(org.springframework.roo.model.JavaType javaType)
Given a primitive type, computes the corresponding Java Parser type. |
static japa.parser.ast.expr.Expression |
importExpressionIfRequired(org.springframework.roo.model.JavaType targetType,
List<japa.parser.ast.ImportDeclaration> imports,
japa.parser.ast.expr.Expression value)
Recognises Expression s of type FieldAccessExpr and ClassExpr and automatically imports them if required,
returning the correct Expression that should subsequently be used. |
static japa.parser.ast.type.ReferenceType |
importParametersForType(org.springframework.roo.model.JavaType targetType,
List<japa.parser.ast.ImportDeclaration> imports,
org.springframework.roo.model.JavaType typeToImport)
|
static japa.parser.ast.expr.NameExpr |
importTypeIfRequired(org.springframework.roo.model.JavaType targetType,
List<japa.parser.ast.ImportDeclaration> imports,
org.springframework.roo.model.JavaType typeToImport)
Attempts to import the presented JavaType . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JavaParserUtils()
Method Detail |
---|
public static final japa.parser.ast.expr.NameExpr getNameExpr(String className)
NamedExpr
or
QualifiedNameExpr
depending on whether a package was presented).
className
- to convert (required; can be fully qualified or simple name only)
public static final int getJdkModifier(int modifiers)
Modifier
integer.
modifiers
- the Java Parser int
public static final int getJavaParserModifier(int modifiers)
Modifier
integer into the equivalent Java Parser modifier.
modifiers
- the JDK int
public static final japa.parser.ast.expr.NameExpr getNameExpr(japa.parser.ast.expr.AnnotationExpr annotationExpr)
NameExpr
) for the passed AnnotationExpr
,
which is the annotation's type.
annotationExpr
- to retrieve the type name from (required)
public static org.springframework.roo.model.JavaType getJavaType(CompilationUnitServices compilationUnitServices, japa.parser.ast.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 final org.springframework.roo.model.JavaType getJavaType(CompilationUnitServices compilationUnitServices, japa.parser.ast.expr.NameExpr nameToFind, Set<org.springframework.roo.model.JavaSymbolName> typeParameters)
JavaType
a NameExpr
represents.
You should use #getJavaType(JavaPackage, List, ClassOrInterfaceType)
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 qualified, that represents the fully-qualified name. 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 final japa.parser.ast.type.ReferenceType getReferenceType(japa.parser.ast.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 final japa.parser.ast.type.ClassOrInterfaceType getClassOrInterfaceType(japa.parser.ast.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 final japa.parser.ast.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(JavaPackage, List, JavaType)
and
then present the NameExpr
it returns to getClassOrInterfaceType(NameExpr)
.
javaType
- a primitive type (required, and must be primitive)
Type
public static final org.springframework.roo.model.JavaType getJavaTypeNow(CompilationUnitServices compilationUnitServices, japa.parser.ast.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 final org.springframework.roo.model.JavaType getJavaType(CompilationUnitServices compilationUnitServices, japa.parser.ast.body.ClassOrInterfaceDeclaration cid)
JavaType
a ClassOrInterfaceDeclaration
represents, including any
type parameters.
compilationUnitServices
- for package management (required)cid
- the class or interface declaration to resolve (required)
public static final japa.parser.ast.type.ReferenceType importParametersForType(org.springframework.roo.model.JavaType targetType, List<japa.parser.ast.ImportDeclaration> imports, org.springframework.roo.model.JavaType typeToImport)
public static final japa.parser.ast.expr.NameExpr importTypeIfRequired(org.springframework.roo.model.JavaType targetType, List<japa.parser.ast.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 final japa.parser.ast.expr.Expression importExpressionIfRequired(org.springframework.roo.model.JavaType targetType, List<japa.parser.ast.ImportDeclaration> imports, japa.parser.ast.expr.Expression value)
Expression
s 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)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |