alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (AbstractReporter.scala)

This example Scala source code file (AbstractReporter.scala) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Scala source code examples by using tags.

All credit for the original source code belongs to scala-lang.org; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Scala tags/keywords

abstractreporter, boolean, collection, compiler, error, info, list, nsc, position, reflection, severity, string, unit, utilities, warning

The AbstractReporter.scala Scala example source code

/* NSC -- new Scala compiler
 * Copyright 2002-2013 LAMP/EPFL
 * @author Martin Odersky
 */

package scala.tools.nsc
package reporters

import scala.collection.mutable
import scala.tools.nsc.Settings
import scala.reflect.internal.util.Position

/**
 * This reporter implements filtering.
 */
abstract class AbstractReporter extends Reporter {
  val settings: Settings
  def display(pos: Position, msg: String, severity: Severity): Unit
  def displayPrompt(): Unit

  private val positions = mutable.Map[Position, Severity]() withDefaultValue INFO
  private val messages  = mutable.Map[Position, List[String]]() withDefaultValue Nil

  override def reset() {
    super.reset()
    positions.clear()
    messages.clear()
  }

  private def isVerbose   = settings.verbose.value
  private def noWarnings  = settings.nowarnings.value
  private def isPromptSet = settings.prompt.value

  protected def info0(pos: Position, msg: String, severity: Severity, force: Boolean) {
    if (severity == INFO) {
      if (isVerbose || force) {
        severity.count += 1
        display(pos, msg, severity)
      }
    }
    else {
      val hidden = testAndLog(pos, severity, msg)
      if (severity == WARNING && noWarnings) ()
      else {
        if (!hidden || isPromptSet) {
          severity.count += 1
          display(pos, msg, severity)
        }
        else if (settings.debug) {
          severity.count += 1
          display(pos, "[ suppressed ] " + msg, severity)
        }

        if (isPromptSet)
          displayPrompt()
      }
    }
  }

  /** 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.
   */
  private def testAndLog(pos: Position, severity: Severity, msg: String): Boolean =
    pos != null && pos.isDefined && {
      val fpos = pos.focus
      val suppress = positions(fpos) match {
        case ERROR                         => true  // already error at position
        case highest if highest > severity => true  // already message higher than present severity
        case `severity`                    => messages(fpos) contains msg // already issued this exact message
        case _                             => false // good to go
      }

      suppress || {
        positions(fpos) = severity
        messages(fpos) ::= msg
        false
      }
    }
}

Other Scala source code examples

Here is a short list of links related to this Scala AbstractReporter.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.