Class Navigator


  • public final class Navigator
    extends java.lang.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.
    • Constructor Detail

      • Navigator

        private Navigator()
    • Method Detail

      • 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.
      • demandNodeOfGivenClass

        public static <N extends Node> N demandNodeOfGivenClass​(Node node,
                                                                java.lang.Class<N> clazz)
      • demandParentNode

        public static Node demandParentNode​(Node node)
      • demandParentNode

        public static Node demandParentNode​(Node node,
                                            java.util.function.Predicate<Node> isAcceptedParentNode)
        Traverses the parent chain starting at node and returns the first Node that returns make isAcceptedParentNode evaluate to true.
      • demandVariableDeclaration

        public static java.util.Optional<VariableDeclarator> demandVariableDeclaration​(Node node,
                                                                                       java.lang.String name)
      • findMethodCall

        public static java.util.Optional<MethodCallExpr> findMethodCall​(Node node,
                                                                        java.lang.String methodName)
      • findNameExpression

        public static java.util.Optional<NameExpr> findNameExpression​(Node node,
                                                                      java.lang.String name)
      • findSimpleName

        public static java.util.Optional<SimpleName> findSimpleName​(Node node,
                                                                    java.lang.String name)
      • findSwitchHelper

        private static java.util.Optional<SwitchStmt> findSwitchHelper​(Node node)
      • findType

        public static java.util.Optional<TypeDeclaration<?>> findType​(CompilationUnit cu,
                                                                      java.lang.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 java.util.Optional<TypeDeclaration<?>> findType​(TypeDeclaration<?> td,
                                                                      java.lang.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".
      • getInnerTypeName

        private static java.lang.String getInnerTypeName​(java.lang.String qualifiedName)
      • getOuterTypeName

        private static java.lang.String getOuterTypeName​(java.lang.String qualifiedName)