public abstract class JDeclaredType extends JReferenceType implements CanHaveSuppressedWarnings, HasJsName, CanBeJsNative
$clinit
) and the instance initializer method
(named $init
).
The class initializer method is responsible for initializing all class variables as well as
those of the superclasses (by calling the superclass class initializer method).
The instance initializer is responsible for initializing all instance variables as well as those
of the superclasses (by calling the superclass instance initializer method).
Optimizations may eliminate class initializers ($clinit
) if no static variables need
initialization, and use the private variable clinitTarget
to keep track which
initializer in the superclass chain needs to be called.Modifier and Type | Class and Description |
---|---|
static class |
JDeclaredType.NestedClassDisposition
The types of nested classes, https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html
|
HasName.Util
Modifier and Type | Field and Description |
---|---|
protected List<JField> |
fields
This type's fields.
|
protected List<JMethod> |
methods
This type's methods.
|
NULL_TYPE
BY_NAME_COMPARATOR
Constructor and Description |
---|
JDeclaredType(SourceInfo info,
String name) |
Modifier and Type | Method and Description |
---|---|
void |
addField(JField field)
Adds a field to this type.
|
void |
addImplements(JInterfaceType superInterface)
Adds an implemented interface to this type.
|
void |
addMethod(int index,
JMethod method)
Adds a method to this type.
|
void |
addMethod(JMethod newMethod) |
boolean |
canBeImplementedExternally() |
boolean |
canBeReferencedExternally() |
boolean |
checkClinitTo(JDeclaredType targetType)
Returns
true if a static field access of
targetType from within this type should generate a clinit
call. |
JMethod |
findMethod(String methodSignature,
boolean recurse)
Returns the method with the given signature, if there is one.
Optionally can search up the super type chain. |
JDeclaredType |
findSubtype(Iterable<JDeclaredType> types)
Determines whether a subclass of this type is in the collection
types . |
JDeclaredType.NestedClassDisposition |
getClassDisposition() |
JMethod |
getClinitMethod()
Returns the class initializer method.
|
JDeclaredType |
getClinitTarget()
Returns the class that must be initialized to use this class.
|
String[] |
getCompoundName()
Returns the compound name.
|
Iterable<JConstructor> |
getConstructors()
Returns the constructors for this type.
|
JDeclaredType |
getEnclosingType()
Returns the type which encloses this type.
|
List<JField> |
getFields()
Returns this type's fields;does not include fields defined in a super type
unless they are overridden by this type.
|
List<JInterfaceType> |
getImplements()
Returns this type's implemented interfaces.
|
abstract JMethod |
getInitMethod()
Returns the instance initializer ($init) method.
|
String |
getJavahSignatureName() |
String |
getJsName() |
String |
getJsNamespace() |
String |
getJsniSignatureName() |
Iterable<JMember> |
getMembers() |
List<JMethod> |
getMethods()
Returns this type's declared methods; does not include methods defined in a
super type unless they are overridden by this type.
|
String |
getQualifiedJsName() |
String |
getSimpleName()
Returns the simple source name for the class.
|
abstract JClassType |
getSuperClass()
Returns this type's super class, or
null if this type is
Object or an interface. |
Set<String> |
getSuppressedWarnings() |
boolean |
hasClinit()
Returns
true when this class's clinit must be run dynamically. |
boolean |
hasJsInteropEntryPoints() |
boolean |
isArrayType() |
boolean |
isClassWideExport() |
boolean |
isExternal()
True if this class is provided externally to the program by the program's
host execution environment.
|
boolean |
isInstantiable()
Returns whether this type can be instantiated.
|
boolean |
isJsFunction() |
boolean |
isJsNative() |
boolean |
isJsType() |
void |
removeField(int i)
Removes the field at the specified index.
|
void |
removeMethod(int i)
Removes the method at the specified index.
|
void |
resolve(List<JInterfaceType> resolvedInterfaces,
JDeclaredType pkgInfo)
Resolves external references during AST stitching.
|
void |
setClassDisposition(JDeclaredType.NestedClassDisposition nestedClassDisposition) |
void |
setEnclosingType(JDeclaredType enclosingType)
Sets the type which encloses this types.
|
void |
setExternal(boolean isExternal) |
void |
setJsTypeInfo(boolean isJsType,
boolean isJsNative,
boolean isJsFunction,
String jsNamespace,
String jsName,
boolean isClassWideExport) |
void |
setSuppressedWarnings(Set<String> suppressedWarnings) |
void |
sortFields(Comparator<? super JField> sort)
Sorts this type's fields according to the specified sort.
|
void |
sortMethods(Comparator<? super JMethod> sort)
Sorts this type's methods according to the specified sort.
|
protected abstract Object |
writeReplace()
Subclasses must replace themselves with a shallow reference when
isExternal() is true . |
canBeNull, canBeSubclass, getDefaultValue, getUnderlyingType, isPrimitiveType, replaces, strengthenToExact, strengthenToNonNull, weakenToNonExact, weakenToNullable
getDescription, getName, getPackageName, getShortName, isEnumOrSubclass, isJavaLangObject, isJsFunctionImplementation, isJsoType, isNullType
getSourceInfo, setSourceInfo, toSource, toString, traverse
isAbstract
isFinal
public JDeclaredType(SourceInfo info, String name)
public void addField(JField field)
public void addImplements(JInterfaceType superInterface)
public final void addMethod(int index, JMethod method)
public void addMethod(JMethod newMethod)
public boolean checkClinitTo(JDeclaredType targetType)
true
if a static field access of
targetType
from within this type should generate a clinit
call. This will be true in cases where targetType
has a live
clinit method which we cannot statically know has already run. We can
statically know the clinit method has already run when:
this == targetType
this
is a subclass of targetType
, because my
clinit would have already run this targetType
's clinit; see
JLS 12.4public JMethod findMethod(String methodSignature, boolean recurse)
public JDeclaredType findSubtype(Iterable<JDeclaredType> types)
types
.types
- a collections of types.types
contains a subtype of this type; null otherwise.public final JMethod getClinitMethod()
public final JDeclaredType getClinitTarget()
null
if this class has no static initializer.public String[] getCompoundName()
JType
The compound name of a class is an array that contains the simple names of all enclosing types followed by the simple name of this type (in outer to inner order).
A simple name is the name as it appears in the class declaration (e.g. Name in "class Name { .. }"), i.e. it is a name that does not include enclosing type names nor package.
getCompoundName
in class JType
public String getSimpleName()
e.g. if the class is a.b.Foo.Bar it returns Bar as opposed to the short name Foo$Bar.
public Iterable<JConstructor> getConstructors()
public JDeclaredType getEnclosingType()
null
.public List<JField> getFields()
public List<JInterfaceType> getImplements()
public abstract JMethod getInitMethod()
public String getJavahSignatureName()
getJavahSignatureName
in class JReferenceType
public String getJsniSignatureName()
getJsniSignatureName
in class JReferenceType
public final List<JMethod> getMethods()
public boolean isArrayType()
isArrayType
in class JType
public boolean isJsFunction()
isJsFunction
in class JType
public boolean isClassWideExport()
public boolean hasJsInteropEntryPoints()
public boolean canBeReferencedExternally()
canBeReferencedExternally
in class JType
public boolean isJsNative()
isJsNative
in interface CanBeJsNative
isJsNative
in class JType
public boolean canBeImplementedExternally()
canBeImplementedExternally
in class JType
public abstract JClassType getSuperClass()
null
if this type is
Object
or an interface.public boolean hasClinit()
true
when this class's clinit must be run dynamically.public boolean isExternal()
JType
isExternal
in class JType
public boolean isInstantiable()
public void removeField(int i)
public void removeMethod(int i)
public void resolve(List<JInterfaceType> resolvedInterfaces, JDeclaredType pkgInfo)
public void setEnclosingType(JDeclaredType enclosingType)
enclosingType
- May be null
.public void setExternal(boolean isExternal)
public void setJsTypeInfo(boolean isJsType, boolean isJsNative, boolean isJsFunction, String jsNamespace, String jsName, boolean isClassWideExport)
public void sortFields(Comparator<? super JField> sort)
public void sortMethods(Comparator<? super JMethod> sort)
protected abstract Object writeReplace()
isExternal()
is true
.public String getJsNamespace()
getJsNamespace
in interface HasJsName
public String getQualifiedJsName()
getQualifiedJsName
in interface HasJsName
public JDeclaredType.NestedClassDisposition getClassDisposition()
public void setClassDisposition(JDeclaredType.NestedClassDisposition nestedClassDisposition)
public Set<String> getSuppressedWarnings()
getSuppressedWarnings
in interface CanHaveSuppressedWarnings
public void setSuppressedWarnings(Set<String> suppressedWarnings)
setSuppressedWarnings
in interface CanHaveSuppressedWarnings
Copyright © 2018. All rights reserved.