站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

ElementHandle (Java Source) - NetBeans API Javadoc (Current Development Version)

org.netbeans.modules.java.source 0.13.0 1

org.netbeans.api.java.source
Class ElementHandle<T extends Element>

java.lang.Object
  extended by org.netbeans.api.java.source.ElementHandle<T>

public final class ElementHandle<T extends Element>
extends Object

Represents a handle for Element which can be kept and later resolved by another javac. The javac Elements are valid only in a single CompilationTask or a single run of a CancellableTask. A client needing to keep a reference to an Element and use it in another CancellableTask must serialize it into an ElementHandle. Currently not all Elements can be serialized. See create(T) for details.

Typical usage of ElementHandle is as follows:

 final ElementHandle[] elementHandle = new ElementHandle[1];
 javaSource.runUserActionTask(new CancellableTask<CompilationController>() {
     public void run(CompilationController compilationController) {
         compilationController.toPhase(Phase.RESOLVED);
         CompilationUnitTree cu = compilationController.getTree();
         List<? extends Tree> types = getTypeDecls(cu);
         Tree tree = getInterestingElementTree(types);
         Element element = compilationController.getElement(tree);
         elementHandle[0] = ElementHandle.create(element);
    }
 }, true);

 otherJavaSource.runUserActionTask(new CancellableTask<CompilationController>() {
     public void run(CompilationController compilationController) {
         compilationController.toPhase(Phase.RESOLVED);
         Element element = elementHandle[0].resolve(compilationController);
         // ....
    }
 }, true);
 


Method Summary
static
<T extends Element>
ElementHandle<T>
create(T element)
          Factory method for creating ElementHandle.
 boolean equals(Object other)
           
 String getBinaryName()
          Returns a binary name of the TypeElement represented by this ElementHandle.
 ElementKind getKind()
          Returns the ElementKind of this element handle, it is the kind of the Element from which the handle was created.
 String getQualifiedName()
          Returns a qualified name of the TypeElement represented by this ElementHandle.
 int hashCode()
           
 T resolve(CompilationInfo compilationInfo)
          Resolves an Element from the ElementHandle.
 boolean signatureEquals(ElementHandle<? extends Element> handle)
          Tests if the handle has the same signature as the parameter.
 boolean signatureEquals(T element)
          Tests if the handle has this same signature as the parameter.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

resolve

public T resolve(CompilationInfo compilationInfo)
Resolves an Element from the ElementHandle.

Parameters:
compilationInfo - representing the CompilationTask in which the Element should be resolved.
Returns:
resolved subclass of Element or null if the elment does not exist on the classpath/sourcepath of CompilationTask.

signatureEquals

public boolean signatureEquals(ElementHandle<? extends Element> handle)
Tests if the handle has the same signature as the parameter. The handles with the same signatures are resolved into the same element in the same JavaCompiler task, but may be resolved into the different Elements in the different JavaCompiler tasks.

Parameters:
handle - to be checked
Returns:
true if the handles resolve into the same Elements in the same JavaCompiler task.

getBinaryName

public String getBinaryName()
                     throws IllegalStateException
Returns a binary name of the TypeElement represented by this ElementHandle. When the ElementHandle doesn't represent a TypeElement it throws a IllegalStateException

Returns:
the qualified name
Throws:
an - IllegalStateException when this ElementHandle isn't creatred for the TypeElement.
IllegalStateException

getQualifiedName

public String getQualifiedName()
                        throws IllegalStateException
Returns a qualified name of the TypeElement represented by this ElementHandle. When the ElementHandle doesn't represent a TypeElement it throws a IllegalStateException

Returns:
the qualified name
Throws:
an - IllegalStateException when this ElementHandle isn't creatred for the TypeElement.
IllegalStateException

signatureEquals

public boolean signatureEquals(T element)
Tests if the handle has this same signature as the parameter. The handles has the same signatures if it is resolved into the same element in the same JavaCompiler task, but may be resolved into the different Element in the different JavaCompiler task.

Parameters:
element - to be checked
Returns:
true if this handle resolves into the same Element in the same JavaCompiler task.

getKind

public ElementKind getKind()
Returns the ElementKind of this element handle, it is the kind of the Element from which the handle was created.

Returns:
ElementKind

create

public static <T extends Element> ElementHandle<T> create(T element)
                                               throws IllegalArgumentException
Factory method for creating ElementHandle.

Parameters:
element - for which the ElementHandle should be created. Permitted ElementKinds are: ElementKind.PACKAGE, ElementKind.CLASS, ElementKind.INTERFACE, ElementKind.ENUM, ElementKind.ANNOTATION_TYPE, ElementKind.METHOD, ElementKind.CONSTRUCTOR, ElementKind.INSTANCE_INIT, ElementKind.STATIC_INIT, ElementKind.FIELD, and ElementKind.ENUM_CONSTANT.
Returns:
a new ElementHandle
Throws:
IllegalArgumentException - if the element is of an unsupported ElementKind

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

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

org.netbeans.modules.java.source 0.13.0 1

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.