Package com.thoughtworks.qdox.model.impl
Class DefaultJavaClass
- java.lang.Object
-
- All Implemented Interfaces:
JavaAnnotatedElement
,JavaClass
,JavaGenericDeclaration
,JavaModel
,JavaType
,java.io.Serializable
public class DefaultJavaClass extends AbstractInheritableJavaEntity implements JavaClass
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DefaultJavaClass()
DefaultJavaClass(JavaSource source)
DefaultJavaClass(java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addClass(JavaClass cls)
void
addConstructor(JavaConstructor constructor)
void
addField(JavaField javaField)
void
addInitializer(JavaInitializer initializer)
void
addMethod(JavaMethod meth)
boolean
equals(java.lang.Object obj)
java.util.List<BeanProperty>
getBeanProperties()
Gets bean properties without looking in superclasses or interfaces.java.util.List<BeanProperty>
getBeanProperties(boolean superclasses)
BeanProperty
getBeanProperty(java.lang.String propertyName)
Gets bean property without looking in superclasses or interfaces.BeanProperty
getBeanProperty(java.lang.String propertyName, boolean superclasses)
java.lang.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.java.lang.String
getCanonicalName()
Equivalent of (@linkClass.getCanonicalName()
.java.lang.String
getCodeBlock()
JavaClass
getComponentType()
Equivalent ofClass.getComponentType()
If this type is an array, return its component typeJavaConstructor
getConstructor(java.util.List<JavaType> parameterTypes)
JavaConstructor
getConstructor(java.util.List<JavaType> parameterTypes, boolean varArgs)
java.util.List<JavaConstructor>
getConstructors()
Equivalent ofClass.getConstructors()
java.util.List<JavaClass>
getDerivedClasses()
Equivalent ofClass.getClasses()
Gets the known derived classes.int
getDimensions()
Returns the depth of this array, 0 if it's not an arrayJavaField
getEnumConstantByName(java.lang.String name)
java.util.List<JavaField>
getEnumConstants()
Based onClass.getEnumConstants()
.JavaField
getFieldByName(java.lang.String name)
Equivalent ofClass.getField(String)
, where this method can resolve every fieldjava.util.List<JavaField>
getFields()
Equivalent ofClass.getFields()
java.lang.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 translatedjava.lang.String
getGenericCanonicalName()
The canonical name with generic information.java.lang.String
getGenericFullyQualifiedName()
The fully qualified name with generic information.java.lang.String
getGenericValue()
A java5+ representation of the class.java.util.List<JavaType>
getImplements()
java.util.List<JavaInitializer>
getInitializers()
A list ifJavaInitializer
, either static or instance initializers.java.util.List<JavaClass>
getInterfaces()
Equivalent ofClass.getInterfaces()
Determines the interfaces implemented by the class or interface represented by this object.ClassLibrary
getJavaClassLibrary()
JavaMethod
getMethod(java.lang.String name, java.util.List<JavaType> parameterTypes, boolean varArgs)
This should be the signature for getMethodBySignature.JavaMethod
getMethodBySignature(java.lang.String name, java.util.List<JavaType> parameterTypes)
JavaMethod
getMethodBySignature(java.lang.String name, java.util.List<JavaType> parameterTypes, boolean superclasses)
JavaMethod
getMethodBySignature(java.lang.String name, java.util.List<JavaType> parameterTypes, boolean superclasses, boolean varArg)
java.util.List<JavaMethod>
getMethods()
Equivalent ofClass.getMethods()
java.util.List<JavaMethod>
getMethods(boolean superclasses)
Return declared methods and optionally the inherited methodsjava.util.List<JavaMethod>
getMethodsBySignature(java.lang.String name, java.util.List<JavaType> parameterTypes, boolean superclasses)
java.util.List<JavaMethod>
getMethodsBySignature(java.lang.String name, java.util.List<JavaType> parameterTypes, boolean superclasses, boolean varArg)
JavaClass
getNestedClassByName(java.lang.String name)
java.util.List<JavaClass>
getNestedClasses()
Equivalent ofClass.getDeclaredClasses()
JavaPackage
getPackage()
Equivalent ofClass.getPackage()
java.lang.String
getPackageName()
If this class has a package, the packagename will be returned.JavaSource
getParentSource()
java.lang.String
getSimpleName()
Equivalent ofClass.getSimpleName()
.JavaSource
getSource()
The compilation unit, which includes the imports, the public and anonymous classesJavaType
getSuperClass()
JavaClass
getSuperJavaClass()
Shorthand for getSuperClass().getJavaClass() with null checking.java.util.List<DocletTag>
getTagsByName(java.lang.String name, boolean superclasses)
java.util.List<DefaultJavaTypeVariable<JavaClass>>
getTypeParameters()
Equivalent ofGenericDeclaration.getTypeParameters()
java.lang.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(java.lang.String fullClassName)
boolean
isAnnotation()
(API description ofClass.isAnnotation()
)boolean
isArray()
boolean
isEnum()
(API description ofClass.isEnum()
)boolean
isInner()
boolean
isInterface()
(API description ofClass.isInterface()
)boolean
isPrimitive()
Equivalent ofClass.isPrimitive()
boolean
isVoid()
void
setAnnotation(boolean anAnnotation)
void
setEnum(boolean anEnum)
void
setImplementz(java.util.List<JavaClass> implementz)
void
setInterface(boolean anInterface)
void
setJavaPackage(JavaPackage javaPackage)
Only used when constructing the model by hand / without sourcevoid
setSuperClass(JavaType type)
void
setTypeParameters(java.util.List<DefaultJavaTypeVariable<JavaClass>> typeParameters)
java.lang.String
toGenericString()
java.lang.String
toString()
(API description ofClass.toString()
) Converts the object to a string.-
Methods inherited from class com.thoughtworks.qdox.model.impl.AbstractInheritableJavaEntity
getTagByName
-
Methods inherited from class com.thoughtworks.qdox.model.impl.AbstractJavaEntity
getDeclaringClass, getModifiers, getName, isAbstract, isFinal, isNative, isPrivate, isProtected, isPublic, isStatic, isStrictfp, isSynchronized, isTransient, isVolatile, setDeclaringClass, setModifiers, setName
-
Methods inherited from class com.thoughtworks.qdox.model.impl.AbstractBaseJavaEntity
getAnnotations, getComment, getNamedParameter, getTagByName, getTags, getTagsByName, setAnnotations, setComment, setSource, setTags
-
Methods inherited from class com.thoughtworks.qdox.model.impl.AbstractJavaModel
getLineNumber, getModelWriter, setLineNumber, setModelWriterFactory
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.thoughtworks.qdox.model.JavaAnnotatedElement
getAnnotations, getComment, getNamedParameter, getTagByName, getTags, getTagsByName
-
Methods inherited from interface com.thoughtworks.qdox.model.JavaClass
getDeclaringClass, getModifiers, getName, isAbstract, isFinal, isPrivate, isProtected, isPublic, isStatic
-
Methods inherited from interface com.thoughtworks.qdox.model.JavaModel
getLineNumber
-
-
-
-
Constructor Detail
-
DefaultJavaClass
protected DefaultJavaClass()
-
DefaultJavaClass
public DefaultJavaClass(java.lang.String name)
-
DefaultJavaClass
public DefaultJavaClass(JavaSource source)
-
-
Method Detail
-
isInterface
public boolean isInterface()
(API description ofClass.isInterface()
)Determines if the specified
Class
object represents an interface type.- Specified by:
isInterface
in interfaceJavaClass
- Returns:
true
if this object represents an interface, otherwisefalse
-
isPrimitive
public boolean isPrimitive()
Equivalent ofClass.isPrimitive()
- Specified by:
isPrimitive
in interfaceJavaClass
- Returns:
true
if this class represents a primitive, otherwisefalse
-
isVoid
public boolean isVoid()
-
isEnum
public boolean isEnum()
(API description ofClass.isEnum()
)Returns
true
if and only if this class was declared as an enum in the source code.
-
isAnnotation
public boolean isAnnotation()
(API description ofClass.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.- Specified by:
isAnnotation
in interfaceJavaClass
- Returns:
true
if this object represents an annotation, otherwisefalse
-
isArray
public boolean isArray()
-
getComponentType
public JavaClass getComponentType()
Equivalent ofClass.getComponentType()
If this type is an array, return its component type- Specified by:
getComponentType
in interfaceJavaClass
- Returns:
- the type of array if it's one, otherwise
null
-
getDimensions
public int getDimensions()
Returns the depth of this array, 0 if it's not an array- Specified by:
getDimensions
in interfaceJavaClass
- Returns:
- The depth of this array, at least
0
-
getSuperClass
public JavaType getSuperClass()
- Specified by:
getSuperClass
in interfaceJavaClass
-
getSuperJavaClass
public JavaClass getSuperJavaClass()
Shorthand for getSuperClass().getJavaClass() with null checking.- Specified by:
getSuperJavaClass
in interfaceJavaClass
- Returns:
- the super class as
JavaClass
-
getImplements
public java.util.List<JavaType> getImplements()
- Specified by:
getImplements
in interfaceJavaClass
-
getInterfaces
public java.util.List<JavaClass> getInterfaces()
Equivalent ofClass.getInterfaces()
Determines the interfaces implemented by the class or interface represented by this object.- Specified by:
getInterfaces
in interfaceJavaClass
- Returns:
- a list of interfaces, never
null
-
getCodeBlock
public java.lang.String getCodeBlock()
- Specified by:
getCodeBlock
in interfaceJavaClass
- Specified by:
getCodeBlock
in interfaceJavaModel
- Returns:
- the codeblock
-
setInterface
public void setInterface(boolean anInterface)
-
setEnum
public void setEnum(boolean anEnum)
-
setAnnotation
public void setAnnotation(boolean anAnnotation)
-
addConstructor
public void addConstructor(JavaConstructor constructor)
-
addMethod
public void addMethod(JavaMethod meth)
-
setSuperClass
public void setSuperClass(JavaType type)
-
setImplementz
public void setImplementz(java.util.List<JavaClass> implementz)
-
getTypeParameters
public java.util.List<DefaultJavaTypeVariable<JavaClass>> getTypeParameters()
Equivalent ofGenericDeclaration.getTypeParameters()
- Specified by:
getTypeParameters
in interfaceJavaGenericDeclaration
- Returns:
- a list of typeParameters, never
null
-
setTypeParameters
public void setTypeParameters(java.util.List<DefaultJavaTypeVariable<JavaClass>> typeParameters)
-
addField
public void addField(JavaField javaField)
-
setJavaPackage
public void setJavaPackage(JavaPackage javaPackage)
Only used when constructing the model by hand / without source- Parameters:
javaPackage
- the package
-
getParentSource
public JavaSource getParentSource()
- Specified by:
getParentSource
in interfaceJavaClass
-
getSource
public JavaSource getSource()
The compilation unit, which includes the imports, the public and anonymous classes- Specified by:
getSource
in interfaceJavaClass
- Overrides:
getSource
in classAbstractBaseJavaEntity
- Returns:
- the
JavaSource
of this element
-
getPackage
public JavaPackage getPackage()
Equivalent ofClass.getPackage()
- Specified by:
getPackage
in interfaceJavaClass
- Returns:
- the package
-
getPackageName
public java.lang.String getPackageName()
If this class has a package, the packagename will be returned. Otherwise an empty String.- Specified by:
getPackageName
in interfaceJavaClass
- Returns:
- the name of the package, otherwise an empty String
-
getSimpleName
public java.lang.String getSimpleName()
Equivalent ofClass.getSimpleName()
.- Specified by:
getSimpleName
in interfaceJavaClass
- Returns:
- the simple name of the underlying class as given in the source code.
-
getBinaryName
public java.lang.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.
- Specified by:
getBinaryName
in interfaceJavaType
- Returns:
- the binary name
- See Also:
- https://docs.oracle.com/javase/specs/jls/se8/html/jls-13.html#jls-13.1
-
getFullyQualifiedName
public java.lang.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 translated- 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[][]
- Specified by:
getFullyQualifiedName
in interfaceJavaType
- Returns:
- the fully qualified name, never
null
- See Also:
JavaClass.getComponentType()
,JavaType.getBinaryName()
, https://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.7
-
getGenericFullyQualifiedName
public java.lang.String getGenericFullyQualifiedName()
The fully qualified name with generic information.- Specified by:
getGenericFullyQualifiedName
in interfaceJavaType
- Returns:
- the generic fully qualified name
-
getCanonicalName
public java.lang.String getCanonicalName()
Equivalent of (@linkClass.getCanonicalName()
.- Specified by:
getCanonicalName
in interfaceJavaType
- Returns:
- the canonical name of this class
-
getGenericCanonicalName
public java.lang.String getGenericCanonicalName()
The canonical name with generic information.- Specified by:
getGenericCanonicalName
in interfaceJavaType
- Returns:
- the generic canonical name
-
getValue
public java.lang.String getValue()
If there's a reference to this class, use the value used in the code. Otherwise return the simple name. When including all imports, you should be safe to use this method. This won't return generics, so it's java1.4 safe. Examples: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"
-
getGenericValue
public java.lang.String getGenericValue()
A java5+ representation of the class. When including all imports, you should be safe to use this method. Examples: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>"
- Specified by:
getGenericValue
in interfaceJavaType
- Returns:
- the generic name of the class as used in the source
-
isInner
public boolean isInner()
-
getInitializers
public java.util.List<JavaInitializer> getInitializers()
A list ifJavaInitializer
, either static or instance initializers.- Specified by:
getInitializers
in interfaceJavaClass
- Returns:
- a List of initializers
-
getConstructors
public java.util.List<JavaConstructor> getConstructors()
Equivalent ofClass.getConstructors()
- Specified by:
getConstructors
in interfaceJavaClass
- Returns:
- the list of constructors
-
getConstructor
public JavaConstructor getConstructor(java.util.List<JavaType> parameterTypes)
- Specified by:
getConstructor
in interfaceJavaClass
- Parameters:
parameterTypes
- the parameter types of the constructor, can benull
- Returns:
- the matching constructor, otherwise
null
-
getConstructor
public JavaConstructor getConstructor(java.util.List<JavaType> parameterTypes, boolean varArgs)
- Specified by:
getConstructor
in interfaceJavaClass
- Parameters:
parameterTypes
- the parameter types of the constructor, can benull
varArgs
- define is the constructor has varArgs- Returns:
- the matching constructor, otherwise
null
-
getMethods
public java.util.List<JavaMethod> getMethods()
Equivalent ofClass.getMethods()
- Specified by:
getMethods
in interfaceJavaClass
- Returns:
- the methods declared or overridden in this class
-
getMethods
public java.util.List<JavaMethod> getMethods(boolean superclasses)
Return declared methods and optionally the inherited methods- Specified by:
getMethods
in interfaceJavaClass
- Parameters:
superclasses
-true
if inherited methods should be returned as well- Returns:
- all methods
-
getMethodBySignature
public JavaMethod getMethodBySignature(java.lang.String name, java.util.List<JavaType> parameterTypes)
- Specified by:
getMethodBySignature
in interfaceJavaClass
- Parameters:
name
- the name of the methodparameterTypes
- the parameter types of the method, can benull
.- Returns:
- the matching method, otherwise
null
-
getMethod
public JavaMethod getMethod(java.lang.String name, java.util.List<JavaType> parameterTypes, boolean varArgs)
This should be the signature for getMethodBySignature.
-
getMethodBySignature
public JavaMethod getMethodBySignature(java.lang.String name, java.util.List<JavaType> parameterTypes, boolean superclasses)
- Specified by:
getMethodBySignature
in interfaceJavaClass
- Parameters:
name
- the name of the methodparameterTypes
- the parameter types of the method, can benull
superclasses
- to define if superclasses should be included as well- Returns:
- the matching method, otherwise
null
-
getMethodBySignature
public JavaMethod getMethodBySignature(java.lang.String name, java.util.List<JavaType> parameterTypes, boolean superclasses, boolean varArg)
- Specified by:
getMethodBySignature
in interfaceJavaClass
- Parameters:
name
- the name of the methodparameterTypes
- the parameter types of the method, can benull
superclasses
-true
if inherited methods should be matched as wellvarArg
- define if the method has varArgs- Returns:
- the matching method, otherwise
null
-
getMethodsBySignature
public java.util.List<JavaMethod> getMethodsBySignature(java.lang.String name, java.util.List<JavaType> parameterTypes, boolean superclasses)
- Specified by:
getMethodsBySignature
in interfaceJavaClass
- Parameters:
name
- the name of the methodparameterTypes
- the parameter types of the method, can benull
superclasses
-true
if inherited methods should be matched as well- Returns:
- the matching methods, otherwise
null
-
getMethodsBySignature
public java.util.List<JavaMethod> getMethodsBySignature(java.lang.String name, java.util.List<JavaType> parameterTypes, boolean superclasses, boolean varArg)
- Specified by:
getMethodsBySignature
in interfaceJavaClass
- Parameters:
name
- the name of the methodparameterTypes
- the parameter types of the method, can benull
superclasses
-true
if inherited methods should be matched as wellvarArg
- define if the method has varArgs- Returns:
- the matching methods, otherwise
null
-
getFields
public java.util.List<JavaField> getFields()
Equivalent ofClass.getFields()
-
getFieldByName
public JavaField getFieldByName(java.lang.String name)
Equivalent ofClass.getField(String)
, where this method can resolve every field- Specified by:
getFieldByName
in interfaceJavaClass
- Parameters:
name
- the name of the field- Returns:
- the field
-
getEnumConstants
public java.util.List<JavaField> getEnumConstants()
Based onClass.getEnumConstants()
.- Specified by:
getEnumConstants
in interfaceJavaClass
- Returns:
- a List of enum constants if this class is an
enum
, otherwisenull
-
getEnumConstantByName
public JavaField getEnumConstantByName(java.lang.String name)
- Specified by:
getEnumConstantByName
in interfaceJavaClass
- Parameters:
name
- the name of the enum constant- Returns:
- the enumConstant matching the
name
, otherwisenull
-
addInitializer
public void addInitializer(JavaInitializer initializer)
-
addClass
public void addClass(JavaClass cls)
-
getNestedClasses
public java.util.List<JavaClass> getNestedClasses()
Equivalent ofClass.getDeclaredClasses()
- Specified by:
getNestedClasses
in interfaceJavaClass
- Returns:
- a list of declared classes, never
null
-
getNestedClassByName
public JavaClass getNestedClassByName(java.lang.String name)
- Specified by:
getNestedClassByName
in interfaceJavaClass
-
isA
public boolean isA(java.lang.String fullClassName)
-
isA
public boolean isA(JavaClass javaClass)
-
getBeanProperties
public java.util.List<BeanProperty> getBeanProperties()
Gets bean properties without looking in superclasses or interfaces.- Specified by:
getBeanProperties
in interfaceJavaClass
- Returns:
- the bean properties
-
getBeanProperties
public java.util.List<BeanProperty> getBeanProperties(boolean superclasses)
- Specified by:
getBeanProperties
in interfaceJavaClass
- Parameters:
superclasses
- to define if superclasses should be included as well- Returns:
- the bean properties
-
getBeanProperty
public BeanProperty getBeanProperty(java.lang.String propertyName)
Gets bean property without looking in superclasses or interfaces.- Specified by:
getBeanProperty
in interfaceJavaClass
- Parameters:
propertyName
- the name of the property- Returns:
- the bean property
-
getBeanProperty
public BeanProperty getBeanProperty(java.lang.String propertyName, boolean superclasses)
- Specified by:
getBeanProperty
in interfaceJavaClass
- Parameters:
propertyName
- the name of the propertysuperclasses
- to define if superclasses should be included as well- Returns:
- the bean property
-
getDerivedClasses
public java.util.List<JavaClass> getDerivedClasses()
Equivalent ofClass.getClasses()
Gets the known derived classes. That is, subclasses or implementing classes.- Specified by:
getDerivedClasses
in interfaceJavaClass
- Returns:
- the derived classes
-
getTagsByName
public java.util.List<DocletTag> getTagsByName(java.lang.String name, boolean superclasses)
- Specified by:
getTagsByName
in interfaceJavaClass
- Specified by:
getTagsByName
in classAbstractInheritableJavaEntity
-
toString
public java.lang.String toString()
Description copied from interface:JavaClass
(API description ofClass.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 bygetName
. If thisClass
object represents a primitive type, this method returns the name of the primitive type. If thisClass
object represents void this method returns "void".
-
toGenericString
public java.lang.String toGenericString()
- Specified by:
toGenericString
in interfaceJavaType
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
getJavaClassLibrary
public ClassLibrary getJavaClassLibrary()
- Specified by:
getJavaClassLibrary
in interfaceJavaClass
-
-