Class DefaultJavaType
- All Implemented Interfaces:
JavaAnnotatedElement
,JavaClass
,JavaGenericDeclaration
,JavaModel
,JavaType
,Serializable
- Direct Known Subclasses:
DefaultJavaParameterizedType
,DefaultJavaTypeVariable
,DefaultJavaWildcardType
JavaType
- Since:
- 2.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
protected String
protected final String
private TypeResolver
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultJavaType
(String fullName) Should only be used by primitives and wildcard, since they don't have a classloader.DefaultJavaType
(String fullName, int dimensions) Should only be used by primitives, since they don't have a classloader.DefaultJavaType
(String name, TypeResolver typeResolver) DefaultJavaType
(String fullName, String name, int dimensions, TypeResolver typeResolver) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Equivalent ofAnnotatedElement.getAnnotations()
Gets bean properties without looking in superclasses or interfaces.getBeanProperties
(boolean superclasses) getBeanProperty
(String propertyName) Gets bean property without looking in superclasses or interfaces.getBeanProperty
(String propertyName, boolean superclasses) 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.Equivalent of (@linkClass.getCanonicalName()
.Retrieve the javadoc comment of this annotated element.Equivalent ofClass.getComponentType()
If this type is an array, return its component typegetConstructor
(List<JavaType> parameterTypes) getConstructor
(List<JavaType> parameterTypes, boolean varArg) Equivalent ofClass.getConstructors()
Equivalent ofClass.getClasses()
Gets the known derived classes.int
Returns the depth of this array, 0 if it's not an arrayprivate static int
getDimensions
(JavaType type) getEnumConstantByName
(String name) Based onClass.getEnumConstants()
.getFieldByName
(String name) Equivalent ofClass.getField(String)
, where this method can resolve every fieldEquivalent ofClass.getFields()
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 translatedThe canonical name with generic information.The fully qualified name with generic information.A java5+ representation of the class.protected static <D extends JavaGenericDeclaration>
StringgetGenericValue
(JavaType base, List<JavaTypeVariable<D>> typeVariableList) A list ifJavaInitializer
, either static or instance initializers.Equivalent ofClass.getInterfaces()
Determines the interfaces implemented by the class or interface represented by this object.int
The line number where this element startedThis should be the signature for getMethodBySignature.getMethodBySignature
(String name, List<JavaType> parameterTypes) getMethodBySignature
(String name, List<JavaType> parameterTypes, boolean superclasses) getMethodBySignature
(String name, List<JavaType> parameterTypes, boolean superclasses, boolean varArg) Equivalent ofClass.getMethods()
getMethods
(boolean superclasses) Return declared methods and optionally the inherited methodsgetMethodsBySignature
(String name, List<JavaType> parameterTypes, boolean superclasses) getMethodsBySignature
(String name, List<JavaType> parameterTypes, boolean superclasses, boolean varArg) Equivalent ofClass.getModifiers()
This does not follow the java-api The Class.getModifiers() returns anint
, which should be decoded with theModifier
.getName()
Equivalent ofClass.getName()
.getNamedParameter
(String tagName, String parameterName) Convenience method forgetTagByName(String).getNamedParameter(String)
that also checks for null tag.getNestedClassByName
(String name) Equivalent ofClass.getDeclaredClasses()
Equivalent ofClass.getPackage()
If this class has a package, the packagename will be returned.protected static <D extends JavaGenericDeclaration>
StringgetResolvedFullyQualifiedName
(JavaType base, List<JavaTypeVariable<D>> typeParameters) protected static <D extends JavaGenericDeclaration>
StringgetResolvedGenericFullyQualifiedName
(JavaType base, List<JavaTypeVariable<D>> typeParameters) protected static <D extends JavaGenericDeclaration>
StringgetResolvedGenericValue
(JavaType base, List<JavaTypeVariable<D>> typeParameters) protected static <D extends JavaGenericDeclaration>
StringgetResolvedValue
(JavaType base, List<JavaTypeVariable<D>> typeParameters) Equivalent ofClass.getSimpleName()
.The compilation unit, which includes the imports, the public and anonymous classesShorthand for getSuperClass().getJavaClass() with null checking.getTagByName
(String name) Retrieve the doclettag by the specified name.getTags()
Retrieve all defined doclet tags.getTagsByName
(String name) Retrieve all doclettags with a specific name.getTagsByName
(String name, boolean superclasses) <D extends JavaGenericDeclaration>
List<JavaTypeVariable<D>>Equivalent ofGenericDeclaration.getTypeParameters()
private static int
getTypeVariableIndex
(JavaClass declaringClass, String fqn) getValue()
If there's a reference to this class, use the value used in the code.int
hashCode()
boolean
boolean
boolean
boolean
(API description ofModifier.isAbstract(int)
) Returntrue
if the class includes the abstract modifier,false
otherwise.boolean
(API description ofClass.isAnnotation()
)boolean
isArray()
boolean
isEnum()
(API description ofClass.isEnum()
)boolean
isFinal()
(API description ofModifier.isFinal(int)
)boolean
isInner()
boolean
(API description ofClass.isInterface()
)boolean
Equivalent ofClass.isPrimitive()
private static boolean
isPrimitive
(String value) boolean
(API description ofModifier.isPrivate(int)
)boolean
(API description ofModifier.isProtected(int)
)boolean
isPublic()
(API description ofModifier.isPublic(int)
)protected boolean
boolean
isStatic()
(API description ofModifier.isStatic(int)
)boolean
isVoid()
protected static JavaType
Consider the following exampleprotected static <D extends JavaGenericDeclaration>
JavaTypeVariable<D>resolve
(JavaType base, List<JavaTypeVariable<D>> typeParameters) private JavaClass
Returns getGenericValue() extended with the array informationtoString()
Equivalent ofClass.toString()
.
-
Field Details
-
name
-
fullName
-
dimensions
private int dimensions -
typeResolver
-
-
Constructor Details
-
DefaultJavaType
DefaultJavaType(String name, TypeResolver typeResolver) -
DefaultJavaType
DefaultJavaType(String fullName, String name, int dimensions, TypeResolver typeResolver) -
DefaultJavaType
DefaultJavaType(String fullName, int dimensions) Should only be used by primitives, since they don't have a classloader.- Parameters:
fullName
- the name of the primitivedimensions
- number of dimensions
-
DefaultJavaType
DefaultJavaType(String fullName) Should only be used by primitives and wildcard, since they don't have a classloader.- Parameters:
fullName
- the name of the primitive or ?
-
-
Method Details
-
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:
-
getSimpleName
Equivalent ofClass.getSimpleName()
.- Specified by:
getSimpleName
in interfaceJavaClass
- Returns:
- the simple name of the underlying class as given in the source code.
-
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:
-
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
-
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
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
-
getGenericValue
protected static <D extends JavaGenericDeclaration> String getGenericValue(JavaType base, List<JavaTypeVariable<D>> typeVariableList) -
getActualTypeArguments
-
getResolvedValue
protected static <D extends JavaGenericDeclaration> String getResolvedValue(JavaType base, List<JavaTypeVariable<D>> typeParameters) -
resolve
protected static <D extends JavaGenericDeclaration> JavaTypeVariable<D> resolve(JavaType base, List<JavaTypeVariable<D>> typeParameters) -
isResolved
protected boolean isResolved() -
isArray
public boolean isArray() -
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
-
toString
Equivalent ofClass.toString()
. Converts the object to a string. -
toGenericString
Returns getGenericValue() extended with the array informationObject > java.lang.Object Object[] > java.lang.Object[] List<Object> > java.lang.List<java.lang.Object> Outer.Inner > Outer$Inner Outer.Inner<Object>[][] > Outer$Inner<java.lang.Object>[][]
- Specified by:
toGenericString
in interfaceJavaType
- Returns:
- a generic string representation of this type.
-
equals
-
hashCode
public int hashCode() -
resolveRealClass
-
isA
- Parameters:
type
- the type to match with- Returns:
true
if this type if of type, otherwisefalse
- Since:
- 1.3
-
isPrimitive
public boolean isPrimitive()Equivalent ofClass.isPrimitive()
- Specified by:
isPrimitive
in interfaceJavaClass
- Returns:
true
if this class represents a primitive, otherwisefalse
-
isPrimitive
-
isVoid
public boolean isVoid() -
resolve
Consider the following examplepublic abstract class AbstractClass<T> { private T value; public AbstractClass( T value ) { this.value = value; } public T getValue() { return value; } } public class ConcreteClass extends AbstractClass<String> { public ConcreteClass( String s ) { super( s ); } }
We want to know the resolved returnType when calling
ConcreteClass.getValue()
. The expected type is String.this
would be TdeclaringClass
would be AbstractClass, since that's where T is usedcallingClass
would be ConcreteClass
- Parameters:
base
- the basedeclaringClass
- the declaring classcallingClass
- the calling class- Returns:
- the resolved type
-
getDimensions
-
getTypeVariableIndex
-
getGenericFullyQualifiedName
The fully qualified name with generic information.- Specified by:
getGenericFullyQualifiedName
in interfaceJavaType
- Returns:
- the generic fully qualified name
-
getGenericCanonicalName
The canonical name with generic information.- Specified by:
getGenericCanonicalName
in interfaceJavaType
- Returns:
- the generic canonical name
-
getResolvedGenericValue
protected static <D extends JavaGenericDeclaration> String getResolvedGenericValue(JavaType base, List<JavaTypeVariable<D>> typeParameters) -
getResolvedGenericFullyQualifiedName
protected static <D extends JavaGenericDeclaration> String getResolvedGenericFullyQualifiedName(JavaType base, List<JavaTypeVariable<D>> typeParameters) -
getResolvedFullyQualifiedName
protected static <D extends JavaGenericDeclaration> String getResolvedFullyQualifiedName(JavaType base, List<JavaTypeVariable<D>> typeParameters) -
getSource
The compilation unit, which includes the imports, the public and anonymous classes- Specified by:
getSource
in interfaceJavaClass
- Returns:
- the
JavaSource
of this element
-
getLineNumber
public int getLineNumber()The line number where this element started- Specified by:
getLineNumber
in interfaceJavaModel
- Returns:
- the line number of this element
-
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
-
getAnnotations
Equivalent ofAnnotatedElement.getAnnotations()
- Specified by:
getAnnotations
in interfaceJavaAnnotatedElement
- Returns:
- a list of Annotations, never
null
-
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. -
getComment
Retrieve the javadoc comment of this annotated element. This is the part between /** and the */, but without the doclet tags- Specified by:
getComment
in interfaceJavaAnnotatedElement
- Returns:
- the comment, otherwise
null
-
getTags
Retrieve all defined doclet tags.- Specified by:
getTags
in interfaceJavaAnnotatedElement
- Returns:
- a list of DocletTags, never
null
-
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
-
getTagsByName
Retrieve all doclettags with a specific name.- Specified by:
getTagsByName
in interfaceJavaAnnotatedElement
- Parameters:
name
- the name of the doclet tag- Returns:
- a list of doclettags, never
null
-
getTagByName
Retrieve the doclettag by the specified name. If there are more than one tags, only return the first one.- Specified by:
getTagByName
in interfaceJavaAnnotatedElement
- Parameters:
name
- the name of the doclettag trying to retrieve- Returns:
- the first doclettag matching the name, otherwise
null
-
getSuperClass
- Specified by:
getSuperClass
in interfaceJavaClass
-
getSuperJavaClass
Shorthand for getSuperClass().getJavaClass() with null checking.- Specified by:
getSuperJavaClass
in interfaceJavaClass
- Returns:
- the super class as
JavaClass
-
getImplements
- Specified by:
getImplements
in interfaceJavaClass
-
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
-
getNamedParameter
Convenience method forgetTagByName(String).getNamedParameter(String)
that also checks for null tag.- Specified by:
getNamedParameter
in interfaceJavaAnnotatedElement
- Parameters:
tagName
- the tag nameparameterName
- the parameter name- Returns:
- the value of the matching parameter, otherwise
null
-
getCodeBlock
- Specified by:
getCodeBlock
in interfaceJavaClass
- Specified by:
getCodeBlock
in interfaceJavaModel
- Returns:
- the codeblock
-
getTypeParameters
Equivalent ofGenericDeclaration.getTypeParameters()
- Specified by:
getTypeParameters
in interfaceJavaGenericDeclaration
- Type Parameters:
D
- the type- Returns:
- a list of typeParameters, never
null
-
getParentSource
- Specified by:
getParentSource
in interfaceJavaClass
-
getPackage
Equivalent ofClass.getPackage()
- Specified by:
getPackage
in interfaceJavaClass
- Returns:
- the package
-
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
-
isInner
public boolean isInner() -
getInitializers
A list ifJavaInitializer
, either static or instance initializers.- Specified by:
getInitializers
in interfaceJavaClass
- Returns:
- a List of initializers
-
getMethods
Equivalent ofClass.getMethods()
- Specified by:
getMethods
in interfaceJavaClass
- Returns:
- the methods declared or overridden in this class
-
getConstructors
Equivalent ofClass.getConstructors()
- Specified by:
getConstructors
in interfaceJavaClass
- Returns:
- the list of constructors
-
getConstructor
- Specified by:
getConstructor
in interfaceJavaClass
- Parameters:
parameterTypes
- the parameter types of the constructor, can benull
- Returns:
- the matching constructor, otherwise
null
-
getConstructor
- Specified by:
getConstructor
in interfaceJavaClass
- Parameters:
parameterTypes
- the parameter types of the constructor, can benull
varArg
- define is the constructor has varArgs- Returns:
- the matching constructor, otherwise
null
-
getMethods
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
- 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
This should be the signature for getMethodBySignature. -
getMethodBySignature
public JavaMethod getMethodBySignature(String name, 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(String name, 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 List<JavaMethod> getMethodsBySignature(String name, 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 List<JavaMethod> getMethodsBySignature(String name, 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
Equivalent ofClass.getFields()
-
getFieldByName
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
Based onClass.getEnumConstants()
.- Specified by:
getEnumConstants
in interfaceJavaClass
- Returns:
- a List of enum constants if this class is an
enum
, otherwisenull
-
getEnumConstantByName
- Specified by:
getEnumConstantByName
in interfaceJavaClass
- Parameters:
name
- the name of the enum constant- Returns:
- the enumConstant matching the
name
, otherwisenull
-
getNestedClasses
Equivalent ofClass.getDeclaredClasses()
- Specified by:
getNestedClasses
in interfaceJavaClass
- Returns:
- a list of declared classes, never
null
-
getNestedClassByName
- Specified by:
getNestedClassByName
in interfaceJavaClass
-
isA
-
isA
-
getBeanProperties
Gets bean properties without looking in superclasses or interfaces.- Specified by:
getBeanProperties
in interfaceJavaClass
- Returns:
- the bean properties
-
getBeanProperties
- Specified by:
getBeanProperties
in interfaceJavaClass
- Parameters:
superclasses
- to define if superclasses should be included as well- Returns:
- the bean properties
-
getBeanProperty
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
- 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
Equivalent ofClass.getClasses()
Gets the known derived classes. That is, subclasses or implementing classes.- Specified by:
getDerivedClasses
in interfaceJavaClass
- Returns:
- the derived classes
-
getTagsByName
- Specified by:
getTagsByName
in interfaceJavaClass
-
getJavaClassLibrary
- Specified by:
getJavaClassLibrary
in interfaceJavaClass
-
getName
Equivalent ofClass.getName()
. -
getCanonicalName
Equivalent of (@linkClass.getCanonicalName()
.- Specified by:
getCanonicalName
in interfaceJavaType
- Returns:
- the canonical name of this class
-
getModifiers
Equivalent ofClass.getModifiers()
This does not follow the java-api The Class.getModifiers() returns anint
, which should be decoded with theModifier
. This method will return a list of strings representing the modifiers. If this member was extracted from a source, it will keep its order. Otherwise if will be in the preferred order of the java-api.- Specified by:
getModifiers
in interfaceJavaClass
- Returns:
- all modifiers is this member
-
isPublic
public boolean isPublic()(API description ofModifier.isPublic(int)
)Return
true
if the class includes the public modifier,false
otherwise. -
isProtected
public boolean isProtected()(API description ofModifier.isProtected(int)
)Return
true
if the class includes the protected modifier,false
otherwise.- Specified by:
isProtected
in interfaceJavaClass
- Returns:
true
if class has the protected modifier, otherwisefalse
-
isPrivate
public boolean isPrivate()(API description ofModifier.isPrivate(int)
)Return
true
if the class includes the private modifier,false
otherwise. -
isFinal
public boolean isFinal()(API description ofModifier.isFinal(int)
)Return
true
if the class includes the final modifier,false
otherwise. -
isStatic
public boolean isStatic()(API description ofModifier.isStatic(int)
)Return
true
if the class includes the static modifier,false
otherwise. -
isAbstract
public boolean isAbstract()(API description ofModifier.isAbstract(int)
) Returntrue
if the class includes the abstract modifier,false
otherwise.- Specified by:
isAbstract
in interfaceJavaClass
- Returns:
true
if class has the abstract modifier, otherwisefalse
-
getDeclaringClass
- Specified by:
getDeclaringClass
in interfaceJavaClass
-