Interface JClassSymbol

    • 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 from Class.getName(), which for array types outputs an internal name.

        For example:

        
         int.class.getName() == "int"
         int[].class.getName() == "[I"
         String.class.getName() == "java.lang.String"
         String[].class.getName() == "[Ljava.lang.String;"
         
        whereas
        
         symbolOf(int.class).getBinaryName() == "int"
         symbolOf(int[].class).getBinaryName() == "int[]"
         symbolOf(String.class).getBinaryName() == "java.lang.String"
         symbolOf(String[].class).getBinaryName() == "java.lang.String[]"
         
      • 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.

      • 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 the Object.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 single int 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 the public 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 list. The returned list is a subset of getDeclaredFields(). The order of fields denotes the normal order of enum constants.
      • getRecordComponents

        default @NonNull List<JRecordComponentSymbol> getRecordComponents()
        Returns a list with all record components. If this symbol does not represent a record, returns an empty list. The order of values denotes the normal order of components.
      • 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()
        Returns the superclass symbol if it exists. Returns null if this class represents the class Object, or a primitive type. If this symbol is an interface, returns the symbol for Object.
      • 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()
      • getPermittedSubtypes

        default List<JClassSymbol> getPermittedSubtypes()
        Return the list of permitted subclasses or subinterfaces, as defined in the permits clause of a sealed class or interface. If this class is sealed but has no permits clause, the permitted subtypes are inferred from the types in the compilation unit. If the class is not sealed, returns an empty list.

        Note that an enum class for which some constants declare a body is technically implicitly sealed, and implicitly permits only the anonymous classes for those enum constants. For consistency, this method will return only symbols that have a canonical name, and therefore always return an empty list for enums.

        See Also:
        isSealed()
      • isSealed

        default boolean isSealed()
        Return true if this type is sealed. Then it has a non-empty list of permitted subclasses (or it is a compile-time error). Note that there is no trace of the non-sealed modifier in class files. A class must have the non-sealed modifier if it is not sealed, not final, and has a sealed supertype.

        Note that an enum class for which some constants declare a body is technically implicitly sealed, and implicitly permits only the anonymous classes for those enum constants. For consistency with getPermittedSubtypes(), we treat such enums as not sealed.

        See Also:
        getPermittedSubtypes()
      • isFinal

        default boolean isFinal()
        Return true if this type is final, that is, does not admit subtypes. Note that array types have both modifiers final and abstract. Note also that enum classes may be non-final if they have constants that declare an anonymous body.
      • 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 the Target 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. Note that this includes in particular records and enums.
      • 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 interface JElementSymbol