From 3237b1cd6fc2b2029080fe9d4b2b76d43ab8011c Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Sat, 30 Jun 2012 03:37:17 +0200 Subject: further improves reflection printers --- src/reflect/scala/reflect/api/Printers.scala | 39 ++++------- src/reflect/scala/reflect/internal/Printers.scala | 75 ++++++++++++++++------ .../scala/reflect/runtime/ReflectionUtils.scala | 15 +++-- test/files/run/showraw_mods.check | 2 +- test/files/run/showraw_tree.check | 4 +- test/files/run/showraw_tree_ids.check | 4 +- test/files/run/showraw_tree_ids.scala | 5 +- test/files/run/showraw_tree_kinds.check | 4 +- test/files/run/showraw_tree_types_ids.check | 20 +++--- test/files/run/showraw_tree_types_ids.scala | 5 +- test/files/run/showraw_tree_types_typed.check | 16 ++--- test/files/run/showraw_tree_types_untyped.check | 4 +- test/files/run/showraw_tree_ultimate.check | 20 +++--- test/files/run/showraw_tree_ultimate.scala | 5 +- 14 files changed, 125 insertions(+), 93 deletions(-) diff --git a/src/reflect/scala/reflect/api/Printers.scala b/src/reflect/scala/reflect/api/Printers.scala index 7f4ff8a7fb..27d3b8ba7d 100644 --- a/src/reflect/scala/reflect/api/Printers.scala +++ b/src/reflect/scala/reflect/api/Printers.scala @@ -10,12 +10,15 @@ trait Printers { self: Universe => protected var printTypes = false protected var printIds = false protected var printKinds = false + protected var printMirrors = false def withTypes: this.type = { printTypes = true; this } def withoutTypes: this.type = { printTypes = false; this } def withIds: this.type = { printIds = true; this } def withoutIds: this.type = { printIds = false; this } def withKinds: this.type = { printKinds = true; this } def withoutKinds: this.type = { printKinds = false; this } + def withMirrors: this.type = { printMirrors = true; this } + def withoutMirrors: this.type = { printMirrors = false; this } } case class BooleanFlag(val value: Option[Boolean]) @@ -25,13 +28,14 @@ trait Printers { self: Universe => implicit def optionToBooleanFlag(value: Option[Boolean]): BooleanFlag = BooleanFlag(value) } - protected def render(what: Any, mkPrinter: PrintWriter => TreePrinter, printTypes: BooleanFlag = None, printIds: BooleanFlag = None, printKinds: BooleanFlag = None): String = { + protected def render(what: Any, mkPrinter: PrintWriter => TreePrinter, printTypes: BooleanFlag = None, printIds: BooleanFlag = None, printKinds: BooleanFlag = None, printMirrors: BooleanFlag = None): String = { val buffer = new StringWriter() val writer = new PrintWriter(buffer) var printer = mkPrinter(writer) printTypes.value.map(printTypes => if (printTypes) printer.withTypes else printer.withoutTypes) printIds.value.map(printIds => if (printIds) printer.withIds else printer.withoutIds) printKinds.value.map(printKinds => if (printKinds) printer.withKinds else printer.withoutKinds) + printMirrors.value.map(printMirrors => if (printMirrors) printer.withMirrors else printer.withoutMirrors) printer.print(what) writer.flush() buffer.toString @@ -40,42 +44,25 @@ trait Printers { self: Universe => /** By default trees are printed with `show` */ override protected def treeToString(tree: Tree) = show(tree) - /** Renders a prettified representation of a tree. + /** Renders a prettified representation of a reflection artifact. * Typically it looks very close to the Scala code it represents. - * This function is used in Tree.toString. */ - def show(tree: Tree, printTypes: BooleanFlag = None, printIds: BooleanFlag = None, printKinds: BooleanFlag = None): String = - render(tree, newTreePrinter(_), printTypes, printIds, printKinds) + def show(any: Any, printTypes: BooleanFlag = None, printIds: BooleanFlag = None, printKinds: BooleanFlag = None, printMirrors: BooleanFlag = None): String = + render(any, newTreePrinter(_), printTypes, printIds, printKinds, printMirrors) - /** Hook to define what `show(tree)` means. + /** Hook to define what `show(...)` means. */ def newTreePrinter(out: PrintWriter): TreePrinter - /** Renders internal structure of a tree. + /** Renders internal structure of a reflection artifact. */ - def showRaw(tree: Tree, printTypes: BooleanFlag = None, printIds: BooleanFlag = None, printKinds: BooleanFlag = None): String = - render(tree, newRawTreePrinter(_), printTypes, printIds, printKinds) + def showRaw(any: Any, printTypes: BooleanFlag = None, printIds: BooleanFlag = None, printKinds: BooleanFlag = None, printMirrors: BooleanFlag = None): String = + render(any, newRawTreePrinter(_), printTypes, printIds, printKinds, printMirrors) - /** Hook to define what `showRaw(tree)` means. + /** Hook to define what `showRaw(...)` means. */ def newRawTreePrinter(out: PrintWriter): TreePrinter - /** Renders a prettified representation of a symbol. - */ - def show(sym: Symbol): String = sym.toString - - /** Renders internal structure of a symbol. - */ - def showRaw(sym: Symbol): String = render(sym, newRawTreePrinter(_)) - - /** Renders a prettified representation of a type. - */ - def show(tpe: Type): String = tpe.toString - - /** Renders internal structure of a type. - */ - def showRaw(tpe: Type): String = render(tpe, newRawTreePrinter(_)) - /** Renders a prettified representation of a name. */ def show(name: Name): String diff --git a/src/reflect/scala/reflect/internal/Printers.scala b/src/reflect/scala/reflect/internal/Printers.scala index 82a8c42f7c..c018ddc88e 100644 --- a/src/reflect/scala/reflect/internal/Printers.scala +++ b/src/reflect/scala/reflect/internal/Printers.scala @@ -10,6 +10,7 @@ package internal import java.io.{ OutputStream, PrintWriter, StringWriter, Writer } import Flags._ +import compat.Platform.EOL trait Printers extends api.Printers { self: SymbolTable => @@ -65,6 +66,7 @@ trait Printers extends api.Printers { self: SymbolTable => printTypes = settings.printtypes.value printIds = settings.uniqid.value printKinds = settings.Yshowsymkinds.value + printMirrors = false // typically there's no point to print mirrors inside the compiler, as there is only one mirror there protected def doPrintPositions = settings.Xprintpos.value def indent() = indentMargin += indentStep @@ -477,22 +479,61 @@ trait Printers extends api.Printers { self: SymbolTable => def flush = { /* do nothing */ } } - // provides footnotes for types - private var typeCounter = 0 - private val typeMap = collection.mutable.WeakHashMap[Type, Int]() - def newRawTreePrinter(writer: PrintWriter): RawTreePrinter = new RawTreePrinter(writer) def newRawTreePrinter(stream: OutputStream): RawTreePrinter = newRawTreePrinter(new PrintWriter(stream)) def newRawTreePrinter(): RawTreePrinter = newRawTreePrinter(new PrintWriter(ConsoleWriter)) + // provides footnotes for types and mirrors + import scala.collection.mutable.{Map, WeakHashMap, SortedSet} + private val footnoteIndex = new FootnoteIndex + private class FootnoteIndex { + private val index = Map[Class[_], WeakHashMap[Any, Int]]() + private def classIndex[T: ClassTag] = index.getOrElseUpdate(classTag[T].runtimeClass, WeakHashMap[Any, Int]()) + private val counters = Map[Class[_], Int]() + private def nextCounter[T: ClassTag] = { + val clazz = classTag[T].runtimeClass + counters.getOrElseUpdate(clazz, 0) + counters(clazz) = counters(clazz) + 1 + counters(clazz) + } + + def mkFootnotes() = new Footnotes + class Footnotes { + private val footnotes = Map[Class[_], SortedSet[Int]]() + private def classFootnotes[T: ClassTag] = footnotes.getOrElseUpdate(classTag[T].runtimeClass, SortedSet[Int]()) + + def put[T: ClassTag](any: T): Int = { + val index = classIndex[T].getOrElseUpdate(any, nextCounter[T]) + classFootnotes[T] += index + index + } + + def get[T: ClassTag]: List[(Int, Any)] = + classFootnotes[T].toList map (fi => (fi, classIndex[T].find{ case (any, ii) => ii == fi }.get._1)) + + def print[T: ClassTag](printer: Printers.super.TreePrinter): Unit = { + val footnotes = get[T] + if (footnotes.nonEmpty) { + printer.print(EOL) + footnotes.zipWithIndex foreach { + case ((fi, any), ii) => + printer.print("[", fi, "] ", any) + if (ii < footnotes.length - 1) printer.print(EOL) + } + } + } + } + } + // emits more or less verbatim representation of the provided tree class RawTreePrinter(out: PrintWriter) extends super.TreePrinter { private var depth = 0 - private var footnotes = collection.mutable.Map[Int, Type]() - private var printingFootnotes = false private var printTypesInFootnotes = true + private var printingFootnotes = false + private var footnotes = footnoteIndex.mkFootnotes() def print(args: Any*): Unit = { + // don't print type footnotes if the argument is a mere type if (depth == 0 && args.length == 1 && args(0) != null && args(0).isInstanceOf[Type]) printTypesInFootnotes = false @@ -544,14 +585,15 @@ trait Printers extends api.Printers { self: SymbolTable => else print(sym.name) if (printIds) print("#", sym.id) if (printKinds) print("#", sym.abbreviatedKindString) + if (printMirrors) print("%M", footnotes.put[MirrorOf[_]](mirrorThatLoaded(sym))) case NoType => print("NoType") case NoPrefix => print("NoPrefix") - case tpe: Type if printTypesInFootnotes && !printingFootnotes => - val index = typeMap.getOrElseUpdate(tpe, { typeCounter += 1; typeCounter }) - footnotes(index) = tpe - print("[", index, "]") + case tpe: Type => + val defer = printTypesInFootnotes && !printingFootnotes + if (defer) print("[", footnotes.put(tpe), "]") + else printProduct(tpe.asInstanceOf[Product]) case mods: Modifiers => print("Modifiers(") if (mods.flags != NoFlags || mods.privateWithin != tpnme.EMPTY || mods.annotations.nonEmpty) print(show(mods.flags)) @@ -569,16 +611,11 @@ trait Printers extends api.Printers { self: SymbolTable => out.print(arg) } depth -= 1 - if (depth == 0 && footnotes.nonEmpty && !printingFootnotes) { + if (depth == 0 && !printingFootnotes) { printingFootnotes = true - out.println() - val typeIndices = footnotes.keys.toList.sorted - typeIndices.zipWithIndex foreach { - case (typeIndex, i) => - print("[" + typeIndex + "] ") - print(footnotes(typeIndex)) - if (i < typeIndices.length - 1) out.println() - } + footnotes.print[Type](this) + footnotes.print[MirrorOf[_]](this) + printingFootnotes = false } } diff --git a/src/reflect/scala/reflect/runtime/ReflectionUtils.scala b/src/reflect/scala/reflect/runtime/ReflectionUtils.scala index 4e82fe8ad2..7839850529 100644 --- a/src/reflect/scala/reflect/runtime/ReflectionUtils.scala +++ b/src/reflect/scala/reflect/runtime/ReflectionUtils.scala @@ -37,12 +37,17 @@ object ReflectionUtils { systemProperties find (_._1 endsWith ".boot.class.path") map (_._2) getOrElse "" ) - def show(cl: ClassLoader) = { + def show(cl: ClassLoader): String = { + def isAbstractFileClassLoader(clazz: Class[_]): Boolean = { + if (clazz == null) return false + if (clazz.getName == "scala.tools.nsc.interpreter.AbstractFileClassLoader") return true + return isAbstractFileClassLoader(clazz.getSuperclass) + } def inferClasspath(cl: ClassLoader): String = cl match { case cl: java.net.URLClassLoader => - "[" + (cl.getURLs mkString ",") + "]" - case cl if cl != null && cl.getClass.getName == "scala.tools.nsc.interpreter.AbstractFileClassLoader" => - "[" + cl.asInstanceOf[{val root: scala.reflect.internal.AbstractFileApi}].root + "] and " + inferClasspath(cl.getParent) + (cl.getURLs mkString ",") + case cl if cl != null && isAbstractFileClassLoader(cl.getClass) => + cl.asInstanceOf[{val root: scala.reflect.internal.AbstractFileApi}].root.canonicalPath case null => inferBootClasspath case _ => @@ -50,7 +55,7 @@ object ReflectionUtils { } cl match { case cl if cl != null => - "%s of type %s with classpath %s".format(cl, cl.getClass, inferClasspath(cl)) + "%s of type %s with classpath [%s] and parent being %s".format(cl, cl.getClass, inferClasspath(cl), show(cl.getParent)) case null => "primordial classloader with boot classpath [%s]".format(inferClasspath(cl)) } diff --git a/test/files/run/showraw_mods.check b/test/files/run/showraw_mods.check index 83055f2b70..6fc3ffe051 100644 --- a/test/files/run/showraw_mods.check +++ b/test/files/run/showraw_mods.check @@ -1 +1 @@ -Block(List(ClassDef(Modifiers(ABSTRACT | DEFAULTPARAM/TRAIT), newTypeName("C"), List(), Template(List(Ident(java.lang.Object)), emptyValDef, List(DefDef(Modifiers(), newTermName("$init$"), List(), List(List()), TypeTree(), Block(List(), Literal(Constant(())))), ValDef(Modifiers(PRIVATE | LOCAL), newTermName("x"), TypeTree(), Literal(Constant(2))), ValDef(Modifiers(MUTABLE), newTermName("y"), TypeTree(), Select(This(newTypeName("C")), newTermName("x"))), ValDef(Modifiers(LAZY), newTermName("z"), TypeTree(), Select(This(newTypeName("C")), newTermName("y"))))))), Literal(Constant(()))) +Block(List(ClassDef(Modifiers(ABSTRACT | DEFAULTPARAM/TRAIT), newTypeName("C"), List(), Template(List(Ident(newTypeName("AnyRef"))), emptyValDef, List(DefDef(Modifiers(), newTermName("$init$"), List(), List(List()), TypeTree(), Block(List(), Literal(Constant(())))), ValDef(Modifiers(PRIVATE | LOCAL), newTermName("x"), TypeTree(), Literal(Constant(2))), ValDef(Modifiers(MUTABLE), newTermName("y"), TypeTree(), Select(This(newTypeName("C")), newTermName("x"))), ValDef(Modifiers(LAZY), newTermName("z"), TypeTree(), Select(This(newTypeName("C")), newTermName("y"))))))), Literal(Constant(()))) diff --git a/test/files/run/showraw_tree.check b/test/files/run/showraw_tree.check index 82724cae44..d3a1fddf48 100644 --- a/test/files/run/showraw_tree.check +++ b/test/files/run/showraw_tree.check @@ -1,2 +1,2 @@ -Apply(Select(New(AppliedTypeTree(Ident(scala.collection.immutable.HashMap), List(Ident(java.lang.String), Ident(java.lang.String)))), nme.CONSTRUCTOR), List()) -Apply(Select(New(AppliedTypeTree(Ident(scala.collection.mutable.HashMap), List(Ident(java.lang.String), Ident(java.lang.String)))), nme.CONSTRUCTOR), List()) +Apply(Select(New(AppliedTypeTree(Ident(scala.collection.immutable.HashMap), List(Ident(newTypeName("String")), Ident(newTypeName("String"))))), nme.CONSTRUCTOR), List()) +Apply(Select(New(AppliedTypeTree(Ident(scala.collection.mutable.HashMap), List(Ident(newTypeName("String")), Ident(newTypeName("String"))))), nme.CONSTRUCTOR), List()) diff --git a/test/files/run/showraw_tree_ids.check b/test/files/run/showraw_tree_ids.check index c6dbd6f1ce..0c189130cf 100644 --- a/test/files/run/showraw_tree_ids.check +++ b/test/files/run/showraw_tree_ids.check @@ -1,2 +1,2 @@ -Apply(Select(New(AppliedTypeTree(Ident(scala.collection.immutable.HashMap#1903), List(Ident(java.lang.String#129), Ident(java.lang.String#129)))), nme.CONSTRUCTOR), List()) -Apply(Select(New(AppliedTypeTree(Ident(scala.collection.mutable.HashMap#1908), List(Ident(java.lang.String#129), Ident(java.lang.String#129)))), nme.CONSTRUCTOR), List()) +Apply(Select(New(AppliedTypeTree(Ident(scala.collection.immutable.HashMap#), List(Ident(newTypeName("String")#), Ident(newTypeName("String")#)))), nme.CONSTRUCTOR), List()) +Apply(Select(New(AppliedTypeTree(Ident(scala.collection.mutable.HashMap#), List(Ident(newTypeName("String")#), Ident(newTypeName("String")#)))), nme.CONSTRUCTOR), List()) diff --git a/test/files/run/showraw_tree_ids.scala b/test/files/run/showraw_tree_ids.scala index b56b8b4476..ea9a3cd4c2 100644 --- a/test/files/run/showraw_tree_ids.scala +++ b/test/files/run/showraw_tree_ids.scala @@ -3,6 +3,7 @@ import scala.reflect.runtime.universe._ object Test extends App { val tree1 = reify(new collection.immutable.HashMap[String, String]) val tree2 = reify(new collection.mutable.HashMap[String, String]) - println(showRaw(tree1.tree, printIds = true)) - println(showRaw(tree2.tree, printIds = true)) + def stabilize(s: String) = """#\d+""".r.replaceAllIn(s, "#") + println(stabilize(showRaw(tree1.tree, printIds = true))) + println(stabilize(showRaw(tree2.tree, printIds = true))) } \ No newline at end of file diff --git a/test/files/run/showraw_tree_kinds.check b/test/files/run/showraw_tree_kinds.check index a12e21c611..7b4ab456b0 100644 --- a/test/files/run/showraw_tree_kinds.check +++ b/test/files/run/showraw_tree_kinds.check @@ -1,2 +1,2 @@ -Apply(Select(New(AppliedTypeTree(Ident(scala.collection.immutable.HashMap#CLS), List(Ident(java.lang.String#CLS), Ident(java.lang.String#CLS)))), nme.CONSTRUCTOR), List()) -Apply(Select(New(AppliedTypeTree(Ident(scala.collection.mutable.HashMap#CLS), List(Ident(java.lang.String#CLS), Ident(java.lang.String#CLS)))), nme.CONSTRUCTOR), List()) +Apply(Select(New(AppliedTypeTree(Ident(scala.collection.immutable.HashMap#CLS), List(Ident(newTypeName("String")#TPE), Ident(newTypeName("String")#TPE)))), nme.CONSTRUCTOR), List()) +Apply(Select(New(AppliedTypeTree(Ident(scala.collection.mutable.HashMap#CLS), List(Ident(newTypeName("String")#TPE), Ident(newTypeName("String")#TPE)))), nme.CONSTRUCTOR), List()) diff --git a/test/files/run/showraw_tree_types_ids.check b/test/files/run/showraw_tree_types_ids.check index 02e7aeed7c..39e68dc881 100644 --- a/test/files/run/showraw_tree_types_ids.check +++ b/test/files/run/showraw_tree_types_ids.check @@ -1,10 +1,10 @@ -Apply[1](Select[2](New[1](TypeTree[1]().setOriginal(AppliedTypeTree(Ident[3](scala.collection.immutable.HashMap#1903), List(TypeTree[4]().setOriginal(Ident[4](java.lang.String#129)), TypeTree[4]().setOriginal(Ident[4](java.lang.String#129)))))), nme.CONSTRUCTOR#1913), List()) -[1] TypeRef(ThisType(scala.collection.immutable#1898), scala.collection.immutable.HashMap#1903, List(TypeRef(ThisType(java.lang#128), java.lang.String#129, List()), TypeRef(ThisType(java.lang#128), java.lang.String#129, List()))) -[2] MethodType(List(), TypeRef(ThisType(scala.collection.immutable#1898), scala.collection.immutable.HashMap#1903, List(TypeRef(ThisType(java.lang#128), java.lang.String#129, List()), TypeRef(ThisType(java.lang#128), java.lang.String#129, List())))) -[3] TypeRef(ThisType(scala.collection.immutable#1898), scala.collection.immutable.HashMap#1903, List()) -[4] TypeRef(ThisType(java.lang#128), java.lang.String#129, List()) -Apply[5](Select[6](New[5](TypeTree[5]().setOriginal(AppliedTypeTree(Ident[7](scala.collection.mutable.HashMap#1908), List(TypeTree[4]().setOriginal(Ident[4](java.lang.String#129)), TypeTree[4]().setOriginal(Ident[4](java.lang.String#129)))))), nme.CONSTRUCTOR#2231), List()) -[4] TypeRef(ThisType(java.lang#128), java.lang.String#129, List()) -[5] TypeRef(ThisType(scala.collection.mutable#1907), scala.collection.mutable.HashMap#1908, List(TypeRef(ThisType(java.lang#128), java.lang.String#129, List()), TypeRef(ThisType(java.lang#128), java.lang.String#129, List()))) -[6] MethodType(List(), TypeRef(ThisType(scala.collection.mutable#1907), scala.collection.mutable.HashMap#1908, List(TypeRef(ThisType(java.lang#128), java.lang.String#129, List()), TypeRef(ThisType(java.lang#128), java.lang.String#129, List())))) -[7] TypeRef(ThisType(scala.collection.mutable#1907), scala.collection.mutable.HashMap#1908, List()) +Apply[1](Select[2](New[1](TypeTree[1]().setOriginal(AppliedTypeTree(Ident[3](scala.collection.immutable.HashMap#), List(TypeTree[4]().setOriginal(Ident[4](newTypeName("String")#)), TypeTree[4]().setOriginal(Ident[4](newTypeName("String")#)))))), nme.CONSTRUCTOR#), List()) +[1] TypeRef(ThisType(scala.collection.immutable#), scala.collection.immutable.HashMap#, List(TypeRef(ThisType(scala.Predef#), newTypeName("String")#, List()), TypeRef(ThisType(scala.Predef#), newTypeName("String")#, List()))) +[2] MethodType(List(), TypeRef(ThisType(scala.collection.immutable#), scala.collection.immutable.HashMap#, List(TypeRef(ThisType(scala.Predef#), newTypeName("String")#, List()), TypeRef(ThisType(scala.Predef#), newTypeName("String")#, List())))) +[3] TypeRef(ThisType(scala.collection.immutable#), scala.collection.immutable.HashMap#, List()) +[4] TypeRef(ThisType(scala.Predef#), newTypeName("String")#, List()) +Apply[5](Select[6](New[5](TypeTree[5]().setOriginal(AppliedTypeTree(Ident[7](scala.collection.mutable.HashMap#), List(TypeTree[4]().setOriginal(Ident[4](newTypeName("String")#)), TypeTree[4]().setOriginal(Ident[4](newTypeName("String")#)))))), nme.CONSTRUCTOR#), List()) +[4] TypeRef(ThisType(scala.Predef#), newTypeName("String")#, List()) +[5] TypeRef(ThisType(scala.collection.mutable#), scala.collection.mutable.HashMap#, List(TypeRef(ThisType(scala.Predef#), newTypeName("String")#, List()), TypeRef(ThisType(scala.Predef#), newTypeName("String")#, List()))) +[6] MethodType(List(), TypeRef(ThisType(scala.collection.mutable#), scala.collection.mutable.HashMap#, List(TypeRef(ThisType(scala.Predef#), newTypeName("String")#, List()), TypeRef(ThisType(scala.Predef#), newTypeName("String")#, List())))) +[7] TypeRef(ThisType(scala.collection.mutable#), scala.collection.mutable.HashMap#, List()) diff --git a/test/files/run/showraw_tree_types_ids.scala b/test/files/run/showraw_tree_types_ids.scala index cb2c2bfb0f..198729e705 100644 --- a/test/files/run/showraw_tree_types_ids.scala +++ b/test/files/run/showraw_tree_types_ids.scala @@ -5,6 +5,7 @@ object Test extends App { val tb = runtimeMirror(getClass.getClassLoader).mkToolBox() val tree1 = reify(new collection.immutable.HashMap[String, String]) val tree2 = reify(new collection.mutable.HashMap[String, String]) - println(showRaw(tb.typeCheck(tree1.tree), printIds = true, printTypes = true)) - println(showRaw(tb.typeCheck(tree2.tree), printIds = true, printTypes = true)) + def stabilize(s: String) = """#\d+""".r.replaceAllIn(s, "#") + println(stabilize(showRaw(tb.typeCheck(tree1.tree), printIds = true, printTypes = true))) + println(stabilize(showRaw(tb.typeCheck(tree2.tree), printIds = true, printTypes = true))) } \ No newline at end of file diff --git a/test/files/run/showraw_tree_types_typed.check b/test/files/run/showraw_tree_types_typed.check index 60176c7192..0a41f5185c 100644 --- a/test/files/run/showraw_tree_types_typed.check +++ b/test/files/run/showraw_tree_types_typed.check @@ -1,10 +1,10 @@ -Apply[1](Select[2](New[1](TypeTree[1]().setOriginal(AppliedTypeTree(Ident[3](scala.collection.immutable.HashMap), List(TypeTree[4]().setOriginal(Ident[4](java.lang.String)), TypeTree[4]().setOriginal(Ident[4](java.lang.String)))))), nme.CONSTRUCTOR), List()) -[1] TypeRef(ThisType(scala.collection.immutable), scala.collection.immutable.HashMap, List(TypeRef(ThisType(java.lang), java.lang.String, List()), TypeRef(ThisType(java.lang), java.lang.String, List()))) -[2] MethodType(List(), TypeRef(ThisType(scala.collection.immutable), scala.collection.immutable.HashMap, List(TypeRef(ThisType(java.lang), java.lang.String, List()), TypeRef(ThisType(java.lang), java.lang.String, List())))) +Apply[1](Select[2](New[1](TypeTree[1]().setOriginal(AppliedTypeTree(Ident[3](scala.collection.immutable.HashMap), List(TypeTree[4]().setOriginal(Ident[4](newTypeName("String"))), TypeTree[4]().setOriginal(Ident[4](newTypeName("String"))))))), nme.CONSTRUCTOR), List()) +[1] TypeRef(ThisType(scala.collection.immutable), scala.collection.immutable.HashMap, List(TypeRef(ThisType(scala.Predef), newTypeName("String"), List()), TypeRef(ThisType(scala.Predef), newTypeName("String"), List()))) +[2] MethodType(List(), TypeRef(ThisType(scala.collection.immutable), scala.collection.immutable.HashMap, List(TypeRef(ThisType(scala.Predef), newTypeName("String"), List()), TypeRef(ThisType(scala.Predef), newTypeName("String"), List())))) [3] TypeRef(ThisType(scala.collection.immutable), scala.collection.immutable.HashMap, List()) -[4] TypeRef(ThisType(java.lang), java.lang.String, List()) -Apply[5](Select[6](New[5](TypeTree[5]().setOriginal(AppliedTypeTree(Ident[7](scala.collection.mutable.HashMap), List(TypeTree[4]().setOriginal(Ident[4](java.lang.String)), TypeTree[4]().setOriginal(Ident[4](java.lang.String)))))), nme.CONSTRUCTOR), List()) -[4] TypeRef(ThisType(java.lang), java.lang.String, List()) -[5] TypeRef(ThisType(scala.collection.mutable), scala.collection.mutable.HashMap, List(TypeRef(ThisType(java.lang), java.lang.String, List()), TypeRef(ThisType(java.lang), java.lang.String, List()))) -[6] MethodType(List(), TypeRef(ThisType(scala.collection.mutable), scala.collection.mutable.HashMap, List(TypeRef(ThisType(java.lang), java.lang.String, List()), TypeRef(ThisType(java.lang), java.lang.String, List())))) +[4] TypeRef(ThisType(scala.Predef), newTypeName("String"), List()) +Apply[5](Select[6](New[5](TypeTree[5]().setOriginal(AppliedTypeTree(Ident[7](scala.collection.mutable.HashMap), List(TypeTree[4]().setOriginal(Ident[4](newTypeName("String"))), TypeTree[4]().setOriginal(Ident[4](newTypeName("String"))))))), nme.CONSTRUCTOR), List()) +[4] TypeRef(ThisType(scala.Predef), newTypeName("String"), List()) +[5] TypeRef(ThisType(scala.collection.mutable), scala.collection.mutable.HashMap, List(TypeRef(ThisType(scala.Predef), newTypeName("String"), List()), TypeRef(ThisType(scala.Predef), newTypeName("String"), List()))) +[6] MethodType(List(), TypeRef(ThisType(scala.collection.mutable), scala.collection.mutable.HashMap, List(TypeRef(ThisType(scala.Predef), newTypeName("String"), List()), TypeRef(ThisType(scala.Predef), newTypeName("String"), List())))) [7] TypeRef(ThisType(scala.collection.mutable), scala.collection.mutable.HashMap, List()) diff --git a/test/files/run/showraw_tree_types_untyped.check b/test/files/run/showraw_tree_types_untyped.check index 82724cae44..d3a1fddf48 100644 --- a/test/files/run/showraw_tree_types_untyped.check +++ b/test/files/run/showraw_tree_types_untyped.check @@ -1,2 +1,2 @@ -Apply(Select(New(AppliedTypeTree(Ident(scala.collection.immutable.HashMap), List(Ident(java.lang.String), Ident(java.lang.String)))), nme.CONSTRUCTOR), List()) -Apply(Select(New(AppliedTypeTree(Ident(scala.collection.mutable.HashMap), List(Ident(java.lang.String), Ident(java.lang.String)))), nme.CONSTRUCTOR), List()) +Apply(Select(New(AppliedTypeTree(Ident(scala.collection.immutable.HashMap), List(Ident(newTypeName("String")), Ident(newTypeName("String"))))), nme.CONSTRUCTOR), List()) +Apply(Select(New(AppliedTypeTree(Ident(scala.collection.mutable.HashMap), List(Ident(newTypeName("String")), Ident(newTypeName("String"))))), nme.CONSTRUCTOR), List()) diff --git a/test/files/run/showraw_tree_ultimate.check b/test/files/run/showraw_tree_ultimate.check index 0b409554a0..400b736704 100644 --- a/test/files/run/showraw_tree_ultimate.check +++ b/test/files/run/showraw_tree_ultimate.check @@ -1,10 +1,10 @@ -Apply[1](Select[2](New[1](TypeTree[1]().setOriginal(AppliedTypeTree(Ident[3](scala.collection.immutable.HashMap#1903#CLS), List(TypeTree[4]().setOriginal(Ident[4](java.lang.String#129#CLS)), TypeTree[4]().setOriginal(Ident[4](java.lang.String#129#CLS)))))), nme.CONSTRUCTOR#1913#PCTOR), List()) -[1] TypeRef(ThisType(scala.collection.immutable#1898#PK), scala.collection.immutable.HashMap#1903#CLS, List(TypeRef(ThisType(java.lang#128#PK), java.lang.String#129#CLS, List()), TypeRef(ThisType(java.lang#128#PK), java.lang.String#129#CLS, List()))) -[2] MethodType(List(), TypeRef(ThisType(scala.collection.immutable#1898#PK), scala.collection.immutable.HashMap#1903#CLS, List(TypeRef(ThisType(java.lang#128#PK), java.lang.String#129#CLS, List()), TypeRef(ThisType(java.lang#128#PK), java.lang.String#129#CLS, List())))) -[3] TypeRef(ThisType(scala.collection.immutable#1898#PK), scala.collection.immutable.HashMap#1903#CLS, List()) -[4] TypeRef(ThisType(java.lang#128#PK), java.lang.String#129#CLS, List()) -Apply[5](Select[6](New[5](TypeTree[5]().setOriginal(AppliedTypeTree(Ident[7](scala.collection.mutable.HashMap#1908#CLS), List(TypeTree[4]().setOriginal(Ident[4](java.lang.String#129#CLS)), TypeTree[4]().setOriginal(Ident[4](java.lang.String#129#CLS)))))), nme.CONSTRUCTOR#2231#CTOR), List()) -[4] TypeRef(ThisType(java.lang#128#PK), java.lang.String#129#CLS, List()) -[5] TypeRef(ThisType(scala.collection.mutable#1907#PK), scala.collection.mutable.HashMap#1908#CLS, List(TypeRef(ThisType(java.lang#128#PK), java.lang.String#129#CLS, List()), TypeRef(ThisType(java.lang#128#PK), java.lang.String#129#CLS, List()))) -[6] MethodType(List(), TypeRef(ThisType(scala.collection.mutable#1907#PK), scala.collection.mutable.HashMap#1908#CLS, List(TypeRef(ThisType(java.lang#128#PK), java.lang.String#129#CLS, List()), TypeRef(ThisType(java.lang#128#PK), java.lang.String#129#CLS, List())))) -[7] TypeRef(ThisType(scala.collection.mutable#1907#PK), scala.collection.mutable.HashMap#1908#CLS, List()) +Apply[1](Select[2](New[1](TypeTree[1]().setOriginal(AppliedTypeTree(Ident[3](scala.collection.immutable.HashMap##CLS), List(TypeTree[4]().setOriginal(Ident[4](newTypeName("String")##TPE)), TypeTree[4]().setOriginal(Ident[4](newTypeName("String")##TPE)))))), nme.CONSTRUCTOR##PCTOR), List()) +[1] TypeRef(ThisType(scala.collection.immutable##PK), scala.collection.immutable.HashMap##CLS, List(TypeRef(ThisType(scala.Predef##MODC), newTypeName("String")##TPE, List()), TypeRef(ThisType(scala.Predef##MODC), newTypeName("String")##TPE, List()))) +[2] MethodType(List(), TypeRef(ThisType(scala.collection.immutable##PK), scala.collection.immutable.HashMap##CLS, List(TypeRef(ThisType(scala.Predef##MODC), newTypeName("String")##TPE, List()), TypeRef(ThisType(scala.Predef##MODC), newTypeName("String")##TPE, List())))) +[3] TypeRef(ThisType(scala.collection.immutable##PK), scala.collection.immutable.HashMap##CLS, List()) +[4] TypeRef(ThisType(scala.Predef##MODC), newTypeName("String")##TPE, List()) +Apply[5](Select[6](New[5](TypeTree[5]().setOriginal(AppliedTypeTree(Ident[7](scala.collection.mutable.HashMap##CLS), List(TypeTree[4]().setOriginal(Ident[4](newTypeName("String")##TPE)), TypeTree[4]().setOriginal(Ident[4](newTypeName("String")##TPE)))))), nme.CONSTRUCTOR##CTOR), List()) +[4] TypeRef(ThisType(scala.Predef##MODC), newTypeName("String")##TPE, List()) +[5] TypeRef(ThisType(scala.collection.mutable##PK), scala.collection.mutable.HashMap##CLS, List(TypeRef(ThisType(scala.Predef##MODC), newTypeName("String")##TPE, List()), TypeRef(ThisType(scala.Predef##MODC), newTypeName("String")##TPE, List()))) +[6] MethodType(List(), TypeRef(ThisType(scala.collection.mutable##PK), scala.collection.mutable.HashMap##CLS, List(TypeRef(ThisType(scala.Predef##MODC), newTypeName("String")##TPE, List()), TypeRef(ThisType(scala.Predef##MODC), newTypeName("String")##TPE, List())))) +[7] TypeRef(ThisType(scala.collection.mutable##PK), scala.collection.mutable.HashMap##CLS, List()) diff --git a/test/files/run/showraw_tree_ultimate.scala b/test/files/run/showraw_tree_ultimate.scala index dfd7abde52..a8507623bc 100644 --- a/test/files/run/showraw_tree_ultimate.scala +++ b/test/files/run/showraw_tree_ultimate.scala @@ -5,6 +5,7 @@ object Test extends App { val tb = runtimeMirror(getClass.getClassLoader).mkToolBox() val tree1 = reify(new collection.immutable.HashMap[String, String]) val tree2 = reify(new collection.mutable.HashMap[String, String]) - println(showRaw(tb.typeCheck(tree1.tree), printIds = true, printKinds = true, printTypes = true)) - println(showRaw(tb.typeCheck(tree2.tree), printIds = true, printKinds = true, printTypes = true)) + def stabilize(s: String) = """#\d+""".r.replaceAllIn(s, "#") + println(stabilize(showRaw(tb.typeCheck(tree1.tree), printIds = true, printKinds = true, printTypes = true))) + println(stabilize(showRaw(tb.typeCheck(tree2.tree), printIds = true, printKinds = true, printTypes = true))) } \ No newline at end of file -- cgit v1.2.3