Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove anonymous class made by Property.Opinionated and make NullValue case object #2426

Merged
merged 1 commit into from Feb 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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