Extension SDK

oracle.jdeveloper.jot
Interface JotClass

All Superinterfaces:
java.lang.Comparable, JotElement, JotFileElement, JotHasModifiers, JotNameable
All Known Subinterfaces:
JotAnonymousClass, JotInnerClass, JotLocalClass

public interface JotClass
extends java.lang.Comparable, JotHasModifiers, JotNameable, JotFileElement

The JotClass interface represents the JOT model for a Java class. A JotClass represents one of four kinds of types: classes, interfaces, arrays, and primitive types. An instance's kind of type can be determined by calling the predicates isInterface(), isArray(), and isPrimitive(): at most one is true, and if all are false the instance is a class.

Other methods retrieve parts of the type's Java definition. Some methods are not meaningful for all four kinds of types.

JotClass provides read and write access to a type. Methods that modify the type may throw a JotException if the type cannot be modified. Arrays and primitive types are immutable, as are class or interface types representing a compiled class file.

Since:
5.0

Method Summary
 void addBlankLine(JotMember member, boolean before)
          Adds a blank line to this file.
 void addComment(JotMember member, boolean before, JotComment comment)
          Adds a comment to this file.
 JotConstructor addConstructor(JotMember member, boolean before)
          Adds a new constructor to this type.
 JotField addField(JotMember member, boolean before, java.lang.String type, java.lang.String name)
          Adds a new field to this type.
 JotClassInitializer addInitializer(JotMember member, boolean before)
          Adds a new initializer to this type.
 JotInnerClass addInnerClass(JotMember member, boolean before, java.lang.String clsName)
          Adds a new member class to this class or interface.
 void addInterface(java.lang.String iface)
          Adds a superinterface to this instance's type declaration.
 JotMethod addMethod(JotMember member, boolean before, java.lang.String returnType, java.lang.String name)
          Adds a new method to this type.
 JotComment convertMemberToComment(JotMember member)
          Converts an existing member to a comment.
 JotComment createComment(int type, java.lang.String text)
          Creates a new comment.
 JotComment getComment(JotMember member, boolean before)
          Retrieves the nearest comment to a member.
 JotComment[] getComments()
          Retrieves all the class-level comments.
 JotType getComponentType()
          Gets the element type, if this is an array type.
 JotConstructor getConstructor(JotType[] parameterTypes)
          Gets the public constructor that takes parameters of the given types.
 JotConstructor[] getConstructors()
          Creates an array of the public constructors declared for this type.
 JotConstructor getDeclaredConstructor(JotType[] parameterTypes)
          Gets the constructor that takes parameters of the given types.
 JotConstructor[] getDeclaredConstructors()
          Creates an array of all the constructors declared for this type.
 JotField getDeclaredField(java.lang.String name)
          Gets the declared field member having the given name.
 JotField[] getDeclaredFields()
          Creates an array of declared field members.
 JotClassInitializer[] getDeclaredInitializers()
          Retrieves the initializers declared within this class.
 JotInnerClass[] getDeclaredInnerClasses()
          Creates an array of the inner classes declared for this type.
 JotMethod getDeclaredMethod(java.lang.String name, JotType[] parameterTypes)
          Gets the declared method having the given name and parameter types.
 JotMethod[] getDeclaredMethods()
          Creates an array of all declared method members.
 JotMethod[] getDeclaredMethods(java.lang.String name)
          Creates an array of all declared methods having a given name.
 JotClass getDeclaringClass()
          Retrieves the class in which this class is declared.
 JotDocComment getDocComment(JotMember member)
          Retrieves the current JavaDoc comment for a member.
 JotField getField(java.lang.String name)
          Gets this type's field member having the given name.
 JotField[] getFields()
          Creates an array of declared and inherited public field members.
 JotFile getFile()
          Retrieves the file associated with this JotClass instance.
 JotInnerClass[] getInnerClasses()
          Creates an array of the public inner classes declared for this type.
 JotType[] getInterfaces()
          Gets this instance's superinterface declarations.
 JotMethod getMethod(java.lang.String name, JotType[] parameterTypes)
          Gets the declared or inherited public method having the given name and parameter types.
 JotMethod[] getMethods()
          Creates an array of public declared and inherited method members.
 JotMethod[] getMethods(java.lang.String methodName)
          Creates an array of declared and inherited public methods having a given name.
 java.lang.String getPackage()
          Retrieves the package name from this class's file's package declaration.
 JotType getSuperclass()
          Gets the superclass type of this class.
 JotType getType()
          Gets the JotType instance that contains this JotClass instance.
 boolean isArray()
          Tests if the type represented by this JotClass instance is an array.
 boolean isAssignableFrom(JotClass cls)
          Tests whether the type represented by this JotClass instance is either the same as, or is a superclass or superinterface of, a given class.
 boolean isDeprecated()
           
 boolean isInterface()
          Tests if the type represented by this JotClass instance is an interface.
 boolean isPrimitive()
          Tests if the type represented by this JotClass instance is a primitive type; boolean, one of the five integer types (byte, char, int, short, and long), or one of the two floating point types (float, and double).
 boolean isSource()
          Whether this JotClass represents a class in a source file or in a compiled class file.
 void removeComment(JotComment comment)
          Removes an existing comment.
 void removeConstructor(JotConstructor ctor)
          Removes an existing constructor from this type.
 void removeField(JotField fld)
          Removes an existing field from this type.
 void removeInitializer(JotClassInitializer init)
          Removes an existing initializer from this type.
 void removeInnerClass(JotClass cls)
          Removes a member class from this class or interface.
 void removeInterface(JotType iface)
          Removes a superinterface from this type declaration.
 void removeMethod(JotMethod method)
          Removes an existing method from this type.
 JotDocComment setDocComment(JotMember member, java.lang.String text)
          Sets the JavaDoc comment for a member.
 void setIsInterface(boolean isIface)
          Marks whether this JotClass instance represents an interface.
 void setSuperclass(java.lang.String sCls)
          Sets the superclass type for this class.
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface oracle.jdeveloper.jot.JotHasModifiers
getModifiers, setModifiers
 
Methods inherited from interface oracle.jdeveloper.jot.JotNameable
getName, setName
 
Methods inherited from interface oracle.jdeveloper.jot.JotElement
getElementName, getElementType, getEndOffset, getID, getJotWorkArea, getParent, getStartOffset, isExistent, isReadOnly, isStructureKnown, setParent
 

Method Detail

getFile

public JotFile getFile()
Retrieves the file associated with this JotClass instance.

Returns:
a descriptor for the file containing this class.

getDeclaringClass

public JotClass getDeclaringClass()
Retrieves the class in which this class is declared. If this JotClass represents an inner class or interface, this method returns the JotClass declaring this JotClass. If this JotClass represents a top-level class, the declaring class will be null.

Returns:
the JotClass declaring this JotClass, or null if this JotClass represents a top-level class or interface.

isAssignableFrom

public boolean isAssignableFrom(JotClass cls)
Tests whether the type represented by this JotClass instance is either the same as, or is a superclass or superinterface of, a given class.

Parameters:
cls - the type to be tested.
Returns:
true if cls can be converted to the type represented by this JotClass through an identity conversion or a widening reference conversion, or if this type is a primitive and identical to cls, else false.
Throws:
java.lang.NullPointerException - if cls is null.
See Also:
"The Java Language Specification, sections 5.1.1 and 5.1.4"

isInterface

public boolean isInterface()
Tests if the type represented by this JotClass instance is an interface.

Returns:
true if this type is an interface, else false.

setIsInterface

public void setIsInterface(boolean isIface)
                    throws JotException
Marks whether this JotClass instance represents an interface.

Parameters:
isIface - true if this JotClass should represent an interface, false if this JotClass should represent a class.
Throws:
JotException - if this type represents a primitive or array type; or this type represents a class or interface obtained from a compiled class file.

isPrimitive

public boolean isPrimitive()
Tests if the type represented by this JotClass instance is a primitive type; boolean, one of the five integer types (byte, char, int, short, and long), or one of the two floating point types (float, and double).

Returns:
true if this type is one of the constants defined in JotPrimitiveClass, else false.

isArray

public boolean isArray()
Tests if the type represented by this JotClass instance is an array.

Returns:
true if this JotClass instance is an array, else false.

isDeprecated

public boolean isDeprecated()
Returns:
true if this JotClass is deprecated.

getComponentType

public JotType getComponentType()
Gets the element type, if this is an array type.

Returns:
the element type if this JotClass instance is an array, else null.

getType

public JotType getType()
Gets the JotType instance that contains this JotClass instance.

Returns:
the JotType representing this instance.

getSuperclass

public JotType getSuperclass()
Gets the superclass type of this class.

Returns:
this instance's superclass, or null if this instance is either not a class or represents the class java.lang.Object.
See Also:
"The Java Virtual Machine Specification, section 8.1.4"

setSuperclass

public void setSuperclass(java.lang.String sCls)
                   throws JotException
Sets the superclass type for this class.

Parameters:
sCls - the name of the superclass; if this classname is not fully qualified, it will be resolved using the import context of the file containing this class.
Throws:
JotException - if this type represents a primitive, array or interface type; or this type represents a class obtained from a compiled class file.

getInterfaces

public JotType[] getInterfaces()
Gets this instance's superinterface declarations.

Returns:
an array of JotType instances containing this instance's declared superinterfaces. If this instance is an array or primitive the array is empty.
See Also:
"The Java Language Specification, sections 8.1.4 and 9.1.3"

addInterface

public void addInterface(java.lang.String iface)
                  throws JotException
Adds a superinterface to this instance's type declaration.

Parameters:
iface - the name of the new interface; if this interface name is not fully qualified, it will be resolved using the import context of the file containing this type.
Throws:
JotException - if this type represents a primitive or array type; or the class or interface represented by this type is obtained from a compiled class file.

removeInterface

public void removeInterface(JotType iface)
                     throws JotException
Removes a superinterface from this type declaration. If the specified type is not a current superinterface, the remove request is ignored.

Parameters:
iface - the interface type to remove.
Throws:
JotException - if this type represents a primitive or array type; or the class or interface represented by this type is obtained from a compiled class file.

getDeclaredFields

public JotField[] getDeclaredFields()
Creates an array of declared field members. The array is empty if this type has no fields.

Returns:
an array of JotField instances representing the fields declared in this JotClass instance. Inherited fields are excluded. The array has length 0 if this type is an array or is primitive, or if it is a class or interface having no declared fields.
See Also:
"The Java Language Specification, sections 8.3 and 9.3"

getDeclaredField

public JotField getDeclaredField(java.lang.String name)
Gets the declared field member having the given name.

Parameters:
name - the simple (unqualified) name of a declared field.
Returns:
a JotField instance representing the named field.
See Also:
"The Java Language Specification, sections 8.3 and 9.3"

getFields

public JotField[] getFields()
Creates an array of declared and inherited public field members. The array is empty if this type has no fields.

Returns:
an array of JotField instances representing the public fields declared in this JotClass instance as well as those inherited from superclasses or superinterfaces. The array has length 0 if this type is an array or is primitive, or if it is a class or interface having no fields.
See Also:
"The Java Language Specification, sections 8.3 and 9.3"

getField

public JotField getField(java.lang.String name)
Gets this type's field member having the given name.

Parameters:
name - the simple (unqualified) name of a declared or inherited field.
Returns:
a JotField instance representing the named field.
See Also:
"The Java Language Specification, sections 8.3 and 9.3"

addField

public JotField addField(JotMember member,
                         boolean before,
                         java.lang.String type,
                         java.lang.String name)
                  throws JotException
Adds a new field to this type.

Parameters:
member - an existing member of this type to position relative to, or null to position at the beginning or end.
before - whether to position the new field before or after the existing member; or, if the member is null, whether to position the new field at the beginning or the end of the declaration.
type - the type of the field; if the type is not fully qualified (or a primitive type), the type will resolved using the import context of the file containing this type.
name - the name of the new field.
Returns:
a JotField representing the new field.
Throws:
JotException - if this type represents a primitive or array type; or the class or interface represented by this type is obtained from a compiled class file.

removeField

public void removeField(JotField fld)
                 throws JotException
Removes an existing field from this type.

Parameters:
fld - the field to remove. If the field is not a current member of this class or interface, the remove request is ignored.
Throws:
JotException - if this type represents a primitive or array type; or the class or interface represented by this type is obtained from a compiled class file.

getDeclaredMethods

public JotMethod[] getDeclaredMethods()
Creates an array of all declared method members. The array is empty if this type has no methods.

Returns:
an array of JotMethod instances representing the methods declared in this JotClass instance. Inherited methods are excluded. The array has length 0 if this type is an array or is primitive, or if it is a class or interface having no declared methods.
See Also:
"The Java Language Specification, sections 8.4 and 9.4"

getDeclaredMethods

public JotMethod[] getDeclaredMethods(java.lang.String name)
Creates an array of all declared methods having a given name. The array is empty if this type has no such methods.

Parameters:
name - a simple (unqualified) name.
Returns:
an array of JotMethod instances representing the name methods declared in this JotClass instance. Inherited methods are excluded. The array has length 0 if this type is an array or is primitive, or if it is a class or interface having no declared methods of the given name.
See Also:
"The Java Language Specification, sections 8.4 and 9.4"

getDeclaredMethod

public JotMethod getDeclaredMethod(java.lang.String name,
                                   JotType[] parameterTypes)
Gets the declared method having the given name and parameter types.

Parameters:
name - the simple (unqualified) name of a method declared for this type.
parameterTypes - an array of parameter types.
Returns:
a JotMethod instance representing the method variant having the given name and whose parameter types, in order, are given in parameterTypes.
See Also:
"The Java Language Specification, sections 8.4 and 9.4"

getMethods

public JotMethod[] getMethods()
Creates an array of public declared and inherited method members. The array is empty if this type has no such methods.

Returns:
an array of JotMethod instances representing the public methods declared in this JotClass instance, or in any superclass or superinterface. The array has length 0 if this type is an array or is primitive, or if it is a class or interface having no such methods.
See Also:
"The Java Language Specification, sections 8.4 and 9.4"

getMethods

public JotMethod[] getMethods(java.lang.String methodName)
Creates an array of declared and inherited public methods having a given name. The array is empty if this type has no such methods.

Returns:
an array of JotMethod instances representing the public name methods declared in this JotClass instance, or in any superclass or superinterface. The array has length 0 if this type is an array or is primitive, or if it is a class or interface having no methods of the given name.
See Also:
"The Java Language Specification, sections 8.4 and 9.4"

getMethod

public JotMethod getMethod(java.lang.String name,
                           JotType[] parameterTypes)
Gets the declared or inherited public method having the given name and parameter types.

Parameters:
name - the simple (unqualified) name of a method declared for this type, or in any superclass or superinterface.
parameterTypes - an array of parameter types.
Returns:
a JotMethod instance representing the method variant having the given name and whose parameter types, in order, are given in parameterTypes; or null if there is no such method.
See Also:
"The Java Language Specification, sections 8.4 and 9.4"

addMethod

public JotMethod addMethod(JotMember member,
                           boolean before,
                           java.lang.String returnType,
                           java.lang.String name)
                    throws JotException
Adds a new method to this type.

Parameters:
member - an existing member of this type to position relative to, or null to position at the beginning or end.
before - whether to position the new method before or after the existing member; or, if the member is null, whether to position the new method at the beginning or the end of the declaration.
returnType - the return type of the method
name - the name of the new method.
Returns:
a JotMethod representing the new method.
Throws:
JotException - if this type represents a primitive or array type; or the class or interface represented by this type is obtained from a compiled class file.

removeMethod

public void removeMethod(JotMethod method)
                  throws JotException
Removes an existing method from this type.

Throws:
JotException - if this type represents a primitive or array type; or the class or interface represented by this type is obtained from a compiled class file.

getDeclaredConstructors

public JotConstructor[] getDeclaredConstructors()
Creates an array of all the constructors declared for this type. The array is empty if this type is an interface, array, or primitive type.

Returns:
an array of JotConstructor instances representing constructors declared in this JotClass instance. The array has length 0 if this type is not a class.
See Also:
"The Java Language Specification, section 8.6"

getDeclaredConstructor

public JotConstructor getDeclaredConstructor(JotType[] parameterTypes)
Gets the constructor that takes parameters of the given types.

Parameters:
parameterTypes - an array of parameter types.
Returns:
a JotConstructor instance representing the constructor whose parameter types, in order, are given in parameterTypes; or null if parameterTypes do not match a constructor.
See Also:
"The Java Language Specification, section 8.6"

getConstructors

public JotConstructor[] getConstructors()
Creates an array of the public constructors declared for this type. The array is empty if this type has no public constructors, or is an interface, array, or primitive type.

Returns:
an array of JotConstructor instances representing public constructors declared in this JotClass instance. The array has length 0 if this type is not a class, or is a class with no public constructors.
See Also:
"The Java Language Specification, section 8.6"

getConstructor

public JotConstructor getConstructor(JotType[] parameterTypes)
Gets the public constructor that takes parameters of the given types.

Parameters:
parameterTypes - an array of parameter types.
Returns:
a JotConstructor instance representing the constructor whose parameter types, in order, are given in parameterTypes; or null if parameterTypes do not match a constructor.
See Also:
"The Java Language Specification, section 8.6"

addConstructor

public JotConstructor addConstructor(JotMember member,
                                     boolean before)
                              throws JotException
Adds a new constructor to this type.

Parameters:
member - an existing member of this type to position relative to, or null to position at the beginning or end.
before - whether to position the new constructor before or after the existing member; or, if the member is null, whether to position the new constructor at the beginning or the end of the declaration.
Returns:
a JotConstructor representing the new constructor.
Throws:
JotException - if this type represents a primitive or array type; or the class or interface represented by this type is obtained from a compiled class file.

removeConstructor

public void removeConstructor(JotConstructor ctor)
                       throws JotException
Removes an existing constructor from this type.

Throws:
JotException - if this type represents a primitive or array type; or the class or interface represented by this type is obtained from a compiled class file.

getDeclaredInitializers

public JotClassInitializer[] getDeclaredInitializers()
Retrieves the initializers declared within this class.

Returns:
an array of JotClassInitializers representing this classes initializers. If this type represents a primitive, array, or interface type, a zero-length array is returned.

addInitializer

public JotClassInitializer addInitializer(JotMember member,
                                          boolean before)
                                   throws JotException
Adds a new initializer to this type.

Parameters:
member - an existing member of this type to position relative to, or null to position at the beginning or end.
before - whether to position the new initializer before or after the existing member; or, if the member is null, whether to position the new initializer at the beginning or the end of the declaration.
Returns:
a JotClassInitializer representing the new initializer.
Throws:
JotException - if this type represents a primitive or array type; or the class or interface represented by this type is obtained from a compiled class file.

removeInitializer

public void removeInitializer(JotClassInitializer init)
                       throws JotException
Removes an existing initializer from this type.

Throws:
JotException - if this type represents a primitive or array type; or the class or interface represented by this type is obtained from a compiled class file.

getDeclaredInnerClasses

public JotInnerClass[] getDeclaredInnerClasses()
Creates an array of the inner classes declared for this type. The array is empty if this type has no inner classes, or is itself not a class.

Returns:
an array of JotInnerClass instances representing the inner classes declared in this JotClass instance. The array has length 0 if this type is not a class, or is a class with no inner classes.

getInnerClasses

public JotInnerClass[] getInnerClasses()
Creates an array of the public inner classes declared for this type. The array is empty if this type has no public inner classes, or is itself not a class.

Returns:
an array of JotInnerClass instances representing the inner classes declared in this JotClass instance. The array has length 0 if this type is not a class, or is a class with no inner classes.

addInnerClass

public JotInnerClass addInnerClass(JotMember member,
                                   boolean before,
                                   java.lang.String clsName)
                            throws JotException
Adds a new member class to this class or interface.

Parameters:
member - an existing member of this type to position relative to, or null to position at the beginning or end.
before - whether to position the new member class before or after the existing member; or, if the member is null, whether to position the new member class at the beginning or the end of the declaration.
clsName - the name of the new member class.
Returns:
a JotInnerClass representing the new member class.
Throws:
JotException - if this type represents a primitive or array type; or the class or interface represented by this type is obtained from a compiled class file.

removeInnerClass

public void removeInnerClass(JotClass cls)
                      throws JotException
Removes a member class from this class or interface. If the specified class is not a member of this class or interface, the request is ignored.

Parameters:
cls - the member class to remove.
Throws:
JotException - if this type represents a primitive or array type; or the class or interface represented by this JotClass is obtained from a compiled class file.

isSource

public boolean isSource()
Whether this JotClass represents a class in a source file or in a compiled class file.

Returns:
true if this JotClass is contained in a source file, or false if this the file is compiled.

setDocComment

public JotDocComment setDocComment(JotMember member,
                                   java.lang.String text)
Sets the JavaDoc comment for a member.

Parameters:
text - the text of the doc comment. The comment start and end characters should be omitted, as well as the '*' characters at the start of each line.
Returns:
the newly created and added doc comment.

getDocComment

public JotDocComment getDocComment(JotMember member)
Retrieves the current JavaDoc comment for a member.

Parameters:
member - the member whose doc comment is desired.
Returns:
the doc comment for the class, or null if no comment exists.

createComment

public JotComment createComment(int type,
                                java.lang.String text)
Creates a new comment. The comment then needs to be added to the file.

Parameters:
type - the type of comment to create.
text - the text of the comment. The comment characters should be omitted.
Returns:
the newly created comment.
See Also:
addComment(JotMember, boolean, JotComment)

addComment

public void addComment(JotMember member,
                       boolean before,
                       JotComment comment)
Adds a comment to this file.

Parameters:
member - the existing member to position the comment relative to.
before - whether to add the comment before or after the member.
comment - the comment to add.

removeComment

public void removeComment(JotComment comment)
Removes an existing comment.

Parameters:
comment - the comment to remove.

getComments

public JotComment[] getComments()
Retrieves all the class-level comments.

Returns:
an array of comments.

getComment

public JotComment getComment(JotMember member,
                             boolean before)
Retrieves the nearest comment to a member.

Parameters:
member - the member to use for finding the comment.
before - whether to look before or after the member.
Returns:
the nearest comment, or null if no comment can be found at the specified location.

addBlankLine

public void addBlankLine(JotMember member,
                         boolean before)
Adds a blank line to this file.

Parameters:
member - the existing member to add the blank line relative to.
before - whether to add the blank line before or after the member.

convertMemberToComment

public JotComment convertMemberToComment(JotMember member)
Converts an existing member to a comment. The member is removed from the class and a comment containing the text of the member is returned.

Parameters:
member - an existing member in the class
Returns:
a comment enclosing the member. If the member does not already exist in the class, null is returned.

getPackage

public java.lang.String getPackage()
Retrieves the package name from this class's file's package declaration.

Returns:
the package declaration without the package keyword, or null if the file does not belong to a package.

Extension SDK

 

Copyright ©1997, 2003, Oracle. All rights reserved.