Class JavaParserFacade
- java.lang.Object
-
- com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade
-
public class JavaParserFacade extends Object
Class to be used by final users to solve symbols for JavaParser ASTs.- Author:
- Federico Tomassetti
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description com.github.javaparser.resolution.types.ResolvedTypeclassToResolvedType(Class<?> clazz)Deprecated.instead consider SymbolSolver.classToResolvedType(Classstatic voidclearInstances()This method is used to clear internal caches for the sake of releasing memory.com.github.javaparser.resolution.types.ResolvedTypeconvert(com.github.javaparser.ast.type.Type type, com.github.javaparser.ast.Node node)com.github.javaparser.resolution.types.ResolvedTypeconvert(com.github.javaparser.ast.type.Type type, com.github.javaparser.resolution.Context context)com.github.javaparser.resolution.types.ResolvedTypeconvertToUsage(com.github.javaparser.ast.type.Type type)Convert aTypeinto the correspondingResolvedType.protected com.github.javaparser.resolution.types.ResolvedTypeconvertToUsage(com.github.javaparser.ast.type.Type type, com.github.javaparser.resolution.Context context)Convert aTypeinto the correspondingResolvedType.protected com.github.javaparser.ast.body.TypeDeclaration<?>findContainingTypeDecl(com.github.javaparser.ast.Node node)Where a node has an interface/class/enum declaration as its ancestor, return the nearest one.protected com.github.javaparser.ast.NodefindContainingTypeDeclOrObjectCreationExpr(com.github.javaparser.ast.Node 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 com.github.javaparser.ast.NodefindContainingTypeDeclOrObjectCreationExpr(com.github.javaparser.ast.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 JavaParserFacadeget(com.github.javaparser.resolution.TypeSolver typeSolver)Note that the addition of the modifiersynchronizedis specific and directly in response to issue #2668.protected com.github.javaparser.resolution.types.ResolvedTypegetBinaryTypeConcrete(com.github.javaparser.ast.Node left, com.github.javaparser.ast.Node right, boolean solveLambdas, com.github.javaparser.ast.expr.BinaryExpr.Operator operator)com.github.javaparser.resolution.SolvergetSymbolSolver()com.github.javaparser.resolution.types.ResolvedTypegetType(com.github.javaparser.ast.Node node)Get the type associated with the node.com.github.javaparser.resolution.types.ResolvedTypegetType(com.github.javaparser.ast.Node node, boolean solveLambdas)com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclarationgetTypeDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration)com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclarationgetTypeDeclaration(com.github.javaparser.ast.body.TypeDeclaration<?> typeDeclaration)com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclarationgetTypeDeclaration(com.github.javaparser.ast.Node node)com.github.javaparser.resolution.types.ResolvedTypegetTypeOfThisIn(com.github.javaparser.ast.Node node)"this" inserted in the given point, which type would have?com.github.javaparser.resolution.TypeSolvergetTypeSolver()com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration>solve(com.github.javaparser.ast.expr.AnnotationExpr annotationExpr)com.github.javaparser.resolution.model.SymbolReference<? extends com.github.javaparser.resolution.declarations.ResolvedValueDeclaration>solve(com.github.javaparser.ast.expr.Expression expr)com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedValueDeclaration>solve(com.github.javaparser.ast.expr.FieldAccessExpr fieldAccessExpr)com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration>solve(com.github.javaparser.ast.expr.MethodCallExpr methodCallExpr)com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration>solve(com.github.javaparser.ast.expr.MethodCallExpr methodCallExpr, boolean solveLambdas)Given a method call find out to which method declaration it corresponds.com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration>solve(com.github.javaparser.ast.expr.MethodReferenceExpr methodReferenceExpr)com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration>solve(com.github.javaparser.ast.expr.MethodReferenceExpr methodReferenceExpr, boolean solveLambdas)Given a method reference find out to which method declaration it corresponds.com.github.javaparser.resolution.model.SymbolReference<? extends com.github.javaparser.resolution.declarations.ResolvedValueDeclaration>solve(com.github.javaparser.ast.expr.NameExpr nameExpr)com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration>solve(com.github.javaparser.ast.expr.ObjectCreationExpr objectCreationExpr)com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration>solve(com.github.javaparser.ast.expr.ObjectCreationExpr objectCreationExpr, boolean solveLambdas)Given a constructor call find out to which constructor declaration it corresponds.com.github.javaparser.resolution.model.SymbolReference<? extends com.github.javaparser.resolution.declarations.ResolvedValueDeclaration>solve(com.github.javaparser.ast.expr.SimpleName nameExpr)com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration>solve(com.github.javaparser.ast.expr.ThisExpr node)com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration>solve(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt explicitConstructorInvocationStmt)com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration>solve(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt explicitConstructorInvocationStmt, boolean solveLambdas)com.github.javaparser.resolution.MethodUsagesolveMethodAsUsage(com.github.javaparser.ast.expr.MethodCallExpr call)protected com.github.javaparser.resolution.MethodUsagetoMethodUsage(com.github.javaparser.ast.expr.MethodReferenceExpr methodReferenceExpr, List<com.github.javaparser.resolution.types.ResolvedType> paramTypes)
-
-
-
Method Detail
-
get
public static JavaParserFacade get(com.github.javaparser.resolution.TypeSolver typeSolver)
Note that the addition of the modifiersynchronizedis 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.
-
getTypeSolver
public com.github.javaparser.resolution.TypeSolver getTypeSolver()
-
getSymbolSolver
public com.github.javaparser.resolution.Solver getSymbolSolver()
-
solve
public com.github.javaparser.resolution.model.SymbolReference<? extends com.github.javaparser.resolution.declarations.ResolvedValueDeclaration> solve(com.github.javaparser.ast.expr.NameExpr nameExpr)
-
solve
public com.github.javaparser.resolution.model.SymbolReference<? extends com.github.javaparser.resolution.declarations.ResolvedValueDeclaration> solve(com.github.javaparser.ast.expr.SimpleName nameExpr)
-
solve
public com.github.javaparser.resolution.model.SymbolReference<? extends com.github.javaparser.resolution.declarations.ResolvedValueDeclaration> solve(com.github.javaparser.ast.expr.Expression expr)
-
solve
public com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration> solve(com.github.javaparser.ast.expr.MethodCallExpr methodCallExpr)
-
solve
public com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration> solve(com.github.javaparser.ast.expr.MethodReferenceExpr methodReferenceExpr)
-
solve
public com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration> solve(com.github.javaparser.ast.expr.ObjectCreationExpr objectCreationExpr)
-
solve
public com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration> solve(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt explicitConstructorInvocationStmt)
-
solve
public com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration> solve(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt explicitConstructorInvocationStmt, boolean solveLambdas)
-
solve
public com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration> solve(com.github.javaparser.ast.expr.ThisExpr node)
-
solve
public com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration> solve(com.github.javaparser.ast.expr.ObjectCreationExpr objectCreationExpr, boolean solveLambdas)Given a constructor call find out to which constructor declaration it corresponds.
-
solve
public com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration> solve(com.github.javaparser.ast.expr.MethodCallExpr methodCallExpr, boolean solveLambdas)Given a method call find out to which method declaration it corresponds.
-
solve
public com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration> solve(com.github.javaparser.ast.expr.MethodReferenceExpr methodReferenceExpr, boolean solveLambdas)Given a method reference find out to which method declaration it corresponds.
-
solve
public com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration> solve(com.github.javaparser.ast.expr.AnnotationExpr annotationExpr)
-
solve
public com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedValueDeclaration> solve(com.github.javaparser.ast.expr.FieldAccessExpr fieldAccessExpr)
-
getType
public com.github.javaparser.resolution.types.ResolvedType getType(com.github.javaparser.ast.Node node)
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
public com.github.javaparser.resolution.types.ResolvedType getType(com.github.javaparser.ast.Node node, boolean solveLambdas)
-
toMethodUsage
protected com.github.javaparser.resolution.MethodUsage toMethodUsage(com.github.javaparser.ast.expr.MethodReferenceExpr methodReferenceExpr, List<com.github.javaparser.resolution.types.ResolvedType> paramTypes)
-
getBinaryTypeConcrete
protected com.github.javaparser.resolution.types.ResolvedType getBinaryTypeConcrete(com.github.javaparser.ast.Node left, com.github.javaparser.ast.Node right, boolean solveLambdas, com.github.javaparser.ast.expr.BinaryExpr.Operator operator)
-
findContainingTypeDecl
protected com.github.javaparser.ast.body.TypeDeclaration<?> findContainingTypeDecl(com.github.javaparser.ast.Node node)
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
protected com.github.javaparser.ast.Node findContainingTypeDeclOrObjectCreationExpr(com.github.javaparser.ast.Node 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.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
protected com.github.javaparser.ast.Node findContainingTypeDeclOrObjectCreationExpr(com.github.javaparser.ast.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.
-
convertToUsage
protected com.github.javaparser.resolution.types.ResolvedType convertToUsage(com.github.javaparser.ast.type.Type type, com.github.javaparser.resolution.Context context)Convert aTypeinto the correspondingResolvedType.- Parameters:
type- The type to be converted.context- The current context.- Returns:
- The type resolved.
-
convertToUsage
public com.github.javaparser.resolution.types.ResolvedType convertToUsage(com.github.javaparser.ast.type.Type type)
Convert aTypeinto the correspondingResolvedType.- Parameters:
type- The type to be converted.- Returns:
- The type resolved.
-
convert
public com.github.javaparser.resolution.types.ResolvedType convert(com.github.javaparser.ast.type.Type type, com.github.javaparser.ast.Node node)
-
convert
public com.github.javaparser.resolution.types.ResolvedType convert(com.github.javaparser.ast.type.Type type, com.github.javaparser.resolution.Context context)
-
solveMethodAsUsage
public com.github.javaparser.resolution.MethodUsage solveMethodAsUsage(com.github.javaparser.ast.expr.MethodCallExpr call)
-
getTypeDeclaration
public com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration getTypeDeclaration(com.github.javaparser.ast.Node node)
-
getTypeDeclaration
public com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration getTypeDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration)
-
getTypeOfThisIn
public com.github.javaparser.resolution.types.ResolvedType getTypeOfThisIn(com.github.javaparser.ast.Node node)
"this" inserted in the given point, which type would have?
-
getTypeDeclaration
public com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration getTypeDeclaration(com.github.javaparser.ast.body.TypeDeclaration<?> typeDeclaration)
-
classToResolvedType
@Deprecated public com.github.javaparser.resolution.types.ResolvedType classToResolvedType(Class<?> clazz)
Deprecated.instead consider SymbolSolver.classToResolvedType(Class> clazz)Convert aClassinto the correspondingResolvedType.- Parameters:
clazz- The class to be converted.- Returns:
- The class resolved.
-
-