Class OverrideResolver
java.lang.Object
io.micronaut.sourcegen.generator.OverrideResolver
Resolves the signature a declared method takes as source when it overrides a generic inherited method with that
method's erased signature: the inherited parameter and return types with the type arguments of the supertype
substituted.
A model written for bytecode overrides with the erased form, which the verifier accepts, such as
Object get() for Supplier<String>; source only overrides with the substituted one. How much of
it depends on the language: Java accepts erased parameters and a raw type for a parameterized one, and needs the
substitution where an erasure changes or a return type is a type variable; Kotlin has no raw types and matches
parameters exactly, so it needs the whole substituted signature.
- Since:
- 2.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe signature of an overridden generic method with the type arguments of the supertype substituted.static final recordThe conversions a method reference to a narrowed method is written with. -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable OverrideResolver.ReferenceAdaptationadaptReference(@Nullable ClassTypeDef owner, @Nullable ObjectDef current, @Nullable MethodDef caller, MethodReferenceExpression reference, GenerationScope scope, boolean exact) How a method reference is written where override resolution narrowed the referenced generated method: as a lambda converting the values the functional interface passes to the narrowed parameter types, and the result to the type the functional interface returns.static @Nullable OverrideResolver.OverriddenMethodemittedSignature(@Nullable ClassTypeDef owner, @Nullable ObjectDef current, @Nullable MethodDef caller, MethodDef callMethod, GenerationScope scope, boolean exact) The signature a generated method is written with, as the receiver of the call sees it: with the type arguments the receiver binds the definition's variables to - `apply(String)` on a `GenericTarget`. static @Nullable TypeDefinheritedAs(TypeDef value, ClassTypeDef.Parameterized bound, GenerationScope scope) A value type as the class a parameterized bound is of, with the type arguments it inherits it with - `GenericListextends ArrayList ` as a `List `. receiverArguments(@Nullable ClassTypeDef owner, @Nullable ObjectDef current, MethodDef callMethod, GenerationScope scope) The type arguments a receiver binds the variables of the class declaring the invoked method with: the receiver's type as that class, with the type arguments it inherits it with - through generated and compiled supertypes alike, and none through a raw one (JLS 4.8) - and those its enclosing types bind, for a member of a parameterized type.static @Nullable TypeDefrecordComponentType(RecordDef recordDef, PropertyDef property, GenerationScope scope, boolean exact) The type a record component is written with, where the accessor it implies overrides a generic inherited method with the erasure of that method's signature: anObject valueof a record implementingT value()of aSource<String>is aString value.static @Nullable OverrideResolver.OverriddenMethodresolve(@Nullable ObjectDef objectDef, MethodDef methodDef, GenerationScope scope) Resolves the substituted signature of an erased override for Java source.static @Nullable OverrideResolver.OverriddenMethodresolve(@Nullable ObjectDef objectDef, MethodDef methodDef, GenerationScope scope, boolean exact) Resolves the substituted signature of an erased override.upperBounds(TypeDef type, @Nullable ObjectDef current, @Nullable MethodDef method) The bounds of a type variable that are no variables themselves, in declaration order, with the bounds of the variables a bound names in its place - `U extends V` with `V extends Number` is bounded by `Number`.
-
Method Details
-
resolve
public static @Nullable OverrideResolver.OverriddenMethod resolve(@Nullable ObjectDef objectDef, MethodDef methodDef, GenerationScope scope) Resolves the substituted signature of an erased override for Java source.- Parameters:
objectDef- The declaring definitionmethodDef- The declared methodscope- The scope of the file being written, which looks up the supertypes only known by name- Returns:
- The substituted signature, or
nullwhen Java source can override with the declared one or a type variable of the supertype cannot be resolved
-
resolve
public static @Nullable OverrideResolver.OverriddenMethod resolve(@Nullable ObjectDef objectDef, MethodDef methodDef, GenerationScope scope, boolean exact) Resolves the substituted signature of an erased override.- Parameters:
objectDef- The declaring definitionmethodDef- The declared methodscope- The scope of the file being written, which looks up the supertypes only known by nameexact- Whether the source language overrides with the substituted types only, as Kotlin does, rather than accepting their erasures and raw types as Java does- Returns:
- The substituted signature, or
nullwhen the source can override with the declared one or a type variable of the supertype cannot be resolved
-
recordComponentType
public static @Nullable TypeDef recordComponentType(RecordDef recordDef, PropertyDef property, GenerationScope scope, boolean exact) The type a record component is written with, where the accessor it implies overrides a generic inherited method with the erasure of that method's signature: anObject valueof a record implementingT value()of aSource<String>is aString value. Java requires the accessor of a component to return the type of the component, so the accessor is narrowed by narrowing the component.- Parameters:
recordDef- The recordproperty- The componentscope- The scope of the file being writtenexact- Whether the source language overrides with the substituted types only- Returns:
- The type, or
nullwhere the component is written as the model declares it
-
emittedSignature
public static @Nullable OverrideResolver.OverriddenMethod emittedSignature(@Nullable ClassTypeDef owner, @Nullable ObjectDef current, @Nullable MethodDef caller, MethodDef callMethod, GenerationScope scope, boolean exact) The signature a generated method is written with, as the receiver of the call sees it: with the type arguments the receiver binds the definition's variables to - `apply(String)` on a `GenericTarget`. - Parameters:
owner- The type of the receiver, ornullcurrent- The definition being written, ornullcaller- The method the call is written in, ornullcallMethod- The invoked method, as the model calls itscope- The scope of the file being writtenexact- Whether the source language overrides with the substituted types only- Returns:
- The signature, or
nullwhere the method is written as the model declares it, or its types cannot be expressed where it is called
-
adaptReference
public static @Nullable OverrideResolver.ReferenceAdaptation adaptReference(@Nullable ClassTypeDef owner, @Nullable ObjectDef current, @Nullable MethodDef caller, MethodReferenceExpression reference, GenerationScope scope, boolean exact) How a method reference is written where override resolution narrowed the referenced generated method: as a lambda converting the values the functional interface passes to the narrowed parameter types, and the result to the type the functional interface returns.- Parameters:
owner- The type of the receiver, ornullcurrent- The definition being written, ornullcaller- The method the reference is written in, ornullreference- The referencescope- The scope of the file being writtenexact- Whether the source language overrides with the substituted types only- Returns:
- The conversions, or
nullwhere the reference is written as is
-
inheritedAs
public static @Nullable TypeDef inheritedAs(TypeDef value, ClassTypeDef.Parameterized bound, GenerationScope scope) A value type as the class a parameterized bound is of, with the type arguments it inherits it with - `GenericListextends ArrayList ` as a `List `. - Parameters:
value- The value typebound- The boundscope- The scope of the file being written, which looks up the types only known by name- Returns:
- The type, or
nullwhere the value does not inherit the bound's class
-
receiverArguments
public static Map<String,TypeDef> receiverArguments(@Nullable ClassTypeDef owner, @Nullable ObjectDef current, MethodDef callMethod, GenerationScope scope) The type arguments a receiver binds the variables of the class declaring the invoked method with: the receiver's type as that class, with the type arguments it inherits it with - through generated and compiled supertypes alike, and none through a raw one (JLS 4.8) - and those its enclosing types bind, for a member of a parameterized type.- Parameters:
owner- The type of the receiver, ornullcurrent- The definition being written, ornullcallMethod- The invoked methodscope- The scope of the file being written- Returns:
- The type arguments by the variables they bind, empty where there are none
-
upperBounds
public static List<TypeDef> upperBounds(TypeDef type, @Nullable ObjectDef current, @Nullable MethodDef method) The bounds of a type variable that are no variables themselves, in declaration order, with the bounds of the variables a bound names in its place - `U extends V` with `V extends Number` is bounded by `Number`.- Parameters:
type- The typecurrent- The definition being written, ornullmethod- The method being written, ornull- Returns:
- The bounds, empty where the type is no variable or an unbounded one
-