Skip to content

Commit 94b41d5

Browse files
committed
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.
1 parent 0eecb71 commit 94b41d5

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

src/dotty/tools/dotc/reporting/ConsoleReporter.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ConsoleReporter(
2222
protected def ErrorLimit = 100
2323

2424
def printSourceLine(pos: SourcePosition) =
25-
printMessage(pos.lineContents.stripLineEnd)
25+
printMessage(pos.lineContent.stripLineEnd)
2626

2727
def printColumnMarker(pos: SourcePosition) =
2828
if (pos.exists) { printMessage(" " * pos.column + "^") }
@@ -42,15 +42,15 @@ class ConsoleReporter(
4242

4343
override def doReport(d: Diagnostic)(implicit ctx: Context): Unit = d match {
4444
case d: Error =>
45-
printMessageAndPos(s"error: ${d.msg}", d.pos)
45+
printMessageAndPos(s"error: ${d.message}", d.pos)
4646
if (ctx.settings.prompt.value) displayPrompt()
4747
case d: ConditionalWarning if !d.enablingOption.value =>
4848
case d: MigrationWarning =>
49-
printMessageAndPos(s"migration warning: ${d.msg}", d.pos)
49+
printMessageAndPos(s"migration warning: ${d.message}", d.pos)
5050
case d: Warning =>
51-
printMessageAndPos(s"warning: ${d.msg}", d.pos)
51+
printMessageAndPos(s"warning: ${d.message}", d.pos)
5252
case _ =>
53-
printMessageAndPos(d.msg, d.pos)
53+
printMessageAndPos(d.message, d.pos)
5454
}
5555

5656
def displayPrompt(): Unit = {

src/dotty/tools/dotc/reporting/Diagnostic.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Diagnostic(msgFn: => String, val pos: SourcePosition, val level: Int) exte
2121
private var myIsNonSensical: Boolean = false
2222

2323
/** The message to report */
24-
def msg: String = {
24+
def message: String = {
2525
if (myMsg == null) {
2626
myMsg = msgFn
2727
if (myMsg.contains(nonSensicalStartTag)) {
@@ -40,8 +40,8 @@ class Diagnostic(msgFn: => String, val pos: SourcePosition, val level: Int) exte
4040
* they look weird and are normally follow-up errors to something that
4141
* was diagnosed before.
4242
*/
43-
def isNonSensical = { msg; myIsNonSensical }
43+
def isNonSensical = { message; myIsNonSensical }
4444

45-
override def toString = s"$getClass at $pos: $msg"
46-
override def getMessage() = msg
45+
override def toString = s"$getClass at $pos: $message"
46+
override def getMessage() = message
4747
}

src/dotty/tools/dotc/reporting/StoreReporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class StoreReporter(outer: Reporter) extends Reporter {
1515
private var infos: mutable.ListBuffer[Diagnostic] = null
1616

1717
def doReport(d: Diagnostic)(implicit ctx: Context): Unit = {
18-
typr.println(s">>>> StoredError: ${d.msg}") // !!! DEBUG
18+
typr.println(s">>>> StoredError: ${d.message}") // !!! DEBUG
1919
if (infos == null) infos = new mutable.ListBuffer
2020
infos += d
2121
}

src/dotty/tools/dotc/util/SourceFile.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) {
113113
def nextLine(offset: Int): Int =
114114
lineToOffset(offsetToLine(offset) + 1 min lineIndices.length - 1)
115115

116-
/** The contents of the line containing position `offset` */
117-
def lineContents(offset: Int): String =
116+
/** The content of the line containing position `offset` */
117+
def lineContent(offset: Int): String =
118118
content.slice(startOfLine(offset), nextLine(offset)).mkString
119119

120120
/** The column corresponding to `offset`, starting at 0 */

src/dotty/tools/dotc/util/SourcePosition.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@ import Positions.{Position, NoPosition}
55

66
/** A source position is comprised of a position in a source file */
77
case class SourcePosition(source: SourceFile, pos: Position) {
8-
def point: Int = pos.point
9-
def start: Int = pos.start
10-
def end: Int = pos.end
118
def exists = pos.exists
129

13-
def lineContents: String = source.lineContents(point)
10+
def lineContent: String = source.lineContent(point)
1411

12+
def point: Int = pos.point
1513
/** The line of the position, starting at 0 */
1614
def line: Int = source.offsetToLine(point)
17-
1815
/** The column of the position, starting at 0 */
1916
def column: Int = source.column(point)
2017

18+
def start: Int = pos.start
19+
def startLine: Int = source.offsetToLine(start)
20+
def startColumn: Int = source.column(start)
21+
22+
def end: Int = pos.end
23+
def endLine: Int = source.offsetToLine(end)
24+
def endColumn: Int = source.column(end)
25+
2126
override def toString =
2227
if (source.exists) s"${source.file}:${line + 1}"
2328
else s"(no source file, offset = ${pos.point})"

0 commit comments

Comments
 (0)