Class RecordImpl

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

public class RecordImpl extends DeclaredImpl implements Record
  • Constructor Details

  • Method Details

    • getRecordComponentOrThrow

      public RecordComponent getRecordComponentOrThrow(String simpleName)
      Specified by:
      getRecordComponentOrThrow in interface Record
    • getRecordComponents

      public List<RecordComponent> getRecordComponents()
      Specified by:
      getRecordComponents in interface Record
    • withGenerics

      public Record withGenerics(Shadow<? extends TypeMirror>... generics)
      Description copied from interface: Record
      shadowApi.getRecordOrThrow("org.example.MyRecord") represents MyRecord shadowApi.getRecordOrThrow("org.example.MyRecord").withGenerics(shadowApi.getDeclaredOrThrow("java.lang.String")) represents MyRecord<String>
      Specified by:
      withGenerics in interface Record
    • withGenerics

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

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

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

      public Record interpolateGenerics()
      Description copied from interface: Record
      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 Record
    • erasure

      public Record erasure()
      Description copied from interface: Record
      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 Records this means for example record MyRecord<T>(T t){} -> record MyRecord<java.lang.Object>(T t){}

      Specified by:
      erasure in interface Record