java.lang.Object
dev.scsupercraft.mc.libraries.corelib.serialization.GenericClass<T>
Type Parameters:
T - The raw class type being represented.

public class GenericClass<T> extends Object
A reflective wrapper around generic types, used to resolve type parameters and annotations for codec generation and serialization logic.

Supports nested generics, arrays, wildcards, and annotated types.

Do not touch unless you know what you are doing!
  • Field Details

    • parent

      public final GenericClass<?> parent
      The enclosing generic class, used to resolve type variables recursively.
    • clazz

      public final Class<T> clazz
      The class that this generic class represents.
    • typeParameters

      public final Map<TypeVariable<Class<T>>,GenericClass<?>> typeParameters
      The type parameters for the class.
    • array

      public final boolean array
      Is this an array type?
    • annotations

      @Nullable public final @Nullable AnnotatedType annotations
      A nullable AnnotatedType for getting annotations if present.

      See TagKeyCodecResolver for an example of how it's used.

  • Constructor Details

    • GenericClass

      public GenericClass(GenericClass<T> arrayType, @Nullable @Nullable AnnotatedType annotations)
      Creates a new generic class as an array type.
      Parameters:
      arrayType - The type stored in the array.
      annotations - The annotations for this type.
    • GenericClass

      public GenericClass(Class<T> tClass, @Nullable @Nullable AnnotatedType annotations)
      Creates a new generic class representing the provided class.
      Parameters:
      tClass - The class this generic class represents.
      annotations - The annotations for this type.
    • GenericClass

      public GenericClass(Class<T> tClass, @Nullable @Nullable AnnotatedType annotations, @Nullable @Nullable GenericClass<?> parent)
      Creates a new generic class representing the provided class.
      Parameters:
      tClass - The class this generic class represents.
      annotations - The annotations for this type.
      parent - The generic class that encloses this one.
    • GenericClass

      public GenericClass(Class<T> tClass, @Nullable @Nullable AnnotatedType annotations, @Nullable @Nullable GenericClass<?> parent, Type[] typeParameters)
      Creates a new generic class representing the provided class.
      Parameters:
      tClass - The class this generic class represents.
      annotations - The annotations for this type.
      parent - The generic class that encloses this one.
      typeParameters - The type parameters used.
    • GenericClass

      public GenericClass(Class<T> tClass, @Nullable @Nullable AnnotatedType annotations, @Nullable @Nullable GenericClass<?> parent, AnnotatedType[] typeParameters)
      Creates a new generic class representing the provided class.
      Parameters:
      tClass - The class this generic class represents.
      annotations - The annotations for this type.
      parent - The generic class that encloses this one.
      typeParameters - The type parameters used.
    • GenericClass

      public GenericClass(Class<T> tClass, @Nullable @Nullable AnnotatedType annotations, @Nullable @Nullable GenericClass<?> parent, Function<GenericClass<T>,GenericClass<?>[]> typeParameterProvider)
      Creates a new generic class representing the provided class.

      Implementation note: Use this constructor when type parameters depend on runtime resolution or recursive context.

      Parameters:
      tClass - The class this generic class represents.
      annotations - The annotations for this type.
      parent - The generic class that encloses this one.
      typeParameterProvider - A function that gets given this generic class during creation and returns the type parameters used. This is here in case you need to use more advanced generics.
  • Method Details

    • of

      public static GenericClass<?> of(AnnotatedType annotatedType)
      Creates a generic class from an AnnotatedType.
      Parameters:
      annotatedType - The annotated type.
      Returns:
      The generic class representing the annotated type.
    • of

      public static GenericClass<?> of(AnnotatedType annotatedType, GenericClass<?> parentType)
      Creates a generic class from an AnnotatedType.
      Parameters:
      annotatedType - The annotated type.
      parentType - The generic class that encloses this one.
      Returns:
      The generic class representing the annotated type.
    • of

      public static GenericClass<?> of(Type type, @Nullable @Nullable AnnotatedType annotatedType)
      Creates a generic class for a Type and a nullable AnnotatedType
      Parameters:
      type - The type.
      annotatedType - The annotated type.
      Returns:
      The generic class representing both the type and annotated type.
    • of

      public static GenericClass<?> of(Type type, @Nullable @Nullable AnnotatedType annotatedType, GenericClass<?> parentType)
      Creates a generic class for a Type and a nullable AnnotatedType
      Parameters:
      type - The type.
      annotatedType - The annotated type.
      parentType - The generic class that encloses this one.
      Returns:
      The generic class representing both the type and annotated type.
    • typeParameterIterator

      public Iterator<? extends GenericClass<?>> typeParameterIterator()
      Creates an Iterator for the type parameters, staying in the order that they were defined in.
      Returns:
      The iterator.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object