public final class TreePathHandle extends Object
TreePath
which can be kept and later resolved
by another javac. The Javac Element
s 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);
Modifier and Type | Method and Description |
---|---|
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 . |
ElementHandle |
getElementHandle()
returns
ElemntHandle corresponding to this TreePathHandle |
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() |
@CheckForNull public FileObject getFileObject()
null
if not availablepublic TreePath resolve(CompilationInfo compilationInfo) throws IllegalArgumentException
TreePath
from the TreePathHandle
.compilationInfo
- representing the CompilationTask
Element
or null if the element does not exist on
the classpath/sourcepath of CompilationTask
.IllegalArgumentException
- when this TreePathHandle
is not created for a source
represented by the compilationInfo.public Element resolveElement(CompilationInfo info)
Element
from the TreePathHandle
.compilationInfo
- representing the CompilationTask
Element
or null if the element does not exist on
the classpath/sourcepath of CompilationTask
.@CheckForNull public ElementHandle getElementHandle()
ElemntHandle
corresponding to this TreePathHandle
ElementHandle
or null if this TreePathHandle
does
not represent any Element
public Tree.Kind getKind()
Tree.Kind
of this TreePathHandle,
it returns the kind of the Tree
from which the handle
was created.Tree.Kind
public static TreePathHandle create(TreePath treePath, CompilationInfo info) throws IllegalArgumentException
TreePathHandle
.treePath
- for which the TrePathHandle
should be created.info
- TreePathHandle
IllegalArgumentException
- if arguments are not supportedpublic static TreePathHandle create(Element element, CompilationInfo info) throws IllegalArgumentException
TreePathHandle
.element
- for which the TrePathHandle
should be created.info
- TreePathHandle
IllegalArgumentException
- if arguments are not supported@NonNull public static TreePathHandle from(@NonNull ElementHandle<?> handle, @NonNull ClasspathInfo cpInfo)
TreePathHandle
that corresponds to the given ElementHandle
.handle
- an ElementHandle
for which the TreePathHandle
should be constructedcpInfo
- a classpath which is supposed to contain the element described by given the ElementHandle
TreePathHandle