-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
InteractiveReporter.scala
56 lines (47 loc) · 1.58 KB
/
InteractiveReporter.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/
package scala.tools.nsc
package interactive
import scala.collection.mutable.ArrayBuffer
import scala.reflect.internal.util.{CodeAction, Position}
import scala.tools.nsc.reporters.FilteringReporter
case class Problem(pos: Position, msg: String, severityLevel: Int, actions: List[CodeAction])
abstract class InteractiveReporter extends FilteringReporter {
def compiler: Global
def settings: Settings = compiler.settings
val otherProblems = new ArrayBuffer[Problem]
override def doReport(pos: Position, msg: String, severity: Severity, actions: List[CodeAction]): Unit = try {
val problems =
if (compiler eq null) {
otherProblems
} else if (pos.isDefined) {
compiler.getUnit(pos.source) match {
case Some(unit) =>
compiler.debugLog(pos.source.file.name + ":" + pos.line + ": " + msg)
unit.problems
case None =>
compiler.debugLog(pos.source.file.name + "[not loaded] :" + pos.line + ": " + msg)
otherProblems
}
} else {
compiler.debugLog("[no position] :" + msg)
otherProblems
}
problems += Problem(pos, msg, severity.id, actions)
} catch {
case ex: UnsupportedOperationException =>
}
override def reset(): Unit = {
super.reset()
otherProblems.clear()
}
}