summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/api/JavaMirrors.scala
blob: e51047a7fe6ec9148aa755efda47771353eb3045 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package scala.reflect
package api

/** A refinement of [[scala.reflect.api.Mirror]] for runtime reflection using JVM classloaders.
 *
 *  This refinement equips mirrors with reflection capabilities for the JVM. `JavaMirror` can
 *  convert Scala reflection artifacts (symbols and types) into Java reflection artifacts (classes)
 *  and vice versa. It can also perform reflective invocations (getting/settings field values, calling methods, etc).
 */
trait JavaMirrors { self: JavaUniverse =>

  /** In runtime reflection universes, runtime representation of a class is [[java.lang.Class]]. */
  type RuntimeClass = java.lang.Class[_]

  /** In runtime reflection universes, mirrors are JavaMirrors. */
  override type Mirror >: Null <: JavaMirror

  /** A refinement of [[scala.reflect.api.Mirror]] for runtime reflection using JVM classloaders.
   *
   *  With this upgrade, mirrors become capable of converting Scala reflection artifacts (symbols and types)
   *  into Java reflection artifacts (classes) and vice versa. Consequently refined mirrors
   *  become capable of performing reflective invocations (getting/settings field values, calling methods, etc).
   *
   *  See [[scala.reflect.api.package the overview page]] for details on how to use runtime reflection.
   */
  trait JavaMirror extends scala.reflect.api.Mirror[self.type] with RuntimeMirror {
    val classLoader: ClassLoader
    override def toString = s"JavaMirror with ${runtime.ReflectionUtils.show(classLoader)}"
  }

  /** Creates a runtime reflection mirror from a JVM classloader.
   *  See [[scala.reflect.api.package the overview page]] for details on how to use runtime reflection.
   */
  def runtimeMirror(cl: ClassLoader): Mirror
}