org.netbeans.modules.java.source 0.80.1 17

org.netbeans.api.java.source
Class TreeUtilities

java.lang.Object
  extended by org.netbeans.api.java.source.TreeUtilities

public final class TreeUtilities
extends Object


Field Summary
static Set<Tree.Kind> CLASS_TREE_KINDS
          Tree.Kinds that are represented by ClassTree.
 
Method Summary
 TypeMirror attributeTree(Tree tree, Scope scope)
          Attribute the given tree in the given context.
 Scope attributeTreeTo(Tree tree, Scope scope, Tree to)
          Attribute the given tree until the given to tree is reached.
 CharSequence decodeIdentifier(CharSequence text)
          Decode escapes defined in: http://wikis.sun.com/display/mlvm/ProjectCoinProposal, 3.1-3.9.
 CharSequence encodeIdentifier(CharSequence ident)
          Encode identifier using escapes defined in: http://wikis.sun.com/display/mlvm/ProjectCoinProposal, 3.1-3.9.
 int[] findNameSpan(ClassTree clazz)
          Find span of the ClassTree.getSimpleName() identifier in the source.
 int[] findNameSpan(MemberSelectTree mst)
          Find span of the MemberSelectTree.getIdentifier() identifier in the source.
 int[] findNameSpan(MethodTree method)
          Find span of the MethodTree.getName() identifier in the source.
 int[] findNameSpan(VariableTree var)
          Find span of the VariableTree.getName() identifier in the source.
 StatementTree getBreakContinueTarget(TreePath breakOrContinue)
          Find the target of break or continue.
 List<Comment> getComments(Tree tree, boolean preceding)
          Returns list of comments attached to a given tree.
 Set<TypeMirror> getUncaughtExceptions(TreePath path)
          Returns uncaught exceptions inside the given tree path.
 boolean isAccessible(Scope scope, Element member, TypeMirror type)
          Checks whether the given element is accessible as a member of the given type in a given scope.
 boolean isAnnotation(ClassTree tree)
          Deprecated. since 0.67, Tree.getKind() == Kind.ANNOTATION_TYPE should be used instead.
 boolean isClass(ClassTree tree)
          Deprecated. since 0.67, Tree.getKind() == Kind.CLASS should be used instead.
 boolean isEnum(ClassTree tree)
          Deprecated. since 0.67, Tree.getKind() == Kind.ENUM should be used instead.
 boolean isEnumConstant(VariableTree tree)
          Checks wheteher given variable tree represents an enum constant.
 boolean isInterface(ClassTree tree)
          Deprecated. since 0.67, Tree.getKind() == Kind.INTERFACE should be used instead.
 boolean isStaticContext(Scope scope)
          Checks whether the given scope is in "static" context.
 boolean isSynthetic(TreePath path)
          Returns whether or not the given tree is synthetic - generated by the parser.
 ExpressionTree parseExpression(String expr, SourcePositions[] sourcePositions)
          Parses given expression.
 StatementTree parseStatement(String stmt, SourcePositions[] sourcePositions)
          Parses given statement.
 BlockTree parseStaticBlock(String block, SourcePositions[] sourcePositions)
          Parses given static block.
 TypeMirror parseType(String expr, TypeElement scope)
          Parses given type in given context.
 ExpressionTree parseVariableInitializer(String init, SourcePositions[] sourcePositions)
          Parses given variable initializer.
 TreePath pathFor(int pos)
           
 TreePath pathFor(TreePath path, int pos)
           
 TreePath pathFor(TreePath path, int pos, SourcePositions sourcePositions)
           
 TypeMirror reattributeTree(Tree tree, Scope scope)
           
 Scope reattributeTreeTo(Tree tree, Scope scope, Tree to)
           
 Scope scopeFor(int pos)
          Computes Scope for the given position.
 TokenSequence<org.netbeans.api.java.lexer.JavaTokenId> tokensFor(Tree tree)
          Returns tokens for a given tree.
 TokenSequence<org.netbeans.api.java.lexer.JavaTokenId> tokensFor(Tree tree, SourcePositions sourcePositions)
          Returns tokens for a given tree.
 Tree translate(Tree original, Map<? extends Tree,? extends Tree> original2Translated)
          Returns new tree based on original, such that each visited subtree that occurs as a key in original2Translated is replaced by the corresponding value from original2Translated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_TREE_KINDS

public static final Set<Tree.Kind> CLASS_TREE_KINDS
Tree.Kinds that are represented by ClassTree.

Since:
0.67
Method Detail

isClass

@Deprecated
public boolean isClass(ClassTree tree)
Deprecated. since 0.67, Tree.getKind() == Kind.CLASS should be used instead.

Checks whether the given tree represents a class.


isInterface

@Deprecated
public boolean isInterface(ClassTree tree)
Deprecated. since 0.67, Tree.getKind() == Kind.INTERFACE should be used instead.

Checks whether the given tree represents an interface.


isEnum

@Deprecated
public boolean isEnum(ClassTree tree)
Deprecated. since 0.67, Tree.getKind() == Kind.ENUM should be used instead.

Checks whether the given tree represents an enum.


isEnumConstant

public boolean isEnumConstant(VariableTree tree)
Checks wheteher given variable tree represents an enum constant.


isAnnotation

@Deprecated
public boolean isAnnotation(ClassTree tree)
Deprecated. since 0.67, Tree.getKind() == Kind.ANNOTATION_TYPE should be used instead.

Checks whether the given tree represents an annotation.


isSynthetic

public boolean isSynthetic(TreePath path)
                    throws NullPointerException
Returns whether or not the given tree is synthetic - generated by the parser. Please note that this method does not check trees transitively - a child of a syntetic tree may be considered non-syntetic.

Returns:
true if the given tree is synthetic, false otherwise
Throws:
NullPointerException - if the given tree is null

getComments

public List<Comment> getComments(Tree tree,
                                 boolean preceding)
Returns list of comments attached to a given tree. Can return either preceding or trailing comments.

Parameters:
tree - for which comments should be returned
preceding - true if preceding comments should be returned, false if trailing comments should be returned.
Returns:
list of preceding/trailing comments attached to the given tree

pathFor

public TreePath pathFor(int pos)

pathFor

public TreePath pathFor(TreePath path,
                        int pos)

pathFor

public TreePath pathFor(TreePath path,
                        int pos,
                        SourcePositions sourcePositions)

parseType

public TypeMirror parseType(String expr,
                            TypeElement scope)
Parses given type in given context.

Parameters:
expr - type specification
scope - in which simple names should be resolved
Returns:
parsed TypeMirror or null if the given specification cannot be parsed

parseStatement

public StatementTree parseStatement(String stmt,
                                    SourcePositions[] sourcePositions)
Parses given statement.

Parameters:
stmt - statement code
sourcePositions - return value - new SourcePositions for the new tree
Returns:
parsed StatementTree or null?

parseExpression

public ExpressionTree parseExpression(String expr,
                                      SourcePositions[] sourcePositions)
Parses given expression.

Parameters:
expr - expression code
sourcePositions - return value - new SourcePositions for the new tree
Returns:
parsed ExpressionTree or null?

parseVariableInitializer

public ExpressionTree parseVariableInitializer(String init,
                                               SourcePositions[] sourcePositions)
Parses given variable initializer.

Parameters:
init - initializer code
sourcePositions - return value - new SourcePositions for the new tree
Returns:
parsed ExpressionTree or null?

parseStaticBlock

public BlockTree parseStaticBlock(String block,
                                  SourcePositions[] sourcePositions)
Parses given static block.

Parameters:
block - block code
sourcePositions - return value - new SourcePositions for the new tree
Returns:
parsed BlockTree or null?

scopeFor

public Scope scopeFor(int pos)
Computes Scope for the given position.


attributeTree

public TypeMirror attributeTree(Tree tree,
                                Scope scope)
Attribute the given tree in the given context.


attributeTreeTo

public Scope attributeTreeTo(Tree tree,
                             Scope scope,
                             Tree to)
Attribute the given tree until the given to tree is reached. Returns scope valid at point when to is reached.


reattributeTree

public TypeMirror reattributeTree(Tree tree,
                                  Scope scope)

reattributeTreeTo

public Scope reattributeTreeTo(Tree tree,
                               Scope scope,
                               Tree to)

tokensFor

public TokenSequence<org.netbeans.api.java.lexer.JavaTokenId> tokensFor(Tree tree)
Returns tokens for a given tree.


tokensFor

public TokenSequence<org.netbeans.api.java.lexer.JavaTokenId> tokensFor(Tree tree,
                                                                        SourcePositions sourcePositions)
Returns tokens for a given tree. Uses specified SourcePositions.


isAccessible

public boolean isAccessible(Scope scope,
                            Element member,
                            TypeMirror type)
Checks whether the given element is accessible as a member of the given type in a given scope.

Parameters:
scope - the scope to be checked
member - the member to be checked
type - the type for which to check if the member is accessible
Returns:
true if member is accessible in type

isStaticContext

public boolean isStaticContext(Scope scope)
Checks whether the given scope is in "static" context.


getUncaughtExceptions

public Set<TypeMirror> getUncaughtExceptions(TreePath path)
Returns uncaught exceptions inside the given tree path.


findNameSpan

public int[] findNameSpan(ClassTree clazz)
Find span of the ClassTree.getSimpleName() identifier in the source. Returns starting and ending offset of the name in the source code that was parsed (ie. CompilationInfo.getText(), which may differ from the positions in the source document if it has been already altered.

Parameters:
clazz - class which name should be searched for
Returns:
the span of the name, or null if cannot be found
Since:
0.25

findNameSpan

public int[] findNameSpan(MethodTree method)
Find span of the MethodTree.getName() identifier in the source. Returns starting and ending offset of the name in the source code that was parsed (ie. CompilationInfo.getText(), which may differ from the positions in the source document if it has been already altered.

Parameters:
method - method which name should be searched for
Returns:
the span of the name, or null if cannot be found
Since:
0.25

findNameSpan

public int[] findNameSpan(VariableTree var)
Find span of the VariableTree.getName() identifier in the source. Returns starting and ending offset of the name in the source code that was parsed (ie. CompilationInfo.getText(), which may differ from the positions in the source document if it has been already altered.

Parameters:
var - variable which name should be searched for
Returns:
the span of the name, or null if cannot be found
Since:
0.25

findNameSpan

public int[] findNameSpan(MemberSelectTree mst)
Find span of the MemberSelectTree.getIdentifier() identifier in the source. Returns starting and ending offset of the name in the source code that was parsed (ie. CompilationInfo.getText(), which may differ from the positions in the source document if it has been already altered.

Parameters:
mst - member select which identifier should be searched for
Returns:
the span of the name, or null if cannot be found
Since:
0.25

getBreakContinueTarget

public StatementTree getBreakContinueTarget(TreePath breakOrContinue)
                                     throws IllegalArgumentException
Find the target of break or continue. The given CompilationInfo has to be at least in the JavaSource.Phase.RESOLVED phase.

Parameters:
breakOrContinue - TreePath to the tree that should be inspected. The breakOrContinue.getLeaf().getKind() has to be either Tree.Kind.BREAK or Tree.Kind.CONTINUE, or an IllegalArgumentException is thrown
Returns:
the tree that is the "target" for the given break or continue statement, or null if there is none.
Throws:
IllegalArgumentException - if the given tree is not a break or continue tree or if the given CompilationInfo is not in the JavaSource.Phase.RESOLVED phase.
Since:
0.16

decodeIdentifier

@NonNull
public CharSequence decodeIdentifier(@NonNull
                                             CharSequence text)
Decode escapes defined in: http://wikis.sun.com/display/mlvm/ProjectCoinProposal, 3.1-3.9. Must be a full token text, including possible #".

Parameters:
text - to decode
Returns:
decoded escapes from the identifier
Since:
0.56
See Also:
http://wikis.sun.com/display/mlvm/ProjectCoinProposal

encodeIdentifier

@NonNull
public CharSequence encodeIdentifier(@NonNull
                                             CharSequence ident)
Encode identifier using escapes defined in: http://wikis.sun.com/display/mlvm/ProjectCoinProposal, 3.1-3.9.

Parameters:
text - to encode
Returns:
encoded identifier, including #" if necessary
Since:
0.56
See Also:
http://wikis.sun.com/display/mlvm/ProjectCoinProposal

translate

@NonNull
public Tree translate(@NonNull
                              Tree original,
                              @NonNull
                              Map<? extends Tree,? extends Tree> original2Translated)
Returns new tree based on original, such that each visited subtree that occurs as a key in original2Translated is replaced by the corresponding value from original2Translated. The value is then translated using the same algorithm. Each key from original2Translated is used at most once. Unless the provided original tree is a key in original2Translated, the resulting tree has the same type as original. Principally, the method inner workings are:
 translate(original, original2Translated) {
      if (original2Translated.containsKey(original))
          return translate(original2Translated.remove(original));
      newTree = copyOf(original);
      for (Tree child : allChildrenOf(original)) {
          newTree.replace(child, translate(child, original2Translated));
      }
      return newTree;
 }
 

Parameters:
original - the tree that should be translated
original2Translated - map containing trees that should be translated
Returns:
translated tree.
Since:
0.64

org.netbeans.modules.java.source 0.80.1 17

Built on December 5 2011.  |  Portions Copyright 1997-2011 Sun Microsystems, Inc. All rights reserved.