Class OverloadRules

java.lang.Object
io.micronaut.sourcegen.generator.OverloadRules

@Internal public final class OverloadRules extends Object
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 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 - the E of a List<String> is String, where the model has the erased Object.
      Parameters:
      paramType - The parameter type of the model
      declaredType - The type the invoked method declares, or null where it is not known
      inferred - The variables the invoked method declares
      receiverArguments - 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 type
      sourceType - The type of the value in the source, or null for the null literal
      inferred - 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 an Object, so a value of a T extends Number is cast to the Object of the model where another overload takes a Number - as the bytecode writers call it.
      Parameters:
      sourceType - The type of the value in the source
      objectDef - The definition the call is written in, or null
      method - The method the call is written in, or null
      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 on
      definition - The definition of the owner, where it is generated
      methodName - The method name
      parameterTypes - The parameter types of the method of the model
      sourceTypes - The types of the values in the source, null for the null literal
      scope - The scope of the file being written
      Returns:
      true if another overload is applicable
    • writtenMethods

      public static List<MethodDef> 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.
      Parameters:
      objectDef - The definition
      scope - 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 definition
      scope - The scope of the file being written
      exact - Whether overrides take the substituted types only
      Returns:
      The methods to write
    • erasedClassVariables

      public static Map<String,TypeDef> erasedClassVariables(ClassTypeDef owner)
      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