Class InterfaceImpl

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

public class InterfaceImpl extends DeclaredImpl implements Interface
  • Constructor Details

  • Method Details

    • isFunctional

      public boolean isFunctional()
      Specified by:
      isFunctional in interface Interface
    • withGenerics

      @SafeVarargs public final Interface withGenerics(Shadow<? extends TypeMirror>... generics)
      Description copied from interface: Interface
      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 Interface
    • withGenerics

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

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

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

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

      public Interface erasure()
      Description copied from interface: Interface
      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 Interfaces this means for example interface MyInterface<T>{} -> interface MyInterface{}

      Specified by:
      erasure in interface Interface