summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/api/TagInterop.scala
blob: 4e43f59706efefa2085561f2f7b8aa16a1668d55 (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
36
37
38
package scala.reflect
package api

/** This trait provides type tag <-> manifest interoperability.
 *  @groupname TagInterop TypeTag and Manifest Interoperability
 */
trait TagInterop { self: Universe =>
  // TODO `mirror` parameters are now of type `Any`, because I can't make these path-dependent types work
  // if you're brave enough, replace `Any` with `Mirror`, recompile and run interop_typetags_are_manifests.scala

  /**
   * Convert a [[scala.reflect.api.TypeTags#TypeTag]] to a [[scala.reflect.Manifest]].
   *
   * Compiler usually generates these conversions automatically, when a type tag for a type `T` is in scope,
   * and an implicit of type `Manifest[T]` is requested, but this method can also be called manually.
   * For example:
   * {{{
   * typeTagToManifest(scala.reflect.runtime.currentMirror, implicitly[TypeTag[String]])
   * }}}
   * @group TagInterop
   */
  def typeTagToManifest[T: ClassTag](mirror: Any, tag: Universe#TypeTag[T]): Manifest[T] =
    throw new UnsupportedOperationException("This universe does not support tag -> manifest conversions. Use a JavaUniverse, e.g. the scala.reflect.runtime.universe.")

  /**
   * Convert a [[scala.reflect.Manifest]] to a [[scala.reflect.api.TypeTags#TypeTag]].
   *
   * Compiler usually generates these conversions automatically, when a manifest for a type `T` is in scope,
   * and an implicit of type `TypeTag[T]` is requested, but this method can also be called manually.
   * For example:
   * {{{
   * manifestToTypeTag(scala.reflect.runtime.currentMirror, implicitly[Manifest[String]])
   * }}}
   * @group TagInterop
   */
  def manifestToTypeTag[T](mirror: Any, manifest: Manifest[T]): Universe#TypeTag[T] =
    throw new UnsupportedOperationException("This universe does not support manifest -> tag conversions. Use a JavaUniverse, e.g. the scala.reflect.runtime.universe.")
}