Skip to content

Commit

Permalink
Remove anonymous class made by Property.Opinionated and make NullValu…
Browse files Browse the repository at this point in the history
…e case object
  • Loading branch information
deusaquilus committed Feb 9, 2022
1 parent 27e8d7e commit d5b5ae3
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions quill-engine/src/main/scala/io/getquill/ast/Ast.scala
Expand Up @@ -83,6 +83,7 @@ object BottomTypedTerminal {
* That means that even if the `NamingSchema` is `UpperCase`, the resulting query will select `t_person` as opposed
* to `T_PERSON` or `Person`.
*/

final class Entity(val name: String, val properties: List[PropertyAlias])(theQuat: => Quat.Product)(val renameable: Renameable) extends Query {
private lazy val computedQuat: Quat.Product = theQuat
def quat: Quat.Product = computedQuat
Expand Down Expand Up @@ -411,6 +412,7 @@ sealed trait Renameable extends Opinion[Renameable] {
case _ => otherwise
}
}

object Renameable extends OpinionValues[Renameable] {
case object Fixed extends Renameable with Opinion[Renameable]
case object ByStrategy extends Renameable with Opinion[Renameable]
Expand All @@ -430,25 +432,31 @@ object Renameable extends OpinionValues[Renameable] {
* (whereas `Property(Ident(p), "s_name")` would become `p.S_NAME`). When Property is constructed without `Opinionated`
* being used, the default opinion `ByStrategy` is used.
*/
case class Property(ast: Ast, name: String) extends Ast {
// Technically this should be part of the Property case class but due to the limitations of how
// scala creates companion objects, the apply/unapply wouldn't be able to work correctly.
def renameable: Renameable = Renameable.neutral

final class Property(val ast: Ast, val name: String)(val renameable: Renameable, val visibility: Visibility) extends Ast {
def quat = ast.quat.lookup(name, Messages.strictQuatChecking)
def bestQuat: Quat = ast.quat.lookup(name, false)
def prevName = ast.quat.beforeRenamed(name)

// Properties that are 'Hidden' are used for embedded objects whose path should not be expressed
// during SQL Tokenization.
def visibility: Visibility = Visibility.Visible
private def id = Property.Id(ast, name)

def copy(ast: Ast = this.ast, name: String = this.name): Property =
Property.Opinionated(ast, name, this.renameable, this.visibility)

override def equals(that: Any) =
that match {
case e: Property => this.id == e.id
case _ => false
}

override def hashCode = id.hashCode()
}

object Property {
def apply(ast: Ast, name: String) = new Property(ast, name)
case class Id(ast: Ast, name: String)

// Properties that are 'Hidden' are used for embedded objects whose path should not be expressed
// during SQL Tokenization.
def apply(ast: Ast, name: String) = new Property(ast, name)(Renameable.neutral, Visibility.Visible)
def unapply(p: Property) = Some((p.ast, p.name))

object Opinionated {
Expand All @@ -457,11 +465,8 @@ object Property {
name: String,
renameableNew: Renameable,
visibilityNew: Visibility
) =
new Property(ast, name) {
override def renameable: Renameable = renameableNew
override def visibility: Visibility = visibilityNew
}
) = new Property(ast, name)(renameableNew, visibilityNew)

def unapply(p: Property) =
Some((p.ast, p.name, p.renameable, p.visibility))
}
Expand Down Expand Up @@ -581,7 +586,7 @@ object Constant {
}
}

object NullValue extends Value { def quat = Quat.Null; def bestQuat = quat }
case object NullValue extends Value { def quat = Quat.Null; def bestQuat = quat }

case class Tuple(values: List[Ast]) extends Value {
private lazy val computedQuat = Quat.Tuple(values.map(_.quat))
Expand Down

0 comments on commit d5b5ae3

Please sign in to comment.