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 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)static Optional<NameExpr>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.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 NoderequireParentNode(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 atnodeand returns the first Node that returns makeisAcceptedParentNodeevaluate 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.
-
-