public class ClassImpl extends MemberImpl implements MClass, JClassRef, JClassRefContext
Implementation of JClass and MClass.
| Modifier and Type | Field and Description |
|---|---|
static int |
INITIALIZING |
static int |
LOADED |
static int |
NEW |
static int |
POPULATING |
static int |
UNINITIALIZED |
static int |
UNPOPULATED |
NO_ANNOTATION, NO_CLASS, NO_COMMENT, NO_CONSTRUCTOR, NO_FIELD, NO_METHOD, NO_NODE, NO_PACKAGE, NO_PARAMETER, NO_PROPERTY| Constructor and Description |
|---|
ClassImpl(String packageName,
String simpleName,
ElementContext ctx,
String[] importSpecs) |
ClassImpl(String packageName,
String simpleName,
ElementContext ctx,
String[] importSpecs,
JamClassPopulator populator) |
| Modifier and Type | Method and Description |
|---|---|
void |
accept(JVisitor visitor)
Accepts the given visitor.
|
void |
accept(MVisitor visitor) |
void |
addInterface(JClass interf)
Adds to the list of interfaces implemented by this class.
|
void |
addInterface(String qcName)
Adds to the list of interfaces implemented by this class.
|
void |
addInterfaceUnqualified(String ucname)
Adds to the list of interfaces implemented by this class.
|
MConstructor |
addNewConstructor()
Creates a new constructor, adds it to this class, and returns it.
|
JProperty |
addNewDeclaredProperty(String name,
JMethod getter,
JMethod setter) |
MField |
addNewField()
Creates a new field, adds it to this class, and returns it.
|
MClass |
addNewInnerClass(String name) |
MMethod |
addNewMethod()
Creates a new method, adds it to this class, and returns it.
|
JProperty |
addNewProperty(String name,
JMethod getter,
JMethod setter) |
void |
ensureLoaded() |
JClass |
forName(String name)
Shorthand for myClass.getClassLoader().loadClass(name)
|
JAnnotation[] |
getAllJavadocTags() |
JAnnotation |
getAnnotation(Class proxyClass)
Returns the JAnnotation which is being proxied by the given subclass
of TypedAnnotationProxyBase, or null if no such annotation exists.
|
JAnnotation |
getAnnotation(String named)
Returns the annotation that represents the named 175 annotation
or javadoc tag on this elements.
|
Object |
getAnnotationProxy(Class proxyClass) |
JAnnotation[] |
getAnnotations()
Returns the metadata JAnnotations that are associated with
this abstraction.
|
JAnnotationValue |
getAnnotationValue(String valueId)
Shortcut method which returns a given annotation value.
|
JClass |
getArrayComponentType()
Returns the Class representing the component type of an array.
|
int |
getArrayDimensions()
If this JClass represents an array type (isArray() == true),
returns the number of dimensions in the array.
|
JClass[] |
getClasses()
Returns an unordered array containing the inner classes for this class.
|
JComment |
getComment()
Returns the comment associated with this abstraction.
|
JConstructor[] |
getConstructors()
Returns an unordered array containing Constructor objects reflecting
all the public constructors of the class represented by this Class
object.
|
JPackage |
getContainingPackage()
Returns a JPackage which represents the package which contains
this JClass.
|
JField[] |
getDeclaredFields()
Returns an unordered array of Field objects reflecting all the fields
declared by the class or interface represented by this Class
object.
|
JMethod[] |
getDeclaredMethods()
Returns an unordered array of Method objects reflecting all the
methods declared by the class or interface represented by this Class
object.
|
JProperty[] |
getDeclaredProperties()
Like getProperties(), but only considers methods explicitly declared
on this class in identifying the properties.
|
String |
getFieldDescriptor()
Returns the name of this member in the format described in
section 4.3.2 of the VM spec, 'Field Descriptors.' This is the
same nasty format returned by java.lang.Class.getName(), and is
the format you need to use in calls to Class.forName().
|
JField[] |
getFields()
REVIEW should we consider renaming this to getAllFields()? I
think this makes it more clear but is not consistent with
java.lang.Class.
|
JClass[] |
getImportedClasses()
Returns an unordered array of classes that were explicitly imported by
this class using an import statement.
|
JPackage[] |
getImportedPackages()
Returns an unordered set of JPackages which are imported by this class
using a package import statement (i.e.
|
String[] |
getImportSpecs() |
JClass[] |
getInterfaces()
Returns an unordered array containing all of the interfaces directly
implemented by this class.
|
JMethod[] |
getMethods()
REVIEW should we consider renaming this to getAllMethods()? I
think this makes it more clear but is not consistent with
java.lang.Class.
|
int |
getModifiers()
Returns the modifiers specifier.
|
MConstructor[] |
getMutableConstructors()
Returns the constructors declared on this class.
|
MField[] |
getMutableFields()
Returns the fields declared on this class.
|
MMethod[] |
getMutableMethods()
Returns the EditableMethods declared on this class.
|
String |
getPackageName() |
Class |
getPrimitiveClass()
If this JClass represents a primitive (isPrimitiveType() returns true),
this method returns the java.lang.Class representing the class of
the primitive.
|
JProperty[] |
getProperties()
Returns a representation of a java bean property as detailed in section
8.3 of the Java Beans specification, 'Design Patterns for Properties.'
A JProperty can be thought of as a union of a getter method and
corresponding setter method, although only one of these is required
(view-only and write-only properties are returned).
|
String |
getQualifiedName()
Returns a qualified name for this abstraction.
|
JClass |
getRefClass() |
JSourcePosition |
getSourcePosition()
Returns an object describing the source file position of this
elements, or null if the position is unknown on not applicable.
|
JClass |
getSuperclass()
Returns the Class representing the superclass of the entity
(class, interface, primitive type or void) represented by this
Class.
|
boolean |
isAbstract()
Return true if this class is abstract.
|
boolean |
isAnnotationType()
Returns true if this JClass represents a JSR175 annotation type.
|
boolean |
isArrayType()
Returns true if this JClass represents an array type.
|
boolean |
isAssignableFrom(JClass arg)
Determines if the class or interface represented by this Class
object is either the same as, or is a superclass or
superinterface of, the class or interface represented by the
specified Class parameter.
|
boolean |
isBuiltinType()
Returns true if this class is a builtin type.
|
boolean |
isEnumType()
Returns true if this class is an enumerated type.
|
boolean |
isFinal()
Return true if this class is final.
|
boolean |
isInterface()
Returns true if this JClass represents an interface.
|
boolean |
isObjectType()
Returns true if this JClass represents java.lang.Object.
|
boolean |
isPrimitiveType()
Return true if this JClass represents primitive type (int, long,
double, and so forth).
|
boolean |
isStatic()
Return true if this class is static.
|
boolean |
isUnresolvedType()
Returns true if a backing entity for this class could not be
resolved.
|
boolean |
isVoidType()
Returns true if this JClass represents the void type.
|
void |
removeConstructor(MConstructor constr)
Removes a constructor from this class.
|
void |
removeDeclaredProperty(JProperty p) |
void |
removeField(MField field)
Removes the given field from this class.
|
void |
removeInnerClass(MClass clazz) |
void |
removeInterface(JClass interf)
Removes an interface from the list of interfaces implemented by
this class.
|
void |
removeInterface(String qcname)
Removes a named interface from the list of interfaces implemented by
this class.
|
void |
removeMethod(MMethod method)
Removes the given method from this class.
|
void |
removeProperty(JProperty p) |
void |
setIsAnnotationType(boolean b) |
void |
setIsEnumType(boolean b) |
void |
setIsInterface(boolean b) |
void |
setSimpleName(String name) |
void |
setState(int state) |
void |
setSuperclass(JClass clazz)
Sets the class which this class extends.
|
void |
setSuperclass(String qualifiedClassName)
Sets the class which this class extends.
|
void |
setSuperclassUnqualified(String unqualifiedClassName)
Sets the name of this class that this class extends.
|
static void |
validateClassName(String className)
Throws an IllegalArgument exception if the given string is not a valid
class name.
|
getContainingClass, isPackagePrivate, isPrivate, isProtected, isPublic, setModifiersaddAnnotationForProxy, addLiteralAnnotation, createComment, findOrCreateAnnotation, getEditableProxy, getMutableAnnotation, getMutableAnnotations, getMutableComment, removeAnnotation, removeCommentcompareTo, createSourcePosition, defaultName, equals, getArtifact, getClassLoader, getContext, getMutableSourcePosition, getParent, getSimpleName, hashCode, removeSourcePosition, setArtifact, toStringsetModifiersaddLiteralAnnotation, createComment, findOrCreateAnnotation, getMutableAnnotation, getMutableAnnotations, getMutableComment, removeCommentcreateSourcePosition, getClassLoader, getMutableSourcePosition, removeSourcePosition, setArtifactequals, getClassLoader, getContainingClassisPackagePrivate, isPrivate, isProtected, isPublicgetArtifact, getParent, getSimpleName, toStringgetClassLoaderpublic static final int NEW
public static final int UNPOPULATED
public static final int POPULATING
public static final int UNINITIALIZED
public static final int INITIALIZING
public static final int LOADED
public ClassImpl(String packageName, String simpleName, ElementContext ctx, String[] importSpecs, JamClassPopulator populator)
public ClassImpl(String packageName, String simpleName, ElementContext ctx, String[] importSpecs)
public JPackage getContainingPackage()
JClassReturns a JPackage which represents the package which contains this JClass.
getContainingPackage in interface JClasspublic JClass getSuperclass()
JClassReturns the Class representing the superclass of the entity (class, interface, primitive type or void) represented by this Class. If this Class represents either the Object class, an interface, a primitive type, or void, then null is returned. If this object represents an array class then the Class object representing the Object class is returned.
getSuperclass in interface JClasspublic JClass[] getInterfaces()
JClassgetInterfaces in interface JClasspublic JField[] getFields()
JClassREVIEW should we consider renaming this to getAllFields()? I think this makes it more clear but is not consistent with java.lang.Class.
Returns an unordered array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object. The elements2 in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if the class or interface has no accessible public fields, or if it represents an array class, a primitive type, or void.
Specifically, if this JClass object represents a class, this method returns the public fields of this class and of all its superclasses. If this JClass object represents an interface, this method returns the fields of this interface and of all its superinterfaces.
The implicit length field for array class is not reflected by this method. User code should use the methods of class Array to manipulate arrays.
Note that no guarantees are made about the ordering of fields in this array.
See The Java Language Specification, sections 8.2 and 8.3.
public JField[] getDeclaredFields()
JClassReturns an unordered array of Field objects reflecting all the fields declared by the class or interface represented by this Class object. This includes public, protected, default (package) access, and private fields, but excludes inherited fields. The elements2 in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if the class or interface declares no fields, or if this Class object represents a primitive type, an array class, or void.
See The Java Language Specification, sections 8.2 and 8.3.
getDeclaredFields in interface JClasspublic JMethod[] getMethods()
JClassREVIEW should we consider renaming this to getAllMethods()? I think this makes it more clear but is not consistent with java.lang.Class.
Returns an array containing Method objects reflecting all the public member methods of the class or interface represented by this Class object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces. The elements2 in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if this Class object represents a class or interface that has no public member methods, or if this Class object represents an array class, primitive type, or void.
The class initialization method
getMethods in interface JClasspublic JProperty[] getProperties()
JClassgetProperties in interface JClasspublic JProperty[] getDeclaredProperties()
JClassLike getProperties(), but only considers methods explicitly declared on this class in identifying the properties.
getDeclaredProperties in interface JClasspublic JMethod[] getDeclaredMethods()
JClassReturns an unordered array of Method objects reflecting all the
methods declared by the class or interface represented by this Class
object. This includes public, protected, default (package)
access, and private methods, but excludes inherited methods. The
elements2 in the array returned are not sorted and are not in any
particular order. This method returns an array of length 0 if the
class or interface declares no methods, or if this Class object
represents a primitive type, an array class, or void. The class
initialization method
See The Java Language Specification, section 8.2.
getDeclaredMethods in interface JClasspublic JConstructor[] getConstructors()
JClassReturns an unordered array containing Constructor objects reflecting all the public constructors of the class represented by this Class object. An array of length 0 is returned if the class has no public constructors, or if the class is an array class, or if the class reflects a primitive type or void.
getConstructors in interface JClasspublic boolean isInterface()
JClassReturns true if this JClass represents an interface.
isInterface in interface JClasspublic boolean isAnnotationType()
JClassReturns true if this JClass represents a JSR175 annotation type.
isAnnotationType in interface JClasspublic boolean isEnumType()
JClassReturns true if this class is an enumerated type.
isEnumType in interface JClasspublic int getModifiers()
JMemberReturns the modifiers specifier. This is a bit field exactly like those returned by java.lang.Class.getModifiers() and can be manipulated using java.lang.reflect.Modifier in the same way.
getModifiers in interface JMembergetModifiers in class MemberImplpublic boolean isFinal()
JClasspublic boolean isStatic()
JClasspublic boolean isAbstract()
JClassisAbstract in interface JClasspublic boolean isAssignableFrom(JClass arg)
JClassDetermines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter. It returns true if so; otherwise it returns false. If this Class object represents a primitive type, this method returns true if the specified Class parameter is exactly this Class object; otherwise it returns false.
Specifically, this method tests whether the type represented by the specified Class parameter can be converted to the type represented by this Class object via an identity conversion or via a widening reference conversion. See The Java Language Specification, sections 5.1.1 and 5.1.4 , for details.
isAssignableFrom in interface JClasspublic JClass[] getClasses()
JClassReturns an unordered array containing the inner classes for this class. The array contains JClass objects representing all the public classes and interfaces that are members of the class represented by this JClass. This includes public class and interface members inherited from superclasses and public class and interface members declared by the class. This method returns an array of length 0 if this Class object has no public member classes or interfaces. This method also returns an array of length 0 if this JClass object represents a primitive type, an array class, or void.
Note that no guarantees are made about the ordering of classes in this array.
getClasses in interface JClasspublic String getFieldDescriptor()
JClassReturns the name of this member in the format described in
section 4.3.2 of the VM spec, 'Field Descriptors.' This is the
same nasty format returned by java.lang.Class.getName(), and is
the format you need to use in calls to Class.forName(). For
example, the ClassfileName of the class of a two-dimensional
array of strings is [[Ljava.lang.String;. For
details, see
http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html
getFieldDescriptor in interface JClasspublic JClass forName(String name)
JClasspublic JPackage[] getImportedPackages()
JClassReturns an unordered set of JPackages which are imported by this class
using a package import statement (i.e. with the '*' wildcard), as well as
the containing packages of all of the JClasses returned by
getImportedClasses().
Note that this is an optional operation; if the source for the class is not available (i.e. this JClass is backed by a java.lang.Class), then this method will return an array of length 0.
getImportedPackages in interface JClasspublic JClass[] getImportedClasses()
JClassReturns an unordered array of classes that were explicitly imported by this class using an import statement. It does not include any classes that might be imported via package imports (i.e. with the '*' wildcard), nor does it include any classes that are simply used via fully-qualified name in the body of this class.
Note that this is an optional operation; if the source for the class is not available (i.e. this JClass is backed by a java.lang.Class), then this method will return an array of length 0.
getImportedClasses in interface JClasspublic void accept(JVisitor visitor)
JElementAccepts the given visitor.
public void setSimpleName(String name)
setSimpleName in interface MElementsetSimpleName in class ElementImplpublic Class getPrimitiveClass()
JClassIf this JClass represents a primitive (isPrimitiveType() returns true), this method returns the java.lang.Class representing the class of the primitive. For example, JClass representing an integer returns the equivalent of 'int.class' or 'java.lang.Integer.type.'
getPrimitiveClass in interface JClasspublic boolean isPrimitiveType()
JClassisPrimitiveType in interface JClasspublic boolean isBuiltinType()
JClassisPrimitive(), isArray(),
isVoid(), or isUnresolved..isBuiltinType in interface JClasspublic boolean isVoidType()
JClassReturns true if this JClass represents the void type.
isVoidType in interface JClasspublic boolean isUnresolvedType()
JClassReturns true if a backing entity for this class could not be resolved. This will be true, for example, of the JClass which you get when requesting a method's return type when no class for that type can be found. In this case, the JClass will be have only a name - all other properties will be null/empty.
isUnresolvedType in interface JClasspublic boolean isObjectType()
JClassReturns true if this JClass represents java.lang.Object.
isObjectType in interface JClasspublic boolean isArrayType()
JClassReturns true if this JClass represents an array type.
isArrayType in interface JClasspublic JClass getArrayComponentType()
JClassReturns the Class representing the component type of an array. If this JClass does not represent an array class this method returns null.
Note that this method differs substantially from
java.lang.Class.getComponentType() in the way it
treats multidimensional arrays. Specifically, let
fooArrayClass be the class of an n dimensional array
of class foo for n > 2. For the java.lang.Class
representation of fooArrayClass,
getComponentType() will return a java.lang.Class for
an (n-1)-dimensional array of foos. By contrast,
the JClass representation of fooArrayClass will
always simply return a JClass representing foo for
any value of n > 1.
In other words, this method always returns the 'core' type of
the array, effectively hiding away all of the intermediary array
types. Given that JClass provides the additional
getArrayDimensions facility, it is felt that this is
a much easier convention for tool authors to work with.
getArrayComponentType in interface JClasspublic int getArrayDimensions()
JClassIf this JClass represents an array type (isArray() == true), returns the number of dimensions in the array. Otherwise returns zero.
getArrayDimensions in interface JClasspublic JAnnotation[] getAnnotations()
JAnnotatedElementReturns the metadata JAnnotations that are associated with this abstraction. Returns an empty array if there are no annotations.
getAnnotations in interface JAnnotatedElementgetAnnotations in class AnnotatedElementImplpublic JAnnotation getAnnotation(Class proxyClass)
JAnnotatedElementReturns the JAnnotation which is being proxied by the given subclass
of TypedAnnotationProxyBase, or null if no such annotation exists. If it
does exist, the getProxy() method on the returned
object is guaranteed to return be an instance of the proxyClass.
getAnnotation in interface JAnnotatedElementgetAnnotation in class AnnotatedElementImplpublic JAnnotation getAnnotation(String named)
JAnnotatedElementReturns the annotation that represents the named 175 annotation or javadoc tag on this elements.
getAnnotation in interface JAnnotatedElementgetAnnotation in class AnnotatedElementImplpublic JAnnotationValue getAnnotationValue(String valueId)
JAnnotatedElementgetAnnotationValue in interface JAnnotatedElementgetAnnotationValue in class AnnotatedElementImplpublic Object getAnnotationProxy(Class proxyClass)
getAnnotationProxy in interface JAnnotatedElementgetAnnotationProxy in class AnnotatedElementImplpublic JComment getComment()
JAnnotatedElementReturns the comment associated with this abstraction. Returns null if it has no comment.
getComment in interface JAnnotatedElementgetComment in class AnnotatedElementImplpublic JAnnotation[] getAllJavadocTags()
getAllJavadocTags in interface JAnnotatedElementgetAllJavadocTags in class AnnotatedElementImplpublic JSourcePosition getSourcePosition()
JElementgetSourcePosition in interface JElementgetSourcePosition in class ElementImplpublic void setSuperclass(String qualifiedClassName)
MClasssetSuperclass in interface MClasspublic void setSuperclassUnqualified(String unqualifiedClassName)
MClasssetSuperclassUnqualified in interface MClasspublic void setSuperclass(JClass clazz)
MClasssetSuperclass in interface MClasspublic void addInterface(JClass interf)
MClassaddInterface in interface MClasspublic void addInterface(String qcName)
MClassaddInterface in interface MClasspublic void addInterfaceUnqualified(String ucname)
MClassaddInterfaceUnqualified in interface MClasspublic void removeInterface(JClass interf)
MClassremoveInterface in interface MClasspublic void removeInterface(String qcname)
MClassremoveInterface in interface MClasspublic MConstructor addNewConstructor()
MClassaddNewConstructor in interface MClasspublic void removeConstructor(MConstructor constr)
MClassremoveConstructor in interface MClasspublic MConstructor[] getMutableConstructors()
MClassgetMutableConstructors in interface MClasspublic MField addNewField()
MClassaddNewField in interface MClasspublic void removeField(MField field)
MClassremoveField in interface MClasspublic MField[] getMutableFields()
MClassgetMutableFields in interface MClasspublic MMethod addNewMethod()
MClassaddNewMethod in interface MClasspublic void removeMethod(MMethod method)
MClassremoveMethod in interface MClasspublic MMethod[] getMutableMethods()
MClassgetMutableMethods in interface MClasspublic JProperty addNewProperty(String name, JMethod getter, JMethod setter)
addNewProperty in interface MClasspublic void removeProperty(JProperty p)
removeProperty in interface MClasspublic JProperty addNewDeclaredProperty(String name, JMethod getter, JMethod setter)
addNewDeclaredProperty in interface MClasspublic void removeDeclaredProperty(JProperty p)
removeDeclaredProperty in interface MClasspublic MClass addNewInnerClass(String name)
addNewInnerClass in interface MClasspublic void removeInnerClass(MClass clazz)
removeInnerClass in interface MClasspublic void setIsInterface(boolean b)
setIsInterface in interface MClasspublic void setIsAnnotationType(boolean b)
setIsAnnotationType in interface MClasspublic void setIsEnumType(boolean b)
setIsEnumType in interface MClasspublic String getQualifiedName()
JElementReturns a qualified name for this abstraction. The exact format of this name depends on the particular abstraction. Please refer to the documentation for each JElement subclass for a detailed description of the qualified name formats.
getQualifiedName in interface JClassRefgetQualifiedName in interface JElementpublic JClass getRefClass()
getRefClass in interface JClassRefpublic String getPackageName()
getPackageName in interface JClassRefContextpublic String[] getImportSpecs()
getImportSpecs in interface JClassRefContextpublic void setState(int state)
public static void validateClassName(String className) throws IllegalArgumentException
IllegalArgumentExceptionpublic void ensureLoaded()
Copyright © 2010 - 2020 Adobe. All Rights Reserved