diff options
author | Paul Phillips <paulp@improving.org> | 2013-09-27 14:38:38 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-09-27 14:42:24 -0700 |
commit | 7d62df035cd4393c73e7530e1cad1130e79d90c6 (patch) | |
tree | 8a643ea65861b7bceb8d22397d991401b8716079 /src/reflect/scala/reflect/internal/util | |
parent | 5a8cd09819f58adcb866722f48b00066d23e7a82 (diff) | |
download | scala-7d62df035cd4393c73e7530e1cad1130e79d90c6.tar.gz scala-7d62df035cd4393c73e7530e1cad1130e79d90c6.tar.bz2 scala-7d62df035cd4393c73e7530e1cad1130e79d90c6.zip |
Updating Position call sites.
Calling position factories rather than instantiating these
particular classes. Not calling deprecated methods. Added a few
position combinator methods.
Diffstat (limited to 'src/reflect/scala/reflect/internal/util')
-rw-r--r-- | src/reflect/scala/reflect/internal/util/Position.scala | 18 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/util/SourceFile.scala | 12 |
2 files changed, 23 insertions, 7 deletions
diff --git a/src/reflect/scala/reflect/internal/util/Position.scala b/src/reflect/scala/reflect/internal/util/Position.scala index 8e7df28167..15cfda26b5 100644 --- a/src/reflect/scala/reflect/internal/util/Position.scala +++ b/src/reflect/scala/reflect/internal/util/Position.scala @@ -169,6 +169,20 @@ private[util] trait InternalPositionImpl { def focus: Position = if (this.isRange) asOffset(point) else this def focusEnd: Position = if (this.isRange) asOffset(end) else this + /** If you have it in for punctuation you might not like these methods. + * However I think they're aptly named. + * + * | means union + * ^ means "the point" (look, it's a caret) + * |^ means union, taking the point of the rhs + * ^| means union, taking the point of the lhs + */ + def |(that: Position, poses: Position*): Position = poses.foldLeft(this | that)(_ | _) + def |(that: Position): Position = this union that + def ^(point: Int): Position = this withPoint point + def |^(that: Position): Position = (this | that) ^ that.point + def ^|(that: Position): Position = (this | that) ^ this.point + def union(pos: Position): Position = ( if (!pos.isRange) this else if (this.isRange) copyRange(start = start min pos.start, end = end max pos.end) @@ -246,9 +260,9 @@ private[util] trait DeprecatedPosition { @deprecated("Use `withSource(source)` and `withShift`", "2.11.0") def withSource(source: SourceFile, shift: Int): Position = this withSource source withShift shift - @deprecated("Use `start`", "2.11.0") + @deprecated("Use `start` instead", "2.11.0") def startOrPoint: Int = if (isRange) start else point - @deprecated("Use `end`", "2.11.0") + @deprecated("Use `end` instead", "2.11.0") def endOrPoint: Int = if (isRange) end else point } diff --git a/src/reflect/scala/reflect/internal/util/SourceFile.scala b/src/reflect/scala/reflect/internal/util/SourceFile.scala index 6bb4cf3f0e..f36c50bff1 100644 --- a/src/reflect/scala/reflect/internal/util/SourceFile.scala +++ b/src/reflect/scala/reflect/internal/util/SourceFile.scala @@ -23,7 +23,7 @@ abstract class SourceFile { def length : Int def position(offset: Int) : Position = { assert(offset < length, file + ": " + offset + " >= " + length) - new OffsetPosition(this, offset) + Position.offset(this, offset) } def offsetToLine(offset: Int): Int @@ -34,7 +34,7 @@ abstract class SourceFile { */ def positionInUltimateSource(position: Position) = position override def toString() = file.name - def dbg(offset: Int) = (new OffsetPosition(this, offset)).dbgString + def dbg(offset: Int) = Position.offset(this, offset).toString def path = file.path def lineToString(index: Int): String = @@ -98,7 +98,7 @@ class ScriptSourceFile(underlying: BatchSourceFile, content: Array[Char], overri override def positionInUltimateSource(pos: Position) = if (!pos.isDefined) super.positionInUltimateSource(pos) - else pos.withSource(underlying, start) + else pos withSource underlying withShift start } /** a file whose contents do not change over time */ @@ -155,10 +155,12 @@ class BatchSourceFile(val file : AbstractFile, val content0: Array[Char]) extend */ def offsetToLine(offset: Int): Int = { val lines = lineIndices - def findLine(lo: Int, hi: Int, mid: Int): Int = - if (offset < lines(mid)) findLine(lo, mid - 1, (lo + mid - 1) / 2) + def findLine(lo: Int, hi: Int, mid: Int): Int = ( + if (mid < lo || hi < mid) mid // minimal sanity check - as written this easily went into infinite loopyland + else if (offset < lines(mid)) findLine(lo, mid - 1, (lo + mid - 1) / 2) else if (offset >= lines(mid + 1)) findLine(mid + 1, hi, (mid + 1 + hi) / 2) else mid + ) lastLine = findLine(0, lines.length, lastLine) lastLine } |