Class Navigator
java.lang.Object
com.github.javaparser.symbolsolver.javaparser.Navigator
This class can be used to easily retrieve nodes from a JavaParser AST.
Note that methods with the prefix `demand` indicate that if the search value is not found, an exception will be thrown.
- Author:
- Federico Tomassetti
-
Method Summary
Modifier and TypeMethodDescriptionstatic ClassOrInterfaceDeclaration
demandClass(CompilationUnit cu, String qualifiedName)
static ClassOrInterfaceDeclaration
demandClassOrInterface(CompilationUnit compilationUnit, String qualifiedName)
static ConstructorDeclaration
demandConstructor(TypeDeclaration<?> td, int index)
Returns the(i+1)
'th constructor of the given type declaration, in textual order.static EnumDeclaration
demandEnum(CompilationUnit cu, String qualifiedName)
static VariableDeclarator
demandField(ClassOrInterfaceDeclaration cd, String name)
static ClassOrInterfaceDeclaration
demandInterface(CompilationUnit cu, String qualifiedName)
static MethodDeclaration
demandMethod(TypeDeclaration<?> cd, String name)
static <N extends Node>
NdemandNodeOfGivenClass(Node node, Class<N> clazz)
static Node
demandParentNode(Node node)
static ReturnStmt
demandReturnStmt(MethodDeclaration method)
static SwitchStmt
demandSwitch(Node node)
static Optional<VariableDeclarator>
demandVariableDeclaration(Node node, String name)
static Optional<MethodCallExpr>
findMethodCall(Node node, String methodName)
findNameExpression(Node node, String name)
static <N extends Node>
NfindNodeOfGivenClass(Node node, Class<N> clazz)
Deprecated.static ReturnStmt
findReturnStmt(MethodDeclaration method)
Deprecated.static Optional<SimpleName>
findSimpleName(Node node, String name)
static SwitchStmt
findSwitch(Node node)
Deprecated.static Optional<TypeDeclaration<?>>
findType(TypeDeclaration<?> td, String qualifiedName)
Looks among the type declared in the TypeDeclaration for one having the specified name.static Optional<TypeDeclaration<?>>
findType(CompilationUnit cu, String qualifiedName)
Looks among the type declared in the Compilation Unit for one having the specified name.static Node
requireParentNode(Node node)
Deprecated.
-
Method Details
-
demandClass
-
demandClassOrInterface
public static ClassOrInterfaceDeclaration demandClassOrInterface(CompilationUnit compilationUnit, String qualifiedName) -
demandConstructor
Returns the(i+1)
'th constructor of the given type declaration, in textual order. The constructor that appears first has the index 0, the second one the index 1, and so on.- Parameters:
td
- The type declaration to search in. Note that only classes and enums have constructors.index
- The index of the desired constructor.- Returns:
- The desired ConstructorDeclaration if it was found, else an exception is thrown.
-
demandEnum
-
demandField
-
demandInterface
public static ClassOrInterfaceDeclaration demandInterface(CompilationUnit cu, String qualifiedName) -
demandMethod
-
demandNodeOfGivenClass
-
demandParentNode
-
demandReturnStmt
-
demandSwitch
-
demandVariableDeclaration
-
findMethodCall
-
findNameExpression
-
findNodeOfGivenClass
Deprecated. -
findReturnStmt
Deprecated. -
findSimpleName
-
findSwitch
Deprecated. -
findType
Looks among the type declared in the Compilation Unit for one having the specified name. The name can be qualified with respect to the compilation unit. For example, if the compilation unit is in package a.b; and it contains two top level classes named C and D, with class E being defined inside D then the qualifiedName that can be resolved are "C", "D", and "D.E". -
findType
Looks among the type declared in the TypeDeclaration for one having the specified name. The name can be qualified with respect to the TypeDeclaration. For example, if the class declaration defines class D and class D contains an internal class named E then the qualifiedName that can be resolved are "D", and "D.E". -
requireParentNode
Deprecated.
-
demandNodeOfGivenClass(Node, Class)