Class ClassImpl

All Implemented Interfaces:
Annotationable<TypeElement>, ApiHolder, ElementBacked<TypeElement>, MirrorBacked<DeclaredType>, AbstractModifiable, AccessModifiable, FinalModifiable, Modifiable, Sealable, StaticModifiable, StrictfpModifiable, QualifiedNameable<TypeElement>, Annotation, Class, Declared, Enum, Shadow<DeclaredType>

public class ClassImpl extends DeclaredImpl implements Class
  • Constructor Details

  • Method Details

    • isAssignableFrom

      public boolean isAssignableFrom(Shadow<? extends TypeMirror> shadow)
      Description copied from interface: Class
      Equivalent to Declared.isSubtypeOf(Shadow) except for primitives. if one is a primitive and the other is not it tries to convert them
      Specified by:
      isAssignableFrom in interface Class
    • getSuperClass

      public Class getSuperClass()
      Description copied from interface: Class
      reruns the super class of this class. calling getSuperClass()) on Integer will return Number. For Object null will be returned
      Specified by:
      getSuperClass in interface Class
    • getPermittedSubClasses

      public List<Class> getPermittedSubClasses()
      Specified by:
      getPermittedSubClasses in interface Class
    • getProperties

      public List<Property> getProperties()
      Specified by:
      getProperties in interface Class
    • getMutableProperties

      public List<MutableProperty> getMutableProperties()
      Specified by:
      getMutableProperties in interface Class
    • getImmutableProperties

      public List<ImmutableProperty> getImmutableProperties()
      Specified by:
      getImmutableProperties in interface Class
    • getOuterType

      public Optional<Declared> getOuterType()
      Description copied from interface: Class
      returns the outer type for not static classes
      Specified by:
      getOuterType in interface Class
    • withGenerics

      @SafeVarargs public final Class withGenerics(Shadow<? extends TypeMirror>... generics)
      Description copied from interface: Class
      shadowApi.getDeclaredOrThrow("java.util.List") represents List shadowApi.getDeclaredOrThrow("java.util.List").withGenerics(shadowApi.getDeclaredOrThrow("java.lang.String")) represents List<String>
      Specified by:
      withGenerics in interface Class
    • withGenerics

      public Class withGenerics(String... qualifiedGenerics)
      Description copied from interface: Class
      Specified by:
      withGenerics in interface Class
    • getGenerics

      public List<Shadow<TypeMirror>> getGenerics()
      Description copied from interface: Class
      List<String>
      Specified by:
      getGenerics in interface Class
    • getFormalGenerics

      public List<Generic> getFormalGenerics()
      Description copied from interface: Class
      List<T>
      Specified by:
      getFormalGenerics in interface Class
    • interpolateGenerics

      public Class interpolateGenerics()
      Description copied from interface: Class
      Used when constructing types to compare to at compile time that contain multiple, on each other depended, generics.

      it answers the question: given public class MyClass<A extends Comparable<B>, B extends Comparable<A>> {} and A being String what can B be by returning the "simplest" possible answer. in this case String

      The code for the example

      
             Class declared = shadowApi.getClassOrThrow("io.determann.shadow.example.processed.MyClass")
                                       .withGenerics(shadowApi.getDeclaredOrThrow("java.lang.String"),
                                                        shadowApi.getConstants().getUnboundWildcard());
             Class capture = declared.interpolateGenerics();
      
             Shadow<TypeMirror> stringRep = convert(capture.getGenerics().get(1))
                                                            .toGeneric()
                                                            .map(Generic::getExtends)
                                                            .map(shadowApi::convert)
                                                            .flatMap(ShadowConverter::toClassOrThrow)
                                                            .map(Class::getGenerics)
                                                            .map(shadows -> shadows.get(0))
                                                            .orElseThrow();
      
             System.out.println(stringRep.representsSameType(shadowApi.getDeclaredOrThrow("java.lang.String")));
       
      Note the use of the unboundWildcardConstant witch gets replaced by calling capture() with the result
      Specified by:
      interpolateGenerics in interface Class
    • erasure

      public Class erasure()
      Description copied from interface: Class
      Information regarding generics is lost after the compilation. For Example List<String> becomes List. This method Does the same. This can be useful if you want to check if a shadow implements for example Collection shadowToTest.erasure().isSubtypeOf(shadowApi.getDeclaredOrThrow("java.util.Collection").erasure())

      for Classs this means for example class MyClass<T>{} -> class MyClass{}

      Specified by:
      erasure in interface Class
    • asUnboxed

      public Primitive asUnboxed()
      Description copied from interface: Class
      Integer -> int
      Long -> long etc...
      Specified by:
      asUnboxed in interface Class