I have an object with some apply method defined and then use it
object Ob {
def apply(i: Int) = ()
def apply(s: String) = ()
}
object Use {
def someMethod(i: Int) = ()
Ob(1)
someMethod(1)
}
When using scalafix/scalameta, I'm unable to find a way to get the handle of the actual apply
method (In my case I'm trying to inspect the argument names and type for a scalafix rule)
When I match and print the resolved SymbolInformation, I get a reference to the object. So this
import scalafix.v1._
import scala.meta._
class NamedLiteralArguments extends SemanticRule("NamedLiteralArguments") {
val minParam = 2
override def fix(implicit doc: SemanticDocument): Patch = {
doc.tree
.collect {
case Term.Apply(fun, args) =>
println(fun.symbol.info)
Patch.empty
}
}
prints
Some(test/Ob. => final object Ob extends AnyRef { +2 decls })
Some(test/Use.someMethod(). => method someMethod(i: Int): Unit)
But I want it to resolve the exact apply
method instead.
(Scalafix version 0.9.20)
Switch on
"-P:semanticdb:synthetics:on"
inbuild.sbt
Then
prints
Notice the line
See:
https://scalameta.org/docs/semanticdb/specification.html#synthetic
https://scalameta.org/docs/semanticdb/specification.html#synthetic-1
https://scalacenter.github.io/scalafix/docs/developers/semantic-tree.html#look-up-inferred-type-parameter
So
will print