org.openide.src
Class ClassElement

java.lang.Object
  extended byorg.openide.src.Element
      extended byorg.openide.src.MemberElement
          extended byorg.openide.src.ClassElement
All Implemented Interfaces:
Cloneable, ElementProperties, Node.Cookie, Serializable

public final class ClassElement
extends MemberElement

Element that describes one class. Note that this is a member element--in fact, it may be either a top-level class (held in a source element), or a named inner class (held in another class element).

Note: If you add an element to a ClassElement, the ClassElement crates its own copy of the passed element. If you perform subsequent modifications to the object passed to addMethod (addField, addWhatever), the original element will be updated, not the one created as a result of the add() operation.

See Also:
Serialized Form

Nested Class Summary
static interface ClassElement.Finder
          Provides a "finder" for class elements.
static interface ClassElement.Impl
          Pluggable behavior for class elements.
 
Nested classes inherited from class org.openide.src.Element
Element.Impl2
 
Field Summary
static boolean CLASS
          Constant indicating that the class is a real class.
static boolean INTERFACE
          Constant indicating that the class is an interface.
static Identifier ROOT_OBJECT
          Default class to extend.
 
Fields inherited from class org.openide.src.Element
impl, impl2
 
Fields inherited from interface org.openide.src.ElementProperties
PROP_ALL_CLASSES, PROP_BODY, PROP_CLASS_OR_INTERFACE, PROP_CLASSES, PROP_CONSTRUCTORS, PROP_EXCEPTIONS, PROP_FIELDS, PROP_IMPORTS, PROP_INIT_VALUE, PROP_INITIALIZERS, PROP_INTERFACES, PROP_JAVADOC, PROP_MEMBERS, PROP_METHODS, PROP_MODIFIERS, PROP_NAME, PROP_PACKAGE, PROP_PARAMETERS, PROP_RETURN, PROP_STATIC, PROP_STATUS, PROP_SUPERCLASS, PROP_TYPE, PROP_VALID
 
Constructor Summary
ClassElement()
          Create a new class element in memory.
ClassElement(ClassElement.Impl impl, ClassElement clazz)
          Factory constructor for defining embedded classes.
ClassElement(ClassElement.Impl impl, SourceElement source)
          Factory constructor for defining top level classes.
 
Method Summary
 void addClass(ClassElement el)
          Add a new inner class to this class.
 void addClasses(ClassElement[] els)
          Add some new inner classes to this class.
 void addConstructor(ConstructorElement el)
          Add a constructor to this class.
 void addConstructors(ConstructorElement[] els)
          Add some constructors to this class.
 void addField(FieldElement el)
          Add a new field to the class.
 void addFields(FieldElement[] els)
          Add some new fields to the class.
 void addInitializer(InitializerElement el)
          Add a new initializer block to this class.
 void addInitializers(InitializerElement[] els)
          Add some initializer blocks to this class.
 void addInterface(Identifier in)
          Add an interface to this class.
 void addInterfaces(Identifier[] ins)
          Add some interfaces to this class.
 void addMethod(MethodElement el)
          Add a method to this class.
 void addMethods(MethodElement[] els)
          Add some methods to this class.
 Object clone()
          Clone this element.
static ClassElement forClass(Class clazz)
          Deprecated. This method variant can no longer work. Use forClass(Class,FileObject) instead.
static ClassElement forClass(Class clazz, FileObject reference)
          Search for a class element throughout the system.
static ClassElement forName(String name)
          Deprecated. This method variant can no longer work. Use forName(String,FileObject) instead.
static ClassElement forName(String name, FileObject reference)
          Search for a class element throughout the system.
 ClassElement getClass(Identifier name)
          Find an inner class by name.
 ClassElement[] getClasses()
          Get all inner classes for this class.
 ConstructorElement getConstructor(Type[] arguments)
          Find a constructor by signature.
 ConstructorElement[] getConstructors()
          Get all constructors in this class.
 FieldElement getField(Identifier name)
          Find a field by name.
 FieldElement[] getFields()
          Get all fields in this class.
 InitializerElement[] getInitializers()
          Get all the initializer blocks for this class.
 Identifier[] getInterfaces()
          Get all interfaces for this class.
 JavaDoc.Class getJavaDoc()
          Get the class documentation.
 MethodElement getMethod(Identifier name, Type[] arguments)
          Find a method by signature.
 MethodElement[] getMethods()
          Get all methods in this class.
 int getModifiersMask()
          Get the permitted modifiers for this type of element.
 String getSignature()
          Returns the signature of the class as used internally in the JVM.
 SourceElement getSource()
          Get the source element of this class.
 Identifier getSuperclass()
          Get the superclass of this class.
 String getVMName()
          Creates a name of the class usable in the JVM.
 boolean hasMainMethod()
          Test whether this class has a declared main method and so may be executed directly.
 boolean isClass()
          Test whether this is really a class.
 boolean isClassOrInterface()
          Test whether this is really a class, or an interface.
 boolean isDeclaredAsApplet()
          Test whether this class is an applet.
 boolean isDeclaredAsJavaBean()
          Test whether this class is a JavaBean.
 boolean isInner()
          Test if this is an inner class.
 boolean isInterface()
          Test whether this is an interface.
 void print(ElementPrinter printer)
          Print this element (and all its subelements) into an element printer.
static void register(ClassElement.Finder f)
          Register a new finder for locating class elements.
 void removeClass(ClassElement el)
          Remove an inner class from this class.
 void removeClasses(ClassElement[] els)
          Remove some inner classes from this class.
 void removeConstructor(ConstructorElement el)
          Remove a constructor from this class.
 void removeConstructors(ConstructorElement[] els)
          Remove some constructors from this class.
 void removeField(FieldElement el)
          Remove a field from the class.
 void removeFields(FieldElement[] els)
          Remove some fields from the class.
 void removeInitializer(InitializerElement el)
          Remove an initializer block from this class.
 void removeInitializers(InitializerElement[] els)
          Remove some initializer blocks from this class.
 void removeInterface(Identifier in)
          Remove an interface from this class.
 void removeInterface(Identifier[] ins)
          Deprecated. the method's name is incorrect; please use removeInterfaces(ins) instead.
 void removeInterfaces(Identifier in)
          Deprecated. the method's name is incorrect; please use removeInterface(i) instead.
 void removeInterfaces(Identifier[] ins)
          Remove some interfaces from this class.
 void removeMethod(MethodElement el)
          Remove a method from this class.
 void removeMethods(MethodElement[] els)
          Remove some methods from this class.
 void setClasses(ClassElement[] els)
          Set the inner classes for this class.
 void setClassOrInterface(boolean isClass)
          Set whether this is really a class, or an interface.
 void setConstructors(ConstructorElement[] els)
          Set the constructors for this class.
 void setFields(FieldElement[] els)
          Set the fields for this class.
 void setInitializers(InitializerElement[] els)
          Set the initializer blocks for this class.
 void setInterfaces(Identifier[] ids)
          Set the interfaces for this class.
 void setMethods(MethodElement[] els)
          Set the methods for this class.
 void setName(Identifier name)
          Set the name of this member.
 void setSuperclass(Identifier superClass)
          Set the superclass of this class.
static void unregister(ClassElement.Finder f)
          Unregister a finder for locating class elements.
 
Methods inherited from class org.openide.src.MemberElement
getDeclaringClass, getModifiers, getName, setModifiers
 
Methods inherited from class org.openide.src.Element
addPropertyChangeListener, addVetoableChangeListener, getCookie, markCurrent, removePropertyChangeListener, removeVetoableChangeListener, toString, writeReplace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS

public static final boolean CLASS
Constant indicating that the class is a real class.

See Also:
isClassOrInterface(), Constant Field Values

INTERFACE

public static final boolean INTERFACE
Constant indicating that the class is an interface.

See Also:
isClassOrInterface(), Constant Field Values

ROOT_OBJECT

public static final Identifier ROOT_OBJECT
Default class to extend. That is, Object.

Constructor Detail

ClassElement

public ClassElement()
Create a new class element in memory.


ClassElement

public ClassElement(ClassElement.Impl impl,
                    ClassElement clazz)
Factory constructor for defining embedded classes.

Parameters:
impl - implementation of functionality
clazz - the declaring class, or null

ClassElement

public ClassElement(ClassElement.Impl impl,
                    SourceElement source)
Factory constructor for defining top level classes.

Parameters:
impl - implementation of functionality
source - the source file this class is contained in, or null
Method Detail

clone

public Object clone()
Clone this element.

Overrides:
clone in class MemberElement
Returns:
new element with the same values as the original, but represented in memory

getSource

public SourceElement getSource()
Get the source element of this class.

Returns:
the source, or null if the class is not attached to any source

setClassOrInterface

public void setClassOrInterface(boolean isClass)
                         throws SourceException
Set whether this is really a class, or an interface.

Parameters:
isClass - one of CLASS or INTERFACE
Throws:
SourceException - if impossible

isClassOrInterface

public boolean isClassOrInterface()
Test whether this is really a class, or an interface.

Returns:
one of CLASS or INTERFACE

isClass

public boolean isClass()
Test whether this is really a class.

Returns:
true if so
See Also:
isClassOrInterface()

isInterface

public boolean isInterface()
Test whether this is an interface.

Returns:
true if so
See Also:
isClassOrInterface()

isInner

public boolean isInner()
Test if this is an inner class. If so, it has a declaring class.

Returns:
true if so
See Also:
ClassElement(ClassElement.Impl, ClassElement)

getModifiersMask

public int getModifiersMask()
Description copied from class: MemberElement
Get the permitted modifiers for this type of element.

Specified by:
getModifiersMask in class MemberElement
Returns:
disjunction of constants from java.lang.reflect.Modifier

setName

public final void setName(Identifier name)
                   throws SourceException
Set the name of this member. When naming an inner class, use dots instead dollar signs to separate inner class' name from outer class' one - $ is a valid character in an identifier. If you pass an Identifier with FQN "Foo$Bar", you will in fact create a ClassElement, which represents a top-level class named "Foo$Bar" instead of inner class "Bar" nested in top-level class "Foo"

Overrides:
setName in class MemberElement
Parameters:
name - the name
Throws:
SourceException - if impossible

getSignature

public final String getSignature()
Returns the signature of the class as used internally in the JVM. Any . are replaced by forward slashes as required by the VM specs.

Returns:
signature of the class.

getVMName

public final String getVMName()
Creates a name of the class usable in the JVM. The method returns a fully qualified name of the class in a form accepted directly by the Java VM, usable for example in java.lang.Class.forName(). This differs from ClassElement.getName().getFullName() in that inner class names are separated by '$' rather than by '.'

Returns:
JVM-compatible fully qualified class name.

setSuperclass

public void setSuperclass(Identifier superClass)
                   throws SourceException
Set the superclass of this class.

Parameters:
superClass - the superclass
Throws:
SourceException - if that is impossible

getSuperclass

public Identifier getSuperclass()
Get the superclass of this class.

Returns:
superclass identifier, or null (for interfaces, or possibly for classes with superclass Object)

addInitializer

public void addInitializer(InitializerElement el)
                    throws SourceException
Add a new initializer block to this class.

Parameters:
el - the block to add
Throws:
SourceException - if impossible

addInitializers

public void addInitializers(InitializerElement[] els)
                     throws SourceException
Add some initializer blocks to this class.

Parameters:
els - the blocks to add
Throws:
SourceException - if impossible

removeInitializer

public void removeInitializer(InitializerElement el)
                       throws SourceException
Remove an initializer block from this class.

Parameters:
el - the block to remove
Throws:
SourceException - if impossible

removeInitializers

public void removeInitializers(InitializerElement[] els)
                        throws SourceException
Remove some initializer blocks from this class.

Parameters:
els - the blocks to remove
Throws:
SourceException - if impossible

setInitializers

public void setInitializers(InitializerElement[] els)
                     throws SourceException
Set the initializer blocks for this class. Any previous ones are just removed.

Parameters:
els - the new blocks
Throws:
SourceException - if impossible

getInitializers

public InitializerElement[] getInitializers()
Get all the initializer blocks for this class.

Returns:
all the blocks

addField

public void addField(FieldElement el)
              throws SourceException
Add a new field to the class.

Parameters:
el - the field to add
Throws:
SourceException - if impossible

addFields

public void addFields(FieldElement[] els)
               throws SourceException
Add some new fields to the class.

Parameters:
els - the fields to add
Throws:
SourceException - if impossible

removeField

public void removeField(FieldElement el)
                 throws SourceException
Remove a field from the class.

Parameters:
el - the field to remove
Throws:
SourceException - if impossible

removeFields

public void removeFields(FieldElement[] els)
                  throws SourceException
Remove some fields from the class.

Parameters:
els - the fields to remove
Throws:
SourceException - if impossible

setFields

public void setFields(FieldElement[] els)
               throws SourceException
Set the fields for this class. Previous fields are removed.

Parameters:
els - the new fields
Throws:
SourceException - if impossible

getFields

public FieldElement[] getFields()
Get all fields in this class.

Returns:
the fields

getField

public FieldElement getField(Identifier name)
Find a field by name.

Parameters:
name - the name of the field to look for
Returns:
the element or null if not found

addMethod

public void addMethod(MethodElement el)
               throws SourceException
Add a method to this class. Note that the `el' object still refers to the original method while the ClassElement creates its own version/copy of it. Subsequent changes made to `el' will not affect the method newly created in this ClassElement, rather the original will be modified.

Parameters:
el - the method to add
Throws:
SourceException - if impossible

addMethods

public void addMethods(MethodElement[] els)
                throws SourceException
Add some methods to this class. Note that the `els' objects still refer to original methods while the ClassElement creates its own versions/copies of them. Subsequent changes made to the passed objects will not affect the methods newly created in this ClassElement, rather the originals will be modified.

Parameters:
els - the methods to add
Throws:
SourceException - if impossible

removeMethod

public void removeMethod(MethodElement el)
                  throws SourceException
Remove a method from this class.

Parameters:
el - the method to remove
Throws:
SourceException - if impossible

removeMethods

public void removeMethods(MethodElement[] els)
                   throws SourceException
Remove some methods from this class.

Parameters:
els - the methods to remove
Throws:
SourceException - if impossible

setMethods

public void setMethods(MethodElement[] els)
                throws SourceException
Set the methods for this class. The old ones are removed.

Parameters:
els - the new methods
Throws:
SourceException - if impossible

getMethods

public MethodElement[] getMethods()
Get all methods in this class.

Returns:
the methods

getMethod

public MethodElement getMethod(Identifier name,
                               Type[] arguments)
Find a method by signature.

Parameters:
name - the method name to look for
arguments - the argument types to look for
Returns:
the method, or null if it was not found

addConstructor

public void addConstructor(ConstructorElement el)
                    throws SourceException
Add a constructor to this class.

Parameters:
el - the constructor to add
Throws:
SourceException - if impossible

addConstructors

public void addConstructors(ConstructorElement[] els)
                     throws SourceException
Add some constructors to this class.

Parameters:
els - the constructors to add
Throws:
SourceException - if impossible

removeConstructor

public void removeConstructor(ConstructorElement el)
                       throws SourceException
Remove a constructor from this class.

Parameters:
el - the constructor to remove
Throws:
SourceException - if impossible

removeConstructors

public void removeConstructors(ConstructorElement[] els)
                        throws SourceException
Remove some constructors from this class.

Parameters:
els - the constructors to remove
Throws:
SourceException - if impossible

setConstructors

public void setConstructors(ConstructorElement[] els)
                     throws SourceException
Set the constructors for this class. The old ones are replaced.

Parameters:
els - the new constructors
Throws:
SourceException - if impossible

getConstructors

public ConstructorElement[] getConstructors()
Get all constructors in this class.

Returns:
the constructors

getConstructor

public ConstructorElement getConstructor(Type[] arguments)
Find a constructor by signature.

Parameters:
arguments - the argument types to look for
Returns:
the constructor, or null if it does not exist

addClass

public void addClass(ClassElement el)
              throws SourceException
Add a new inner class to this class.

Parameters:
el - the inner class to add
Throws:
SourceException - if impossible

addClasses

public void addClasses(ClassElement[] els)
                throws SourceException
Add some new inner classes to this class.

Parameters:
els - the inner classes to add
Throws:
SourceException - if impossible

removeClass

public void removeClass(ClassElement el)
                 throws SourceException
Remove an inner class from this class.

Parameters:
el - the inner class to remove
Throws:
SourceException - if impossible

removeClasses

public void removeClasses(ClassElement[] els)
                   throws SourceException
Remove some inner classes from this class.

Parameters:
els - the inner classes to remove
Throws:
SourceException - if impossible

setClasses

public void setClasses(ClassElement[] els)
                throws SourceException
Set the inner classes for this class. The old ones are replaced.

Parameters:
els - the new inner classes
Throws:
SourceException - if impossible

getClasses

public ClassElement[] getClasses()
Get all inner classes for this class.

Returns:
the inner classes

getClass

public ClassElement getClass(Identifier name)
Find an inner class by name.

Parameters:
name - the name to look for
Returns:
the inner class, or null if it does not exist

addInterface

public void addInterface(Identifier in)
                  throws SourceException
Add an interface to this class. I.e., one which this class will implement.

Parameters:
in - the interface to add, by name
Throws:
SourceException - if impossible

addInterfaces

public void addInterfaces(Identifier[] ins)
                   throws SourceException
Add some interfaces to this class.

Parameters:
ins - the interfaces to add, by name
Throws:
SourceException - if impossible

removeInterface

public void removeInterface(Identifier in)
                     throws SourceException
Remove an interface from this class.

Parameters:
in - the interface to remove. by name
Throws:
SourceException - if impossible

removeInterfaces

public void removeInterfaces(Identifier in)
                      throws SourceException
Deprecated. the method's name is incorrect; please use removeInterface(i) instead.

Remove an interface from this class.

Parameters:
in - the interface to remove. by name
Throws:
SourceException - if impossible

removeInterfaces

public void removeInterfaces(Identifier[] ins)
                      throws SourceException
Remove some interfaces from this class.

Parameters:
ins - the interfaces to remove, by name
Throws:
SourceException - if impossible

removeInterface

public void removeInterface(Identifier[] ins)
                     throws SourceException
Deprecated. the method's name is incorrect; please use removeInterfaces(ins) instead.

Remove some interfaces from this class.

Parameters:
ins - the interfaces to remove, by name
Throws:
SourceException - if impossible

setInterfaces

public void setInterfaces(Identifier[] ids)
                   throws SourceException
Set the interfaces for this class. The old ones are replaced.

Parameters:
ids - the new interfaces, by name
Throws:
SourceException - if impossible

getInterfaces

public Identifier[] getInterfaces()
Get all interfaces for this class. I.e., all interfaces which this class implements (directly), or (if an interface) all interfaces which it extends (directly).

Returns:
the interfaces

getJavaDoc

public JavaDoc.Class getJavaDoc()
Get the class documentation.

Returns:
the JavaDoc

print

public void print(ElementPrinter printer)
           throws ElementPrinterInterruptException
Description copied from class: Element
Print this element (and all its subelements) into an element printer.

Specified by:
print in class Element
Parameters:
printer - the element printer
Throws:
ElementPrinterInterruptException - if the printer canceled the printing

hasMainMethod

public boolean hasMainMethod()
Test whether this class has a declared main method and so may be executed directly.

Returns:
true if this class contains a public static void main(String[]) method, otherwise false

isDeclaredAsJavaBean

public boolean isDeclaredAsJavaBean()
Test whether this class is a JavaBean. It must: Note that these are technical requirements: satisfying them does not imply that the class is really intended to be used as a JavaBean; this could have been accidental.

Returns:
true if this class could be a JavaBean, otherwise false

isDeclaredAsApplet

public boolean isDeclaredAsApplet()
Test whether this class is an applet. It must:

Returns:
true if this class could be an applet, otherwise false.

register

public static void register(ClassElement.Finder f)
Register a new finder for locating class elements.

Parameters:
f - the finder to add

unregister

public static void unregister(ClassElement.Finder f)
Unregister a finder for locating class elements.

Parameters:
f - the finder to remove

forName

public static ClassElement forName(String name,
                                   FileObject reference)
Search for a class element throughout the system. Asks all registered finders if they know where to find such a class.

Parameters:
name - class name separated by dots, e.g. java.lang.String. For inner classes is accepted delimiting by '$' or by '.' e.g. inner class A.B in package org.netbeans.test could be specified like: org.netbeans.A.B or org.netbeans.A$B Both possibilities are accepted.
reference - a file that is thought to belong to the same class path structure as the desired class, used as a reference point
Returns:
class element for that name, or null if none exists
See Also:
ClassElement.Finder

forName

public static ClassElement forName(String name)
Deprecated. This method variant can no longer work. Use forName(String,FileObject) instead.

Search for a class element throughout the system. First goes through repository and find the appropriate DataObject Tests if it has SourceCookie and if there exist the right one, it is returned. Otherwise tries to creates the Class.forName and asks all registered finders if they know where to find such a class.

Parameters:
name - class name separated by dots, e.g. java.lang.String. For inner classes is accepted delimiting by '$' or by '.' e.g. inner class A.B in package org.netbeans.test could be specified like: org.netbeans.A.B or org.netbeans.A$B Both possibilities are accepted.
Returns:
class element for that name, or null if none exists
See Also:
ClassElement.Finder

forClass

public static ClassElement forClass(Class clazz,
                                    FileObject reference)
Search for a class element throughout the system. Asks all registered finders if they know where to find such a class.

Parameters:
clazz - class name separated by dots, e.g. java.lang.String
reference - a file that is thought to belong to the same class path structure as the desired class, used as a reference point
Returns:
class element for that name, or null if none exists
See Also:
ClassElement.Finder

forClass

public static ClassElement forClass(Class clazz)
Deprecated. This method variant can no longer work. Use forClass(Class,FileObject) instead.

Search for a class element throughout the system. Asks all registered finders if they know where to find such a class.

Parameters:
clazz - class name separated by dots, e.g. java.lang.String
Returns:
class element for that name, or null if none exists
See Also:
ClassElement.Finder

 

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