From 94b41d5c491878543288af1bedb4daf57226ca07 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Wed, 24 Feb 2016 23:50:34 +0100 Subject: Small API changes in preparation for dotty-interfaces - Rename Diagnostic#msg to message, this is nicer for a public API - Rename SourceFile#lineContents and SourcePosition#lineContents to lineContent, the former is not grammatically correct. - Add some convenience methods to SourcePosition. --- src/dotty/tools/dotc/reporting/ConsoleReporter.scala | 10 +++++----- src/dotty/tools/dotc/reporting/Diagnostic.scala | 8 ++++---- src/dotty/tools/dotc/reporting/StoreReporter.scala | 2 +- src/dotty/tools/dotc/util/SourceFile.scala | 4 ++-- src/dotty/tools/dotc/util/SourcePosition.scala | 15 ++++++++++----- 5 files changed, 22 insertions(+), 17 deletions(-) (limited to 'src/dotty') diff --git a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala index 61678dee1..f35293d8d 100644 --- a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala +++ b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala @@ -22,7 +22,7 @@ class ConsoleReporter( protected def ErrorLimit = 100 def printSourceLine(pos: SourcePosition) = - printMessage(pos.lineContents.stripLineEnd) + printMessage(pos.lineContent.stripLineEnd) def printColumnMarker(pos: SourcePosition) = if (pos.exists) { printMessage(" " * pos.column + "^") } @@ -42,15 +42,15 @@ class ConsoleReporter( override def doReport(d: Diagnostic)(implicit ctx: Context): Unit = d match { case d: Error => - printMessageAndPos(s"error: ${d.msg}", d.pos) + printMessageAndPos(s"error: ${d.message}", d.pos) if (ctx.settings.prompt.value) displayPrompt() case d: ConditionalWarning if !d.enablingOption.value => case d: MigrationWarning => - printMessageAndPos(s"migration warning: ${d.msg}", d.pos) + printMessageAndPos(s"migration warning: ${d.message}", d.pos) case d: Warning => - printMessageAndPos(s"warning: ${d.msg}", d.pos) + printMessageAndPos(s"warning: ${d.message}", d.pos) case _ => - printMessageAndPos(d.msg, d.pos) + printMessageAndPos(d.message, d.pos) } def displayPrompt(): Unit = { diff --git a/src/dotty/tools/dotc/reporting/Diagnostic.scala b/src/dotty/tools/dotc/reporting/Diagnostic.scala index c57be3d26..ea3ea4112 100644 --- a/src/dotty/tools/dotc/reporting/Diagnostic.scala +++ b/src/dotty/tools/dotc/reporting/Diagnostic.scala @@ -21,7 +21,7 @@ class Diagnostic(msgFn: => String, val pos: SourcePosition, val level: Int) exte private var myIsNonSensical: Boolean = false /** The message to report */ - def msg: String = { + def message: String = { if (myMsg == null) { myMsg = msgFn if (myMsg.contains(nonSensicalStartTag)) { @@ -40,8 +40,8 @@ class Diagnostic(msgFn: => String, val pos: SourcePosition, val level: Int) exte * they look weird and are normally follow-up errors to something that * was diagnosed before. */ - def isNonSensical = { msg; myIsNonSensical } + def isNonSensical = { message; myIsNonSensical } - override def toString = s"$getClass at $pos: $msg" - override def getMessage() = msg + override def toString = s"$getClass at $pos: $message" + override def getMessage() = message } diff --git a/src/dotty/tools/dotc/reporting/StoreReporter.scala b/src/dotty/tools/dotc/reporting/StoreReporter.scala index d19e8cf5c..954bff88e 100644 --- a/src/dotty/tools/dotc/reporting/StoreReporter.scala +++ b/src/dotty/tools/dotc/reporting/StoreReporter.scala @@ -15,7 +15,7 @@ class StoreReporter(outer: Reporter) extends Reporter { private var infos: mutable.ListBuffer[Diagnostic] = null def doReport(d: Diagnostic)(implicit ctx: Context): Unit = { - typr.println(s">>>> StoredError: ${d.msg}") // !!! DEBUG + typr.println(s">>>> StoredError: ${d.message}") // !!! DEBUG if (infos == null) infos = new mutable.ListBuffer infos += d } diff --git a/src/dotty/tools/dotc/util/SourceFile.scala b/src/dotty/tools/dotc/util/SourceFile.scala index da2e54132..ac3ee298e 100644 --- a/src/dotty/tools/dotc/util/SourceFile.scala +++ b/src/dotty/tools/dotc/util/SourceFile.scala @@ -113,8 +113,8 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) { def nextLine(offset: Int): Int = lineToOffset(offsetToLine(offset) + 1 min lineIndices.length - 1) - /** The contents of the line containing position `offset` */ - def lineContents(offset: Int): String = + /** The content of the line containing position `offset` */ + def lineContent(offset: Int): String = content.slice(startOfLine(offset), nextLine(offset)).mkString /** The column corresponding to `offset`, starting at 0 */ diff --git a/src/dotty/tools/dotc/util/SourcePosition.scala b/src/dotty/tools/dotc/util/SourcePosition.scala index 9e02841f2..fa7a4650d 100644 --- a/src/dotty/tools/dotc/util/SourcePosition.scala +++ b/src/dotty/tools/dotc/util/SourcePosition.scala @@ -5,19 +5,24 @@ import Positions.{Position, NoPosition} /** A source position is comprised of a position in a source file */ case class SourcePosition(source: SourceFile, pos: Position) { - def point: Int = pos.point - def start: Int = pos.start - def end: Int = pos.end def exists = pos.exists - def lineContents: String = source.lineContents(point) + def lineContent: String = source.lineContent(point) + def point: Int = pos.point /** The line of the position, starting at 0 */ def line: Int = source.offsetToLine(point) - /** The column of the position, starting at 0 */ def column: Int = source.column(point) + def start: Int = pos.start + def startLine: Int = source.offsetToLine(start) + def startColumn: Int = source.column(start) + + def end: Int = pos.end + def endLine: Int = source.offsetToLine(end) + def endColumn: Int = source.column(end) + override def toString = if (source.exists) s"${source.file}:${line + 1}" else s"(no source file, offset = ${pos.point})" -- cgit v1.2.3