summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/util/Position.scala
diff options
context:
space:
mode:
authorSean McDirmid <sean.mcdirmid@gmail.com>2006-01-27 19:22:18 +0000
committerSean McDirmid <sean.mcdirmid@gmail.com>2006-01-27 19:22:18 +0000
commitc717ffa0fdfcd72b1cc5ebc9b28e91e41442aad3 (patch)
treeac91ecc809b1ffceca52a0c1cc4a1fb090e42dc4 /src/compiler/scala/tools/nsc/util/Position.scala
parent05a91221bd83a75b92d63af99fe87dab12edc010 (diff)
downloadscala-c717ffa0fdfcd72b1cc5ebc9b28e91e41442aad3.tar.gz
scala-c717ffa0fdfcd72b1cc5ebc9b28e91e41442aad3.tar.bz2
scala-c717ffa0fdfcd72b1cc5ebc9b28e91e41442aad3.zip
Format changes, updates to IDE highlighting.
Diffstat (limited to 'src/compiler/scala/tools/nsc/util/Position.scala')
-rw-r--r--src/compiler/scala/tools/nsc/util/Position.scala23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/util/Position.scala b/src/compiler/scala/tools/nsc/util/Position.scala
index 29f4d74cf7..290eb7e248 100644
--- a/src/compiler/scala/tools/nsc/util/Position.scala
+++ b/src/compiler/scala/tools/nsc/util/Position.scala
@@ -19,6 +19,15 @@ object Position {
val FIRSTLINE = 1;
def line(source : SourceFile, offset : Int) = (new Position(source, offset)).line;
+
+ def lineToOffset(line : Int) = {
+ assert(line >= 1);
+ NOPOS - line;
+ }
+ def offsetToLine(pos : Int) = {
+ assert(pos < NOPOS);
+ NOPOS - pos;
+ }
}
@@ -30,9 +39,14 @@ class Position( val source : SourceFile, val offset: Int) {
def this(sourceName : String) = this(new SourceFile(sourceName, new Array[Char](0)), Position.NOPOS);
def this(sourceName : String, _offset : Int) = this(new SourceFile(sourceName, new Array[Char](0)), _offset);
- def hasOffset = offset != NOPOS;
+ private def hasOffset = offset > NOPOS;
+ private def isLine = offset < NOPOS;
+
+
+ def line: Int =
+ if (hasOffset) source.offsetToLine(offset) + FIRSTLINE
+ else if (isLine) Position.offsetToLine(offset) else NOLINE;
- def line: Int = if (hasOffset) source.offsetToLine(offset) + FIRSTLINE else NOLINE;
// for display purposes only.
def column: Int = if (hasOffset) {
var column = 1;
@@ -52,8 +66,9 @@ class Position( val source : SourceFile, val offset: Int) {
def dbgString =
- if (!hasOffset) "NOP"
- else if (offset >= source.content.length) "OB-" + offset else {
+ if (isLine) "line-" + line;
+ else if (!hasOffset) "NOP";
+ else if (offset >= source.content.length) "out-of-bounds-" + offset else {
val ret = "offset=" + offset + " line=" + line;
var add = "";
while (offset + add.length() < source.content.length &&