mirror of https://github.com/sbt/sbt.git
move to revised warning interface in the compiler
This commit is contained in:
parent
13e62fd645
commit
99a04466f1
|
|
@ -115,7 +115,7 @@ class LoggerReporter(maximumErrors: Int, log: Logger) extends xsbti.Reporter
|
||||||
|
|
||||||
def log(pos: Position, msg: String, severity: Severity): Unit =
|
def log(pos: Position, msg: String, severity: Severity): Unit =
|
||||||
{
|
{
|
||||||
allProblems += problem(pos, msg, severity)
|
allProblems += problem("", pos, msg, severity)
|
||||||
severity match
|
severity match
|
||||||
{
|
{
|
||||||
case Warn | Error =>
|
case Warn | Error =>
|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,11 @@ private final class AnalysisCallback(internalMap: File => Option[File], external
|
||||||
private def add[A,B](map: Map[A,Set[B]], a: A, b: B): Unit =
|
private def add[A,B](map: Map[A,Set[B]], a: A, b: B): Unit =
|
||||||
map.getOrElseUpdate(a, new HashSet[B]) += b
|
map.getOrElseUpdate(a, new HashSet[B]) += b
|
||||||
|
|
||||||
def problem(pos: Position, msg: String, severity: Severity, reported: Boolean): Unit =
|
def problem(category: String, pos: Position, msg: String, severity: Severity, reported: Boolean): Unit =
|
||||||
{
|
{
|
||||||
for(source <- m2o(pos.sourceFile)) {
|
for(source <- m2o(pos.sourceFile)) {
|
||||||
val map = if(reported) reporteds else unreporteds
|
val map = if(reported) reporteds else unreporteds
|
||||||
map.getOrElseUpdate(source, ListBuffer.empty) += Logger.problem(pos, msg, severity)
|
map.getOrElseUpdate(source, ListBuffer.empty) += Logger.problem(category, pos, msg, severity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ private final class CachedCompiler0(args: Array[String], initialLog: WeakLog) ex
|
||||||
} finally {
|
} finally {
|
||||||
compiler.clear()
|
compiler.clear()
|
||||||
}
|
}
|
||||||
dreporter.problems foreach { p => callback.problem(p.position, p.message, p.severity, true) }
|
dreporter.problems foreach { p => callback.problem(p.category, p.position, p.message, p.severity, true) }
|
||||||
}
|
}
|
||||||
dreporter.printSummary()
|
dreporter.printSummary()
|
||||||
if(!noErrors(dreporter)) handleErrors(dreporter, log)
|
if(!noErrors(dreporter)) handleErrors(dreporter, log)
|
||||||
|
|
@ -96,10 +96,14 @@ private final class CachedCompiler0(args: Array[String], initialLog: WeakLog) ex
|
||||||
}
|
}
|
||||||
def processUnreportedWarnings(run: compiler.Run)
|
def processUnreportedWarnings(run: compiler.Run)
|
||||||
{
|
{
|
||||||
implicit def listToBoolean[T](l: List[T]): Boolean = error("source compatibility only, should never be called")
|
// allConditionalWarnings and the ConditionalWarning class are only in 2.10+
|
||||||
implicit def listToInt[T](l: List[T]): Int = error("source compatibility only, should never be called")
|
final class CondWarnCompat(val what: String, val warnings: mutable.ListBuffer[(compiler.Position, String)])
|
||||||
compiler.logUnreportedWarnings(run.deprecationWarnings)
|
implicit def compat(run: AnyRef): Compat = new Compat
|
||||||
compiler.logUnreportedWarnings(run.uncheckedWarnings)
|
final class Compat { def allConditionalWarnings = List[CondWarnCompat]() }
|
||||||
|
|
||||||
|
val warnings = run.allConditionalWarnings
|
||||||
|
if(!warnings.isEmpty)
|
||||||
|
compiler.logUnreportedWarnings(warnings.map(cw => ("" /*cw.what*/, cw.warnings.toList)))
|
||||||
}
|
}
|
||||||
object compiler extends CallbackGlobal(command.settings, dreporter)
|
object compiler extends CallbackGlobal(command.settings, dreporter)
|
||||||
{
|
{
|
||||||
|
|
@ -149,13 +153,12 @@ private final class CachedCompiler0(args: Array[String], initialLog: WeakLog) ex
|
||||||
meth.setAccessible(true)
|
meth.setAccessible(true)
|
||||||
meth.invoke(this)
|
meth.invoke(this)
|
||||||
}
|
}
|
||||||
def logUnreportedWarnings(seq: List[(Position,String)]): Unit = // Scala 2.10.x and later
|
def logUnreportedWarnings(seq: Seq[(String, List[(Position,String)])]): Unit = // Scala 2.10.x and later
|
||||||
{
|
{
|
||||||
for( (pos, msg) <- seq) yield
|
val drep = reporter.asInstanceOf[DelegatingReporter]
|
||||||
callback.problem(reporter.asInstanceOf[DelegatingReporter].convert(pos), msg, Severity.Warn, false)
|
for( (what, warnings) <- seq; (pos, msg) <- warnings) yield
|
||||||
|
callback.problem(what, drep.convert(pos), msg, Severity.Warn, false)
|
||||||
}
|
}
|
||||||
def logUnreportedWarnings(count: Boolean): Unit = () // for source compatibility with Scala 2.8.x
|
|
||||||
def logUnreportedWarnings(count: Int): Unit = () // for source compatibility with Scala 2.9.x
|
|
||||||
|
|
||||||
def set(callback: AnalysisCallback, dreporter: DelegatingReporter)
|
def set(callback: AnalysisCallback, dreporter: DelegatingReporter)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ object AnalysisFormats
|
||||||
wrap[SourceInfo, (Seq[Problem],Seq[Problem])](si => (si.reportedProblems, si.unreportedProblems), { case (a,b) => SourceInfos.makeInfo(a,b)})
|
wrap[SourceInfo, (Seq[Problem],Seq[Problem])](si => (si.reportedProblems, si.unreportedProblems), { case (a,b) => SourceInfos.makeInfo(a,b)})
|
||||||
|
|
||||||
implicit def problemFormat(implicit posF: Format[Position], msgF: Format[String], sevF: Format[Severity]): Format[Problem] =
|
implicit def problemFormat(implicit posF: Format[Position], msgF: Format[String], sevF: Format[Severity]): Format[Problem] =
|
||||||
asProduct3(problem _)( p => (p.position, p.message, p.severity))
|
asProduct4(problem _)( p => (p.category, p.position, p.message, p.severity))
|
||||||
|
|
||||||
implicit def positionFormat: Format[Position] =
|
implicit def positionFormat: Format[Position] =
|
||||||
asProduct7( position _ )( p => (m2o(p.line), p.lineContent, m2o(p.offset), m2o(p.pointer), m2o(p.pointerSpace), m2o(p.sourcePath), m2o(p.sourceFile)))
|
asProduct7( position _ )( p => (m2o(p.line), p.lineContent, m2o(p.offset), m2o(p.pointer), m2o(p.pointerSpace), m2o(p.sourcePath), m2o(p.sourceFile)))
|
||||||
|
|
|
||||||
|
|
@ -26,5 +26,5 @@ public interface AnalysisCallback
|
||||||
public void api(File sourceFile, xsbti.api.SourceAPI source);
|
public void api(File sourceFile, xsbti.api.SourceAPI source);
|
||||||
/** Provides problems discovered during compilation. These may be reported (logged) or unreported.
|
/** Provides problems discovered during compilation. These may be reported (logged) or unreported.
|
||||||
* Unreported problems are usually unreported because reporting was not enabled via a command line switch. */
|
* Unreported problems are usually unreported because reporting was not enabled via a command line switch. */
|
||||||
public void problem(Position pos, String msg, Severity severity, boolean reported);
|
public void problem(String what, Position pos, String msg, Severity severity, boolean reported);
|
||||||
}
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ package xsbti;
|
||||||
|
|
||||||
public interface Problem
|
public interface Problem
|
||||||
{
|
{
|
||||||
|
String category();
|
||||||
Severity severity();
|
Severity severity();
|
||||||
String message();
|
String message();
|
||||||
Position position();
|
Position position();
|
||||||
|
|
|
||||||
|
|
@ -79,9 +79,10 @@ object Logger
|
||||||
val sourceFile = o2m(sourceFile0)
|
val sourceFile = o2m(sourceFile0)
|
||||||
}
|
}
|
||||||
|
|
||||||
def problem(pos: Position, msg: String, sev: Severity): Problem =
|
def problem(cat: String, pos: Position, msg: String, sev: Severity): Problem =
|
||||||
new Problem
|
new Problem
|
||||||
{
|
{
|
||||||
|
val category = cat
|
||||||
val position = pos
|
val position = pos
|
||||||
val message = msg
|
val message = msg
|
||||||
val severity = sev
|
val severity = sev
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue