com.sun.tools.javac.tree
Class TreeInfo

java.lang.Object
  extended by com.sun.tools.javac.tree.TreeInfo

public class TreeInfo
extends java.lang.Object

Utility class containing inspector methods for trees.

This is NOT part of any API supported by Sun Microsystems. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.


Field Summary
static int addPrec
          Operator precedences values.
static int andPrec
          Operator precedences values.
static int assignopPrec
          Operator precedences values.
static int assignPrec
          Operator precedences values.
static int bitandPrec
          Operator precedences values.
static int bitorPrec
          Operator precedences values.
static int bitxorPrec
          Operator precedences values.
static int condPrec
          Operator precedences values.
static int eqPrec
          Operator precedences values.
static int mulPrec
          Operator precedences values.
static int noPrec
          Operator precedences values.
static int notExpression
          Operator precedences values.
private  Name[] opname
          The names of all operators.
static int ordPrec
          Operator precedences values.
static int orPrec
          Operator precedences values.
static int postfixPrec
          Operator precedences values.
static int precCount
          Operator precedences values.
static int prefixPrec
          Operator precedences values.
static int shiftPrec
          Operator precedences values.
protected static Context.Key<TreeInfo> treeInfoKey
           
 
Constructor Summary
private TreeInfo(Context context)
           
 
Method Summary
static Name calledMethodName(JCTree tree)
          If the expression is a method call, return the method name, null otherwise.
static JCTree declarationFor(Symbol sym, JCTree tree)
          Find the declaration for a symbol, where that symbol is defined somewhere in the given tree.
static JCDiagnostic.DiagnosticPosition diagEndPos(JCTree tree)
          A DiagnosticPosition with the preferred position set to the end position of given tree, if it is a block with defined endpos.
static JCDiagnostic.DiagnosticPosition diagnosticPositionFor(Symbol sym, JCTree tree)
          Find the position for reporting an error about a symbol, where that symbol is defined somewhere in the given tree.
static int endPos(JCTree tree)
          The end position of given tree, if it is a block with defined endpos.
static int finalizerPos(JCTree tree)
          The position of the finalizer of given try/synchronized statement.
static JCTree.JCMethodInvocation firstConstructorCall(JCTree tree)
          Return the first call in a constructor definition.
static long firstFlag(long flags)
          Return first (smallest) flag in `flags': pre: flags != 0
static int firstStatPos(JCTree tree)
          The position of the first statement in a block, or the position of the block itself if it is empty.
static java.lang.String flagNames(long flags)
          Return flags as a string, separated by " ".
static long flags(JCTree tree)
          If this tree is a declaration or a block, return its flags field, otherwise return 0.
static Name fullName(JCTree tree)
          If this tree is a qualified identifier, its return fully qualified name, otherwise return null.
static int getEndPos(JCTree tree, java.util.Map<JCTree,java.lang.Integer> endPositions)
          The end position of given tree, given a table of end positions generated by the parser
static int getStartPos(JCTree tree)
          Get the start position for a tree node.
static boolean hasConstructors(List<JCTree> trees)
          Is there a constructor declaration in the given list of trees?
static TreeInfo instance(Context context)
           
static boolean isConstructor(JCTree tree)
          Is tree a constructor declaration?
static boolean isInitialConstructor(JCTree tree)
          Is this a constructor whose first (non-synthetic) statement is not of the form this(...)?
static boolean isNull(JCTree tree)
          Return true if a tree represents the null literal.
static boolean isSelfCall(JCTree tree)
          Is this a call to this or super?
static boolean isSuperCall(JCTree tree)
          Is this a call to super?
static boolean isSyntheticInit(JCTree stat)
          Is statement an initializer for a synthetic field?
static Name name(JCTree tree)
          If this tree is an identifier or a field or a parameterized type, return its name, otherwise return null.
static boolean nonstaticSelect(JCTree tree)
          Return true if this is a nonstatic selection.
 Name operatorName(int tag)
          Return name of operator with given tree tag.
static int opPrec(int op)
          Map operators to their precedence levels.
static List<JCTree> pathFor(JCTree node, JCTree.JCCompilationUnit unit)
           
static int positionFor(Symbol sym, JCTree tree)
          Find the position for reporting an error about a symbol, where that symbol is defined somewhere in the given tree.
static JCTree referencedStatement(JCTree.JCLabeledStatement tree)
          Return the statement referenced by a label.
static Env<AttrContext> scopeFor(JCTree node, JCTree.JCCompilationUnit unit)
           
static Env<AttrContext> scopeFor(List<JCTree> path)
           
static void setSymbol(JCTree tree, Symbol sym)
          If this tree is an identifier or a field, set its symbol, otherwise skip.
static JCTree.JCExpression skipParens(JCTree.JCExpression tree)
          Skip parens and return the enclosed expression
static JCTree skipParens(JCTree tree)
          Skip parens and return the enclosed expression
static Symbol symbol(JCTree tree)
          If this tree is an identifier or a field, return its symbol, otherwise return null.
static Symbol symbolFor(JCTree node)
           
(package private) static Tree.Kind tagToKind(int tag)
           
static List<Type> types(List<? extends JCTree> trees)
          Return the types of a list of trees.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

treeInfoKey

protected static final Context.Key<TreeInfo> treeInfoKey

opname

private Name[] opname
The names of all operators.


notExpression

public static final int notExpression
Operator precedences values.

See Also:
Constant Field Values

noPrec

public static final int noPrec
Operator precedences values.

See Also:
Constant Field Values

assignPrec

public static final int assignPrec
Operator precedences values.

See Also:
Constant Field Values

assignopPrec

public static final int assignopPrec
Operator precedences values.

See Also:
Constant Field Values

condPrec

public static final int condPrec
Operator precedences values.

See Also:
Constant Field Values

orPrec

public static final int orPrec
Operator precedences values.

See Also:
Constant Field Values

andPrec

public static final int andPrec
Operator precedences values.

See Also:
Constant Field Values

bitorPrec

public static final int bitorPrec
Operator precedences values.

See Also:
Constant Field Values

bitxorPrec

public static final int bitxorPrec
Operator precedences values.

See Also:
Constant Field Values

bitandPrec

public static final int bitandPrec
Operator precedences values.

See Also:
Constant Field Values

eqPrec

public static final int eqPrec
Operator precedences values.

See Also:
Constant Field Values

ordPrec

public static final int ordPrec
Operator precedences values.

See Also:
Constant Field Values

shiftPrec

public static final int shiftPrec
Operator precedences values.

See Also:
Constant Field Values

addPrec

public static final int addPrec
Operator precedences values.

See Also:
Constant Field Values

mulPrec

public static final int mulPrec
Operator precedences values.

See Also:
Constant Field Values

prefixPrec

public static final int prefixPrec
Operator precedences values.

See Also:
Constant Field Values

postfixPrec

public static final int postfixPrec
Operator precedences values.

See Also:
Constant Field Values

precCount

public static final int precCount
Operator precedences values.

See Also:
Constant Field Values
Constructor Detail

TreeInfo

private TreeInfo(Context context)
Method Detail

instance

public static TreeInfo instance(Context context)

operatorName

public Name operatorName(int tag)
Return name of operator with given tree tag.


isConstructor

public static boolean isConstructor(JCTree tree)
Is tree a constructor declaration?


hasConstructors

public static boolean hasConstructors(List<JCTree> trees)
Is there a constructor declaration in the given list of trees?


isSyntheticInit

public static boolean isSyntheticInit(JCTree stat)
Is statement an initializer for a synthetic field?


calledMethodName

public static Name calledMethodName(JCTree tree)
If the expression is a method call, return the method name, null otherwise.


isSelfCall

public static boolean isSelfCall(JCTree tree)
Is this a call to this or super?


isSuperCall

public static boolean isSuperCall(JCTree tree)
Is this a call to super?


isInitialConstructor

public static boolean isInitialConstructor(JCTree tree)
Is this a constructor whose first (non-synthetic) statement is not of the form this(...)?


firstConstructorCall

public static JCTree.JCMethodInvocation firstConstructorCall(JCTree tree)
Return the first call in a constructor definition.


isNull

public static boolean isNull(JCTree tree)
Return true if a tree represents the null literal.


firstStatPos

public static int firstStatPos(JCTree tree)
The position of the first statement in a block, or the position of the block itself if it is empty.


endPos

public static int endPos(JCTree tree)
The end position of given tree, if it is a block with defined endpos.


getStartPos

public static int getStartPos(JCTree tree)
Get the start position for a tree node. The start position is defined to be the position of the first character of the first token of the node's source text.

Parameters:
tree - The tree node

getEndPos

public static int getEndPos(JCTree tree,
                            java.util.Map<JCTree,java.lang.Integer> endPositions)
The end position of given tree, given a table of end positions generated by the parser


diagEndPos

public static JCDiagnostic.DiagnosticPosition diagEndPos(JCTree tree)
A DiagnosticPosition with the preferred position set to the end position of given tree, if it is a block with defined endpos.


finalizerPos

public static int finalizerPos(JCTree tree)
The position of the finalizer of given try/synchronized statement.


positionFor

public static int positionFor(Symbol sym,
                              JCTree tree)
Find the position for reporting an error about a symbol, where that symbol is defined somewhere in the given tree.


diagnosticPositionFor

public static JCDiagnostic.DiagnosticPosition diagnosticPositionFor(Symbol sym,
                                                                    JCTree tree)
Find the position for reporting an error about a symbol, where that symbol is defined somewhere in the given tree.


declarationFor

public static JCTree declarationFor(Symbol sym,
                                    JCTree tree)
Find the declaration for a symbol, where that symbol is defined somewhere in the given tree.


scopeFor

public static Env<AttrContext> scopeFor(JCTree node,
                                        JCTree.JCCompilationUnit unit)

scopeFor

public static Env<AttrContext> scopeFor(List<JCTree> path)

pathFor

public static List<JCTree> pathFor(JCTree node,
                                   JCTree.JCCompilationUnit unit)

referencedStatement

public static JCTree referencedStatement(JCTree.JCLabeledStatement tree)
Return the statement referenced by a label. If the label refers to a loop or switch, return that switch otherwise return the labelled statement itself


skipParens

public static JCTree.JCExpression skipParens(JCTree.JCExpression tree)
Skip parens and return the enclosed expression


skipParens

public static JCTree skipParens(JCTree tree)
Skip parens and return the enclosed expression


types

public static List<Type> types(List<? extends JCTree> trees)
Return the types of a list of trees.


name

public static Name name(JCTree tree)
If this tree is an identifier or a field or a parameterized type, return its name, otherwise return null.


fullName

public static Name fullName(JCTree tree)
If this tree is a qualified identifier, its return fully qualified name, otherwise return null.


symbolFor

public static Symbol symbolFor(JCTree node)

symbol

public static Symbol symbol(JCTree tree)
If this tree is an identifier or a field, return its symbol, otherwise return null.


nonstaticSelect

public static boolean nonstaticSelect(JCTree tree)
Return true if this is a nonstatic selection.


setSymbol

public static void setSymbol(JCTree tree,
                             Symbol sym)
If this tree is an identifier or a field, set its symbol, otherwise skip.


flags

public static long flags(JCTree tree)
If this tree is a declaration or a block, return its flags field, otherwise return 0.


firstFlag

public static long firstFlag(long flags)
Return first (smallest) flag in `flags': pre: flags != 0


flagNames

public static java.lang.String flagNames(long flags)
Return flags as a string, separated by " ".


opPrec

public static int opPrec(int op)
Map operators to their precedence levels.


tagToKind

static Tree.Kind tagToKind(int tag)