Class OverloadRules
java.lang.Object
io.micronaut.sourcegen.generator.OverloadRules
Which method an invocation names. The bytecode binds the one of the model by its descriptor; a source language selects the most
specific one that takes the values as the source types them, so a value is cast to the parameter of the model
wherever another overload would take it - and to the type the receiver binds a variable of its class with.
- Since:
- 2.3
-
Method Summary
Modifier and TypeMethodDescriptionerasedClassVariables(ClassTypeDef owner) The variables a compiled class declares, as a raw receiver sees them: erased to their bounds.static booleanhasApplicableOverload(@Nullable ClassTypeDef owner, @Nullable ObjectDef definition, String methodName, List<TypeDef> parameterTypes, List<@Nullable TypeDef> sourceTypes, GenerationScope scope) Whether the owner declares another method of the name that takes the values as the source types them.static TypeDeflexicalErasure(TypeDef sourceType, @Nullable ObjectDef objectDef, @Nullable MethodDef method) The erasure a compiler selects an overload by for a variable named alone: that of the bound the method or the class declares it with.static booleanpinsOverload(TypeDef paramType, @Nullable TypeDef sourceType, List<TypeDef.TypeVariable> inferred) Whether a value is cast to the parameter so that the overload of the model is the one selected.static TypeDefreceiverBound(TypeDef paramType, @Nullable TypeDef declaredType, List<TypeDef.TypeVariable> inferred, Map<String, TypeDef> receiverArguments) The parameter as the receiver sees it: a variable of the receiver's class is the type argument it is bound with - theEof aList<String>isString, where the model has the erasedObject.writtenMethods(ObjectDef objectDef, GenerationScope scope) The methods of a definition without the bridges the model declares itself: an erased method that is resolved to the signature of another one, which javac writes the bridge of.writtenMethods(ObjectDef objectDef, GenerationScope scope, boolean exact) The methods of a definition without the bridges the model declares itself, as a source language that overrides with the exact substituted signature, as Kotlin does, or with its erasure as Java does, resolves them.
-
Method Details
-
receiverBound
public static TypeDef receiverBound(TypeDef paramType, @Nullable TypeDef declaredType, List<TypeDef.TypeVariable> inferred, Map<String, TypeDef> receiverArguments) The parameter as the receiver sees it: a variable of the receiver's class is the type argument it is bound with - theEof aList<String>isString, where the model has the erasedObject.- Parameters:
paramType- The parameter type of the modeldeclaredType- The type the invoked method declares, ornullwhere it is not knowninferred- The variables the invoked method declaresreceiverArguments- The type arguments the receiver binds the variables of its class with- Returns:
- The parameter type as the receiver sees it
-
pinsOverload
public static boolean pinsOverload(TypeDef paramType, @Nullable TypeDef sourceType, List<TypeDef.TypeVariable> inferred) Whether a value is cast to the parameter so that the overload of the model is the one selected.- Parameters:
paramType- The parameter typesourceType- The type of the value in the source, ornullfor thenullliteralinferred- The variables the invoked method declares- Returns:
- true if the value is cast
-
lexicalErasure
public static TypeDef lexicalErasure(TypeDef sourceType, @Nullable ObjectDef objectDef, @Nullable MethodDef method) The erasure a compiler selects an overload by for a variable named alone: that of the bound the method or the class declares it with. The model resolves a call by name without that bound, taking the variable as anObject, so a value of aT extends Numberis cast to theObjectof the model where another overload takes aNumber- as the bytecode writers call it.- Parameters:
sourceType- The type of the value in the sourceobjectDef- The definition the call is written in, ornullmethod- The method the call is written in, ornull- Returns:
- The erased bound of a variable named alone, or of an array of one, else the type as it is
-
hasApplicableOverload
public static boolean hasApplicableOverload(@Nullable ClassTypeDef owner, @Nullable ObjectDef definition, String methodName, List<TypeDef> parameterTypes, List<@Nullable TypeDef> sourceTypes, GenerationScope scope) Whether the owner declares another method of the name that takes the values as the source types them.- Parameters:
owner- The type the method is invoked ondefinition- The definition of the owner, where it is generatedmethodName- The method nameparameterTypes- The parameter types of the method of the modelsourceTypes- The types of the values in the source,nullfor thenullliteralscope- The scope of the file being written- Returns:
- true if another overload is applicable
-
writtenMethods
The methods of a definition without the bridges the model declares itself: an erased method that is resolved to the signature of another one, which javac writes the bridge of.- Parameters:
objectDef- The definitionscope- The scope of the file being written- Returns:
- The methods to write
-
writtenMethods
public static List<MethodDef> writtenMethods(ObjectDef objectDef, GenerationScope scope, boolean exact) The methods of a definition without the bridges the model declares itself, as a source language that overrides with the exact substituted signature, as Kotlin does, or with its erasure as Java does, resolves them.- Parameters:
objectDef- The definitionscope- The scope of the file being writtenexact- Whether overrides take the substituted types only- Returns:
- The methods to write
-
erasedClassVariables
The variables a compiled class declares, as a raw receiver sees them: erased to their bounds.- Parameters:
owner- The type of the receiver- Returns:
- The erased bound of each variable, by its name
-