diff options
author | Martin Odersky <odersky@gmail.com> | 2013-05-10 16:48:47 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-05-10 16:52:43 +0200 |
commit | aad2d3a71f65e1b542bbfafbf387394331a270ee (patch) | |
tree | 20b71bc654557cd02d3a965d87afdf1a76a2cfa1 /src/dotty/tools/dotc/util/SourceFile.scala | |
parent | 5ec2199c4966404d462eb866533dc0589fe7f239 (diff) | |
download | dotty-aad2d3a71f65e1b542bbfafbf387394331a270ee.tar.gz dotty-aad2d3a71f65e1b542bbfafbf387394331a270ee.tar.bz2 dotty-aad2d3a71f65e1b542bbfafbf387394331a270ee.zip |
Refactored and augmented source positions.
Also Implemented ConsoleReporter formatting.
Diffstat (limited to 'src/dotty/tools/dotc/util/SourceFile.scala')
-rw-r--r-- | src/dotty/tools/dotc/util/SourceFile.scala | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/util/SourceFile.scala b/src/dotty/tools/dotc/util/SourceFile.scala index b67eefdfa..91b296962 100644 --- a/src/dotty/tools/dotc/util/SourceFile.scala +++ b/src/dotty/tools/dotc/util/SourceFile.scala @@ -38,6 +38,9 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) { def this(sourceName: String, cs: Seq[Char]) = this(new VirtualFile(sourceName), cs.toArray) def this(file: AbstractFile, cs: Seq[Char]) = this(file, cs.toArray) + /** Tab increment; can be overridden */ + def tabInc = 8 + override def equals(that : Any) = that match { case that : SourceFile => file.path == that.file.path && start == that.start case _ => false @@ -103,6 +106,24 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) { lastLine = findLine(0, lines.length, lastLine) lastLine } + + def startOfLine(offset: Int): Int = lineToOffset(offsetToLine(offset)) + + def nextLine(offset: Int): Int = + lineToOffset(offsetToLine(offset) + 1 min lineIndices.length - 1) + + def lineContents(offset: Int): String = + content.slice(startOfLine(offset), nextLine(offset)).mkString + + def column(offset: Int): Int = { + var idx = startOfLine(offset) + var col = 0 + while (idx != offset) { + col += (if (content(idx) == '\t') tabInc - col % tabInc else 1) + idx += 1 + } + col + 1 + } } object NoSource extends SourceFile("<no source>", Nil) { |