Package io.determann.shadow.api.shadow
Interface Record
- All Superinterfaces:
AccessModifiable,Annotationable<TypeElement>,ApiHolder,Declared,ElementBacked<TypeElement>,FinalModifiable,MirrorBacked<DeclaredType>,Modifiable,QualifiedNameable<TypeElement>,Shadow<DeclaredType>,StaticModifiable,StrictfpModifiable
- All Known Implementing Classes:
RecordImpl
-
Method Summary
Modifier and TypeMethodDescriptionbooleanbe careful using this equalserasure()Information regarding generics is lost after the compilation.MyRecord<T>MyRecord<String>getRecordComponentOrThrow(String simpleName) Used when constructing types to compare to at compile time that contain multiple, on each other depended, generics.withGenerics(Shadow<? extends TypeMirror>... generics) shadowApi.getRecordOrThrow("org.example.MyRecord")representsMyRecordshadowApi.getRecordOrThrow("org.example.MyRecord").withGenerics(shadowApi.getDeclaredOrThrow("java.lang.String"))representsMyRecord<String>withGenerics(String... qualifiedGenerics) likewithGenerics(Shadow[])but resolves the names usingDeclaredHolder.getDeclaredOrThrow(String)Methods inherited from interface io.determann.shadow.api.modifier.AccessModifiable
isPackagePrivate, isPrivate, isProtected, isPublicMethods inherited from interface io.determann.shadow.api.Annotationable
getAnnotationUsages, getDirectAnnotationUsages, getDirectUsageOf, getDirectUsageOfOrThrow, getDirectUsagesOf, getUsageOf, getUsageOfOrThrow, getUsagesOf, isAnnotatedWith, isDirectlyAnnotatedWithMethods inherited from interface io.determann.shadow.api.shadow.Declared
asArray, asExtendsWildcard, asSuperWildcard, getBinaryName, getConstructors, getDirectInterfaceOrThrow, getDirectInterfaces, getDirectSuperTypes, getFieldOrThrow, getFields, getInterfaceOrThrow, getInterfaces, getMethods, getMethods, getNesting, getPackage, getSuperTypes, isSubtypeOfMethods inherited from interface io.determann.shadow.api.ElementBacked
getElement, getJavaDoc, getModifiers, getModule, getSimpleName, logError, logInfo, logWarningMethods inherited from interface io.determann.shadow.api.modifier.FinalModifiable
isFinalMethods inherited from interface io.determann.shadow.api.modifier.Modifiable
hasModifierMethods inherited from interface io.determann.shadow.api.QualifiedNameable
getQualifiedNameMethods inherited from interface io.determann.shadow.api.shadow.Shadow
getApi, getMirror, getTypeKind, isTypeKind, representsSameTypeMethods inherited from interface io.determann.shadow.api.modifier.StaticModifiable
isStaticMethods inherited from interface io.determann.shadow.api.modifier.StrictfpModifiable
isStrictfp
-
Method Details
-
getRecordComponentOrThrow
-
getRecordComponents
List<RecordComponent> getRecordComponents() -
withGenerics
shadowApi.getRecordOrThrow("org.example.MyRecord")representsMyRecordshadowApi.getRecordOrThrow("org.example.MyRecord").withGenerics(shadowApi.getDeclaredOrThrow("java.lang.String"))representsMyRecord<String> -
withGenerics
likewithGenerics(Shadow[])but resolves the names usingDeclaredHolder.getDeclaredOrThrow(String) -
getGenerics
List<Shadow<TypeMirror>> getGenerics()MyRecord<String> -
getFormalGenerics
MyRecord<T> -
interpolateGenerics
Record interpolateGenerics()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 beingStringwhat can B be by returning the "simplest" possible answer. in this case StringThe code for the example
Note the use of the unboundWildcardConstant witch gets replaced by callingClass 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")));capture()with the result -
erasure
Record erasure()Information regarding generics is lost after the compilation. For ExampleList<String>becomesList. This method Does the same. This can be useful if you want to check if a shadow implements for exampleCollectionshadowToTest.erasure().isSubtypeOf(shadowApi.getDeclaredOrThrow("java.util.Collection").erasure())for
Records this means for examplerecord MyRecord<T>(T t){}->record MyRecord<java.lang.Object>(T t){} -
equals
be careful using this equals
-