diff options
author | michelou <michelou@epfl.ch> | 2007-11-08 16:16:20 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2007-11-08 16:16:20 +0000 |
commit | 05b59f2c7d2e653b1bc5d132703aa60e062a2af4 (patch) | |
tree | 8a5e8f2423dc8c4a0b6e38bbbd217c40a0c5847b | |
parent | 98d92d4659ee62384671c7a8ea1bba286165f413 (diff) | |
download | scala-05b59f2c7d2e653b1bc5d132703aa60e062a2af4.tar.gz scala-05b59f2c7d2e653b1bc5d132703aa60e062a2af4.tar.bz2 scala-05b59f2c7d2e653b1bc5d132703aa60e062a2af4.zip |
small cleanup
-rw-r--r-- | src/compiler/scala/tools/nsc/util/Position.scala | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/util/Position.scala b/src/compiler/scala/tools/nsc/util/Position.scala index ae4cd55086..a895780d1c 100644 --- a/src/compiler/scala/tools/nsc/util/Position.scala +++ b/src/compiler/scala/tools/nsc/util/Position.scala @@ -1,25 +1,26 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - +/* NSC -- new Scala compiler + * Copyright 2005-2007 LAMP/EPFL + * @author Martin Odersky + */ // $Id$ + package scala.tools.nsc.util + object Position { // a static field private val tabInc = 8 } + trait Position { import Position.tabInc def offset : Option[Int] = None def source : Option[SourceFile] = None - def line : Option[Int] = - if (offset.isEmpty || source.isEmpty) None else Some(source.get.offsetToLine(offset.get) + 1) - def column : Option[Int] = { + def line: Option[Int] = + if (offset.isEmpty || source.isEmpty) None + else Some(source.get.offsetToLine(offset.get) + 1) + + def column: Option[Int] = { if (offset.isEmpty || source.isEmpty) return None var column = 1 // find beginning offset for line @@ -30,18 +31,18 @@ trait Position { if (coffset == offset.get(-1)) continue = false else if (source.get.asInstanceOf[BatchSourceFile].content(coffset) == '\t') column = ((column - 1) / tabInc * tabInc) + tabInc + 1 - else column = column + 1 - coffset = coffset + 1 + else column += 1 + coffset += 1 } Some(column) } + def lineContent: String = { val line = this.line if (!line.isEmpty) source.get.lineToString(line.get - 1) else "NO_LINE" } - /** Map this position to a position in an original source * file. If the SourceFile is a normal SourceFile, simply * return this. @@ -67,17 +68,18 @@ trait Position { } -object NoPosition extends Position; -case class FakePos(msg : String) extends Position; +object NoPosition extends Position +case class FakePos(msg: String) extends Position -case class LinePosition(source0 : SourceFile, line0 : Int) extends Position { +case class LinePosition(source0: SourceFile, line0: Int) extends Position { assert(line0 >= 1) override def offset = None override def column = None override def line = Some(line0) override def source = Some(source0) } -case class OffsetPosition(source0 : SourceFile, offset0 : Int) extends Position { + +case class OffsetPosition(source0: SourceFile, offset0: Int) extends Position { override def source = Some(source0) override def offset = Some(offset0) } |