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

scalafix.v0.Document.scala Maven / Gradle / Ivy

package scalafix.v0

import scala.compat.Platform.EOL
import scala.math.Ordering
import scala.meta.inputs._

final case class Document(
    input: Input,
    language: String,
    names: List[ResolvedName],
    messages: List[Message],
    symbols: List[ResolvedSymbol],
    synthetics: List[Synthetic]
) {

  def syntax: String = {
    val lines = scala.collection.mutable.ListBuffer[String]()
    def appendSection(name: String, section: Seq[String]): Unit = {
      if (section.nonEmpty) {
        lines += (name + ":")
        lines ++= section
        lines += ""
      }
    }
    appendSection("Language", List(language))
    appendSection("Names", names.sorted.map(_.syntax))
    appendSection("Messages", messages.sorted.map(_.syntax))
    appendSection("Symbols", symbols.sorted.map(_.syntax))
    appendSection("Synthetics", synthetics.sorted.map(_.syntax))
    lines.mkString(EOL)
  }

  private implicit def positionOrder: Ordering[Position] =
    Ordering.by(p => (p.start, p.end))
  private implicit def resolvedNameOrder: Ordering[ResolvedName] =
    Ordering.by(n => (n.position, n.syntax))
  private implicit def messageOrder: Ordering[Message] =
    Ordering.by(m => (m.position, m.syntax))
  private implicit def resolvedSymbolOrder: Ordering[ResolvedSymbol] =
    Ordering.by(_.syntax)
  private implicit def synthOrder: Ordering[Synthetic] =
    Ordering.by(s => (s.position, s.syntax))

  def structure: String = ???

  override def toString: String = syntax
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy