Modifier and Type | Method and Description |
---|---|
static @Nullable ClassTree |
enclosingClass(TreePath path)
Gets the enclosing class of the tree node defined by the given
TreePath . |
static @Nullable MethodTree |
enclosingMethod(TreePath path)
Gets the enclosing method of the tree node defined by the given
TreePath . |
static @Nullable Tree |
enclosingMethodOrLambda(TreePath path)
Gets the enclosing method or lambda expression of the tree node defined by the given
TreePath . |
static Pair<Tree,Tree> |
enclosingNonParen(TreePath path)
Gets the first (innermost) enclosing tree in path, that is not a parenthesis.
|
static <T extends Tree> |
enclosingOfClass(TreePath path,
Class<T> treeClass)
Gets the first (innermost) enclosing tree in path, of the specified class.
|
static @Nullable Tree |
enclosingOfKind(TreePath path,
Set<Tree.Kind> kinds)
Gets the first (innermost) enclosing tree in path, with any one of the specified kinds.
|
static @Nullable Tree |
enclosingOfKind(TreePath path,
Tree.Kind kind)
Gets the first (innermost) enclosing tree in path, of the specified kind.
|
static @Nullable BlockTree |
enclosingTopLevelBlock(TreePath path)
Returns the top-level block that encloses the given path, or null if none does.
|
static @Nullable VariableTree |
enclosingVariable(TreePath path)
Gets the enclosing variable of a tree node defined by the given
TreePath . |
static @Nullable Tree |
getAssignmentContext(TreePath treePath)
Returns the "assignment context" for the leaf of
treePath , which is often the leaf of
the parent of treePath . |
static boolean |
inConstructor(TreePath path)
Returns true if the tree is in a constructor or an initializer block.
|
static boolean |
isTreeInStaticScope(TreePath path)
Returns true if the leaf of the tree path is in a static scope.
|
static String |
leafToStringTruncated(@Nullable TreePath path,
int length)
Returns a string representation of the leaf of the given path, using
TreeUtils.toStringTruncated(com.sun.source.tree.Tree, int) . |
static @Nullable TreePath |
pathTillClass(TreePath path)
Gets path to the first (innermost) enclosing class tree, where class is defined by the
TreeUtils.classTreeKinds() method. |
static @Nullable TreePath |
pathTillMethod(TreePath path)
Gets path to the first (innermost) enclosing method tree.
|
static @Nullable TreePath |
pathTillOfKind(TreePath path,
Set<Tree.Kind> kinds)
Gets path to the first (innermost) enclosing tree with any one of the specified kinds.
|
static @Nullable TreePath |
pathTillOfKind(TreePath path,
Tree.Kind kind)
Gets path to the first (innermost) enclosing tree of the specified kind.
|
static String |
toString(TreePath path)
Return a printed representation of a TreePath.
|
public static @Nullable TreePath pathTillOfKind(TreePath path, Tree.Kind kind)
path
- the path defining the tree nodekind
- the kind of the desired treenull
otherwisepublic static @Nullable TreePath pathTillOfKind(TreePath path, Set<Tree.Kind> kinds)
path
- the path defining the tree nodekinds
- the set of kinds of the desired treenull
otherwisepublic static @Nullable TreePath pathTillClass(TreePath path)
TreeUtils.classTreeKinds()
method.path
- the path defining the tree nodenull
otherwisepublic static @Nullable TreePath pathTillMethod(TreePath path)
path
- the path defining the tree nodenull
otherwisepublic static @Nullable Tree enclosingOfKind(TreePath path, Tree.Kind kind)
path
- the path defining the tree nodekind
- the kind of the desired treenull
otherwisepublic static @Nullable Tree enclosingOfKind(TreePath path, Set<Tree.Kind> kinds)
path
- the path defining the tree nodekinds
- the set of kinds of the desired treenull
otherwisepublic static <T extends Tree> T enclosingOfClass(TreePath path, Class<T> treeClass)
T
- the type of treeClass
path
- the path defining the tree nodetreeClass
- the class of the desired treenull
otherwisepublic static @Nullable ClassTree enclosingClass(TreePath path)
TreePath
. It returns a
Tree
, from which checkers.types.AnnotatedTypeMirror
or Element
can be
obtained.path
- the path defining the tree nodenull
if one does
not existpublic static @Nullable VariableTree enclosingVariable(TreePath path)
TreePath
.path
- the path defining the tree nodenull
if one does not existpublic static @Nullable MethodTree enclosingMethod(TreePath path)
TreePath
. It returns a
Tree
, from which an checkers.types.AnnotatedTypeMirror
or Element
can
be obtained.
Also see AnnotatedTypeFactory#getEnclosingMethod
and AnnotatedTypeFactory#getEnclosingClassOrMethod
, which do not require a TreePath.
path
- the path defining the tree nodenull
if one does not existpublic static @Nullable Tree enclosingMethodOrLambda(TreePath path)
TreePath
. It returns a Tree
, from which an checkers.types.AnnotatedTypeMirror
or Element
can be obtained.path
- the path defining the tree nodenull
if one does not
existpublic static @Nullable BlockTree enclosingTopLevelBlock(TreePath path)
path
- a pathpublic static Pair<Tree,Tree> enclosingNonParen(TreePath path)
path
- the path defining the tree nodepublic static @Nullable Tree getAssignmentContext(TreePath treePath)
treePath
, which is often the leaf of
the parent of treePath
. (Does not handle pseudo-assignment of an argument to a
parameter or a receiver expression to a receiver.) This is not the same as org.checkerframework.dataflow.cfg.node.AssignmentContext
, which represents the left-hand side
rather than the assignment itself.
The assignment context for treePath
is the leaf of its parent, if that leaf is one
of the following trees:
If the leaf is a ParenthesizedTree, then recurse on the parent.
Otherwise, null is returned.
treePath
- a pathnull
otherwisepublic static boolean inConstructor(TreePath path)
path
- the path to testpublic static boolean isTreeInStaticScope(TreePath path)
path
- TreePath whose leaf may or may not be in static scopepublic static String toString(TreePath path)
path
- a TreePathpublic static String leafToStringTruncated(@Nullable TreePath path, int length)
TreeUtils.toStringTruncated(com.sun.source.tree.Tree, int)
.path
- a pathlength
- the maximum length for the result; must be at least 6length
characters long