Package com.github.javaparser.resolution
Class Navigator
java.lang.Object
com.github.javaparser.resolution.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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ClassOrInterfaceDeclarationdemandClass(CompilationUnit cu, String qualifiedName) static ClassOrInterfaceDeclarationdemandClassOrInterface(CompilationUnit compilationUnit, String qualifiedName) static ConstructorDeclarationdemandConstructor(TypeDeclaration<?> td, int index) Returns the(i+1)'th constructor of the given type declaration, in textual order.static EnumDeclarationdemandEnum(CompilationUnit cu, String qualifiedName) static VariableDeclaratordemandField(ClassOrInterfaceDeclaration cd, String name) static ClassOrInterfaceDeclarationdemandInterface(CompilationUnit cu, String qualifiedName) static MethodDeclarationdemandMethod(TypeDeclaration<?> cd, String name) static <N extends Node>
NdemandNodeOfGivenClass(Node node, Class<N> clazz) static NodedemandParentNode(Node node) static NodedemandParentNode(Node node, Predicate<Node> isAcceptedParentNode) Traverses the parent chain starting atnodeand returns the first Node that returns makeisAcceptedParentNodeevaluate totrue.static ReturnStmtdemandReturnStmt(MethodDeclaration method) static SwitchStmtdemandSwitch(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 ReturnStmtfindReturnStmt(MethodDeclaration method) Deprecated.static Optional<SimpleName> findSimpleName(Node node, String name) static SwitchStmtfindSwitch(Node node) Deprecated.private static Optional<SwitchStmt> findSwitchHelper(Node node) 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.private static StringgetInnerTypeName(String qualifiedName) private static StringgetOuterTypeName(String qualifiedName) static NoderequireParentNode(Node node) Deprecated.
-
Constructor Details
-
Navigator
private Navigator()
-
-
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
-
demandMethod
-
demandNodeOfGivenClass
-
demandParentNode
-
demandParentNode
Traverses the parent chain starting atnodeand returns the first Node that returns makeisAcceptedParentNodeevaluate totrue. -
demandReturnStmt
-
demandSwitch
-
demandVariableDeclaration
-
findMethodCall
-
findNameExpression
-
findNodeOfGivenClass
Deprecated. -
findReturnStmt
Deprecated. -
findSimpleName
-
findSwitch
Deprecated. -
findSwitchHelper
-
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". -
getInnerTypeName
-
getOuterTypeName
-
requireParentNode
Deprecated.
-
demandNodeOfGivenClass(Node, Class)