public class JavaParserUtils
extends java.lang.Object
Constructor and Description |
---|
JavaParserUtils() |
Modifier and Type | Method and Description |
---|---|
static com.github.javaparser.ast.expr.NameExpr |
classToNameExpr(java.lang.Class<?> clazz)
Converts a class to
NameExpr node |
static com.github.javaparser.ast.CompilationUnit |
getCompilationUnit(java.lang.Class<?> classObject)
Obtains a JavaParser compilation unit from a class object.
|
static boolean |
isATypeParameter(com.github.javaparser.ast.body.MethodDeclaration method,
com.github.javaparser.ast.body.Parameter param)
Tells if the passed parameter is a generic type parameter
|
static boolean |
isATypeParameter(com.github.javaparser.ast.body.MethodDeclaration method,
com.github.javaparser.ast.type.Type param)
Tells if the passed type is a generic type parameter
|
static com.github.javaparser.ast.CompilationUnit |
parse(java.lang.String source)
Parse the source of the class
|
static com.github.javaparser.ast.body.VariableDeclarator |
searchField(com.github.javaparser.ast.CompilationUnit unit,
java.lang.Class<?> clazz,
java.lang.String name)
Search a field node in the compilation unit
|
static com.github.javaparser.ast.body.FieldDeclaration |
searchFieldDeclaration(com.github.javaparser.ast.CompilationUnit unit,
java.lang.Class<?> clazz,
java.lang.String name)
Search a field declaration in the compilation unit
|
static com.github.javaparser.ast.body.FieldDeclaration |
searchFieldDeclarationFromJavaParserCU(com.github.javaparser.ast.CompilationUnit unit,
java.lang.Class<?> clazz,
java.lang.String name)
Search a field declaration in the compilation unit
|
static com.github.javaparser.ast.body.MethodDeclaration |
searchMethod(com.github.javaparser.ast.CompilationUnit unit,
java.lang.Class<?> clazz,
java.lang.String name)
Search a method node in the compilation unit
|
static com.github.javaparser.ast.body.MethodDeclaration |
searchMethod(com.github.javaparser.ast.CompilationUnit unit,
java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?>[] parameterClasses,
java.lang.Class<?> returnClass)
Search a method node in the compilation unit
|
static com.github.javaparser.ast.body.MethodDeclaration |
searchMethodFromJavaParserCU(com.github.javaparser.ast.CompilationUnit unit,
java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?>[] parameterClasses,
java.lang.Class<?> returnClass)
Search a method node in the compilation unit
|
static com.github.javaparser.ast.body.TypeDeclaration |
searchType(com.github.javaparser.ast.CompilationUnit unit,
java.lang.Class<?> clazz)
Obtains the
TypeDeclaration of the specified class from the
compilation Unit |
static com.github.javaparser.ast.body.TypeDeclaration |
searchType(com.github.javaparser.ast.CompilationUnit unit,
java.lang.String clazzName)
Obtains the
TypeDeclaration of the specified class from the
compilation Unit |
static com.github.javaparser.ast.body.TypeDeclaration |
searchTypeFromJavaParserCU(com.github.javaparser.ast.CompilationUnit unit,
java.lang.Class<?> clazz)
Obtains the
TypeDeclaration of the specified class from the
compilation Unit |
static com.github.javaparser.ast.body.TypeDeclaration |
searchTypeFromOriginalVersion(com.github.javaparser.ast.CompilationUnit unit,
java.lang.String clazzName)
Obtains the
TypeDeclaration of the specified class from the
compilation Unit regardless if it is a version class |
static com.github.javaparser.ast.type.Type |
transform(java.lang.Class<?> clazz)
Tranforms a class to
Type node |
static com.github.javaparser.ast.type.Type |
transform(java.lang.reflect.Type type)
Transforms
Type to java parser Type |
static java.lang.Class<?> |
typeName2Class(java.lang.String typeName)
Maps a JavaParser type name to its corresponding Java class
|
public static com.github.javaparser.ast.CompilationUnit parse(java.lang.String source) throws com.github.javaparser.ParseException
source
- The source codeCompilationUnit
with the AST of the classcom.github.javaparser.ParseException
- When the class cannot be parsedpublic static com.github.javaparser.ast.expr.NameExpr classToNameExpr(java.lang.Class<?> clazz)
NameExpr
nodeclazz
- The classNameExpr
nodepublic static com.github.javaparser.ast.type.Type transform(java.lang.Class<?> clazz)
Type
nodeclazz
- The classType
nodepublic static com.github.javaparser.ast.type.Type transform(java.lang.reflect.Type type)
Type
to java parser Type
type
- Type
Type
or nullpublic static com.github.javaparser.ast.body.TypeDeclaration searchTypeFromJavaParserCU(com.github.javaparser.ast.CompilationUnit unit, java.lang.Class<?> clazz)
TypeDeclaration
of the specified class from the
compilation Unitunit
- The Compilation unitclazz
- The classTypeDeclaration
or nullpublic static com.github.javaparser.ast.body.TypeDeclaration searchType(com.github.javaparser.ast.CompilationUnit unit, java.lang.Class<?> clazz)
TypeDeclaration
of the specified class from the
compilation Unitunit
- The Compilation unitclazz
- The classTypeDeclaration
or nullpublic static com.github.javaparser.ast.body.TypeDeclaration searchType(com.github.javaparser.ast.CompilationUnit unit, java.lang.String clazzName)
TypeDeclaration
of the specified class from the
compilation Unitunit
- The Compilation unitclazzName
- The name of the classTypeDeclaration
or nullpublic static com.github.javaparser.ast.body.TypeDeclaration searchTypeFromOriginalVersion(com.github.javaparser.ast.CompilationUnit unit, java.lang.String clazzName)
TypeDeclaration
of the specified class from the
compilation Unit regardless if it is a version classunit
- The Compilation unitclazzName
- The name of the classTypeDeclaration
or nullpublic static com.github.javaparser.ast.body.MethodDeclaration searchMethodFromJavaParserCU(com.github.javaparser.ast.CompilationUnit unit, java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>[] parameterClasses, java.lang.Class<?> returnClass) throws java.lang.NoSuchMethodException
unit
- The compilation Unitclazz
- The class ownername
- The name of the methodparameterClasses
- The parameter classesreturnClass
- The type of the methodjava.lang.NoSuchMethodException
- If the method is not in the CompilationUnitpublic static com.github.javaparser.ast.body.MethodDeclaration searchMethod(com.github.javaparser.ast.CompilationUnit unit, java.lang.Class<?> clazz, java.lang.String name, java.lang.Class<?>[] parameterClasses, java.lang.Class<?> returnClass) throws java.lang.NoSuchMethodException
unit
- The compilation Unitclazz
- The class ownername
- The name of the methodparameterClasses
- The parameter classesreturnClass
- The type of the methodjava.lang.NoSuchMethodException
- If the method is not in the CompilationUnitpublic static com.github.javaparser.ast.body.MethodDeclaration searchMethod(com.github.javaparser.ast.CompilationUnit unit, java.lang.Class<?> clazz, java.lang.String name) throws java.lang.NoSuchMethodException
unit
- The compilation Unitclazz
- The class ownername
- The name of the methodjava.lang.NoSuchMethodException
- If the method is not in the CompilationUnitpublic static com.github.javaparser.ast.body.VariableDeclarator searchField(com.github.javaparser.ast.CompilationUnit unit, java.lang.Class<?> clazz, java.lang.String name) throws java.lang.NoSuchFieldException
unit
- The compilation Unitclazz
- The class ownername
- The name of the fieldjava.lang.NoSuchFieldException
- If the field is not in the CompilationUnitpublic static com.github.javaparser.ast.body.FieldDeclaration searchFieldDeclarationFromJavaParserCU(com.github.javaparser.ast.CompilationUnit unit, java.lang.Class<?> clazz, java.lang.String name) throws java.lang.NoSuchFieldException
unit
- The compilation Unitclazz
- The class ownername
- The name of the fieldjava.lang.NoSuchFieldException
- If the field is not in the CompilationUnitpublic static com.github.javaparser.ast.body.FieldDeclaration searchFieldDeclaration(com.github.javaparser.ast.CompilationUnit unit, java.lang.Class<?> clazz, java.lang.String name) throws java.lang.NoSuchFieldException
unit
- The compilation Unitclazz
- The class ownername
- The name of the fieldjava.lang.NoSuchFieldException
- If the field is not in the CompilationUnitpublic static boolean isATypeParameter(com.github.javaparser.ast.body.MethodDeclaration method, com.github.javaparser.ast.type.Type param)
method
- param
- public static boolean isATypeParameter(com.github.javaparser.ast.body.MethodDeclaration method, com.github.javaparser.ast.body.Parameter param)
method
- param
- public static java.lang.Class<?> typeName2Class(java.lang.String typeName) throws java.lang.ClassNotFoundException
typeName
- java.lang.ClassNotFoundException
public static com.github.javaparser.ast.CompilationUnit getCompilationUnit(java.lang.Class<?> classObject) throws StructuralIntercessionException
classObject
- Class objectStructuralIntercessionException
- If some problem occurs trying to locate the source of the .class file