org.netbeans.modules.java.source 0.104.0 23

org.netbeans.api.java.source
Class WorkingCopy

java.lang.Object
  extended by org.netbeans.api.java.source.CompilationInfo
      extended by org.netbeans.api.java.source.CompilationController
          extended by org.netbeans.api.java.source.WorkingCopy

public class WorkingCopy
extends CompilationController

XXX: extends CompilationController now, finish method delegation


Nested Class Summary
 
Nested classes/interfaces inherited from class org.netbeans.api.java.source.CompilationInfo
CompilationInfo.CacheClearPolicy
 
Method Summary
static WorkingCopy get(Parser.Result result)
          Returns an instance of the WorkingCopy for given Parser.Result if it is a result of a java parser.
 TreeMaker getTreeMaker()
           
 Tree resolveRewriteTarget(Tree in)
          Returns the tree into which the given tree was rewritten using the rewrite(com.sun.source.tree.Tree, com.sun.source.tree.Tree) method, transitively.
 void rewrite(Tree oldTree, Tree newTree)
          Replaces the original tree oldTree with the new one - newTree.
 void rewriteInComment(int start, int length, String newText)
          Replace a part of a comment token with the given text.
 void tag(Tree t, Object tag)
          Tags a tree.
 JavaSource.Phase toPhase(JavaSource.Phase phase)
          Moves the state to required phase.
 
Methods inherited from class org.netbeans.api.java.source.CompilationController
doInvalidate
 
Methods inherited from class org.netbeans.api.java.source.CompilationInfo
getCachedValue, getChangedTree, getClasspathInfo, getCompilationUnit, getDiagnostics, getDocument, getElements, getElementUtilities, getFileObject, getJavaSource, getPhase, getPositionConverter, getSnapshot, getSourceVersion, getText, getTokenHierarchy, getTopLevelElements, getTrees, getTreeUtilities, getTypes, getTypeUtilities, putCachedValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

get

@NullUnknown
public static WorkingCopy get(@NonNull
                                          Parser.Result result)
Returns an instance of the WorkingCopy for given Parser.Result if it is a result of a java parser.

Parameters:
result - for which the WorkingCopy should be returned.
Returns:
a WorkingCopy or null when the given result is not a result of java parsing.
Since:
0.42

toPhase

@NonNull
public JavaSource.Phase toPhase(@NonNull
                                        JavaSource.Phase phase)
                         throws IOException
Description copied from class: CompilationController
Moves the state to required phase. If given state was already reached the state is not changed. The method will throw exception if a state is illegal required. Acceptable parameters for thid method are
  • api.java.source.JavaSource.Phase.PARSED
  • api.java.source.JavaSource.Phase.ELEMENTS_RESOLVED
  • api.java.source.JavaSource.Phase.RESOLVED
  • api.java.source.JavaSource.Phase.UP_TO_DATE

    Overrides:
    toPhase in class CompilationController
    Parameters:
    phase - The required phase
    Returns:
    the reached state
    Throws:
    IOException - when the file cannot be red

  • getTreeMaker

    @NonNull
    public TreeMaker getTreeMaker()
                           throws IllegalStateException
    Throws:
    IllegalStateException

    rewrite

    public void rewrite(@NullAllowed
                        Tree oldTree,
                        @NonNull
                        Tree newTree)
    Replaces the original tree oldTree with the new one - newTree.

    To create a new file, use rewrite(null, compilationUnitTree). Use GeneratorUtilities.createFromTemplate() to create a new compilation unit tree from a template.

    newTree cannot be null, use methods in TreeMaker for tree element removal. If oldTree is null, newTree must be of kind COMPILATION_UNIT.

    Parameters:
    oldTree - tree to be replaced, use tree already represented in source code. null to create a new file.
    newTree - new tree, either created by TreeMaker or obtained from different place. null values are not allowed.
    Throws:
    IllegalStateException - if toPhase() method was not called before.
    IllegalArgumentException - when null was passed to the method.
    See Also:
    GeneratorUtilities.createFromTemplate(org.openide.filesystems.FileObject, java.lang.String, javax.lang.model.element.ElementKind), TreeMaker

    rewriteInComment

    public void rewriteInComment(int start,
                                 int length,
                                 @NonNull
                                 String newText)
                          throws IllegalArgumentException
    Replace a part of a comment token with the given text. Please note that this is a special purpose method to handle eg. "Apply Rename in Comments" option in the Rename refactoring. It is caller's responsibility to ensure that replacements done by this method will not clash with replacements done by the general-purpose method rewrite(Tree,Tree).

    Parameters:
    start - absolute offset in the original text to start the replacement
    length - how many characters should be deleted from the original text
    newText - new text to be inserted at the specified offset
    Throws:
    IllegalArgumentException - when an attempt is made to replace non-comment text
    Since:
    0.23

    tag

    public void tag(@NonNull
                    Tree t,
                    @NonNull
                    Object tag)
    Tags a tree. Used in ModificationResult to determine position of tree inside document.

    Parameters:
    t - the tree to be tagged
    tag - an Object used as tag
    Since:
    0.37

    resolveRewriteTarget

    @NonNull
    public Tree resolveRewriteTarget(@NonNull
                                             Tree in)
    Returns the tree into which the given tree was rewritten using the rewrite(com.sun.source.tree.Tree, com.sun.source.tree.Tree) method, transitively. Will return the input tree if the input tree was never passed as the first parameter of the rewrite(com.sun.source.tree.Tree, com.sun.source.tree.Tree) method.

    Note that the returned tree will be exactly equivalent to a tree passed as the second parameter to rewrite(com.sun.source.tree.Tree, com.sun.source.tree.Tree). No attribution or other information will be added (or removed) to (or from) the tree.

    Parameters:
    in - the tree to inspect
    Returns:
    tree into which the given tree was rewritten using the rewrite(com.sun.source.tree.Tree, com.sun.source.tree.Tree) method, transitively
    Since:
    0.102

    org.netbeans.modules.java.source 0.104.0 23

    Built on May 22 2012.  |  Portions Copyright 1997-2012 Oracle. All rights reserved.