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

scala.meta.contrib.equality.Syntactically.scala Maven / Gradle / Ivy

There is a newer version: 4.11.2
Show newest version
package scala.meta.contrib.equality

import scala.meta.Tree
import scala.meta.XtensionSyntax

import scala.language.implicitConversions

/**
 * Represents syntactic equality between trees Two trees are syntactically equal if their .syntax is
 * equal.
 */
class Syntactically[+A <: Tree](val tree: A) extends TreeEquality[A] {
  private lazy val syntax = tree.syntax
  override def hashCode(): Int = syntax.hashCode
  override def equals(obj: scala.Any): Boolean = obj match {
    case e2: Syntactically[_] => syntax == e2.syntax
    case _ => false
  }
}

object Syntactically {
  def apply[A <: Tree](tree: A): Syntactically[A] = new Syntactically(tree)

  implicit def SyntacticEq[A <: Tree]: Equal[Syntactically[A]] = new Equal[Syntactically[A]] {
    override def isEqual(a: Syntactically[A], b: Syntactically[A]): Boolean = a.equals(b)
  }
  implicit def toSyntactic[A <: Tree](e: A): Syntactically[A] = apply(e)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy