Interface JClassSymbol
-
- All Superinterfaces:
AnnotableSymbol
,JAccessibleElementSymbol
,JElementSymbol
,JTypeDeclSymbol
,JTypeParameterOwnerSymbol
public interface JClassSymbol extends JTypeDeclSymbol, JTypeParameterOwnerSymbol
Abstraction over aClass
instance. This is not a type, it's the *declaration* of a type. For example, a class symbol representing a generic class can provide access to the formal type parameters, but the symbol does not represent a specific parametrization of a type.Class symbols represent the full range of types represented by
Class
: classes, interfaces, arrays, and primitives. This excludes type variables, intersection types, parameterized types, wildcard types, etc., which are only compile-time constructs.Class symbols are used to back
JClassType
,JArrayType
, andJPrimitiveType
. SeeJTypeMirror.getSymbol()
.- Since:
- 7.0.0
-
-
Field Summary
-
Fields inherited from interface net.sourceforge.pmd.lang.java.symbols.JAccessibleElementSymbol
PRIMITIVE_PACKAGE
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <R,P>
RacceptVisitor(SymbolVisitor<R,P> visitor, P param)
Dispatch to the appropriate visit method of the visitor and returns its result.default boolean
annotationAppliesTo(ElementType elementType)
Return whether annotations of this annotation type apply to the given construct, as per theTarget
annotation.default org.pcollections.PSet<String>
getAnnotationAttributeNames()
Return the simple names of all annotation attributes.default @Nullable RetentionPolicy
getAnnotationRetention()
Returns the retention policy of this annotation, if this is an annotation symbol.@Nullable JTypeDeclSymbol
getArrayComponent()
Returns the component symbol, returns null if this is not an array.@NonNull String
getBinaryName()
Returns the binary name of this type, as specified by the JLS: the JLS.@Nullable String
getCanonicalName()
Returns the simple name of this class, as specified byClass.getCanonicalName()
.List<JConstructorSymbol>
getConstructors()
Returns the constructors declared by this class.default @Nullable JClassSymbol
getDeclaredClass(String name)
Returns a class with the given name defined in this class.List<JClassSymbol>
getDeclaredClasses()
Returns the member classes declared directly in this class.default @Nullable JFieldSymbol
getDeclaredField(String name)
Returns a field with the given name defined in this class.List<JFieldSymbol>
getDeclaredFields()
Returns the fields declared directly in this class.List<JMethodSymbol>
getDeclaredMethods()
Returns the methods declared directly in this class.default @Nullable SymbolicValue
getDefaultAnnotationAttributeValue(String attrName)
Return the default value of the attribute if this is an annotation type with a default.@Nullable JExecutableSymbol
getEnclosingMethod()
Returns the method or constructor this symbol is declared in, if it represents a local class declaration.default JTypeParameterOwnerSymbol
getEnclosingTypeParameterOwner()
Returns theenclosing method
or theenclosing class
, in that order of priority.default @NonNull List<JFieldSymbol>
getEnumConstants()
Returns a list with all enum constants.default @NonNull JClassSymbol
getNestRoot()
Returns the toplevel class containing this class.@Nullable JClassSymbol
getSuperclass()
Returns the superclass symbol if it exists.@Nullable JClassType
getSuperclassType(Substitution substitution)
Returns the superclass type, under the given substitution.List<JClassSymbol>
getSuperInterfaces()
Returns the direct super-interfaces of this class or interface symbol.List<JClassType>
getSuperInterfaceTypes(Substitution substitution)
Returns the list of super interface types, under the given substitution.default boolean
isAbstract()
boolean
isAnnotation()
boolean
isAnonymousClass()
boolean
isArray()
default boolean
isClass()
This returns true if this is not an interface, primitive or array.boolean
isEnum()
boolean
isLocalClass()
boolean
isPrimitive()
boolean
isRecord()
default @Nullable N
tryGetNode()
Returns the node that declares this symbol.-
Methods inherited from interface net.sourceforge.pmd.lang.java.symbols.AnnotableSymbol
getDeclaredAnnotation, getDeclaredAnnotations, isAnnotationPresent
-
Methods inherited from interface net.sourceforge.pmd.lang.java.symbols.JAccessibleElementSymbol
getEnclosingClass, getModifiers, getPackageName, isStatic
-
Methods inherited from interface net.sourceforge.pmd.lang.java.symbols.JElementSymbol
equals, getTypeSystem, nameEquals
-
Methods inherited from interface net.sourceforge.pmd.lang.java.symbols.JTypeDeclSymbol
getSimpleName, isInterface, isUnresolved
-
Methods inherited from interface net.sourceforge.pmd.lang.java.symbols.JTypeParameterOwnerSymbol
getLexicalScope, getTypeParameterCount, getTypeParameters, isGeneric
-
-
-
-
Method Detail
-
getBinaryName
@NonNull String getBinaryName()
Returns the binary name of this type, as specified by the JLS: the JLS. For array types this returns the binary name of the component followed by "[]". This differs fromClass.getName()
, which for array types outputs an internal name.For example:
whereasint.class.getName() == "int" int[].class.getName() == "[I" String.class.getName() == "java.lang.String" String[].class.getName() == "[Ljava.lang.String;"
symbolOf(int.class).getBinaryName() == "int" symbolOf(int[].class).getBinaryName() == "int[]" symbolOf(String.class).getBinaryName() == "java.lang.String" symbolOf(String[].class).getBinaryName() == "java.lang.String[]"
-
getCanonicalName
@Nullable String getCanonicalName()
Returns the simple name of this class, as specified byClass.getCanonicalName()
.
-
getEnclosingMethod
@Nullable JExecutableSymbol getEnclosingMethod()
Returns the method or constructor this symbol is declared in, if it represents a local class declaration.Notice, that this returns null also if this class is local to a class or instance initializer.
-
getEnclosingTypeParameterOwner
default JTypeParameterOwnerSymbol getEnclosingTypeParameterOwner()
Description copied from interface:JTypeParameterOwnerSymbol
Returns theenclosing method
or theenclosing class
, in that order of priority.- Specified by:
getEnclosingTypeParameterOwner
in interfaceJTypeParameterOwnerSymbol
-
getDeclaredClasses
List<JClassSymbol> getDeclaredClasses()
Returns the member classes declared directly in this class.- See Also:
Class.getDeclaredClasses()
-
getDeclaredClass
default @Nullable JClassSymbol getDeclaredClass(String name)
Returns a class with the given name defined in this class.
-
getDeclaredMethods
List<JMethodSymbol> getDeclaredMethods()
Returns the methods declared directly in this class. This excludes bridges and other synthetic methods.For an array type T[], to the difference of
Class
, this method returns a one-element list with theObject.clone()
method, as if declared like so:public final T[] clone() {...}
.- See Also:
Class.getDeclaredMethods()
-
getConstructors
List<JConstructorSymbol> getConstructors()
Returns the constructors declared by this class. This excludes synthetic constructors.For an array type T[], and to the difference of
Class
, this should return a one-element list with a constructor having the same modifiers as the array type, and a singleint
parameter.- See Also:
Class.getDeclaredConstructors()
-
getDeclaredFields
List<JFieldSymbol> getDeclaredFields()
Returns the fields declared directly in this class. This excludes synthetic fields.For arrays, and to the difference of
Class
, this should return a one-element list with thepublic final int length
field.- See Also:
Class.getDeclaredFields()
-
getDeclaredField
default @Nullable JFieldSymbol getDeclaredField(String name)
Returns a field with the given name defined in this class.
-
getEnumConstants
default @NonNull List<JFieldSymbol> getEnumConstants()
Returns a list with all enum constants. If this symbol does not represent an enum, returns an empty set. The returned list is a subset ofgetDeclaredFields()
. The order of fields denotes the normal order of enum constants.
-
getSuperInterfaceTypes
List<JClassType> getSuperInterfaceTypes(Substitution substitution)
Returns the list of super interface types, under the given substitution.
-
getSuperclassType
@Nullable JClassType getSuperclassType(Substitution substitution)
Returns the superclass type, under the given substitution.
-
getSuperclass
@Nullable JClassSymbol getSuperclass()
-
getSuperInterfaces
List<JClassSymbol> getSuperInterfaces()
Returns the direct super-interfaces of this class or interface symbol.
-
isAbstract
default boolean isAbstract()
-
getArrayComponent
@Nullable JTypeDeclSymbol getArrayComponent()
Returns the component symbol, returns null if this is not an array.
-
isArray
boolean isArray()
-
isPrimitive
boolean isPrimitive()
-
isEnum
boolean isEnum()
-
isRecord
boolean isRecord()
-
isAnnotation
boolean isAnnotation()
-
isLocalClass
boolean isLocalClass()
-
isAnonymousClass
boolean isAnonymousClass()
-
getAnnotationAttributeNames
default org.pcollections.PSet<String> getAnnotationAttributeNames()
Return the simple names of all annotation attributes. If this is not an annotation type, return an empty set.
-
getDefaultAnnotationAttributeValue
default @Nullable SymbolicValue getDefaultAnnotationAttributeValue(String attrName)
Return the default value of the attribute if this is an annotation type with a default. Return null if this is not an annotation type, if there is no such attribute, or the attribute has no default value. If the name is in the attribute name set, then the null return value can only mean that the attribute exists but has no default value.- Parameters:
attrName
- Attribute name
-
getAnnotationRetention
default @Nullable RetentionPolicy getAnnotationRetention()
Returns the retention policy of this annotation, if this is an annotation symbol. Otherwise returns null.
-
annotationAppliesTo
default boolean annotationAppliesTo(ElementType elementType)
Return whether annotations of this annotation type apply to the given construct, as per theTarget
annotation. Return false if this is not an annotation.
-
isClass
default boolean isClass()
This returns true if this is not an interface, primitive or array.
-
getNestRoot
default @NonNull JClassSymbol getNestRoot()
Returns the toplevel class containing this class. If this is a toplevel class, returns this.
-
acceptVisitor
default <R,P> R acceptVisitor(SymbolVisitor<R,P> visitor, P param)
Description copied from interface:JElementSymbol
Dispatch to the appropriate visit method of the visitor and returns its result.- Specified by:
acceptVisitor
in interfaceJElementSymbol
-
tryGetNode
default @Nullable N tryGetNode()
Description copied from interface:JElementSymbol
Returns the node that declares this symbol. Eg forJMethodSymbol
, it's anASTMethodDeclaration
. Will only return non-null if the symbol is declared in the file currently being analysed.- Specified by:
tryGetNode
in interfaceJElementSymbol
-
-