Class ScalaParameterDefaultValueProvider

java.lang.Object
io.micronaut.scala.processing.visitor.ScalaParameterDefaultValueProvider
All Implemented Interfaces:
io.micronaut.core.order.Ordered, io.micronaut.inject.writer.ParameterDefaultValueProvider

@Internal public final class ScalaParameterDefaultValueProvider extends Object implements io.micronaut.inject.writer.ParameterDefaultValueProvider
Supplies a Scala default argument as an expression the caller evaluates.

Scala compiles a default argument to a zero-argument accessor rather than to anything in the method signature: class Greeter(greeting: String = "hello") emits a static $lessinit$greater$default$1() on the class, and def repeat(word: String, count: Int = 3) an instance repeat$default$2(). Nothing about the parameter itself changes, which is why a default argument was previously invisible and the parameter was treated as required.

This is Scala's whole convention: there is no bitmask and no synthetic overload, so the caller-side SPI fits it exactly, and a Kotlin-style calling convention would not.

  • Field Summary

    Fields inherited from interface io.micronaut.core.order.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Optional<io.micronaut.sourcegen.model.ExpressionDef>
    defaultValueExpression(io.micronaut.inject.ast.ParameterElement parameter, @Nullable io.micronaut.sourcegen.model.ExpressionDef target)
     
    boolean
    supports(io.micronaut.inject.ast.ParameterElement parameter)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.micronaut.core.order.Ordered

    getOrder
  • Constructor Details

    • ScalaParameterDefaultValueProvider

      public ScalaParameterDefaultValueProvider()
  • Method Details

    • supports

      public boolean supports(io.micronaut.inject.ast.ParameterElement parameter)
      Specified by:
      supports in interface io.micronaut.inject.writer.ParameterDefaultValueProvider
    • defaultValueExpression

      public Optional<io.micronaut.sourcegen.model.ExpressionDef> defaultValueExpression(io.micronaut.inject.ast.ParameterElement parameter, @Nullable io.micronaut.sourcegen.model.ExpressionDef target)
      Specified by:
      defaultValueExpression in interface io.micronaut.inject.writer.ParameterDefaultValueProvider