diff options
Diffstat (limited to 'src/compiler/scala/tools/reflect/StdTags.scala')
-rw-r--r-- | src/compiler/scala/tools/reflect/StdTags.scala | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/src/compiler/scala/tools/reflect/StdTags.scala b/src/compiler/scala/tools/reflect/StdTags.scala index 18cbf9c4b7..25a42a82cd 100644 --- a/src/compiler/scala/tools/reflect/StdTags.scala +++ b/src/compiler/scala/tools/reflect/StdTags.scala @@ -4,46 +4,55 @@ package reflect import java.lang.{Class => jClass} import scala.reflect.{ClassTag, classTag} import scala.reflect.base.{MirrorOf, TypeCreator, Universe => BaseUniverse} -import scala.reflect.runtime.{universe => ru} // [Eugene++] Before 2.10 is released, I suggest we don't rely on automated type tag generation // sure, it's convenient, but then refactoring reflection / reification becomes a pain // `ClassTag` tags are fine, because they don't need a reifier to be generated -object StdTags { - // root mirror is fine for these guys, since scala-library.jar is guaranteed to be reachable from the root mirror - lazy val tagOfString = ru.TypeTag[String]( - ru.rootMirror, - new TypeCreator { - def apply[U <: BaseUniverse with Singleton](m: MirrorOf[U]): U # Type = { - val u = m.universe - u.definitions.StringClass.asTypeConstructor - } - }) - lazy val tagOfListOfString = ru.TypeTag[List[String]]( - ru.rootMirror, - new TypeCreator { - def apply[U <: BaseUniverse with Singleton](m: MirrorOf[U]): U # Type = { - val u = m.universe - val pre = u.ThisType(m.staticModule("scala.collection.immutable").moduleClass.asInstanceOf[u.Symbol]) - u.TypeRef(pre, u.definitions.ListClass, List(u.definitions.StringClass.asTypeConstructor)) - } - }) +trait StdTags { + val u: BaseUniverse with Singleton + val m: MirrorOf[u.type] - // root mirror is NOT fine for these guys, hence we use the `currentMirror` trick - private val ourClassloader = getClass.getClassLoader - private def tagOfStaticClass[T: ClassTag] = - ru.TypeTag[T]( - ru.runtimeMirror(ourClassloader), + lazy val tagOfListOfString: u.TypeTag[List[String]] = + u.TypeTag[List[String]]( + m, + new TypeCreator { + def apply[U <: BaseUniverse with Singleton](m: MirrorOf[U]): U # Type = { + val u = m.universe + val pre = u.ThisType(m.staticPackage("scala.collection.immutable").moduleClass.asInstanceOf[u.Symbol]) + u.TypeRef(pre, u.definitions.ListClass, List(u.definitions.StringClass.asTypeConstructor)) + } + }) + + private def tagOfStaticClass[T: ClassTag]: u.TypeTag[T] = + u.TypeTag[T]( + m, new TypeCreator { def apply[U <: BaseUniverse with Singleton](m: MirrorOf[U]): U # Type = m.staticClass(classTag[T].runtimeClass.getName).asTypeConstructor.asInstanceOf[U # Type] }) - lazy val tagOfInt = ru.TypeTag.Int + lazy val tagOfInt = u.TypeTag.Int + lazy val tagOfString = tagOfStaticClass[String] lazy val tagOfFile = tagOfStaticClass[scala.tools.nsc.io.File] lazy val tagOfDirectory = tagOfStaticClass[scala.tools.nsc.io.Directory] lazy val tagOfStdReplVals = tagOfStaticClass[scala.tools.nsc.interpreter.StdReplVals] lazy val tagOfIMain = tagOfStaticClass[scala.tools.nsc.interpreter.IMain] lazy val tagOfThrowable = tagOfStaticClass[java.lang.Throwable] lazy val tagOfClassLoader = tagOfStaticClass[java.lang.ClassLoader] + lazy val tagOfBigInt = tagOfStaticClass[BigInt] + lazy val tagOfBigDecimal = tagOfStaticClass[BigDecimal] + lazy val tagOfCalendar = tagOfStaticClass[java.util.Calendar] + lazy val tagOfDate = tagOfStaticClass[java.util.Date] +} + +object StdRuntimeTags extends StdTags { + val u: scala.reflect.runtime.universe.type = scala.reflect.runtime.universe + val m = u.runtimeMirror(getClass.getClassLoader) + // we need getClass.getClassLoader to support the stuff from scala-compiler.jar +} + +abstract class StdContextTags extends StdTags { + val tc: scala.reflect.makro.Context + val u: tc.universe.type = tc.universe + val m = tc.mirror } |