Is there an equivalent to SuppressWarnings in Scala?

前端 未结 4 1104
感动是毒
感动是毒 2020-12-05 12:30

I was wondering if scala had an equivalent to java\'s @SuppressWarnings that can be applied to a function or whatever to ignore any deprecation warnings[1] that function emi

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 13:30

    Here is how to suppress all warnings in sbt:

    import sbt._
    import Keys._
    import KeyRanks.DTask
    import xsbti.{Reporter, Problem, Position, Severity}
    
    private lazy val compilerReporter = TaskKey[xsbti.Reporter](
      "compilerReporter",
      "Experimental hook to listen (or send) compilation failure messages.",
      DTask
    )
    
    val ignoreWarnings = Seq(
      compilerReporter in (Compile, compile) :=
        new xsbti.Reporter {
          private val buffer = collection.mutable.ArrayBuffer.empty[Problem]
          def reset(): Unit = buffer.clear()
          def hasErrors: Boolean = buffer.exists(_.severity == Severity.Error)
          def hasWarnings: Boolean = buffer.exists(_.severity == Severity.Warn)
          def printSummary(): Unit = {
    
            print("\033c")
            if (problems.nonEmpty) {
              problems.foreach{ p =>
                println("=====================================================")
                println(p.position)
                println(p.message)
                println()
                println()
              }
            }
          }
          def problems: Array[Problem] = buffer.toArray
    
          def log(problem: Problem): Unit = {
            if (problem.severity == Severity.Error) {
              buffer.append(problem)
            }
          }
          def log(pos: Position, msg: String, sev: Severity): Unit = {
            log(new Problem {
              def category: String = "foo"
              def severity: Severity = sev
              def message: String = msg
              def position: Position = pos
            })
          }
          def comment(pos: xsbti.Position, msg: String): Unit = ()
        }
    )
    

提交回复
热议问题