Class JavaParserFacade
- Author:
- Federico Tomassetti
-
Method Summary
Modifier and TypeMethodDescriptionclassToResolvedType(Class<?> clazz)
Convert aClass
into the correspondingResolvedType
.static void
This method is used to clear internal caches for the sake of releasing memory.protected ResolvedType
convertArrayTypeToUsage(ArrayType arrayType, Context context)
Convert aArrayType
into aResolvedType
.protected ResolvedType
convertClassOrInterfaceTypeToUsage(ClassOrInterfaceType classOrInterfaceType, Context context)
Convert aClassOrInterfaceType
into aResolvedType
.convertToUsage(Type type)
Convert aType
into the correspondingResolvedType
.convertToUsage(Type type, Node context)
Convert aType
into the correspondingResolvedType
.protected ResolvedType
convertToUsage(Type type, Context context)
Convert aType
into the correspondingResolvedType
.protected ResolvedType
convertUnionTypeToUsage(UnionType unionType, Context context)
Convert aUnionType
into aResolvedType
.protected ResolvedType
convertVarTypeToUsage(VarType varType, Context context)
Convert aVarType
into aResolvedType
.protected ResolvedType
convertWildcardTypeToUsage(WildcardType wildcardType, Context context)
Convert aWildcardType
into aResolvedType
.protected TypeDeclaration<?>
findContainingTypeDecl(Node node)
Where a node has an interface/class/enum declaration as its ancestor, return the nearest one.protected Node
Where a node has an interface/class/enum declaration -- or an object creation expression (anonymous inner class) -- as its ancestor, return the nearest one.protected Node
findContainingTypeDeclOrObjectCreationExpr(Node node, String className)
Where a node has an interface/class/enum declaration -- or an object creation expression in an inner class references an outer class -- as its ancestor, return the declaration corresponding to the class name specified.static JavaParserFacade
get(TypeSolver typeSolver)
Note that the addition of the modifiersynchronized
is specific and directly in response to issue #2668.protected ResolvedType
getBinaryTypeConcrete(Node left, Node right, boolean solveLambdas, BinaryExpr.Operator operator)
Get the type associated with the node.getTypeDeclaration(ClassOrInterfaceDeclaration classOrInterfaceDeclaration)
getTypeDeclaration(TypeDeclaration<?> typeDeclaration)
getTypeDeclaration(Node node)
getTypeOfThisIn(Node node)
"this" inserted in the given point, which type would have?solve(AnnotationExpr annotationExpr)
SymbolReference<? extends ResolvedValueDeclaration>
solve(Expression expr)
solve(FieldAccessExpr fieldAccessExpr)
solve(MethodCallExpr methodCallExpr)
solve(MethodCallExpr methodCallExpr, boolean solveLambdas)
Given a method call find out to which method declaration it corresponds.solve(MethodReferenceExpr methodReferenceExpr)
solve(MethodReferenceExpr methodReferenceExpr, boolean solveLambdas)
Given a method reference find out to which method declaration it corresponds.SymbolReference<? extends ResolvedValueDeclaration>
solve(ObjectCreationExpr objectCreationExpr)
solve(ObjectCreationExpr objectCreationExpr, boolean solveLambdas)
Given a constructor call find out to which constructor declaration it corresponds.SymbolReference<? extends ResolvedValueDeclaration>
solve(SimpleName nameExpr)
solve(ExplicitConstructorInvocationStmt explicitConstructorInvocationStmt)
solve(ExplicitConstructorInvocationStmt explicitConstructorInvocationStmt, boolean solveLambdas)
protected static ResolvedType
solveGenericTypes(ResolvedType type, Context context)
solveMethodAsUsage(MethodCallExpr call)
protected MethodUsage
toMethodUsage(MethodReferenceExpr methodReferenceExpr, List<ResolvedType> paramTypes)
-
Method Details
-
get
Note that the addition of the modifiersynchronized
is specific and directly in response to issue #2668.
This MUST NOT be misinterpreted as a signal that JavaParser is safe to use within a multi-threaded environment.
Additional discussion and context from a user attempting multithreading can be found within issue #2671 . -
clearInstances
public static void clearInstances()This method is used to clear internal caches for the sake of releasing memory. -
solveGenericTypes
-
getTypeSolver
-
getSymbolSolver
-
solve
-
solve
-
solve
-
solve
-
solve
-
solve
public SymbolReference<ResolvedConstructorDeclaration> solve(ObjectCreationExpr objectCreationExpr) -
solve
public SymbolReference<ResolvedConstructorDeclaration> solve(ExplicitConstructorInvocationStmt explicitConstructorInvocationStmt) -
solve
public SymbolReference<ResolvedConstructorDeclaration> solve(ExplicitConstructorInvocationStmt explicitConstructorInvocationStmt, boolean solveLambdas) -
solve
-
solve
public SymbolReference<ResolvedConstructorDeclaration> solve(ObjectCreationExpr objectCreationExpr, boolean solveLambdas)Given a constructor call find out to which constructor declaration it corresponds. -
solve
public SymbolReference<ResolvedMethodDeclaration> solve(MethodCallExpr methodCallExpr, boolean solveLambdas)Given a method call find out to which method declaration it corresponds. -
solve
public SymbolReference<ResolvedMethodDeclaration> solve(MethodReferenceExpr methodReferenceExpr, boolean solveLambdas)Given a method reference find out to which method declaration it corresponds. -
solve
-
solve
-
getType
Get the type associated with the node.This method was originally intended to get the type of a value: any value has a type.
For example:
int foo(int a) { return a; // when getType is invoked on "a" it returns the type "int" }
Now, users started using also of names of types itself, which do not have a type.
For example:
class A { int foo(int a) { return A.someStaticField; // when getType is invoked on "A", which represents a class, it returns // the type "A" itself while it used to throw UnsolvedSymbolException }
To accommodate this usage and avoid confusion this method return the type itself when used on the name of type.
-
getType
-
toMethodUsage
protected MethodUsage toMethodUsage(MethodReferenceExpr methodReferenceExpr, List<ResolvedType> paramTypes) -
getBinaryTypeConcrete
protected ResolvedType getBinaryTypeConcrete(Node left, Node right, boolean solveLambdas, BinaryExpr.Operator operator) -
findContainingTypeDecl
Where a node has an interface/class/enum declaration as its ancestor, return the nearest one.NOTE: See
findContainingTypeDeclOrObjectCreationExpr(com.github.javaparser.ast.Node)
if wanting to include anonymous inner classes.For example, these all return X:
public interface X { ... node here ... }
public class X { ... node here ... }
public enum X { ... node here ... }
- Parameters:
node
- The Node whose ancestors will be traversed,- Returns:
- The first class/interface/enum declaration in the Node's ancestry.
-
findContainingTypeDeclOrObjectCreationExpr
Where a node has an interface/class/enum declaration -- or an object creation expression (anonymous inner class) -- as its ancestor, return the nearest one.NOTE: See
findContainingTypeDecl(com.github.javaparser.ast.Node)
if wanting to not include anonymous inner classes.For example, these all return X:
public interface X { ... node here ... }
public class X { ... node here ... }
public enum X { ... node here ... }
new ActionListener() { ... node here ... public void actionPerformed(ActionEvent e) { ... or node here ... } }
- Parameters:
node
- The Node whose ancestors will be traversed,- Returns:
- The first class/interface/enum declaration -- or object creation expression (anonymous inner class) -- in the Node's ancestry.
-
findContainingTypeDeclOrObjectCreationExpr
Where a node has an interface/class/enum declaration -- or an object creation expression in an inner class references an outer class -- as its ancestor, return the declaration corresponding to the class name specified. -
convertToUsageVariableType
-
convertToUsage
Convert aType
into the correspondingResolvedType
.- Parameters:
type
- The type to be converted.context
- The current context.- Returns:
- The type resolved.
-
convertToUsage
Convert aType
into the correspondingResolvedType
.- Parameters:
type
- The type to be converted.context
- The current context.- Returns:
- The type resolved.
-
convertToUsage
Convert aType
into the correspondingResolvedType
.- Parameters:
type
- The type to be converted.- Returns:
- The type resolved.
-
convertClassOrInterfaceTypeToUsage
protected ResolvedType convertClassOrInterfaceTypeToUsage(ClassOrInterfaceType classOrInterfaceType, Context context)Convert aClassOrInterfaceType
into aResolvedType
.- Parameters:
classOrInterfaceType
- The class of interface type to be converted.context
- The current context.- Returns:
- The type resolved.
-
convertWildcardTypeToUsage
Convert aWildcardType
into aResolvedType
.- Parameters:
wildcardType
- The wildcard type to be converted.context
- The current context.- Returns:
- The type resolved.
-
convertArrayTypeToUsage
Convert aArrayType
into aResolvedType
.- Parameters:
arrayType
- The array type to be converted.context
- The current context.- Returns:
- The type resolved.
-
convertUnionTypeToUsage
Convert aUnionType
into aResolvedType
.- Parameters:
unionType
- The union type to be converted.context
- The current context.- Returns:
- The type resolved.
-
convertVarTypeToUsage
Convert aVarType
into aResolvedType
.- Parameters:
varType
- The var type to be converted.context
- The current context.- Returns:
- The type resolved.
-
convert
-
convert
-
solveMethodAsUsage
-
getTypeDeclaration
-
getTypeDeclaration
public ResolvedReferenceTypeDeclaration getTypeDeclaration(ClassOrInterfaceDeclaration classOrInterfaceDeclaration) -
getTypeOfThisIn
"this" inserted in the given point, which type would have? -
getTypeDeclaration
-
classToResolvedType
Convert aClass
into the correspondingResolvedType
.- Parameters:
clazz
- The class to be converted.- Returns:
- The class resolved.
-