Package com.github.javaparser.resolution
Class Navigator
- java.lang.Object
-
- com.github.javaparser.resolution.Navigator
-
public final class Navigator extends Object
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
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static 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 Node
demandParentNode(Node node, Predicate<Node> isAcceptedParentNode)
Traverses the parent chain starting atnode
and returns the first Node that returns makeisAcceptedParentNode
evaluate totrue
.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)
static Optional<NameExpr>
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 Detail
-
demandClass
public static ClassOrInterfaceDeclaration demandClass(CompilationUnit cu, String qualifiedName)
-
demandClassOrInterface
public static ClassOrInterfaceDeclaration demandClassOrInterface(CompilationUnit compilationUnit, String qualifiedName)
-
demandConstructor
public static ConstructorDeclaration demandConstructor(TypeDeclaration<?> td, int index)
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
public static EnumDeclaration demandEnum(CompilationUnit cu, String qualifiedName)
-
demandField
public static VariableDeclarator demandField(ClassOrInterfaceDeclaration cd, String name)
-
demandInterface
public static ClassOrInterfaceDeclaration demandInterface(CompilationUnit cu, String qualifiedName)
-
demandMethod
public static MethodDeclaration demandMethod(TypeDeclaration<?> cd, String name)
-
demandNodeOfGivenClass
public static <N extends Node> N demandNodeOfGivenClass(Node node, Class<N> clazz)
-
demandParentNode
public static Node demandParentNode(Node node, Predicate<Node> isAcceptedParentNode)
Traverses the parent chain starting atnode
and returns the first Node that returns makeisAcceptedParentNode
evaluate totrue
.
-
demandReturnStmt
public static ReturnStmt demandReturnStmt(MethodDeclaration method)
-
demandSwitch
public static SwitchStmt demandSwitch(Node node)
-
demandVariableDeclaration
public static Optional<VariableDeclarator> demandVariableDeclaration(Node node, String name)
-
findMethodCall
public static Optional<MethodCallExpr> findMethodCall(Node node, String methodName)
-
findNodeOfGivenClass
@Deprecated public static <N extends Node> N findNodeOfGivenClass(Node node, Class<N> clazz)
Deprecated.
-
findReturnStmt
@Deprecated public static ReturnStmt findReturnStmt(MethodDeclaration method)
Deprecated.
-
findSimpleName
public static Optional<SimpleName> findSimpleName(Node node, String name)
-
findSwitch
@Deprecated public static SwitchStmt findSwitch(Node node)
Deprecated.
-
findType
public static Optional<TypeDeclaration<?>> findType(CompilationUnit cu, String qualifiedName)
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
public static Optional<TypeDeclaration<?>> findType(TypeDeclaration<?> td, String qualifiedName)
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 public static Node requireParentNode(Node node)
Deprecated.
-
-