summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-07-13 12:09:16 -0700
committerPaul Phillips <paulp@improving.org>2012-07-13 12:25:08 -0700
commitb355fb2c7f622c2d263c43864469b862ef0bc768 (patch)
tree2f47f42921a20c8e4e7b85229e793caa2c236001 /src/reflect
parent453b7068ed4294eef18bf10a321a5b63497c7466 (diff)
downloadscala-b355fb2c7f622c2d263c43864469b862ef0bc768.tar.gz
scala-b355fb2c7f622c2d263c43864469b862ef0bc768.tar.bz2
scala-b355fb2c7f622c2d263c43864469b862ef0bc768.zip
Avoid conflict with String's apply.
This brought to light that Name extends (Int => Char), and that small convenience was not paying for itself. I updated the places taking advantage of it to use Name#charAt.
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/internal/Names.scala10
-rw-r--r--src/reflect/scala/reflect/internal/StdNames.scala8
-rw-r--r--src/reflect/scala/reflect/internal/TreeInfo.scala2
3 files changed, 10 insertions, 10 deletions
diff --git a/src/reflect/scala/reflect/internal/Names.scala b/src/reflect/scala/reflect/internal/Names.scala
index 3c0848f77f..20da38fd63 100644
--- a/src/reflect/scala/reflect/internal/Names.scala
+++ b/src/reflect/scala/reflect/internal/Names.scala
@@ -145,7 +145,7 @@ trait Names extends api.Names with LowPriorityNames {
* or Strings as Names. Give names the key functions the absence of which
* make people want Strings all the time.
*/
- sealed abstract class Name(protected val index: Int, protected val len: Int) extends NameApi with Function1[Int, Char] {
+ sealed abstract class Name(protected val index: Int, protected val len: Int) extends NameApi {
type ThisNameType >: Null <: Name
protected[this] def thisName: ThisNameType
@@ -226,7 +226,7 @@ trait Names extends api.Names with LowPriorityNames {
}
/** @return the i'th Char of this name */
- final def apply(i: Int): Char = chrs(index + i)
+ final def charAt(i: Int): Char = chrs(index + i)
/** @return the index of first occurrence of char c in this name, length if not found */
final def pos(c: Char): Int = pos(c, 0)
@@ -355,8 +355,8 @@ trait Names extends api.Names with LowPriorityNames {
/** Some thoroughly self-explanatory convenience functions. They
* assume that what they're being asked to do is known to be valid.
*/
- final def startChar: Char = apply(0)
- final def endChar: Char = apply(len - 1)
+ final def startChar: Char = this charAt 0
+ final def endChar: Char = this charAt len - 1
final def startsWith(char: Char): Boolean = len > 0 && startChar == char
final def startsWith(name: String): Boolean = startsWith(newTermName(name))
final def endsWith(char: Char): Boolean = len > 0 && endChar == char
@@ -380,7 +380,7 @@ trait Names extends api.Names with LowPriorityNames {
val cs = new Array[Char](len)
var i = 0
while (i < len) {
- val ch = this(i)
+ val ch = charAt(i)
cs(i) = if (ch == from) to else ch
i += 1
}
diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala
index 51dd309a61..165e04863c 100644
--- a/src/reflect/scala/reflect/internal/StdNames.scala
+++ b/src/reflect/scala/reflect/internal/StdNames.scala
@@ -374,9 +374,9 @@ trait StdNames {
*/
def originalName(name: Name): Name = {
var i = name.length
- while (i >= 2 && !(name(i - 1) == '$' && name(i - 2) == '$')) i -= 1
+ while (i >= 2 && !(name.charAt(i - 1) == '$' && name.charAt(i - 2) == '$')) i -= 1
if (i >= 2) {
- while (i >= 3 && name(i - 3) == '$') i -= 1
+ while (i >= 3 && name.charAt(i - 3) == '$') i -= 1
name.subName(i, name.length)
} else name
}
@@ -455,10 +455,10 @@ trait StdNames {
// Otherwise return the argument.
def stripAnonNumberSuffix(name: Name): Name = {
var pos = name.length
- while (pos > 0 && name(pos - 1).isDigit)
+ while (pos > 0 && name.charAt(pos - 1).isDigit)
pos -= 1
- if (pos <= 0 || pos == name.length || name(pos - 1) != '$') name
+ if (pos <= 0 || pos == name.length || name.charAt(pos - 1) != '$') name
else name.subName(0, pos - 1)
}
diff --git a/src/reflect/scala/reflect/internal/TreeInfo.scala b/src/reflect/scala/reflect/internal/TreeInfo.scala
index 698d219634..745065b024 100644
--- a/src/reflect/scala/reflect/internal/TreeInfo.scala
+++ b/src/reflect/scala/reflect/internal/TreeInfo.scala
@@ -316,7 +316,7 @@ abstract class TreeInfo {
/** Is name a variable name? */
def isVariableName(name: Name): Boolean = {
- val first = name(0)
+ val first = name.startChar
((first.isLower && first.isLetter) || first == '_') && !reserved(name)
}