public class DefaultJavaClass extends AbstractInheritableJavaEntity implements JavaClass
Modifier | Constructor and Description |
---|---|
protected |
DefaultJavaClass() |
|
DefaultJavaClass(JavaSource source) |
|
DefaultJavaClass(String name) |
Modifier and Type | Method and Description |
---|---|
void |
addClass(JavaClass cls) |
void |
addConstructor(JavaConstructor constructor) |
void |
addField(JavaField javaField) |
void |
addInitializer(JavaInitializer initializer) |
void |
addMethod(JavaMethod meth) |
boolean |
equals(Object obj) |
List<BeanProperty> |
getBeanProperties()
Gets bean properties without looking in superclasses or interfaces.
|
List<BeanProperty> |
getBeanProperties(boolean superclasses) |
BeanProperty |
getBeanProperty(String propertyName)
Gets bean property without looking in superclasses or interfaces.
|
BeanProperty |
getBeanProperty(String propertyName,
boolean superclasses) |
String |
getBinaryName()
The class or interface must be named by its binary name, which must meet the following constraints:
The binary name of a top level type is its canonical name.
The binary name of a member type consists of the binary name of its immediately enclosing type, followed by $, followed by the simple name of the member.
|
String |
getCanonicalName()
Equivalent of (@link
Class.getCanonicalName() . |
String |
getCodeBlock() |
JavaClass |
getComponentType()
Equivalent of
Class.getComponentType()
If this type is an array, return its component type |
JavaConstructor |
getConstructor(List<JavaType> parameterTypes) |
JavaConstructor |
getConstructor(List<JavaType> parameterTypes,
boolean varArgs) |
List<JavaConstructor> |
getConstructors()
Equivalent of
Class.getConstructors() |
List<JavaClass> |
getDerivedClasses()
Equivalent of
Class.getClasses()
Gets the known derived classes. |
int |
getDimensions()
Returns the depth of this array, 0 if it's not an array
|
JavaField |
getEnumConstantByName(String name) |
List<JavaField> |
getEnumConstants()
Based on
Class.getEnumConstants() . |
JavaField |
getFieldByName(String name)
Equivalent of
Class.getField(String) , where this method can resolve every field |
List<JavaField> |
getFields()
Equivalent of
Class.getFields() |
String |
getFullyQualifiedName()
Every primitive type, named package, top level class, and top level interface has a fully qualified name:
The fully qualified name of a primitive type is the keyword for that primitive type, namely byte, short, char, int, long, float, double, or boolean.
The fully qualified name of a named package that is not a subpackage of a named package is its simple name.
The fully qualified name of a named package that is a subpackage of another named package consists of the fully qualified name of the containing package, followed by ".", followed by the simple (member) name of the subpackage.
The fully qualified name of a top level class or top level interface that is declared in an unnamed package is the simple name of the class or interface.
The fully qualified name of a top level class or top level interface that is declared in a named package consists of the fully qualified name of the package, followed by ".", followed by the simple name of the class or interface.
Each member class, member interface, and array type may have a fully qualified name:
A member class or member interface M of another class or interface C has a fully qualified name if and only if C has a fully qualified name.
In that case, the fully qualified name of M consists of the fully qualified name of C, followed by ".", followed by the simple name of M.
An array type has a fully qualified name if and only if its element type has a fully qualified name.
In that case, the fully qualified name of an array type consists of the fully qualified name of the component type of the array type followed by "[]".
Some examples how names will be translated
|
String |
getGenericCanonicalName()
The canonical name with generic information.
|
String |
getGenericFullyQualifiedName()
The fully qualified name with generic information.
|
String |
getGenericValue()
A java5+ representation of the class.
|
List<JavaType> |
getImplements() |
List<JavaInitializer> |
getInitializers()
A list if
JavaInitializer , either static or instance initializers. |
List<JavaClass> |
getInterfaces()
Equivalent of
Class.getInterfaces()
Determines the interfaces implemented by the class or interface represented by this object. |
ClassLibrary |
getJavaClassLibrary() |
JavaMethod |
getMethod(String name,
List<JavaType> parameterTypes,
boolean varArgs)
This should be the signature for getMethodBySignature.
|
JavaMethod |
getMethodBySignature(String name,
List<JavaType> parameterTypes) |
JavaMethod |
getMethodBySignature(String name,
List<JavaType> parameterTypes,
boolean superclasses) |
JavaMethod |
getMethodBySignature(String name,
List<JavaType> parameterTypes,
boolean superclasses,
boolean varArg) |
List<JavaMethod> |
getMethods()
Equivalent of
Class.getMethods() |
List<JavaMethod> |
getMethods(boolean superclasses)
Return declared methods and optionally the inherited methods
|
List<JavaMethod> |
getMethodsBySignature(String name,
List<JavaType> parameterTypes,
boolean superclasses) |
List<JavaMethod> |
getMethodsBySignature(String name,
List<JavaType> parameterTypes,
boolean superclasses,
boolean varArg) |
JavaClass |
getNestedClassByName(String name) |
List<JavaClass> |
getNestedClasses()
Equivalent of
Class.getDeclaredClasses() |
JavaPackage |
getPackage()
Equivalent of
Class.getPackage() |
String |
getPackageName()
If this class has a package, the packagename will be returned.
|
JavaSource |
getParentSource() |
String |
getSimpleName()
Equivalent of
Class.getSimpleName() . |
JavaSource |
getSource()
The compilation unit, which includes the imports, the public and anonymous classes
|
JavaType |
getSuperClass() |
JavaClass |
getSuperJavaClass()
Shorthand for getSuperClass().getJavaClass() with null checking.
|
List<DocletTag> |
getTagsByName(String name,
boolean superclasses) |
List<DefaultJavaTypeVariable<JavaClass>> |
getTypeParameters()
Equivalent of
GenericDeclaration.getTypeParameters() |
String |
getValue()
If there's a reference to this class, use the value used in the code.
|
int |
hashCode() |
boolean |
isA(JavaClass javaClass) |
boolean |
isA(String fullClassName) |
boolean |
isAnnotation()
(API description of
Class.isAnnotation() ) |
boolean |
isArray() |
boolean |
isEnum()
(API description of
Class.isEnum() ) |
boolean |
isInner() |
boolean |
isInterface()
(API description of
Class.isInterface() ) |
boolean |
isPrimitive()
Equivalent of
Class.isPrimitive() |
boolean |
isVoid() |
void |
setAnnotation(boolean anAnnotation) |
void |
setEnum(boolean anEnum) |
void |
setImplementz(List<JavaClass> implementz) |
void |
setInterface(boolean anInterface) |
void |
setJavaPackage(JavaPackage javaPackage)
Only used when constructing the model by hand / without source
|
void |
setSuperClass(JavaType type) |
void |
setTypeParameters(List<DefaultJavaTypeVariable<JavaClass>> typeParameters) |
String |
toGenericString() |
String |
toString()
(API description of
Class.toString() )
Converts the object to a string. |
getTagByName
getDeclaringClass, getModifiers, getName, isAbstract, isFinal, isNative, isPrivate, isProtected, isPublic, isStatic, isStrictfp, isSynchronized, isTransient, isVolatile, setDeclaringClass, setModifiers, setName
getAnnotations, getComment, getNamedParameter, getTagByName, getTags, getTagsByName, setAnnotations, setComment, setSource, setTags
getLineNumber, getModelWriter, setLineNumber, setModelWriterFactory
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getDeclaringClass, getModifiers, getName, isAbstract, isFinal, isPrivate, isProtected, isPublic, isStatic
getAnnotations, getComment, getNamedParameter, getTagByName, getTags, getTagsByName
getLineNumber
protected DefaultJavaClass()
public DefaultJavaClass(String name)
public DefaultJavaClass(JavaSource source)
public boolean isInterface()
Class.isInterface()
)
Determines if the specified Class
object represents an interface type.
isInterface
in interface JavaClass
true
if this object represents an interface, otherwise false
public boolean isPrimitive()
Class.isPrimitive()
isPrimitive
in interface JavaClass
true
if this class represents a primitive, otherwise false
public boolean isVoid()
public boolean isEnum()
Class.isEnum()
)
Returns true
if and only if this class was declared as an enum in the source code.
public boolean isAnnotation()
Class.isAnnotation()
)
Returns true if this Class
object represents an annotation type.
Note that if this method returns true, JavaClass.isInterface()
would also return true, as all annotation types are also interfaces.
isAnnotation
in interface JavaClass
true
if this object represents an annotation, otherwise false
public boolean isArray()
public JavaClass getComponentType()
Class.getComponentType()
If this type is an array, return its component typegetComponentType
in interface JavaClass
null
public int getDimensions()
getDimensions
in interface JavaClass
0
public JavaType getSuperClass()
getSuperClass
in interface JavaClass
public JavaClass getSuperJavaClass()
getSuperJavaClass
in interface JavaClass
JavaClass
public List<JavaType> getImplements()
getImplements
in interface JavaClass
public List<JavaClass> getInterfaces()
Class.getInterfaces()
Determines the interfaces implemented by the class or interface represented by this object.getInterfaces
in interface JavaClass
null
public String getCodeBlock()
getCodeBlock
in interface JavaClass
getCodeBlock
in interface JavaModel
public void setInterface(boolean anInterface)
public void setEnum(boolean anEnum)
public void setAnnotation(boolean anAnnotation)
public void addConstructor(JavaConstructor constructor)
public void addMethod(JavaMethod meth)
public void setSuperClass(JavaType type)
public List<DefaultJavaTypeVariable<JavaClass>> getTypeParameters()
GenericDeclaration.getTypeParameters()
getTypeParameters
in interface JavaGenericDeclaration
null
public void setTypeParameters(List<DefaultJavaTypeVariable<JavaClass>> typeParameters)
public void addField(JavaField javaField)
public void setJavaPackage(JavaPackage javaPackage)
javaPackage
- the packagepublic JavaSource getParentSource()
getParentSource
in interface JavaClass
public JavaSource getSource()
getSource
in interface JavaClass
getSource
in class AbstractBaseJavaEntity
JavaSource
of this elementpublic JavaPackage getPackage()
Class.getPackage()
getPackage
in interface JavaClass
public String getPackageName()
getPackageName
in interface JavaClass
public String getSimpleName()
Class.getSimpleName()
.getSimpleName
in interface JavaClass
public String getBinaryName()
The class or interface must be named by its binary name, which must meet the following constraints:
- The binary name of a top level type is its canonical name.
- The binary name of a member type consists of the binary name of its immediately enclosing type, followed by $, followed by the simple name of the member.
getBinaryName
in interface JavaType
public String getFullyQualifiedName()
Every primitive type, named package, top level class, and top level interface has a fully qualified name:Some examples how names will be translatedEach member class, member interface, and array type may have a fully qualified name:
- The fully qualified name of a primitive type is the keyword for that primitive type, namely byte, short, char, int, long, float, double, or boolean.
- The fully qualified name of a named package that is not a subpackage of a named package is its simple name.
- The fully qualified name of a named package that is a subpackage of another named package consists of the fully qualified name of the containing package, followed by ".", followed by the simple (member) name of the subpackage.
- The fully qualified name of a top level class or top level interface that is declared in an unnamed package is the simple name of the class or interface.
- The fully qualified name of a top level class or top level interface that is declared in a named package consists of the fully qualified name of the package, followed by ".", followed by the simple name of the class or interface.
- A member class or member interface M of another class or interface C has a fully qualified name if and only if C has a fully qualified name.
- In that case, the fully qualified name of M consists of the fully qualified name of C, followed by ".", followed by the simple name of M.
- An array type has a fully qualified name if and only if its element type has a fully qualified name.
- In that case, the fully qualified name of an array type consists of the fully qualified name of the component type of the array type followed by "[]".
Object > java.lang.Object java.util.List > java.util.List ? > ? T > T anypackage.Outer.Inner > anypackage.Outer.Inner String[][] > java.lang.String[][]
getFullyQualifiedName
in interface JavaType
null
JavaClass.getComponentType()
,
JavaType.getBinaryName()
,
https://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.7public String getGenericFullyQualifiedName()
getGenericFullyQualifiedName
in interface JavaType
public String getCanonicalName()
Class.getCanonicalName()
.getCanonicalName
in interface JavaType
public String getGenericCanonicalName()
getGenericCanonicalName
in interface JavaType
public String getValue()
private String fieldA; // getValue() will return "String" private java.lang.String fieldA; // getValue() will return "java.lang.String" private List>String> aList; // getValue() will return "List"
public String getGenericValue()
private String fieldA; // getValue() will return "String" private java.lang.String fieldA; // getValue() will return "java.lang.String" private List>String> aList; // getValue() will return "List>String>"
getGenericValue
in interface JavaType
public boolean isInner()
public List<JavaInitializer> getInitializers()
JavaInitializer
, either static or instance initializers.getInitializers
in interface JavaClass
public List<JavaConstructor> getConstructors()
Class.getConstructors()
getConstructors
in interface JavaClass
public JavaConstructor getConstructor(List<JavaType> parameterTypes)
getConstructor
in interface JavaClass
parameterTypes
- the parameter types of the constructor, can be null
null
public JavaConstructor getConstructor(List<JavaType> parameterTypes, boolean varArgs)
getConstructor
in interface JavaClass
parameterTypes
- the parameter types of the constructor, can be null
varArgs
- define is the constructor has varArgsnull
public List<JavaMethod> getMethods()
Class.getMethods()
getMethods
in interface JavaClass
public List<JavaMethod> getMethods(boolean superclasses)
getMethods
in interface JavaClass
superclasses
- true
if inherited methods should be returned as wellpublic JavaMethod getMethodBySignature(String name, List<JavaType> parameterTypes)
getMethodBySignature
in interface JavaClass
name
- the name of the methodparameterTypes
- the parameter types of the method, can be null
.null
public JavaMethod getMethod(String name, List<JavaType> parameterTypes, boolean varArgs)
public JavaMethod getMethodBySignature(String name, List<JavaType> parameterTypes, boolean superclasses)
getMethodBySignature
in interface JavaClass
name
- the name of the methodparameterTypes
- the parameter types of the method, can be null
superclasses
- to define if superclasses should be included as wellnull
public JavaMethod getMethodBySignature(String name, List<JavaType> parameterTypes, boolean superclasses, boolean varArg)
getMethodBySignature
in interface JavaClass
name
- the name of the methodparameterTypes
- the parameter types of the method, can be null
superclasses
- true
if inherited methods should be matched as wellvarArg
- define if the method has varArgsnull
public List<JavaMethod> getMethodsBySignature(String name, List<JavaType> parameterTypes, boolean superclasses)
getMethodsBySignature
in interface JavaClass
name
- the name of the methodparameterTypes
- the parameter types of the method, can be null
superclasses
- true
if inherited methods should be matched as wellnull
public List<JavaMethod> getMethodsBySignature(String name, List<JavaType> parameterTypes, boolean superclasses, boolean varArg)
getMethodsBySignature
in interface JavaClass
name
- the name of the methodparameterTypes
- the parameter types of the method, can be null
superclasses
- true
if inherited methods should be matched as wellvarArg
- define if the method has varArgsnull
public List<JavaField> getFields()
Class.getFields()
public JavaField getFieldByName(String name)
Class.getField(String)
, where this method can resolve every fieldgetFieldByName
in interface JavaClass
name
- the name of the fieldpublic List<JavaField> getEnumConstants()
Class.getEnumConstants()
.getEnumConstants
in interface JavaClass
enum
, otherwise null
public JavaField getEnumConstantByName(String name)
getEnumConstantByName
in interface JavaClass
name
- the name of the enum constantname
, otherwise null
public void addInitializer(JavaInitializer initializer)
public void addClass(JavaClass cls)
public List<JavaClass> getNestedClasses()
Class.getDeclaredClasses()
getNestedClasses
in interface JavaClass
null
public JavaClass getNestedClassByName(String name)
getNestedClassByName
in interface JavaClass
public boolean isA(String fullClassName)
public boolean isA(JavaClass javaClass)
public List<BeanProperty> getBeanProperties()
getBeanProperties
in interface JavaClass
public List<BeanProperty> getBeanProperties(boolean superclasses)
getBeanProperties
in interface JavaClass
superclasses
- to define if superclasses should be included as wellpublic BeanProperty getBeanProperty(String propertyName)
getBeanProperty
in interface JavaClass
propertyName
- the name of the propertypublic BeanProperty getBeanProperty(String propertyName, boolean superclasses)
getBeanProperty
in interface JavaClass
propertyName
- the name of the propertysuperclasses
- to define if superclasses should be included as wellpublic List<JavaClass> getDerivedClasses()
Class.getClasses()
Gets the known derived classes. That is, subclasses or implementing classes.getDerivedClasses
in interface JavaClass
public List<DocletTag> getTagsByName(String name, boolean superclasses)
getTagsByName
in interface JavaClass
getTagsByName
in class AbstractInheritableJavaEntity
public String toString()
JavaClass
Class.toString()
)
Converts the object to a string.
The string representation is the string "class" or "interface", followed by a space, and then by the fully qualified name of the class in the format returned by getName
.
If this Class
object represents a primitive type, this method returns the name of the primitive type.
If this Class
object represents void this method returns "void".toString
in interface JavaClass
toString
in class Object
Class.toString()
public String toGenericString()
toGenericString
in interface JavaType
public ClassLibrary getJavaClassLibrary()
getJavaClassLibrary
in interface JavaClass
Copyright © 2002–2023. All rights reserved.