aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/reporting/UniqueMessagePositions.scala
blob: c5ff8cb6b593587b5ba4be87eedb59d2139057ef (plain) (blame)
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
package dotty.tools
package dotc
package reporting

import scala.collection.mutable
import util.{SourcePosition, SourceFile}
import core.Contexts.Context
import diagnostic.MessageContainer

/**
 * This trait implements `isHidden` so that multiple messages per position
 * are suppressed, unless they are of increasing severity.
 */
trait UniqueMessagePositions extends Reporter {

  private val positions = new mutable.HashMap[(SourceFile, Int), Int]

  /** Logs a position and returns true if it was already logged.
   *  @note  Two positions are considered identical for logging if they have the same point.
   */
  override def isHidden(m: MessageContainer)(implicit ctx: Context): Boolean =
    super.isHidden(m) || {
      m.pos.exists && {
        positions get (ctx.source, m.pos.point) match {
          case Some(level) if level >= m.level => true
          case _ => positions((ctx.source, m.pos.point)) = m.level; false
        }
      }
    }
}