|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.stjs.generator.javac.TreeUtils
public final class TreeUtils
A utility class made for helping to analyze a given Tree.
| Method Summary | ||
|---|---|---|
static boolean |
canHaveTypeAnnotation(com.sun.source.tree.Tree tree)
|
|
static boolean |
containsThisConstructorInvocation(com.sun.source.tree.MethodTree node)
|
|
static TypeElement |
elementFromDeclaration(com.sun.source.tree.ClassTree node)
Gets the element for a class corresponding to a declaration. |
|
static ExecutableElement |
elementFromDeclaration(com.sun.source.tree.MethodTree node)
Gets the element for a method corresponding to a declaration. |
|
static VariableElement |
elementFromDeclaration(com.sun.source.tree.VariableTree node)
Gets the element for a variable corresponding to its declaration. |
|
static Element |
elementFromUse(com.sun.source.tree.ExpressionTree node)
Gets the element for the declaration corresponding to this use of an element. |
|
static ExecutableElement |
elementFromUse(com.sun.source.tree.MethodInvocationTree node)
|
|
static ExecutableElement |
elementFromUse(com.sun.source.tree.NewClassTree node)
|
|
static com.sun.source.tree.ClassTree |
enclosingClass(com.sun.source.util.TreePath path)
Gets the enclosing class of the tree node defined by the given {@link TreePath} . |
|
static com.sun.source.tree.MethodTree |
enclosingMethod(com.sun.source.util.TreePath path)
Gets the enclosing method of the tree node defined by the given {@link TreePath} . |
|
static
|
enclosingOfClass(com.sun.source.util.TreePath path,
Class<T> treeClass)
Gets the first enclosing tree in path, of the specified class |
|
static com.sun.source.tree.Tree |
enclosingOfKind(com.sun.source.util.TreePath path,
Set<com.sun.source.tree.Tree.Kind> kinds)
Gets the first enclosing tree in path, with any one of the specified kinds. |
|
static com.sun.source.tree.Tree |
enclosingOfKind(com.sun.source.util.TreePath path,
com.sun.source.tree.Tree.Kind kind)
Gets the first enclosing tree in path, of the specified kind. |
|
static
|
enclosingPathOfType(com.sun.source.util.TreePath path,
Class<T> clz)
Gets the first enclosing tree in path, with any one of the specified kinds. |
|
static com.sun.source.tree.BlockTree |
enclosingTopLevelBlock(com.sun.source.util.TreePath path)
|
|
static com.sun.source.tree.VariableTree |
enclosingVariable(com.sun.source.util.TreePath path)
Gets the enclosing variable of a tree node defined by the given TreePath. |
|
static com.sun.source.tree.Tree |
firstStatement(com.sun.source.tree.Tree tree)
|
|
static com.sun.source.tree.Tree |
getAssignmentContext(com.sun.source.util.TreePath treePath)
Returns the tree with the assignment context for the treePath leaf node. |
|
static VariableElement |
getField(String typeName,
String fieldName,
ProcessingEnvironment env)
Returns the VariableElement for a field declaration. |
|
static String |
getFieldName(com.sun.source.tree.Tree tree)
Compute the name of the field that the field access tree accesses. |
|
static ExecutableElement |
getMethod(String typeName,
String methodName,
int params,
ProcessingEnvironment env)
Returns the ExecutableElement for a method declaration of methodName, in class typeName, with params parameters. |
|
static String |
getMethodName(com.sun.source.tree.Tree tree)
Compute the name of the method that the method access tree accesses. |
|
static com.sun.source.tree.ExpressionTree |
getReceiverTree(com.sun.source.tree.ExpressionTree expression)
Returns the receiver tree of a field access or a method invocation |
|
static boolean |
hasExplicitConstructor(com.sun.source.tree.ClassTree node)
Determine whether the given class contains an explicit constructor. |
|
static boolean |
isCompileTimeString(com.sun.source.tree.ExpressionTree node)
Returns true if the node is a constant-time expression. |
|
static boolean |
isConstructor(com.sun.source.tree.MethodTree tree)
Checks if the provided method is a constructor method or no. |
|
static boolean |
isDiamondTree(com.sun.source.tree.Tree tree)
Returns true if the tree is of a diamond type |
|
static boolean |
isEnumSuper(com.sun.source.tree.MethodInvocationTree node)
|
|
static boolean |
isExpressionTree(com.sun.source.tree.Tree tree)
Determine whether the given tree represents an ExpressionTree. |
|
static boolean |
isFieldAccess(com.sun.source.tree.Tree tree)
Determine whether tree is a field access expressions, such as
f
obj . |
|
static boolean |
isMethodAccess(com.sun.source.tree.Tree tree)
Determine whether tree refers to a method element, such as
m(...) |
|
static boolean |
isMethodInvocation(com.sun.source.tree.Tree tree,
ExecutableElement method,
ProcessingEnvironment env)
Returns true if the given element is an invocation of the method, or of any method that overrides that one. |
|
static boolean |
isSelfAccess(com.sun.source.tree.ExpressionTree tree)
Returns true if the tree is a tree that 'looks like' either an access of a field or an invocation of a method that are owned by the same accessing instance. |
|
static boolean |
isSpecificFieldAccess(com.sun.source.tree.Tree tree,
VariableElement var)
Returns true if and only if the given tree represents a field access of the given VariableElement
. |
|
static boolean |
isStringCompoundConcatenation(com.sun.source.tree.CompoundAssignmentTree tree)
Returns true if the compound assignment tree is a string concatenation |
|
static boolean |
isStringConcatenation(com.sun.source.tree.Tree tree)
Returns true if the tree represents a String concatenation operation |
|
static boolean |
isSuperCall(com.sun.source.tree.MethodInvocationTree tree)
Checks if the method invocation is a call to super. |
|
static boolean |
isTypeTree(com.sun.source.tree.Tree tree)
Is the given tree a type instantiation? |
|
static boolean |
isUseOfElement(com.sun.source.tree.ExpressionTree node)
Determine whether the given ExpressionTree has an underlying element. |
|
static Name |
methodName(com.sun.source.tree.MethodInvocationTree node)
|
|
static com.sun.source.util.TreePath |
pathTillOfKind(com.sun.source.util.TreePath path,
Set<com.sun.source.tree.Tree.Kind> kinds)
Gets path to the the first enclosing tree with any one of the specified kinds. |
|
static com.sun.source.util.TreePath |
pathTillOfKind(com.sun.source.util.TreePath path,
com.sun.source.tree.Tree.Kind kind)
Gets path to the the first enclosing tree of the specified kind. |
|
static com.sun.source.tree.ExpressionTree |
skipParens(com.sun.source.tree.ExpressionTree tree)
If the given tree is a parenthesized tree, it returns the enclosed non-parenthesized tree. |
|
static Set<com.sun.source.tree.Tree.Kind> |
typeTreeKinds()
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static boolean isConstructor(com.sun.source.tree.MethodTree tree)
tree - a tree defining the method
public static boolean isSuperCall(com.sun.source.tree.MethodInvocationTree tree)
tree - a tree defining a method invocation
public static boolean isSelfAccess(com.sun.source.tree.ExpressionTree tree)
field this.field method() this.method()It does not perform any semantical check to differentiate between fields and local variables; local methods or imported static methods.
tree - expression tree representing an access to object member
true iff the member is a member of this instance
public static com.sun.source.tree.Tree enclosingOfKind(com.sun.source.util.TreePath path,
com.sun.source.tree.Tree.Kind kind)
path - the path defining the tree nodekind - the kind of the desired tree
public static com.sun.source.tree.Tree enclosingOfKind(com.sun.source.util.TreePath path,
Set<com.sun.source.tree.Tree.Kind> kinds)
path - the path defining the tree nodekinds - the set of kinds of the desired tree
public static <T extends com.sun.source.tree.Tree> com.sun.source.util.TreePath enclosingPathOfType(com.sun.source.util.TreePath path,
Class<T> clz)
path - the path defining the tree nodekinds - the set of kinds of the desired tree
public static com.sun.source.util.TreePath pathTillOfKind(com.sun.source.util.TreePath path,
com.sun.source.tree.Tree.Kind kind)
path - the path defining the tree nodekind - the kind of the desired tree
public static com.sun.source.util.TreePath pathTillOfKind(com.sun.source.util.TreePath path,
Set<com.sun.source.tree.Tree.Kind> kinds)
path - the path defining the tree nodekinds - the set of kinds of the desired tree
public static <T extends com.sun.source.tree.Tree> T enclosingOfClass(com.sun.source.util.TreePath path,
Class<T> treeClass)
path - the path defining the tree nodetreeClass - the class of the desired tree
public static com.sun.source.tree.ClassTree enclosingClass(com.sun.source.util.TreePath path)
path - the path defining the tree node
public static com.sun.source.tree.VariableTree enclosingVariable(com.sun.source.util.TreePath path)
TreePath.
path - the path defining the tree node
public static com.sun.source.tree.MethodTree enclosingMethod(com.sun.source.util.TreePath path)
path - the path defining the tree node
public static com.sun.source.tree.BlockTree enclosingTopLevelBlock(com.sun.source.util.TreePath path)
public static com.sun.source.tree.ExpressionTree skipParens(com.sun.source.tree.ExpressionTree tree)
tree - an expression tree
public static com.sun.source.tree.Tree getAssignmentContext(com.sun.source.util.TreePath treePath)
treePath -
public static final TypeElement elementFromDeclaration(com.sun.source.tree.ClassTree node)
node -
public static final ExecutableElement elementFromDeclaration(com.sun.source.tree.MethodTree node)
node -
public static final VariableElement elementFromDeclaration(com.sun.source.tree.VariableTree node)
node -
public static final Element elementFromUse(com.sun.source.tree.ExpressionTree node)
Trees.getElement(TreePath) instead.
TODO: remove this method, as it really doesn't do anything.
node - the tree corresponding to a use of an element
public static final ExecutableElement elementFromUse(com.sun.source.tree.MethodInvocationTree node)
public static final ExecutableElement elementFromUse(com.sun.source.tree.NewClassTree node)
public static final boolean isUseOfElement(com.sun.source.tree.ExpressionTree node)
node - the ExpressionTree to test
public static final Name methodName(com.sun.source.tree.MethodInvocationTree node)
public static final boolean containsThisConstructorInvocation(com.sun.source.tree.MethodTree node)
public static final com.sun.source.tree.Tree firstStatement(com.sun.source.tree.Tree tree)
public static boolean hasExplicitConstructor(com.sun.source.tree.ClassTree node)
node - A class tree.
public static final boolean isDiamondTree(com.sun.source.tree.Tree tree)
public static final boolean isStringConcatenation(com.sun.source.tree.Tree tree)
String concatenation operation
public static final boolean isStringCompoundConcatenation(com.sun.source.tree.CompoundAssignmentTree tree)
public static boolean isCompileTimeString(com.sun.source.tree.ExpressionTree node)
public static com.sun.source.tree.ExpressionTree getReceiverTree(com.sun.source.tree.ExpressionTree expression)
public static Set<com.sun.source.tree.Tree.Kind> typeTreeKinds()
public static boolean isTypeTree(com.sun.source.tree.Tree tree)
tree - the tree to test
public static boolean isMethodInvocation(com.sun.source.tree.Tree tree,
ExecutableElement method,
ProcessingEnvironment env)
public static ExecutableElement getMethod(String typeName,
String methodName,
int params,
ProcessingEnvironment env)
public static boolean isFieldAccess(com.sun.source.tree.Tree tree)
tree is a field access expressions, such as
f obj . f
public static String getFieldName(com.sun.source.tree.Tree tree)
tree accesses. Requires tree to be
a field access, as determined by isFieldAccess.
tree.public static boolean isMethodAccess(com.sun.source.tree.Tree tree)
tree refers to a method element, such as
m(...) obj . m(...)
public static String getMethodName(com.sun.source.tree.Tree tree)
tree accesses. Requires tree to
be a method access, as determined by isMethodAccess.
tree.public static boolean canHaveTypeAnnotation(com.sun.source.tree.Tree tree)
true if and only if tree can have a type annotation.
TODO: is this implementation precise enough? E.g. does a .class literal work correctly?
public static boolean isSpecificFieldAccess(com.sun.source.tree.Tree tree,
VariableElement var)
tree represents a field access of the given VariableElement
.
public static VariableElement getField(String typeName,
String fieldName,
ProcessingEnvironment env)
typeName - the class where the field is declared.fieldName - the name of the field.env - the processing environment.
public static boolean isExpressionTree(com.sun.source.tree.Tree tree)
tree - the Tree to test.
public static boolean isEnumSuper(com.sun.source.tree.MethodInvocationTree node)
node - the method invocation to check
Enum constructor
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||