From ad7983b70a43ba9033a491c00ad22691e7a0a7b4 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 27 Jan 2014 22:47:36 +0300 Subject: additional class tags for reflection API Introduces a test that iterates all abstract types in reflection API and makes sure that every one of them has an associated class tag. After being introduced, the test has immediately failed exposing the lack of tags for TreeCopier, Mirror and RuntimeClass, which has been subsequently fixed in this commit. --- test/files/run/reflection-tags.check | 1 + test/files/run/reflection-tags.scala | 17 +++++++++++++++++ .../tools/nsc/symtab/SymbolTableForUnitTesting.scala | 6 ++++++ 3 files changed, 24 insertions(+) create mode 100644 test/files/run/reflection-tags.check create mode 100644 test/files/run/reflection-tags.scala (limited to 'test') diff --git a/test/files/run/reflection-tags.check b/test/files/run/reflection-tags.check new file mode 100644 index 0000000000..375518e921 --- /dev/null +++ b/test/files/run/reflection-tags.check @@ -0,0 +1 @@ +List() diff --git a/test/files/run/reflection-tags.scala b/test/files/run/reflection-tags.scala new file mode 100644 index 0000000000..fba90f61e9 --- /dev/null +++ b/test/files/run/reflection-tags.scala @@ -0,0 +1,17 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.ClassTag + +object Test extends App { + var typeMembers = typeOf[scala.reflect.api.Universe].members.filter(sym => sym.isType && !sym.isClass).toList + typeMembers = typeMembers.filter(_.name != TypeName("ModifiersCreator")) // type ModifiersCreator = ModifiersExtractor + val tags = typeOf[scala.reflect.api.Universe].members.filter(sym => sym.isImplicit).toList + + typeMembers.foreach(_.typeSignature) + tags.foreach(_.typeSignature) + + val outliers = typeMembers.filter(tm => !tags.exists(tag => tag.typeSignature match { + case NullaryMethodType(TypeRef(_, sym, targ :: Nil)) => sym == typeOf[ClassTag[_]].typeSymbol && targ.typeSymbol == tm + case _ => false + })) + println(outliers) +} \ No newline at end of file diff --git a/test/junit/scala/tools/nsc/symtab/SymbolTableForUnitTesting.scala b/test/junit/scala/tools/nsc/symtab/SymbolTableForUnitTesting.scala index b42e9a07cb..25d8c4667f 100644 --- a/test/junit/scala/tools/nsc/symtab/SymbolTableForUnitTesting.scala +++ b/test/junit/scala/tools/nsc/symtab/SymbolTableForUnitTesting.scala @@ -1,6 +1,7 @@ package scala.tools.nsc package symtab +import scala.reflect.ClassTag import scala.reflect.internal.{Phase, NoPhase, SomePhase} import scala.tools.util.PathResolver import util.ClassPath @@ -89,4 +90,9 @@ class SymbolTableForUnitTesting extends SymbolTable { val currentFreshNameCreator = new reflect.internal.util.FreshNameCreator phase = SomePhase + + type RuntimeClass = java.lang.Class[_] + implicit val RuntimeClassTag: ClassTag[RuntimeClass] = ClassTag[RuntimeClass](classOf[RuntimeClass]) + implicit val MirrorTag: ClassTag[Mirror] = ClassTag[Mirror](classOf[GlobalMirror]) + implicit val TreeCopierTag: ClassTag[TreeCopier] = ClassTag[TreeCopier](classOf[TreeCopier]) } -- cgit v1.2.3