score:4

Accepted answer

Could this answer help you?

Here is an example for scalaVersion := "2.11.1"

import scala.reflect.runtime.{universe => u}

def companionMembers(clazzTag: scala.reflect.ClassTag[_]): u.MemberScope = {
  val runtimeClass = clazzTag.runtimeClass
  val rootMirror = u.runtimeMirror(runtimeClass.getClassLoader)
  val classSymbol = rootMirror.classSymbol(runtimeClass)
  // get the companion here
  classSymbol.companion.typeSignature.members
}

case class MyClass(value: Int)

val applyMethods =
  companionMembers(scala.reflect.classTag[MyClass])
  .filter { m => m.isMethod && m.name.toString == "apply"}

println(applyMethods)

prints

Scope{
  case def apply(value: scala.Int): MyClass
}

Related Query

More Query from same tag