Merge pull request #370 from vigdorchik/introduce_range_positions

Remember the range for settings read from .sbt files
This commit is contained in:
Mark Harrah 2012-02-17 05:04:59 -08:00
commit 79caa03093
2 changed files with 21 additions and 5 deletions

20
util/collection/Positions.scala Executable file
View File

@ -0,0 +1,20 @@
package sbt
sealed trait SourcePosition
sealed trait FilePosition {
def path: String
def startLine: Int
}
case object NoPosition extends SourcePosition
final case class LinePosition(path: String, startLine: Int) extends SourcePosition with FilePosition
final case class LineRange(start: Int, end: Int) {
def shift(n: Int) = new LineRange(start + n, end + n)
}
final case class RangePosition(path: String, range: LineRange) extends SourcePosition with FilePosition {
def startLine = range.start
}

View File

@ -255,14 +255,10 @@ trait Init[Scope]
def mapKey(g: MapScoped): Setting[T] = new Setting(g(key), init, pos)
def mapInit(f: (ScopedKey[T], T) => T): Setting[T] = new Setting(key, init(t => f(key,t)), pos)
def mapConstant(g: MapConstant): Setting[T] = new Setting(key, init mapConstant g, pos)
def withPos(pos: SourceCoord) = new Setting(key, init, pos)
def withPos(pos: SourcePosition) = new Setting(key, init, pos)
override def toString = "setting(" + key + ") at " + pos
}
sealed trait SourcePosition
case object NoPosition extends SourcePosition
final case class SourceCoord(fileName: String, line: Int) extends SourcePosition
// mainly for reducing generated class count
private[this] def validateReferencedT(g: ValidateRef) =
new (Initialize ~> ValidatedInit) { def apply[T](i: Initialize[T]) = i validateReferenced g }