aboutsummaryrefslogblamecommitdiff
path: root/src/dotty/tools/dotc/reporting/UniqueMessagePositions.scala
blob: 704317f23db2314056aa581e36cf50a910b98727 (plain) (tree)
1
2
3
4
5
6
7
8




                               

                                    
                                            













                                                                                            
                                                                                                  











                                                                      
package dotty.tools
package dotc
package reporting

import scala.collection.mutable
import util.Positions.SourcePosition
import util.SourceFile
import Reporter.Severity.{Value => Severity}
import core.Contexts.Context

/**
 * This trait implements `isHidden` do 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), Severity]

  /** 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(severity: Severity, pos: SourcePosition)(implicit ctx: Context): Boolean =
    pos.exists && {
      positions get (ctx.source, pos.point) match {
        case Some(level) if level >= severity => true
        case _ => positions((ctx.source, pos.point)) = severity; false
      }
    }

  override def reset(): Unit = {
    super.reset()
    positions.clear()
  }
}