summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-09-15 20:32:48 +0000
committerPaul Phillips <paulp@improving.org>2011-09-15 20:32:48 +0000
commit3b357972e911aed24842f4c2229058b4a1311d1b (patch)
tree373369e510f69336a90f86ab57a989aad3bf7949
parent09b1a31309c9cbf1394c317b87d2073d39a8cd56 (diff)
downloadscala-3b357972e911aed24842f4c2229058b4a1311d1b.tar.gz
scala-3b357972e911aed24842f4c2229058b4a1311d1b.tar.bz2
scala-3b357972e911aed24842f4c2229058b4a1311d1b.zip
Removed parens from calls to Name#toString.
This commit doesn't include the line which would change anything interesting (that being making toString in Name a val), it is all the changes elsewhere which one would have to make to do that. I didn't want to waste them. A quirk of scala is that if you call an empty-parameter-list method: foo.bar() // e.g. x.toString() foo.bar // where you could have called x.toString then if you decide in the future to make it a val, every call site must potentially be modified. This is a bit of a bummer. One can try to defend against that future decision by eschewing parentheses, but it's not very satisfying or effective. No review.
-rw-r--r--src/compiler/scala/reflect/internal/Names.scala14
-rw-r--r--src/compiler/scala/reflect/internal/pickling/UnPickler.scala2
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala30
-rw-r--r--src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala4
-rw-r--r--src/compiler/scala/tools/nsc/interactive/Picklers.scala2
-rw-r--r--src/compiler/scala/tools/nsc/javac/JavaScanners.scala2
-rw-r--r--src/compiler/scala/tools/nsc/matching/Patterns.scala8
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala10
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala2
-rw-r--r--src/compiler/scala/tools/nsc/util/ShowPickled.scala2
11 files changed, 43 insertions, 35 deletions
diff --git a/src/compiler/scala/reflect/internal/Names.scala b/src/compiler/scala/reflect/internal/Names.scala
index 608ec09413..189929b1df 100644
--- a/src/compiler/scala/reflect/internal/Names.scala
+++ b/src/compiler/scala/reflect/internal/Names.scala
@@ -78,8 +78,12 @@ trait Names extends api.Names {
while ((n ne null) && (n.length != len || !equals(n.start, cs, offset, len)))
n = n.next;
if (n eq null) {
- n = new TermName(nc, len, h)
+ // The logic order here is future-proofing against the possibility
+ // that name.toString will become an eager val, in which case the call
+ // to enterChars cannot follow the construction of the TermName.
+ val ncStart = nc
enterChars(cs, offset, len)
+ n = new TermName(ncStart, len, h)
}
n
}
@@ -144,6 +148,10 @@ trait Names extends api.Names {
/** @return the string representation of this name */
final override def toString(): String = new String(chrs, index, len)
+ // Should we opt to make toString into a val to avoid the creation
+ // of 750,000 copies of x$1, here's the line.
+ // final override val toString = new String(chrs, index, len)
+
def debugString() = NameTransformer.decode(toString) + (if (isTypeName) "!" else "")
/** Write to UTF8 representation of this name to given character array.
@@ -335,7 +343,7 @@ trait Names extends api.Names {
/** Replace operator symbols by corresponding $op_name. */
def encode: Name = {
- val str = toString()
+ val str = toString
val res = NameTransformer.encode(str)
if (res == str) this
else if (isTypeName) newTypeName(res)
@@ -347,7 +355,7 @@ trait Names extends api.Names {
/** Replace $op_name by corresponding operator symbol. */
def decode: String = (
- NameTransformer.decode(toString()) +
+ NameTransformer.decode(toString) +
(if (nameDebug && isTypeName) "!" else ""))//debug
def isOperatorName: Boolean = decode != toString
diff --git a/src/compiler/scala/reflect/internal/pickling/UnPickler.scala b/src/compiler/scala/reflect/internal/pickling/UnPickler.scala
index 1bd0d23849..47677fad91 100644
--- a/src/compiler/scala/reflect/internal/pickling/UnPickler.scala
+++ b/src/compiler/scala/reflect/internal/pickling/UnPickler.scala
@@ -413,7 +413,7 @@ abstract class UnPickler /*extends reflect.generic.UnPickler*/ {
case LITERALlong => Constant(readLong(len))
case LITERALfloat => Constant(intBitsToFloat(readLong(len).toInt))
case LITERALdouble => Constant(longBitsToDouble(readLong(len)))
- case LITERALstring => Constant(readNameRef().toString())
+ case LITERALstring => Constant(readNameRef().toString)
case LITERALnull => Constant(null)
case LITERALclass => Constant(readTypeRef())
case LITERALenum => Constant(readSymbolRef())
diff --git a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala
index 47715e5e68..0feb6ed5ce 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala
@@ -44,12 +44,12 @@ abstract class TreeBrowsers {
/** Pseudo tree class, so that all JTree nodes are treated uniformly */
case class ProgramTree(units: List[UnitTree]) extends ValidTree {
- override def toString(): String = "Program"
+ override def toString: String = "Program"
}
/** Pseudo tree class, so that all JTree nodes are treated uniformly */
case class UnitTree(unit: CompilationUnit) extends ValidTree {
- override def toString(): String = unit.toString()
+ override def toString: String = unit.toString
}
/**
@@ -206,7 +206,7 @@ abstract class TreeBrowsers {
row: Int, hasFocus: Boolean) = {
val (cls, name) = TreeInfo.treeName(value.asInstanceOf[Tree])
if (name != EMPTY)
- cls + "[" + name.toString() + "]"
+ cls + "[" + name + "]"
else
cls
}
@@ -214,7 +214,7 @@ abstract class TreeBrowsers {
jTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
def valueChanged(e: javax.swing.event.TreeSelectionEvent): Unit = {
- textArea.setText(e.getPath().getLastPathComponent().toString())
+ textArea.setText(e.getPath().getLastPathComponent().toString)
infoPanel.update(e.getPath().getLastPathComponent())
}
})
@@ -336,21 +336,21 @@ abstract class TreeBrowsers {
str.append(t.symbol.tpe).append("\n")
buf = new StringWriter()
TypePrinter.toDocument(t.symbol.tpe).format(getWidth() / getColumnWidth(), buf)
- str.append(buf.toString())
+ str.append(buf.toString)
}
str.append("\n\nSymbol info: \n")
TreeInfo.symbolTypeDoc(t).format(getWidth() / getColumnWidth(), buf)
- str.append(buf.toString())
+ str.append(buf.toString)
str.append("\n\nSymbol Attributes: \n").append(TreeInfo.symbolAttributes(t))
str.append("\ntree.tpe: ")
if (t.tpe ne null) {
- str.append(t.tpe.toString()).append("\n")
+ str.append(t.tpe.toString).append("\n")
buf = new StringWriter()
TypePrinter.toDocument(t.tpe).format(getWidth() / getColumnWidth(), buf)
- str.append(buf.toString())
+ str.append(buf.toString)
}
}
- setText(str.toString())
+ setText(str.toString)
}
}
@@ -366,7 +366,7 @@ abstract class TreeBrowsers {
("Program", EMPTY)
case UnitTree(unit) =>
- ("CompilationUnit", unit.toString())
+ ("CompilationUnit", unit.toString)
case DocDef(comment, definition) =>
("DocDef", EMPTY)
@@ -447,7 +447,7 @@ abstract class TreeBrowsers {
("Apply", EMPTY)
case Super(qualif, mix) =>
- ("Super", "mix: " + mix.toString())
+ ("Super", "mix: " + mix)
case This(qualifier) =>
("This", qualifier)
@@ -717,7 +717,7 @@ abstract class TreeBrowsers {
case SingleType(pre, sym) =>
Document.group(
Document.nest(4, "SingleType(" :/:
- toDocument(pre) :: ", " :/: sym.name.toString() :: ")")
+ toDocument(pre) :: ", " :/: sym.name.toString :: ")")
)
case ConstantType(value) =>
@@ -727,7 +727,7 @@ abstract class TreeBrowsers {
Document.group(
Document.nest(4, "TypeRef(" :/:
toDocument(pre) :: ", " :/:
- sym.name.toString() + sym.idString :: ", " :/:
+ sym.name.toString + sym.idString :: ", " :/:
"[ " :: toDocument(args) ::"]" :: ")")
)
@@ -748,7 +748,7 @@ abstract class TreeBrowsers {
Document.group(
Document.nest(4,"ClassInfoType(" :/:
toDocument(parents) :: ", " :/:
- clazz.name.toString() + clazz.idString :: ")")
+ clazz.name.toString + clazz.idString :: ")")
)
case MethodType(params, result) =>
@@ -798,7 +798,7 @@ abstract class TreeBrowsers {
toDocument(thistpe) :/: ", " :/:
toDocument(supertpe) ::")"))
case _ =>
- sys.error("Unknown case: " + t.toString() +", "+ t.getClass)
+ sys.error("Unknown case: " + t.toString +", "+ t.getClass)
}
}
diff --git a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala
index cb77df2e6a..e208f5a8da 100644
--- a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala
+++ b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala
@@ -474,7 +474,7 @@ abstract class GenMSIL extends SubComponent {
// "Clone": if the code is non-portable, "Clone" is defined, not "clone"
// TODO: improve condition (should override AnyRef.clone)
if (iclass.methods.forall(m => {
- !((m.symbol.name.toString() != "clone" || m.symbol.name.toString() != "Clone") &&
+ !((m.symbol.name.toString != "clone" || m.symbol.name.toString != "Clone") &&
m.symbol.tpe.paramTypes.length != 0)
})) {
debuglog("auto-generating cloneable method for " + sym)
@@ -1615,7 +1615,7 @@ abstract class GenMSIL extends SubComponent {
if (sym.isNestedClass) sym.simpleName
else sym.fullName
} else
- sym.simpleName.toString().trim()) + suffix
+ sym.simpleName.toString.trim()) + suffix
}
diff --git a/src/compiler/scala/tools/nsc/interactive/Picklers.scala b/src/compiler/scala/tools/nsc/interactive/Picklers.scala
index 561fa47e94..2b6e793c5c 100644
--- a/src/compiler/scala/tools/nsc/interactive/Picklers.scala
+++ b/src/compiler/scala/tools/nsc/interactive/Picklers.scala
@@ -85,7 +85,7 @@ trait Picklers { self: Global =>
implicit lazy val position: Pickler[Position] = transparentPosition | rangePosition | offsetPosition | noPosition
implicit lazy val namePickler: Pickler[Name] =
- pkl[String] .wrapped {
+ pkl[String] .wrapped[Name] {
str => if ((str.length > 1) && (str endsWith "!")) newTypeName(str.init) else newTermName(str)
} {
name => if (name.isTypeName) name.toString+"!" else name.toString
diff --git a/src/compiler/scala/tools/nsc/javac/JavaScanners.scala b/src/compiler/scala/tools/nsc/javac/JavaScanners.scala
index 95e1ff1482..5422fc1c9e 100644
--- a/src/compiler/scala/tools/nsc/javac/JavaScanners.scala
+++ b/src/compiler/scala/tools/nsc/javac/JavaScanners.scala
@@ -811,7 +811,7 @@ trait JavaScanners extends ast.parser.ScannersCommon {
val limit: Double =
if (token == DOUBLELIT) Double.MaxValue else Float.MaxValue
try {
- val value: Double = java.lang.Double.valueOf(name.toString()).doubleValue()
+ val value: Double = java.lang.Double.valueOf(name.toString).doubleValue()
if (value > limit)
syntaxError("floating point number too large")
if (negated) -value else value
diff --git a/src/compiler/scala/tools/nsc/matching/Patterns.scala b/src/compiler/scala/tools/nsc/matching/Patterns.scala
index 3abb0c5ba3..5684932eae 100644
--- a/src/compiler/scala/tools/nsc/matching/Patterns.scala
+++ b/src/compiler/scala/tools/nsc/matching/Patterns.scala
@@ -84,7 +84,7 @@ trait Patterns extends ast.TreeDSL {
def isSwitchable = cond(const.tag) { case ByteTag | ShortTag | IntTag | CharTag => true }
def intValue = const.intValue
override def description = {
- val s = if (value == null) "null" else value.toString()
+ val s = if (value == null) "null" else value.toString
"Lit(%s)".format(s)
}
}
@@ -387,7 +387,7 @@ trait Patterns extends ast.TreeDSL {
def name: Name
override def sufficientType = tpe.narrow
override def simplify(pv: PatternVar) = this.rebindToEqualsCheck()
- override def description = name.toString()
+ override def description = name.toString
}
sealed trait UnapplyPattern extends Pattern {
@@ -469,9 +469,9 @@ trait Patterns extends ast.TreeDSL {
case _ => super.equals(other)
}
override def hashCode() = boundTree.hashCode()
- def description = super.toString()
+ def description = super.toString
- final override def toString() = description
+ final override def toString = description
def toTypeString() = "%s <: x <: %s".format(necessaryType, sufficientType)
}
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
index d9eaad55a0..a3c1ebf231 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
@@ -342,7 +342,7 @@ abstract class ClassfileParser {
val start = starts(index)
value = (in.buf(start).toInt: @switch) match {
case CONSTANT_STRING =>
- Constant(getName(in.getChar(start + 1).toInt).toString())
+ Constant(getName(in.getChar(start + 1).toInt).toString)
case CONSTANT_INTEGER =>
Constant(in.getInt(start + 1))
case CONSTANT_FLOAT =>
@@ -882,13 +882,13 @@ abstract class ClassfileParser {
case tpnme.ScalaSignatureATTR =>
if (!isScalaAnnot) {
debuglog("warning: symbol " + sym.fullName + " has pickled signature in attribute")
- unpickler.unpickle(in.buf, in.bp, clazz, staticModule, in.file.toString())
+ unpickler.unpickle(in.buf, in.bp, clazz, staticModule, in.file.toString)
}
in.skip(attrLen)
case tpnme.ScalaATTR =>
isScalaRaw = true
case tpnme.JacoMetaATTR =>
- val meta = pool.getName(in.nextChar).toString().trim()
+ val meta = pool.getName(in.nextChar).toString.trim()
metaParser.parse(meta, sym, symtype)
this.hasMeta = true
// Attribute on methods of java annotation classes when that method has a default
@@ -904,7 +904,7 @@ abstract class ClassfileParser {
case Some(san: AnnotationInfo) =>
val bytes =
san.assocs.find({ _._1 == nme.bytes }).get._2.asInstanceOf[ScalaSigBytes].bytes
- unpickler.unpickle(bytes, 0, clazz, staticModule, in.file.toString())
+ unpickler.unpickle(bytes, 0, clazz, staticModule, in.file.toString)
case None =>
throw new RuntimeException("Scala class file does not contain Scala annotation")
}
@@ -939,7 +939,7 @@ abstract class ClassfileParser {
val index = in.nextChar
tag match {
case STRING_TAG =>
- Some(LiteralAnnotArg(Constant(pool.getName(index).toString())))
+ Some(LiteralAnnotArg(Constant(pool.getName(index).toString)))
case BOOL_TAG | BYTE_TAG | CHAR_TAG | SHORT_TAG | INT_TAG |
LONG_TAG | FLOAT_TAG | DOUBLE_TAG =>
Some(LiteralAnnotArg(pool.getConstant(index)))
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala
index 930459e7cd..a203b8a78b 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala
@@ -105,7 +105,7 @@ abstract class ICodeReader extends ClassfileParser {
if (sym == NoSymbol) {
log("Could not find symbol for " + name + ": " + tpe)
log(owner.info.member(name).tpe + " : " + tpe)
- if (name.toString() == "toMap")
+ if (name.toString == "toMap")
tpe = pool.getType(dummySym, ch)
if (field)
sym = owner.newValue(owner.pos, name).setInfo(tpe).setFlag(MUTABLE | javaToScalaFlags(jflags))
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index dcc0b1c6ac..5106d7a4e6 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1479,7 +1479,7 @@ trait Typers extends Modes with Adaptations {
}
if (!forMSIL && (value.hasAnnotation(BeanPropertyAttr) ||
value.hasAnnotation(BooleanBeanPropertyAttr))) {
- val nameSuffix = name.toString().capitalize
+ val nameSuffix = name.toString.capitalize
val beanGetterName =
(if (value.hasAnnotation(BooleanBeanPropertyAttr)) "is" else "get") +
nameSuffix
diff --git a/src/compiler/scala/tools/nsc/util/ShowPickled.scala b/src/compiler/scala/tools/nsc/util/ShowPickled.scala
index 818b5a06ab..fc39a218f8 100644
--- a/src/compiler/scala/tools/nsc/util/ShowPickled.scala
+++ b/src/compiler/scala/tools/nsc/util/ShowPickled.scala
@@ -197,7 +197,7 @@ object ShowPickled extends Names {
tag match {
case TERMname =>
out.print(" ")
- out.print(newTermName(buf.bytes, buf.readIndex, len).toString())
+ out.print(newTermName(buf.bytes, buf.readIndex, len).toString)
buf.readIndex = end
case TYPEname =>
out.print(" ")