All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.scalafmt.ScalafmtRunner.scala Maven / Gradle / Ivy

There is a newer version: 2.0.0-RC1
Show newest version
package org.scalafmt

import scala.meta.Tree
import scala.meta.parsers.Parse

import org.scalafmt.FormatEvent.CompleteFormat
import org.scalafmt.FormatEvent.Enqueue
import org.scalafmt.FormatEvent.Explored
import org.scalafmt.FormatEvent.VisitToken
import org.scalafmt.util.LoggerOps

/**
  * A FormatRunner configures how formatting should behave.
  *
  * @param debug         Should we collect debugging statistics?
  * @param eventCallback Listen to events that happens while formatting
  * @param parser        Are we formatting a scala.meta.{Source,Stat,Case,...}? For
  *                      more details, see members of [[scala.meta.parsers]].
  */
case class ScalafmtRunner(debug: Boolean,
                          eventCallback: FormatEvent => Unit,
                          parser: Parse[_ <: Tree],
                          optimizer: ScalafmtOptimizer,
                          maxStateVisits: Int) {

  def withParser(newParser: Parse[_ <: Tree]): ScalafmtRunner =
    this.copy(parser = newParser)
}

object ScalafmtRunner {
  import LoggerOps._

  /**
    * The default runner formats a compilation unit and listens to no events.
    */
  val default = ScalafmtRunner(debug = false,
                               eventCallback = _ => Unit,
                               parser = scala.meta.parsers.Parse.parseSource,
                               optimizer = ScalafmtOptimizer.default,
                               maxStateVisits = 1000000)

  /**
    * Same as [[default]], except formats the input as a statement/expression.
    *
    * An example of how to format something other than a compilation unit.
    */
  val statement = default.withParser(scala.meta.parsers.Parse.parseStat)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy