summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugene Vigdorchik <eugenevigdorchik@epfl.ch>2010-09-23 07:58:28 +0000
committerEugene Vigdorchik <eugenevigdorchik@epfl.ch>2010-09-23 07:58:28 +0000
commitb82c43199139fd79e675d17634ffb20f5d6072f2 (patch)
tree261a2d7e766a406e1362896b00cc2abd04238f3a /src
parent0a0cdb03d8c4c9c42da114fe5b0bc8c7911f0c24 (diff)
downloadscala-b82c43199139fd79e675d17634ffb20f5d6072f2.tar.gz
scala-b82c43199139fd79e675d17634ffb20f5d6072f2.tar.bz2
scala-b82c43199139fd79e675d17634ffb20f5d6072f2.zip
Rollback MutableSourceFile, the whole idea is b...
Rollback MutableSourceFile, the whole idea is broken
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/util/SourceFile.scala65
1 files changed, 24 insertions, 41 deletions
diff --git a/src/compiler/scala/tools/nsc/util/SourceFile.scala b/src/compiler/scala/tools/nsc/util/SourceFile.scala
index b0c819fc08..8c1d308209 100644
--- a/src/compiler/scala/tools/nsc/util/SourceFile.scala
+++ b/src/compiler/scala/tools/nsc/util/SourceFile.scala
@@ -85,10 +85,29 @@ class ScriptSourceFile(underlying: BatchSourceFile, content: Array[Char], overri
else new OffsetPosition(underlying, pos.point + start)
}
-sealed trait LineOffsetMapper {
- def content : Array[Char]
- def length : Int
- def lineIndices : Array[Int]
+/** a file whose contents do not change over time */
+class BatchSourceFile(val file : AbstractFile, val content: Array[Char]) extends SourceFile {
+
+ def this(_file: AbstractFile) = this(_file, _file.toCharArray)
+ def this(sourceName: String, cs: Seq[Char]) = this(new VirtualFile(sourceName), cs.toArray)
+ def this(file: AbstractFile, cs: Seq[Char]) = this(file, cs.toArray)
+
+ override def equals(that : Any) = that match {
+ case that : BatchSourceFile => file.path == that.file.path && start == that.start
+ case _ => false
+ }
+ override def hashCode = file.path.## + start.##
+ val length = content.length
+ def start = 0
+ def isSelfContained = true
+
+ override def identifier(pos: Position, compiler: Global) =
+ if (pos.isDefined && pos.source == this && pos.point != -1) {
+ def isOK(c: Char) = isIdentifierPart(c) || isOperatorPart(c)
+ Some(new String(content drop pos.point takeWhile isOK))
+ } else {
+ super.identifier(pos, compiler)
+ }
def isLineBreak(idx: Int) =
if (idx >= length) false else {
@@ -105,6 +124,7 @@ sealed trait LineOffsetMapper {
buf += cs.length // sentinel, so that findLine below works smoother
buf.toArray
}
+ private lazy val lineIndices: Array[Int] = calculateLineIndices(content)
def lineToOffset(index : Int): Int = lineIndices(index)
@@ -123,40 +143,3 @@ sealed trait LineOffsetMapper {
lastLine
}
}
-
-/** a file whose contents do not change over time */
-class BatchSourceFile(val file : AbstractFile, val content: Array[Char]) extends SourceFile with LineOffsetMapper {
-
- def this(_file: AbstractFile) = this(_file, _file.toCharArray)
- def this(sourceName: String, cs: Seq[Char]) = this(new VirtualFile(sourceName), cs.toArray)
- def this(file: AbstractFile, cs: Seq[Char]) = this(file, cs.toArray)
-
- override def equals(that : Any) = that match {
- case that : BatchSourceFile => file.path == that.file.path && start == that.start
- case _ => false
- }
- override def hashCode = file.path.## + start.##
- val length = content.length
- def start = 0
- def isSelfContained = true
-
- lazy val lineIndices: Array[Int] = calculateLineIndices(content)
-}
-
-/** a file whose contents do change over time */
-class MutableSourceFile(val file : AbstractFile, var content: Array[Char]) extends SourceFile with LineOffsetMapper {
- def this(_file: AbstractFile) = this(_file, _file.toCharArray)
- def this(sourceName: String, cs: Seq[Char]) = this(new VirtualFile(sourceName), cs.toArray)
- def this(file: AbstractFile, cs: Seq[Char]) = this(file, cs.toArray)
-
- override def equals(that : Any) = that match {
- case that : MutableSourceFile => file.path == that.file.path && start == that.start
- case _ => false
- }
- override def hashCode = file.path.## + start.##
- def length = content.length
- def start = 0
- def isSelfContained = true
-
- def lineIndices : Array[Int] = calculateLineIndices(content)
-}