diff options
-rw-r--r-- | src/reflect/scala/reflect/internal/Printers.scala | 22 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/ReificationSupport.scala | 12 | ||||
-rw-r--r-- | test/junit/scala/reflect/internal/PrintersTest.scala | 25 |
3 files changed, 44 insertions, 15 deletions
diff --git a/src/reflect/scala/reflect/internal/Printers.scala b/src/reflect/scala/reflect/internal/Printers.scala index 45be394231..0cf7987b4b 100644 --- a/src/reflect/scala/reflect/internal/Printers.scala +++ b/src/reflect/scala/reflect/internal/Printers.scala @@ -308,6 +308,9 @@ trait Printers extends api.Printers { self: SymbolTable => print("this") } + protected def printBlock(stats: List[Tree], expr: Tree) = + printColumn(stats ::: List(expr), "{", ";", "}") + def printTree(tree: Tree) = { tree match { case EmptyTree => @@ -367,7 +370,7 @@ trait Printers extends api.Printers { self: SymbolTable => currentOwner = currentOwner1 case Block(stats, expr) => - printColumn(stats ::: List(expr), "{", ";", "}") + printBlock(stats, expr) case Match(selector, cases) => val selectorType1 = selectorType @@ -867,7 +870,8 @@ trait Printers extends api.Printers { self: SymbolTable => printColumn(modBody, "", ";", "}") } - case Block(stats, expr) => super.printTree(tree) + case bl @ Block(stats, expr) => + printBlock(build.unattributedBlockBody(bl), expr) case Match(selector, cases) => /* Insert braces if match is inner @@ -1097,14 +1101,16 @@ trait Printers extends api.Printers { self: SymbolTable => def printTp = print("(", tp, ")") tp match { - case EmptyTree | build.SyntacticEmptyTypeTree() | _: Annotated => printTp + case EmptyTree | build.SyntacticEmptyTypeTree() => printTp + // case for untypechecked trees + case Annotated(annot, arg) if (expr ne null) && (arg ne null) && expr.equalsStructure(arg) => printTp //to remove double arg - 5: 5: @unchecked case tt: TypeTree if tt.original.isInstanceOf[Annotated] => printTp case _ => super.processTreePrinting(tree) } case This(qual) => // todo: add symbol checking for common printer - if (tree.symbol.isPackage) print(tree.symbol.fullName) + if (tree.hasExistingSymbol && tree.symbol.isPackage) print(tree.symbol.fullName) else super.processTreePrinting(tree) case st @ Super(th @ This(qual), mix) => @@ -1119,12 +1125,8 @@ trait Printers extends api.Printers { self: SymbolTable => def xprintTree(treePrinter: TreePrinter, tree: Tree) = treePrinter.print(tree.productPrefix+tree.productIterator.mkString("(", ", ", ")")) - def newCodePrinter(writer: PrintWriter, tree: Tree, printRootPkg: Boolean): TreePrinter = { - if (build.detectAttributedTree(tree)) - new TypedTreePrinter(writer, printRootPkg) - else - new ParsedTreePrinter(writer) - } + def newCodePrinter(writer: PrintWriter, tree: Tree, printRootPkg: Boolean): TreePrinter = + new TypedTreePrinter(writer, printRootPkg) def newTreePrinter(writer: PrintWriter): TreePrinter = new TreePrinter(writer) def newTreePrinter(stream: OutputStream): TreePrinter = newTreePrinter(new PrintWriter(stream)) diff --git a/src/reflect/scala/reflect/internal/ReificationSupport.scala b/src/reflect/scala/reflect/internal/ReificationSupport.scala index 44cda24242..375605bf7f 100644 --- a/src/reflect/scala/reflect/internal/ReificationSupport.scala +++ b/src/reflect/scala/reflect/internal/ReificationSupport.scala @@ -241,10 +241,14 @@ trait ReificationSupport { self: SymbolTable => case _ => false } - // recover template body to parsed state - private[internal] def unattributedTemplBody(templ: Template) = { - val tbody = templ.body + private[internal] def unattributedTemplBody(templ: Template) = + unattributedTreeBody(templ, templ.body) + + private[internal] def unattributedBlockBody(block: Block) = + unattributedTreeBody(block, block.stats) + // recover template body to parsed state + private[internal] def unattributedTreeBody(tree: Tree, tbody: List[Tree]) = { def filterBody(body: List[Tree]) = body filter { case _: ValDef | _: TypeDef => true // keep valdef or getter for val/var @@ -283,7 +287,7 @@ trait ReificationSupport { self: SymbolTable => case tree => tree } - if (detectAttributedTree(templ)) { + if (detectAttributedTree(tree)) { recoverBody(filterBody(tbody)) } else tbody } diff --git a/test/junit/scala/reflect/internal/PrintersTest.scala b/test/junit/scala/reflect/internal/PrintersTest.scala index 0e93e30dcc..4c9dfaf038 100644 --- a/test/junit/scala/reflect/internal/PrintersTest.scala +++ b/test/junit/scala/reflect/internal/PrintersTest.scala @@ -976,6 +976,29 @@ trait ValAndDefPrintTests { @Test def testDef9 = assertPrintedCode("def a(x: scala.Int)(implicit z: scala.Double, y: scala.Float): scala.Unit = ()") + @Test def testDefWithLazyVal1 = assertResultCode( + code = "def a = { lazy val test: Int = 42 }")( + parsedCode = sm""" + |def a = { + | lazy val test: Int = 42; + | () + |} + """, + typedCode = sm""" + |def a = { + | lazy val test: scala.Int = 42; + | () + |}""") + + @Test def testDefWithLazyVal2 = assertPrintedCode(sm""" + |def a = { + | lazy val test = { + | scala.Predef.println(); + | scala.Predef.println() + | }; + | () + |}""") + @Test def testDefWithParams1 = assertPrintedCode("def foo(x: scala.Int*) = ()") @Test def testDefWithParams2 = assertPrintedCode(sm""" @@ -1140,4 +1163,4 @@ trait QuasiTreesPrintTests { | def y = "test" |}""") } -*/
\ No newline at end of file +*/ |