summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/internal/Printers.scala
diff options
context:
space:
mode:
authorVladimirNik <vladimir.nikolaev9@gmail.com>2014-02-12 05:59:57 +0400
committerVladimirNik <vladimir.nikolaev9@gmail.com>2014-02-20 01:23:25 +0400
commit9505aff3aa44bb3a37c47c244ac6ab9de83fd2a4 (patch)
tree8bbd87a84cb5b422ac1080f1a8c8632428d8800e /src/reflect/scala/reflect/internal/Printers.scala
parent931edcc94ebd73b420b2359d989442bf700588eb (diff)
downloadscala-9505aff3aa44bb3a37c47c244ac6ab9de83fd2a4.tar.gz
scala-9505aff3aa44bb3a37c47c244ac6ab9de83fd2a4.tar.bz2
scala-9505aff3aa44bb3a37c47c244ac6ab9de83fd2a4.zip
printers flag processing improvements: printRootPkg flag fixed, comments to flags metadata printing added
Diffstat (limited to 'src/reflect/scala/reflect/internal/Printers.scala')
-rw-r--r--src/reflect/scala/reflect/internal/Printers.scala35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/reflect/scala/reflect/internal/Printers.scala b/src/reflect/scala/reflect/internal/Printers.scala
index cb4abd8bd8..45be394231 100644
--- a/src/reflect/scala/reflect/internal/Printers.scala
+++ b/src/reflect/scala/reflect/internal/Printers.scala
@@ -73,11 +73,14 @@ trait Printers extends api.Printers { self: SymbolTable =>
def indent() = indentMargin += indentStep
def undent() = indentMargin -= indentStep
- def printPosition(tree: Tree) = if (printPositions) print(tree.pos.show)
+ def printPosition(tree: Tree) =
+ if (printPositions) comment(print(tree.pos.show))
protected def printTypesInfo(tree: Tree) =
if (printTypes && tree.isTerm && tree.canHaveAttrs)
- print("{", if (tree.tpe eq null) "<null>" else tree.tpe.toString, "}")
+ comment{
+ print("{", if (tree.tpe eq null) "<null>" else tree.tpe.toString, "}")
+ }
def println() = {
out.println()
@@ -128,12 +131,17 @@ trait Printers extends api.Printers { self: SymbolTable =>
print(symName(p, p.name)); printOpt(": ", TypeTree() setType p.tpe)
}
- protected def parenthesize(condition: Boolean = true)(body: => Unit) = {
- if (condition) print("(")
+ protected def parenthesize(condition: Boolean = true, open: String = "(", close: String = ")")(body: => Unit) = {
+ if (condition) print(open)
body
- if (condition) print(")")
+ if (condition) print(close)
}
+ protected val commentsRequired = false
+
+ protected def comment(body: => Unit) =
+ parenthesize(commentsRequired, "/*", "*/")(body)
+
protected def printImplicitInParamsList(vds: List[ValDef]) =
if (vds.nonEmpty) printFlags(vds.head.mods.flags & IMPLICIT, "")
@@ -279,7 +287,11 @@ trait Printers extends api.Printers { self: SymbolTable =>
print("(");
printValueParams
print(" => ", body, ")")
- if (printIds && tree.symbol != null) print("#" + tree.symbol.id)
+ if (printIds && tree.symbol != null)
+ comment{
+ print("#" + tree.symbol.id)
+ }
+
if (printOwners && tree.symbol != null) print("@" + tree.symbol.owner.id)
}
@@ -547,6 +559,8 @@ trait Printers extends api.Printers { self: SymbolTable =>
qualIsIntLit && name.isOperatorName
}
+ override protected val commentsRequired = true
+
protected def needsParentheses(parent: Tree)(insideIf: Boolean = true, insideMatch: Boolean = true,
insideTry: Boolean = true, insideAnnotated: Boolean = true, insideBlock: Boolean = true, insideLabelDef: Boolean = true) = {
parent match {
@@ -1040,11 +1054,7 @@ trait Printers extends api.Printers { self: SymbolTable =>
case _ if syntheticToRemove(tree) =>
case tt: TypeTree =>
- if (printPositions) {
- if (tt.original != null)
- print("<type: ", tt.original.toString(), ">")
- else print("<type ?>")
- } else if (!emptyTree(tt)) print(tt.original)
+ if (!emptyTree(tt)) print(tt.original)
// print only fun when targs are TypeTrees with empty original
case TypeApply(fun, targs) =>
@@ -1076,7 +1086,7 @@ trait Printers extends api.Printers { self: SymbolTable =>
}) && (tr match { // check that Select contains package
case Select(q, _) => checkRootPackage(q)
case _: Ident | _: This => val sym = tr.symbol
- tr.hasExistingSymbol && sym.isPackage && !sym.isRootPackage
+ tr.hasExistingSymbol && sym.isPackage && sym.name != nme.ROOTPKG
case _ => false
})
@@ -1093,6 +1103,7 @@ trait Printers extends api.Printers { self: SymbolTable =>
}
case This(qual) =>
+ // todo: add symbol checking for common printer
if (tree.symbol.isPackage) print(tree.symbol.fullName)
else super.processTreePrinting(tree)