public final class TypeMirrorHandle<T extends TypeMirror> extends Object
TypeMirror
which can be kept and later resolved
by another javac. The Javac TypeMirror
s are valid only in the single
JavaCompiler.CompilationTask
or single run of the
CancellableTask
. If the client needs to
keep a reference to the TypeMirror
and use it in the other CancellableTask
he has to serialize it into the TypeMirrorHandle
.
Typical usage of TypeMirrorHandle is:
final TypeMirrorHandle[] typeMirrorHandle = new TypeMirrorHandle[1];
javaSource.runCompileControlTask(new CancellableTask<CompilationController>() {
public void run(CompilationController compilationController) {
parameter.toPhase(Phase.RESOLVED);
CompilationUnitTree cu = compilationController.getTree ();
TypeMirror type = getInterestingType(cu);
typeMirrorHandle[0] = TypeMirrorHandle.create (type);
}
},priority);
otherJavaSource.runCompileControlTask(new CancellableTask<CompilationController>() {
public void run(CompilationController compilationController) {
parameter.toPhase(Phase.RESOLVED);
TypeMirror type = typeMirrorHandle[0].resolve (compilationController);
....
}
},priority);
TypeMirror
kinds
are supported by handle.
The unsupported kinds
are: TypeKind.EXECUTABLE
, TypeKind.OTHER
,
and TypeKind.PACKAGE
.Modifier and Type | Method and Description |
---|---|
static <T extends TypeMirror> |
create(T tm)
Factory method for creating
TypeMirrorHandle . |
TypeKind |
getKind()
Returns the
TypeKind of this handle,
it is the kind of the TypeMirror from which the handle
was created. |
T |
resolve(CompilationInfo info)
Resolves an
TypeMirror from the TypeMirrorHandle . |
@NonNull public static <T extends TypeMirror> TypeMirrorHandle<T> create(@NonNull T tm)
TypeMirrorHandle
.tm
- for which the TypeMirrorHandle
should be created.
Not all the TypeMirror
kinds
are currently supported.
The unsupported kinds
are: TypeKind.EXECUTABLE
, TypeKind.OTHER
,
and TypeKind.PACKAGE
.TypeMirrorHandle
IllegalArgumentException
- if the TypeMirror
is of an unsupported
TypeKind
.public T resolve(@NonNull CompilationInfo info)
TypeMirror
from the TypeMirrorHandle
.info
- representing the JavaCompiler.CompilationTask
in which the TypeMirror
should be resolved.TypeMirror
or null if the type cannot be
resolved in this JavaCompiler.CompilationTask
.@NonNull public TypeKind getKind()
TypeKind
of this handle,
it is the kind of the TypeMirror
from which the handle
was created.TypeKind