Class TreeUtils


  • public class TreeUtils
    extends Object
    • Method Detail

      • firstAncestor

        @CheckForNull
        public static Tree firstAncestor​(Tree tree,
                                         Predicate<Tree> predicate)
      • firstAncestorOfKind

        @CheckForNull
        public static Tree firstAncestorOfKind​(Tree tree,
                                               Tree.Kind... kinds)
      • nonWhitespaceTokens

        public static List<Token> nonWhitespaceTokens​(Tree tree)
      • hasDescendant

        public static boolean hasDescendant​(Tree tree,
                                            Predicate<Tree> predicate)
      • getSymbolFromTree

        public static Optional<Symbol> getSymbolFromTree​(@Nullable
                                                         Tree tree)
      • getClassSymbolFromDef

        @CheckForNull
        public static ClassSymbol getClassSymbolFromDef​(@Nullable
                                                        ClassDef classDef)
      • getParentClassesFQN

        public static List<String> getParentClassesFQN​(ClassDef classDef)
      • getFunctionSymbolFromDef

        @CheckForNull
        public static FunctionSymbol getFunctionSymbolFromDef​(@Nullable
                                                              FunctionDef functionDef)
      • topLevelFunctionDefs

        public static List<FunctionDef> topLevelFunctionDefs​(ClassDef classDef)
        Collects all top-level function definitions within a class def. It is used to discover methods defined within "strange" constructs, such as class A: if p: def f(self): ...
      • isBooleanLiteral

        public static boolean isBooleanLiteral​(Tree tree)
      • nameFromExpression

        public static String nameFromExpression​(Expression expression)
      • nameFromQualifiedExpression

        public static String nameFromQualifiedExpression​(QualifiedExpression qualifiedExpression)
      • decoratorNameFromExpression

        @CheckForNull
        public static String decoratorNameFromExpression​(Expression expression)
      • fullyQualifiedNameFromQualifiedExpression

        public static String fullyQualifiedNameFromQualifiedExpression​(QualifiedExpression qualifiedExpression)
      • fullyQualifiedNameFromExpression

        @CheckForNull
        public static String fullyQualifiedNameFromExpression​(Expression expression)
      • getTreeSeparatorOrLastToken

        public static Token getTreeSeparatorOrLastToken​(Tree tree)
        Statements can have a separator like semicolon. When handling ranges we want to take them into account.