org.netbeans.modules.java.source 0.80.1 17

org.netbeans.api.java.source
Class TreePathHandle

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

public final class TreePathHandle
extends Object

Represents a handle for TreePath which can be kept and later resolved by another javac. The Javac Elements are valid only in the single CompilationTask or single run of the CancellableTask. If the client needs to keep a reference to the TreePath and use it in the other CancellableTask he has to serialize it into the TreePathHandle.

Typical usage of TreePathHandle enclElIsCorrespondingEl:

                                                                                                                                                                                                                       
 final TreePathHandle[] tpHandle = new TreePathHandle[1];                                                                                                                                                                    
 javaSource.runCompileControlTask(new CancellableTask() {                                                                                                                                             
     public void run(CompilationController compilationController) {                                                                                                                                                          
         parameter.toPhase(Phase.RESOLVED);                                                                                                                                                                                  
         CompilationUnitTree cu = compilationController.getTree ();                                                                                                                                                          
         TreePath treePath = getInterestingTreePath (cu);                                                                                                                                                                    
         treePathHandle[0] = TreePathHandle.create (element, compilationController);                                                                                                                                         
    }                                                                                                                                                                                                                        
 },priority);                                                                                                                                                                                                                
                                                                                                                                                                                                                             
 otherJavaSource.runCompileControlTask(new CancellableTask() {                                                                                                                                        
     public void run(CompilationController compilationController) {                                                                                                                                                          
         parameter.toPhase(Phase.RESOLVED);                                                                                                                                                                                  
         TreePath treePath = treePathHanlde[0].resolve (compilationController);                                                                                                                                              
         ....                                                                                                                                                                                                                
    }                                                                                                                                                                                                                        
 },priority);                                                                                                                                                                                                                
 


Method Summary
static TreePathHandle create(Element element, CompilationInfo info)
          Factory method for creating TreePathHandle.
static TreePathHandle create(TreePath treePath, CompilationInfo info)
          Factory method for creating TreePathHandle.
 boolean equals(Object obj)
           
static TreePathHandle from(ElementHandle<?> handle, ClasspathInfo cpInfo)
          Constructs a TreePathHandle that corresponds to the given ElementHandle.
 FileObject getFileObject()
          getter for FileObject from give TreePathHandle
 Tree.Kind getKind()
          Returns the Tree.Kind of this TreePathHandle, it returns the kind of the Tree from which the handle was created.
 int hashCode()
           
 TreePath resolve(CompilationInfo compilationInfo)
          Resolves an TreePath from the TreePathHandle.
 Element resolveElement(CompilationInfo info)
          Resolves an Element from the TreePathHandle.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getFileObject

@CheckForNull
public FileObject getFileObject()
getter for FileObject from give TreePathHandle

Returns:
FileObject for which was this handle created, or null if not available

resolve

public TreePath resolve(CompilationInfo compilationInfo)
                 throws IllegalArgumentException
Resolves an TreePath from the TreePathHandle.

Parameters:
compilationInfo - representing the CompilationTask
Returns:
resolved subclass of Element or null if the element does not exist on the classpath/sourcepath of CompilationTask.
Throws:
IllegalArgumentException - when this TreePathHandle is not created for a source represented by the compilationInfo.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

resolveElement

public Element resolveElement(CompilationInfo info)
Resolves an Element from the TreePathHandle.

Parameters:
compilationInfo - representing the CompilationTask
Returns:
resolved subclass of Element or null if the element does not exist on the classpath/sourcepath of CompilationTask.

getKind

public Tree.Kind getKind()
Returns the Tree.Kind of this TreePathHandle, it returns the kind of the Tree from which the handle was created.

Returns:
Tree.Kind

create

public static TreePathHandle create(TreePath treePath,
                                    CompilationInfo info)
                             throws IllegalArgumentException
Factory method for creating TreePathHandle.

Parameters:
treePath - for which the TrePathHandle should be created.
info -
Returns:
a new TreePathHandle
Throws:
IllegalArgumentException - if arguments are not supported

create

public static TreePathHandle create(Element element,
                                    CompilationInfo info)
                             throws IllegalArgumentException
Factory method for creating TreePathHandle.

Parameters:
element - for which the TrePathHandle should be created.
info -
Returns:
a new TreePathHandle
Throws:
IllegalArgumentException - if arguments are not supported

from

@NonNull
public static TreePathHandle from(@NonNull
                                          ElementHandle<?> handle,
                                          @NonNull
                                          ClasspathInfo cpInfo)
Constructs a TreePathHandle that corresponds to the given ElementHandle.

Parameters:
handle - an ElementHandle for which the TreePathHandle should be constructed
cpInfo - a classpath which is supposed to contain the element described by given the ElementHandle
Returns:
a newly constructed TreePathHandle
Since:
0.79

toString

public String toString()
Overrides:
toString in class Object

org.netbeans.modules.java.source 0.80.1 17

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