From 73693454088fe82f4a668d99a106afb3a1812e09 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 18:18:30 +0400 Subject: [PATCH 01/21] Add Scalafix --- .scalafix.conf | 34 +++ build.sbt | 28 +- project/plugins.sbt | 1 + .../io/getquill/CassandraAlpakkaContext.scala | 2 +- .../io/getquill/CassandraMonixContext.scala | 3 +- .../io/getquill/CassandraStreamContext.scala | 4 +- .../io/getquill/CassandraZioContext.scala | 4 +- .../io/getquill/CassandraZioSession.scala | 6 +- .../io/getquill/cassandrazio/Quill.scala | 6 +- .../io/getquill/CassandraAsyncContext.scala | 3 +- .../io/getquill/CassandraContextConfig.scala | 2 +- .../io/getquill/CassandraMirrorContext.scala | 1 - .../scala/io/getquill/context/Caches.scala | 1 - .../getquill/context/CassandraSession.scala | 2 +- .../context/cassandra/CassandraContext.scala | 2 +- .../cassandra/CassandraSessionContext.scala | 2 +- .../io/getquill/context/cassandra/Ops.scala | 2 + .../cassandra/cluster/SessionBuilder.scala | 1 - .../cassandra/encoding/CassandraMapper.scala | 2 +- .../cassandra/encoding/CassandraTypes.scala | 2 +- .../encoding/CollectionEncoders.scala | 2 - .../context/cassandra/encoding/Decoders.scala | 12 +- .../context/cassandra/encoding/Encoders.scala | 4 +- .../cassandra/encoding/UdtEncodingMacro.scala | 2 +- .../context/cassandra/encoding/UdtOps.scala | 13 +- .../cassandra/util/FutureConversions.scala | 2 +- .../jdbc/ComposeableTraitsJdbcCodegen.scala | 7 +- .../getquill/codegen/jdbc/DatabaseTypes.scala | 16 +- .../jdbc/gen/DefaultJdbcSchemaReader.scala | 4 +- .../gen/JdbcCodeGeneratorComponents.scala | 2 +- .../codegen/jdbc/gen/JdbcGenerator.scala | 2 +- .../codegen/jdbc/model/DefaultJdbcTyper.scala | 2 +- .../codegen/jdbc/model/JdbcTypeInfo.scala | 2 +- .../codegen/gen/AbstractCodeEmitter.scala | 8 +- .../codegen/gen/CodeGeneratorComponents.scala | 2 +- .../io/getquill/codegen/gen/Generator.scala | 28 +- .../codegen/gen/StereotypePackager.scala | 2 +- .../codegen/model/CustomNameParser.scala | 4 +- .../io/getquill/codegen/model/Fuser.scala | 2 +- .../io/getquill/codegen/model/Naming.scala | 12 +- .../codegen/model/PackagingStrategy.scala | 18 +- .../getquill/codegen/model/SchemaModel.scala | 10 +- .../codegen/model/StereotypedModel.scala | 6 +- .../getquill/codegen/util/MapExtensions.scala | 4 +- .../getquill/codegen/util/ScalaLangUtil.scala | 4 +- .../getquill/codegen/util/StringSeqUtil.scala | 2 +- .../io/getquill/codegen/util/StringUtil.scala | 14 +- .../io/getquill/AsyncMirrorContext.scala | 14 +- .../main/scala/io/getquill/FutureTests.scala | 4 - .../scala/io/getquill/MirrorContext.scala | 20 +- .../io/getquill/context/ActionMacro.scala | 2 +- .../scala/io/getquill/context/Context.scala | 4 +- .../io/getquill/context/ContextMacro.scala | 2 +- .../scala/io/getquill/context/Expand.scala | 13 +- .../io/getquill/context/ProbeStatement.scala | 2 +- .../context/mirror/MirrorDecoders.scala | 6 +- .../context/mirror/MirrorEncoders.scala | 4 +- .../io/getquill/context/mirror/Row.scala | 10 +- .../io/getquill/dsl/DynamicQueryDSL.scala | 18 +- .../scala/io/getquill/dsl/MetaDslMacro.scala | 2 +- .../main/scala/io/getquill/dsl/QueryDsl.scala | 1 - .../io/getquill/dsl/ValueComputation.scala | 3 +- .../scala/io/getquill/log/ContextLog.scala | 2 +- .../scala/io/getquill/monad/IOMonad.scala | 2 +- .../getquill/monad/ScalaFutureIOMonad.scala | 2 +- .../scala/io/getquill/quat/QuatMaking.scala | 6 +- .../io/getquill/quotation/IsDynamic.scala | 2 +- .../quotation/MacroUtilUniverse.scala | 12 +- .../scala/io/getquill/quotation/Parsing.scala | 28 +- .../getquill/quotation/QuatUnliftable.scala | 8 +- .../io/getquill/quotation/Quotation.scala | 10 +- .../io/getquill/quotation/ReifyLiftings.scala | 6 +- .../quotation/TranspileConfigSummoning.scala | 8 +- .../getquill/util/EnableReflectiveCalls.scala | 5 +- .../scala/io/getquill/util/NullCheck.scala | 2 +- .../io/getquill/util/OrderedGroupByExt.scala | 2 +- .../scala/io/getquill/util/QueryLogger.scala | 2 +- .../getquill/doobie/DoobieContextBase.scala | 2 +- .../main/scala/io/getquill/AstPrinter.scala | 12 +- .../main/scala/io/getquill/H2Dialect.scala | 2 +- .../main/scala/io/getquill/IdiomContext.scala | 10 +- .../scala/io/getquill/MappedEncoding.scala | 2 +- .../main/scala/io/getquill/MirrorIdiom.scala | 4 +- .../src/main/scala/io/getquill/Model.scala | 1 - .../main/scala/io/getquill/MySQLDialect.scala | 6 +- .../scala/io/getquill/NamingStrategy.scala | 32 +-- .../scala/io/getquill/OracleDialect.scala | 6 +- .../src/main/scala/io/getquill/OrdModel.scala | 2 +- .../scala/io/getquill/PostgresDialect.scala | 31 +-- .../main/scala/io/getquill/ReturnAction.scala | 2 +- .../scala/io/getquill/SQLServerDialect.scala | 6 +- .../scala/io/getquill/SqliteDialect.scala | 4 +- .../src/main/scala/io/getquill/ast/Ast.scala | 258 +++++++++--------- .../main/scala/io/getquill/ast/AstOps.scala | 16 +- .../scala/io/getquill/ast/CollectAst.scala | 6 +- .../io/getquill/ast/StatefulTransformer.scala | 4 +- .../ast/StatefulTransformerWithStack.scala | 8 +- .../scala/io/getquill/ast/Transform.scala | 2 +- .../io/getquill/context/ProtoContext.scala | 2 +- .../io/getquill/context/RowContext.scala | 4 +- .../getquill/context/cassandra/CqlIdiom.scala | 6 +- .../context/cassandra/CqlNormalize.scala | 2 +- .../getquill/context/cassandra/CqlQuery.scala | 10 +- .../ExpandMappedInfixCassandra.scala | 2 +- .../context/mirror/MirrorSession.scala | 4 +- .../scala/io/getquill/idiom/Statement.scala | 22 +- .../idiom/StatementInterpolator.scala | 8 +- .../io/getquill/norm/AdHocReduction.scala | 2 +- .../scala/io/getquill/norm/ApplyMap.scala | 2 +- .../io/getquill/norm/BetaReduction.scala | 2 +- .../scala/io/getquill/norm/DisablePhase.scala | 6 +- .../io/getquill/norm/ExpandReturning.scala | 2 +- .../norm/FlattenOptionOperation.scala | 11 +- .../scala/io/getquill/norm/Normalize.scala | 3 +- .../scala/io/getquill/norm/OrderTerms.scala | 2 +- .../io/getquill/norm/RenameProperties.scala | 4 +- .../io/getquill/norm/RepropagateQuats.scala | 6 +- .../io/getquill/norm/SheathLeafClauses.scala | 16 +- .../io/getquill/norm/StabilizeLifts.scala | 10 +- .../io/getquill/norm/SymbolicReduction.scala | 2 +- .../norm/capture/AvoidAliasConflict.scala | 10 +- .../io/getquill/norm/capture/Dealias.scala | 6 +- .../capture/DemarcateExternalAliases.scala | 6 +- .../norm/capture/TemporaryIdent.scala | 2 +- .../io/getquill/quat/BooQuatSerializer.scala | 2 +- .../scala/io/getquill/quat/FindBranches.scala | 40 +-- .../main/scala/io/getquill/quat/Quat.scala | 44 +-- .../main/scala/io/getquill/quat/QuatOps.scala | 6 +- .../io/getquill/quotation/FreeVariables.scala | 4 +- .../quotation/NonQuotedException.scala | 2 +- .../io/getquill/quotation/QuatException.scala | 4 +- .../main/scala/io/getquill/sql/Common.scala | 2 +- .../main/scala/io/getquill/sql/SqlQuery.scala | 46 ++-- .../sql/idiom/BooleanLiteralSupport.scala | 2 +- .../io/getquill/sql/idiom/ConcatSupport.scala | 2 +- .../io/getquill/sql/idiom/SqlIdiom.scala | 44 +-- .../getquill/sql/idiom/VerifySqlQuery.scala | 10 +- .../io/getquill/sql/norm/ExpandJoin.scala | 4 +- .../sql/norm/ExpandNestedQueries.scala | 6 +- .../sql/norm/FlattenGroupByAggregation.scala | 4 +- .../sql/norm/HideTopLevelFilterAlias.scala | 4 +- .../sql/norm/NormalizeActionAliases.scala | 3 +- .../getquill/sql/norm/RemoveExtraAlias.scala | 2 +- .../sql/norm/RemoveUnusedSelects.scala | 9 +- .../sql/norm/SelectPropertyProtractor.scala | 16 +- .../io/getquill/sql/norm/SqlNormalize.scala | 3 +- .../sql/norm/StatelessQueryTransformer.scala | 4 +- .../getquill/sql/norm/VendorizeBooleans.scala | 6 +- .../getquill/sql/norm/nested/Elements.scala | 2 +- .../norm/nested/FindUnexpressedInfixes.scala | 6 +- .../main/scala/io/getquill/util/Cache.scala | 2 +- .../io/getquill/util/ContextLogger.scala | 4 +- .../scala/io/getquill/util/IndentUtil.scala | 2 +- .../scala/io/getquill/util/Interpolator.scala | 14 +- .../scala/io/getquill/util/LoadConfig.scala | 3 +- .../scala/io/getquill/util/Messages.scala | 58 ++-- .../main/scala/io/getquill/util/Show.scala | 4 +- .../main/scala/io/getquill/util/Using.scala | 2 +- .../getquill/MysqlJAsyncContextConfig.scala | 2 +- .../io/getquill/PostgresJAsyncContext.scala | 1 - .../PostgresJAsyncContextConfig.scala | 2 +- .../context/jasync/ArrayDecoders.scala | 1 - .../qzio/PostgresJAsyncContextConfig.scala | 2 +- .../context/qzio/jasync/ArrayDecoders.scala | 1 - .../io/getquill/context/qzio/Decoders.scala | 5 +- .../io/getquill/context/qzio/Encoders.scala | 3 +- .../context/qzio/UUIDObjectEncoding.scala | 2 +- .../context/qzio/UUIDStringEncoding.scala | 2 +- .../io/getquill/context/qzio/ZIOMonad.scala | 2 +- .../context/qzio/ZioJAsyncContext.scala | 10 +- .../io/getquill/context/jasync/Decoders.scala | 4 +- .../io/getquill/context/jasync/Encoders.scala | 2 +- .../context/jasync/JAsyncContext.scala | 18 +- .../TransactionalExecutionContext.scala | 2 +- .../context/jasync/UUIDObjectEncoding.scala | 2 +- .../context/jasync/UUIDStringEncoding.scala | 2 +- .../context/monix/MonixJdbcContext.scala | 6 +- .../context/json/PostgresJsonExtensions.scala | 4 +- .../qzio/ZioJdbcUnderlyingContext.scala | 3 +- .../scala/io/getquill/JdbcContextConfig.scala | 6 +- .../getquill/context/jdbc/ArrayDecoders.scala | 3 +- .../getquill/context/jdbc/ArrayEncoders.scala | 1 - .../context/jdbc/BooleanIntEncoding.scala | 2 +- .../io/getquill/context/jdbc/Decoders.scala | 39 ++- .../io/getquill/context/jdbc/Encoders.scala | 7 +- .../getquill/context/jdbc/JdbcContext.scala | 8 +- .../context/jdbc/JdbcContextTypes.scala | 8 +- .../context/jdbc/JdbcContextVerbExecute.scala | 3 +- .../context/jdbc/ResultSetExtractor.scala | 2 +- .../context/jdbc/UUIDObjectEncoding.scala | 2 +- .../context/jdbc/UUIDStringEncoding.scala | 2 +- .../getquill/context/monix/MonixContext.scala | 1 - .../io/getquill/OrientDBContextConfig.scala | 2 +- .../context/orientdb/OrientDBIdiom.scala | 6 +- .../orientdb/OrientDBSessionContext.scala | 5 +- .../context/orientdb/dsl/OrientDBDsl.scala | 3 +- .../encoding/CollectionDecoders.scala | 6 +- .../context/orientdb/encoding/Decoders.scala | 26 +- .../context/orientdb/encoding/Encoders.scala | 8 +- .../scala/io/getquill/QuillSparkContext.scala | 11 +- .../io/getquill/context/spark/Binding.scala | 4 +- .../io/getquill/context/spark/Encoders.scala | 2 +- .../getquill/context/spark/SparkDialect.scala | 5 +- .../spark/norm/QuestionMarkEscaper.scala | 6 +- .../io/getquill/context/sql/dsl/SqlDsl.scala | 5 +- .../scala/io/getquill/util/ThrowableOps.scala | 2 +- 206 files changed, 842 insertions(+), 839 deletions(-) create mode 100644 .scalafix.conf diff --git a/.scalafix.conf b/.scalafix.conf new file mode 100644 index 0000000000..982438fdc7 --- /dev/null +++ b/.scalafix.conf @@ -0,0 +1,34 @@ +rules = [ + Disable + DisableSyntax + ExplicitResultTypes + LeakingImplicitClassVal + NoAutoTupling + NoValInForComprehension + ProcedureSyntax + RemoveUnused + MissingFinal + EmptyCollectionsUnified +] + +Disable { + ifSynthetic = [ + "scala/Option.option2Iterable" + "scala/Predef.any2stringadd" + ] +} + +DisableSyntax.regex = [] + +RemoveUnused { + imports = true + privates = true + locals = true + patternvars = false + params = true +} + +DisableSyntax.noReturns = true +DisableSyntax.noXml = true +DisableSyntax.noFinalize = true +DisableSyntax.noValPatterns = true \ No newline at end of file diff --git a/build.sbt b/build.sbt index ef922dabac..93507196e0 100644 --- a/build.sbt +++ b/build.sbt @@ -5,6 +5,10 @@ import scala.collection.immutable.ListSet Global / onChangedBuildSource := ReloadOnSourceChanges +val scala_v_12 = "2.12.18" +val scala_v_13 = "2.13.12" +val scala_v_30 = "3.3.1" + inThisBuild( List( organization := "io.getquill", @@ -17,9 +21,19 @@ inThisBuild( scmInfo := Some( ScmInfo(url("https://github.com/zio/zio-quill"), "git:git@github.com:zio/zio-quill.git") ), - scalafmtCheck := true, - scalafmtSbtCheck := true, - scalafmtOnCompile := !insideCI.value + scalaVersion := scala_v_13, + crossScalaVersions := Seq(scala_v_12, scala_v_13, scala_v_30), + scalafmtCheck := true, + scalafmtSbtCheck := true, + scalafmtOnCompile := !insideCI.value, + semanticdbEnabled := scalaVersion.value.startsWith("2.13"), + semanticdbOptions += "-P:semanticdb:synthetics:on", + semanticdbVersion := scalafixSemanticdb.revision, // use Scalafix compatible version + scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value), + scalafixDependencies ++= List( + "com.github.vovapolu" %% "scaluzzi" % "0.1.23", + "io.github.ghostbuster91.scalafix-unified" %% "unified" % "0.0.9" + ) ) ) @@ -618,10 +632,6 @@ def excludePaths(paths: Seq[String]) = { }) } -val scala_v_12 = "2.12.18" -val scala_v_13 = "2.13.12" -val scala_v_30 = "3.3.1" - val scalaCollectionCompatVersion = "2.11.0" lazy val loggingSettings = Seq( @@ -632,8 +642,6 @@ lazy val loggingSettings = Seq( lazy val basicSettings = excludeFilterSettings ++ Seq( Test / testOptions += Tests.Argument("-oI"), - scalaVersion := scala_v_13, - crossScalaVersions := Seq(scala_v_12, scala_v_13, scala_v_30), libraryDependencies ++= Seq( "org.scalatest" %% "scalatest" % "3.2.17" % Test, "org.scala-lang.modules" %% "scala-collection-compat" % scalaCollectionCompatVersion, @@ -666,7 +674,7 @@ lazy val basicSettings = excludeFilterSettings ++ Seq( scalacOptions ++= { CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, 13)) => - Seq("-Ypatmat-exhaust-depth", "40") + Seq("-Ypatmat-exhaust-depth", "40", "-Ywarn-unused") case Some((2, 12)) => Seq( // "-Xfatal-warnings", diff --git a/project/plugins.sbt b/project/plugins.sbt index 0f8118549a..351f398f7d 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -10,3 +10,4 @@ addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.3") addSbtPlugin("com.etsy" % "sbt-compile-quick-plugin" % "1.4.0") addSbtPlugin("dev.zio" % "zio-sbt-website" % "0.3.10") addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1") diff --git a/quill-cassandra-alpakka/src/main/scala/io/getquill/CassandraAlpakkaContext.scala b/quill-cassandra-alpakka/src/main/scala/io/getquill/CassandraAlpakkaContext.scala index ceb2c9af64..2ee875d0f0 100644 --- a/quill-cassandra-alpakka/src/main/scala/io/getquill/CassandraAlpakkaContext.scala +++ b/quill-cassandra-alpakka/src/main/scala/io/getquill/CassandraAlpakkaContext.scala @@ -100,7 +100,7 @@ class CassandraAlpakkaContext[+N <: NamingStrategy]( } .map(_ => Done) - override def close() = { + override def close(): Unit = { alpakkaSession.close(scala.concurrent.ExecutionContext.Implicits.global) () } diff --git a/quill-cassandra-monix/src/main/scala/io/getquill/CassandraMonixContext.scala b/quill-cassandra-monix/src/main/scala/io/getquill/CassandraMonixContext.scala index a45fd7556f..fc19bf683a 100644 --- a/quill-cassandra-monix/src/main/scala/io/getquill/CassandraMonixContext.scala +++ b/quill-cassandra-monix/src/main/scala/io/getquill/CassandraMonixContext.scala @@ -7,7 +7,6 @@ import io.getquill.context.ExecutionInfo import io.getquill.context.cassandra.CqlIdiom import io.getquill.context.monix.MonixContext import io.getquill.util.{ContextLogger, LoadConfig} -import io.getquill.context.cassandra.util.FutureConversions._ import monix.eval.Task import monix.execution.Scheduler import monix.reactive.Observable @@ -64,7 +63,7 @@ class CassandraMonixContext[+N <: NamingStrategy]( dc: Runner ): Task[List[T]] = streamQuery[T](None, cql, prepare, extractor)(info, dc) - .foldLeftL(List[T]()) { case (l, r) => r +: l } + .foldLeftL(List.empty[T]) { case (l, r) => r +: l } .map(_.reverse) def executeQuerySingle[T]( diff --git a/quill-cassandra-monix/src/main/scala/io/getquill/CassandraStreamContext.scala b/quill-cassandra-monix/src/main/scala/io/getquill/CassandraStreamContext.scala index 5ff7e77f4c..6ee0a90690 100644 --- a/quill-cassandra-monix/src/main/scala/io/getquill/CassandraStreamContext.scala +++ b/quill-cassandra-monix/src/main/scala/io/getquill/CassandraStreamContext.scala @@ -1,14 +1,12 @@ package io.getquill import com.datastax.oss.driver.api.core.CqlSession -import com.datastax.oss.driver.api.core.cql.{AsyncResultSet, ResultSet, Row} +import com.datastax.oss.driver.api.core.cql.{AsyncResultSet, Row} import com.typesafe.config.Config import io.getquill.context.ExecutionInfo -import io.getquill.context.cassandra.util.FutureConversions._ import io.getquill.util.{ContextLogger, LoadConfig} import monix.eval.Task import monix.execution.Scheduler -import monix.execution.Scheduler.Implicits import monix.reactive.Observable import scala.compat.java8.FutureConverters._ diff --git a/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala b/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala index 9118cbfa1d..bc73e6240f 100644 --- a/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala +++ b/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala @@ -45,7 +45,7 @@ class CassandraZioContext[+N <: NamingStrategy](val naming: N) with Context[CqlIdiom, N] with Probing { - private val logger = ContextLogger(classOf[CassandraZioContext[_]]) + ContextLogger(classOf[CassandraZioContext[_]]) override type Error = Throwable override type Environment = CassandraZioSession @@ -94,7 +94,7 @@ class CassandraZioContext[+N <: NamingStrategy](val naming: N) cql: String, prepare: Prepare = identityPrepare, extractor: Extractor[T] = identityExtractor - )(info: ExecutionInfo, dc: Runner) = { + )(info: ExecutionInfo, dc: Runner): ZStream[CassandraZioSession,Throwable,T] = { val stream = for { csession <- ZStream.service[CassandraZioSession] diff --git a/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioSession.scala b/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioSession.scala index 7c49a60ab4..4e92668160 100644 --- a/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioSession.scala +++ b/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioSession.scala @@ -6,7 +6,7 @@ import io.getquill.context.{AsyncFutureCache, CassandraSession, SyncCache} import io.getquill.util.LoadConfig import zio.{ZIO, ZLayer} -case class CassandraZioSession( +final case class CassandraZioSession( override val session: CqlSession, override val preparedStatementCacheSize: Long ) extends CassandraSession @@ -29,7 +29,7 @@ object CassandraZioSession { def fromContextConfig(config: CassandraContextConfig): ZLayer[Any, Throwable, CassandraZioSession] = ZLayer.succeed(config) >>> live - def fromConfig(config: Config) = fromContextConfig(CassandraContextConfig(config)) + def fromConfig(config: Config): ZLayer[Any,Throwable,CassandraZioSession] = fromContextConfig(CassandraContextConfig(config)) // Call the by-name constructor for the construction to fail inside of the effect if it fails - def fromPrefix(configPrefix: String) = fromContextConfig(CassandraContextConfig(LoadConfig(configPrefix))) + def fromPrefix(configPrefix: String): ZLayer[Any,Throwable,CassandraZioSession] = fromContextConfig(CassandraContextConfig(LoadConfig(configPrefix))) } diff --git a/quill-cassandra-zio/src/main/scala/io/getquill/cassandrazio/Quill.scala b/quill-cassandra-zio/src/main/scala/io/getquill/cassandrazio/Quill.scala index da44ff31cb..6f8306f0c1 100644 --- a/quill-cassandra-zio/src/main/scala/io/getquill/cassandrazio/Quill.scala +++ b/quill-cassandra-zio/src/main/scala/io/getquill/cassandrazio/Quill.scala @@ -19,13 +19,13 @@ object Quill { ZLayer.fromFunction((session: CassandraZioSession) => new Cassandra[N](naming, session)) } - case class Cassandra[+N <: NamingStrategy](val naming: N, session: CassandraZioSession) + final case class Cassandra[+N <: NamingStrategy](val naming: N, session: CassandraZioSession) extends CassandraRowContext[N] with ZioContext[CqlIdiom, N] with Context[CqlIdiom, N] with Probing { - private val logger = ContextLogger(classOf[Quill.Cassandra[_]]) + ContextLogger(classOf[Quill.Cassandra[_]]) override type Error = Throwable override type Environment = Any @@ -79,6 +79,6 @@ object Quill { private def onSessionStream[T](zio: ZStream[CassandraZioSession, Throwable, T]) = zio.provideEnvironment(ZEnvironment(session)) - override def close() = session.close() + override def close(): Unit = session.close() } } diff --git a/quill-cassandra/src/main/scala/io/getquill/CassandraAsyncContext.scala b/quill-cassandra/src/main/scala/io/getquill/CassandraAsyncContext.scala index 2df23b8625..c531d9e6b8 100644 --- a/quill-cassandra/src/main/scala/io/getquill/CassandraAsyncContext.scala +++ b/quill-cassandra/src/main/scala/io/getquill/CassandraAsyncContext.scala @@ -1,9 +1,8 @@ package io.getquill -import com.datastax.oss.driver.api.core.{CqlSession, CqlSessionBuilder} +import com.datastax.oss.driver.api.core.CqlSession import com.typesafe.config.Config import io.getquill.context.ExecutionInfo -import io.getquill.context.cassandra.util.FutureConversions._ import io.getquill.monad.ScalaFutureIOMonad import io.getquill.util.{ContextLogger, LoadConfig} diff --git a/quill-cassandra/src/main/scala/io/getquill/CassandraContextConfig.scala b/quill-cassandra/src/main/scala/io/getquill/CassandraContextConfig.scala index d77250e919..0034c13253 100644 --- a/quill-cassandra/src/main/scala/io/getquill/CassandraContextConfig.scala +++ b/quill-cassandra/src/main/scala/io/getquill/CassandraContextConfig.scala @@ -4,7 +4,7 @@ import com.datastax.oss.driver.api.core.{CqlSession, CqlSessionBuilder} import com.typesafe.config.Config import io.getquill.context.cassandra.cluster.SessionBuilder -case class CassandraContextConfig(config: Config) { +final case class CassandraContextConfig(config: Config) { def preparedStatementCacheSize: Long = if (config.hasPath("preparedStatementCacheSize")) config.getLong("preparedStatementCacheSize") diff --git a/quill-cassandra/src/main/scala/io/getquill/CassandraMirrorContext.scala b/quill-cassandra/src/main/scala/io/getquill/CassandraMirrorContext.scala index aae195a6ca..88fb07bb18 100644 --- a/quill-cassandra/src/main/scala/io/getquill/CassandraMirrorContext.scala +++ b/quill-cassandra/src/main/scala/io/getquill/CassandraMirrorContext.scala @@ -1,6 +1,5 @@ package io.getquill -import java.util.Date import io.getquill.context.cassandra.encoding.{CassandraMapper, CassandraType} import io.getquill.context.cassandra.{CassandraContext, CqlIdiom} diff --git a/quill-cassandra/src/main/scala/io/getquill/context/Caches.scala b/quill-cassandra/src/main/scala/io/getquill/context/Caches.scala index 73e237ed49..43e1d0be3f 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/Caches.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/Caches.scala @@ -2,7 +2,6 @@ package io.getquill.context import com.datastax.oss.driver.api.core.cql.{BoundStatement, PreparedStatement} import io.getquill.context.cassandra.PrepareStatementCache -import io.getquill.context.cassandra.util.FutureConversions._ import java.util.concurrent.CompletionStage import scala.concurrent.{ExecutionContext, Future} diff --git a/quill-cassandra/src/main/scala/io/getquill/context/CassandraSession.scala b/quill-cassandra/src/main/scala/io/getquill/context/CassandraSession.scala index 2bd4e9f902..db23781f9f 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/CassandraSession.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/CassandraSession.scala @@ -19,7 +19,7 @@ trait CassandraSession extends UdtValueLookup { .groupBy(_.getName.toString) override def udtValueOf(udtName: String, keyspace: Option[String] = None): UdtValue = - udtMetadata.getOrElse(udtName.toLowerCase, Nil) match { + udtMetadata.getOrElse(udtName.toLowerCase, List.empty) match { case udt :: Nil => udt.newValue() case Nil => fail(s"Could not find UDT `$udtName` in any keyspace") diff --git a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/CassandraContext.scala b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/CassandraContext.scala index 9942aecd70..b12237281b 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/CassandraContext.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/CassandraContext.scala @@ -1,6 +1,6 @@ package io.getquill.context.cassandra -import java.util.{Date, UUID} +import java.util.UUID import io.getquill.NamingStrategy import io.getquill.context.Context import io.getquill.context.cassandra.encoding.{CassandraMapper, Encodings} diff --git a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/CassandraSessionContext.scala b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/CassandraSessionContext.scala index 5211f5c21a..afbbd7d119 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/CassandraSessionContext.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/CassandraSessionContext.scala @@ -2,7 +2,7 @@ package io.getquill.context.cassandra import com.datastax.oss.driver.api.core.cql.{BoundStatement, Row} import io.getquill.NamingStrategy -import io.getquill.context.{CassandraSession, Context, ContextVerbPrepareLambda, ExecutionInfo, UdtValueLookup} +import io.getquill.context.{CassandraSession, Context, ExecutionInfo, UdtValueLookup} import io.getquill.context.cassandra.encoding.{CassandraTypes, Decoders, Encoders, UdtEncoding} import io.getquill.util.ContextLogger import io.getquill.util.Messages.fail diff --git a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/Ops.scala b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/Ops.scala index 4befe0ef2f..0b79f2e659 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/Ops.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/Ops.scala @@ -2,6 +2,8 @@ package io.getquill.context.cassandra import io.getquill.{Action, Delete, EntityQuery, Insert, Query, Update} +@SuppressWarnings(Array("scalafix:ExplicitResultTypes")) +// noinspection TypeAnnotation trait Ops { this: CassandraContext[_] => diff --git a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/cluster/SessionBuilder.scala b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/cluster/SessionBuilder.scala index fb410d70d5..72b77fb582 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/cluster/SessionBuilder.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/cluster/SessionBuilder.scala @@ -3,7 +3,6 @@ package io.getquill.context.cassandra.cluster import com.datastax.oss.driver.api.core.{CqlSession, CqlSessionBuilder} import com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader import com.typesafe.config.Config -import io.getquill.util.Messages._ import java.util.function.Supplier diff --git a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CassandraMapper.scala b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CassandraMapper.scala index abd42873ff..ba80d3cd54 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CassandraMapper.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CassandraMapper.scala @@ -7,7 +7,7 @@ import io.getquill.context.UdtValueLookup * * End-users should rely on MappedEncoding since it's more general. */ -case class CassandraMapper[I, O](f: (I, UdtValueLookup) => O) +final case class CassandraMapper[I, O](f: (I, UdtValueLookup) => O) object CassandraMapper { def simple[I, O](f: I => O): CassandraMapper[I, O] = CassandraMapper[I, O]((iOrig, _) => f(iOrig)) } diff --git a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CassandraTypes.scala b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CassandraTypes.scala index 365ee6aadb..40c8827d69 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CassandraTypes.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CassandraTypes.scala @@ -11,7 +11,7 @@ import java.lang.{ } import java.math.{BigDecimal => JBigDecimal} import java.nio.ByteBuffer -import java.util.{Date, UUID} +import java.util.UUID import java.time.{Instant, LocalDate} /** diff --git a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CollectionEncoders.scala b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CollectionEncoders.scala index d6d1fcaf28..8a4134c798 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CollectionEncoders.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CollectionEncoders.scala @@ -1,7 +1,5 @@ package io.getquill.context.cassandra.encoding -import com.datastax.oss.driver.api.core.`type`.reflect.GenericType -import com.datastax.oss.driver.shaded.guava.common.reflect.{TypeParameter, TypeToken} import io.getquill.context.cassandra.CassandraRowContext import io.getquill.context.cassandra.util.ClassTagConversions.asClassOf diff --git a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/Decoders.scala b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/Decoders.scala index 673b2caabb..85a88ee12c 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/Decoders.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/Decoders.scala @@ -1,11 +1,11 @@ package io.getquill.context.cassandra.encoding -import com.datastax.oss.driver.internal.core.`type`.{DefaultListType, PrimitiveType} +import com.datastax.oss.driver.internal.core.`type`.PrimitiveType import io.getquill.context.cassandra.CassandraRowContext import io.getquill.util.Messages.fail import java.time.{Instant, LocalDate, LocalTime} -import java.util.{Date, UUID} +import java.util.UUID trait Decoders extends CollectionDecoders { this: CassandraRowContext[_] => @@ -13,7 +13,7 @@ trait Decoders extends CollectionDecoders { type Decoder[T] = CassandraDecoder[T] case class CassandraDecoder[T](decoder: BaseDecoder[T]) extends BaseDecoder[T] { - override def apply(index: Index, row: ResultRow, session: Session) = + override def apply(index: Index, row: ResultRow, session: Session): T = decoder(index, row, session) } @@ -26,7 +26,7 @@ trait Decoders extends CollectionDecoders { ) def decoder[T](f: ResultRow => Index => T): Decoder[T] = - decoder((index, row, session) => f(row)(index)) + decoder((index, row, _) => f(row)(index)) implicit def optionDecoder[T](implicit d: Decoder[T]): Decoder[Option[T]] = CassandraDecoder { (index, row, session) => @@ -41,7 +41,7 @@ trait Decoders extends CollectionDecoders { implicit val stringDecoder: Decoder[String] = decoder(_.getString) implicit val bigDecimalDecoder: Decoder[BigDecimal] = - decoder((index, row, session) => row.getBigDecimal(index)) + decoder((index, row, _) => row.getBigDecimal(index)) implicit val booleanDecoder: Decoder[Boolean] = decoder(_.getBoolean) implicit val byteDecoder: Decoder[Byte] = decoder(_.getByte) implicit val shortDecoder: Decoder[Short] = decoder(_.getShort) @@ -50,7 +50,7 @@ trait Decoders extends CollectionDecoders { implicit val floatDecoder: Decoder[Float] = decoder(_.getFloat) implicit val doubleDecoder: Decoder[Double] = decoder(_.getDouble) implicit val byteArrayDecoder: Decoder[Array[Byte]] = - decoder { (index, row, session) => + decoder { (index, row, _) => val bb = row.getByteBuffer(index) val b = new Array[Byte](bb.remaining()) bb.get(b) diff --git a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/Encoders.scala b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/Encoders.scala index cb6a907f41..909a02d540 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/Encoders.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/Encoders.scala @@ -4,7 +4,7 @@ import io.getquill.context.cassandra.CassandraRowContext import java.nio.ByteBuffer import java.time.{Instant, LocalDate, LocalTime} -import java.util.{Date, UUID} +import java.util.UUID trait Encoders extends CollectionEncoders { this: CassandraRowContext[_] => @@ -12,7 +12,7 @@ trait Encoders extends CollectionEncoders { type Encoder[T] = CassandraEncoder[T] case class CassandraEncoder[T](encoder: BaseEncoder[T]) extends BaseEncoder[T] { - override def apply(index: Index, value: T, row: PrepareRow, session: Session) = + override def apply(index: Index, value: T, row: PrepareRow, session: Session): PrepareRow = encoder(index, value, row, session) } diff --git a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/UdtEncodingMacro.scala b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/UdtEncodingMacro.scala index ce005618ee..43d45d0445 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/UdtEncodingMacro.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/UdtEncodingMacro.scala @@ -222,7 +222,7 @@ class UdtEncodingMacro(val c: MacroContext) { !(tpe.baseType(t.tpe.typeSymbol) =:= NoType) private def makeTypeDef(name: String) = - TypeDef(Modifiers(Flag.PARAM), TypeName(name), Nil, TypeBoundsTree(EmptyTree, EmptyTree)) + TypeDef(Modifiers(Flag.PARAM), TypeName(name), List.empty, TypeBoundsTree(EmptyTree, EmptyTree)) private def buildUdtMeta(tpe: Type): Tree = { val meta = OptionalTypecheck(c)(q"implicitly[$prefix.UdtMeta[$tpe]]") getOrElse { diff --git a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/UdtOps.scala b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/UdtOps.scala index 1896f385d5..133423873c 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/UdtOps.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/UdtOps.scala @@ -3,24 +3,25 @@ package io.getquill.context.cassandra.encoding import com.datastax.oss.driver.api.core.data.UdtValue import scala.jdk.CollectionConverters._ +import scala.collection.mutable class UdtValueOps(val udt: UdtValue) extends AnyVal { - def getScalaList[A](name: String, cls: Class[A]) = + def getScalaList[A](name: String, cls: Class[A]): mutable.Buffer[A] = udt.getList(name, cls).asScala - def getScalaSet[A](name: String, cls: Class[A]) = + def getScalaSet[A](name: String, cls: Class[A]): mutable.Set[A] = udt.getSet(name, cls).asScala - def getScalaMap[K, V](name: String, kcls: Class[K], vcls: Class[V]) = + def getScalaMap[K, V](name: String, kcls: Class[K], vcls: Class[V]): mutable.Map[K,V] = udt.getMap(name, kcls, vcls).asScala - def setScalaList[A](name: String, v: Seq[A], cls: Class[A]) = + def setScalaList[A](name: String, v: Seq[A], cls: Class[A]): UdtValue = udt.setList(name, v.asJava, cls) - def setScalaSet[A](name: String, v: Set[A], cls: Class[A]) = + def setScalaSet[A](name: String, v: Set[A], cls: Class[A]): UdtValue = udt.setSet(name, v.asJava, cls) - def setScalaMap[K, V](name: String, v: Map[K, V], kcls: Class[K], vcls: Class[V]) = + def setScalaMap[K, V](name: String, v: Map[K, V], kcls: Class[K], vcls: Class[V]): UdtValue = udt.setMap(name, v.asJava, kcls, vcls) } diff --git a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/util/FutureConversions.scala b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/util/FutureConversions.scala index da7ef50a03..f5a232fbca 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/util/FutureConversions.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/util/FutureConversions.scala @@ -9,7 +9,7 @@ import scala.util.Try object FutureConversions { - implicit class ListenableFutureConverter[A](val lf: ListenableFuture[A]) extends AnyVal { + implicit class ListenableFutureConverter[A](private val lf: ListenableFuture[A]) extends AnyVal { def asScala(implicit ec: ExecutionContext): Future[A] = { val promise = Promise[A]() lf.addListener( diff --git a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/ComposeableTraitsJdbcCodegen.scala b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/ComposeableTraitsJdbcCodegen.scala index 32ea211c37..46087ef926 100644 --- a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/ComposeableTraitsJdbcCodegen.scala +++ b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/ComposeableTraitsJdbcCodegen.scala @@ -11,6 +11,7 @@ import io.getquill.codegen.model.{BySomeTableData, JdbcColumnMeta, JdbcTableMeta import io.getquill.codegen.util.StringUtil._ import io.getquill.util.LoadConfig import javax.sql.DataSource +import io.getquill.codegen.model.TableStereotype /** * This generator generates a query schema trait which can be composed with a @@ -142,7 +143,7 @@ class ComposeableTraitsJdbcCodegen( ) = this(Seq(connectionMaker), packagePrefix, false) override def makeGenerators: Seq[ContextifiedUnitGenerator] = new MultiGeneratorFactory(generatorMaker).apply - override def generatorMaker = new SingleGeneratorFactory[ContextifiedUnitGenerator] { + override def generatorMaker: SingleGeneratorFactory[ContextifiedUnitGenerator] = new SingleGeneratorFactory[ContextifiedUnitGenerator] { override def apply(emitterSettings: EmitterSettings[JdbcTableMeta, JdbcColumnMeta]): ContextifiedUnitGenerator = new ContextifiedUnitGenerator(emitterSettings) } @@ -159,7 +160,7 @@ class ComposeableTraitsJdbcCodegen( class ContextifiedUnitGenerator(emitterSettings: EmitterSettings[JdbcTableMeta, JdbcColumnMeta]) extends CodeEmitter(emitterSettings) { - def possibleTraitNesting(innerCode: String) = if (nestedTrait) { + def possibleTraitNesting(innerCode: String): String = if (nestedTrait) { s""" |object ${packageName.getOrElse(defaultNamespace).capitalize}Schema { | ${indent(innerCode)} @@ -179,7 +180,7 @@ class ComposeableTraitsJdbcCodegen( |""".stripMargin.trimFront) .getOrElse("") - override def CombinedTableSchemas = new CombinedTableSchemasGen(_, _) { + override def CombinedTableSchemas: (TableStereotype[TableMeta,ColumnMeta], QuerySchemaNaming) => CombinedTableSchemasGen = new CombinedTableSchemasGen(_, _) { override def objectName: Option[String] = super.objectName.map(_ + "Dao") } } diff --git a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/DatabaseTypes.scala b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/DatabaseTypes.scala index 3de7315bcf..548797a5e0 100644 --- a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/DatabaseTypes.scala +++ b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/DatabaseTypes.scala @@ -27,23 +27,23 @@ object DatabaseTypes { def databaseName: String; def context: Class[_ <: JdbcContext[_, _]]; def dialect: Class[_ <: SqlIdiom] } case object H2 extends DatabaseType { - def databaseName = "H2"; def context = classOf[H2JdbcContext[_]]; def dialect = classOf[H2Dialect] + def databaseName = "H2"; def context: Class[_ <: JdbcContext[_, _]] = classOf[H2JdbcContext[_]]; def dialect: Class[H2Dialect] = classOf[H2Dialect] } case object MySql extends DatabaseType { - def databaseName = "MySQL"; def context = classOf[MysqlJdbcContext[_]]; def dialect = classOf[MySQLDialect] + def databaseName = "MySQL"; def context: Class[_ <: JdbcContext[_, _]] = classOf[MysqlJdbcContext[_]]; def dialect: Class[MySQLDialect] = classOf[MySQLDialect] } case object SqlServer extends DatabaseType { - def databaseName = "Microsoft SQL Server"; def context = classOf[SqlServerJdbcContext[_]]; - def dialect = classOf[SQLServerDialect] + def databaseName = "Microsoft SQL Server"; def context: Class[_ <: JdbcContext[_, _]] = classOf[SqlServerJdbcContext[_]]; + def dialect: Class[SQLServerDialect] = classOf[SQLServerDialect] } case object Postgres extends DatabaseType { - def databaseName = "PostgreSQL"; def context = classOf[PostgresJdbcContext[_]]; - def dialect = classOf[PostgresDialect] + def databaseName = "PostgreSQL"; def context: Class[_ <: JdbcContext[_, _]] = classOf[PostgresJdbcContext[_]]; + def dialect: Class[PostgresDialect] = classOf[PostgresDialect] } case object Sqlite extends DatabaseType { - def databaseName = "SQLite"; def context = classOf[SqliteJdbcContext[_]]; def dialect = classOf[SqliteDialect] + def databaseName = "SQLite"; def context: Class[_ <: JdbcContext[_, _]] = classOf[SqliteJdbcContext[_]]; def dialect: Class[SqliteDialect] = classOf[SqliteDialect] } case object Oracle extends DatabaseType { - def databaseName = "Oracle"; def context = classOf[SqliteJdbcContext[_]]; def dialect = classOf[OracleDialect] + def databaseName = "Oracle"; def context: Class[_ <: JdbcContext[_, _]] = classOf[SqliteJdbcContext[_]]; def dialect: Class[OracleDialect] = classOf[OracleDialect] } } diff --git a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/DefaultJdbcSchemaReader.scala b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/DefaultJdbcSchemaReader.scala index 800707aa5e..952a3662a9 100644 --- a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/DefaultJdbcSchemaReader.scala +++ b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/DefaultJdbcSchemaReader.scala @@ -17,7 +17,7 @@ class DefaultJdbcSchemaReader( ) extends JdbcSchemaReader { @tailrec - private def resultSetExtractor[T](rs: ResultSet, extractor: (ResultSet) => T, acc: List[T] = List()): List[T] = + private def resultSetExtractor[T](rs: ResultSet, extractor: (ResultSet) => T, acc: List[T] = List.empty): List[T] = if (!rs.next()) acc.reverse else @@ -29,7 +29,7 @@ class DefaultJdbcSchemaReader( case _ => null } - def jdbcEntityFilter(ts: JdbcTableMeta) = + def jdbcEntityFilter(ts: JdbcTableMeta): Boolean = ts.tableType.existsInSetNocase("table", "view", "user table", "user view", "base table") private[getquill] def extractTables(connectionMaker: () => Connection): List[JdbcTableMeta] = { diff --git a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/JdbcCodeGeneratorComponents.scala b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/JdbcCodeGeneratorComponents.scala index 996df443cb..592e8da6ba 100644 --- a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/JdbcCodeGeneratorComponents.scala +++ b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/JdbcCodeGeneratorComponents.scala @@ -21,7 +21,7 @@ trait JdbcCodeGeneratorComponents extends CodeGeneratorComponents { def nameParser: NameParser = LiteralNames - override def defaultExcludedSchemas = Set("information_schema", "performance_schema", "sys", "mysql") + override def defaultExcludedSchemas: Set[String] = Set("information_schema", "performance_schema", "sys", "mysql") /** * When the Jdbc Typer tries to figure out which Scala/Java objects to use for diff --git a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/JdbcGenerator.scala b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/JdbcGenerator.scala index 0d217de47e..4be69b89d7 100644 --- a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/JdbcGenerator.scala +++ b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/JdbcGenerator.scala @@ -23,7 +23,7 @@ class JdbcGeneratorBase(val connectionMakers: Seq[JdbcConnectionMaker], val pack trait JdbcGenerator extends Generator { this: JdbcCodeGeneratorComponents with JdbcStereotyper => val connectionMakers: Seq[JdbcConnectionMaker] val databaseType: DatabaseType = DiscoverDatabaseType.apply(connectionMakers.head) - val columnGetter = (cm: ColumnMeta) => cm.columnName + val columnGetter: ColumnMeta => String = (cm: ColumnMeta) => cm.columnName override def filter(tc: RawSchema[JdbcTableMeta, JdbcColumnMeta]): Boolean = databaseType match { diff --git a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/model/DefaultJdbcTyper.scala b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/model/DefaultJdbcTyper.scala index 7ab8368544..97fe850933 100644 --- a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/model/DefaultJdbcTyper.scala +++ b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/model/DefaultJdbcTyper.scala @@ -12,7 +12,7 @@ class DefaultJdbcTyper( numericPreference: NumericPreference ) extends (JdbcTypeInfo => Option[ClassTag[_]]) { - private val logger = ContextLogger(classOf[DefaultJdbcTyper]) + ContextLogger(classOf[DefaultJdbcTyper]) private[getquill] val MaxIntDigits = 9 private[getquill] val MaxLongDigits = 18 diff --git a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/model/JdbcTypeInfo.scala b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/model/JdbcTypeInfo.scala index d6c219e87c..c41f0d622a 100644 --- a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/model/JdbcTypeInfo.scala +++ b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/model/JdbcTypeInfo.scala @@ -2,7 +2,7 @@ package io.getquill.codegen.jdbc.model import io.getquill.codegen.model.JdbcColumnMeta -case class JdbcTypeInfo(jdbcType: Int, size: Int, typeName: Option[String]) +final case class JdbcTypeInfo(jdbcType: Int, size: Int, typeName: Option[String]) object JdbcTypeInfo { def apply(cs: JdbcColumnMeta): JdbcTypeInfo = JdbcTypeInfo(cs.dataType, cs.size, Some(cs.typeName)) } diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/gen/AbstractCodeEmitter.scala b/quill-codegen/src/main/scala/io/getquill/codegen/gen/AbstractCodeEmitter.scala index 61efd1c4b5..2816ce44ae 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/gen/AbstractCodeEmitter.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/gen/AbstractCodeEmitter.scala @@ -3,7 +3,7 @@ package io.getquill.codegen.gen import io.getquill.codegen.model._ import io.getquill.codegen.util.StringUtil.{indent, _} -case class EmitterSettings[TableMeta, ColumnMeta]( +final case class EmitterSettings[TableMeta, ColumnMeta]( caseClassTables: Seq[TableStereotype[TableMeta, ColumnMeta]], querySchemaTables: Seq[TableStereotype[TableMeta, ColumnMeta]], codeWrapper: CodeWrapper @@ -35,7 +35,7 @@ abstract class AbstractCodeEmitter { def code: String def tableName: String def schemaName: Option[String] - def fullTableName = schemaName.map(_ + ".").getOrElse("") + tableName + def fullTableName: String = schemaName.map(_ + ".").getOrElse("") + tableName def rawCaseClassName: String def actualCaseClassName: String @@ -53,7 +53,7 @@ abstract class AbstractCodeEmitter { trait ObjectGen { def objectName: Option[String] - def surroundByObject(innerCode: String) = + def surroundByObject(innerCode: String): String = objectName match { case None => innerCode case Some(objectNameActual) => @@ -76,7 +76,7 @@ trait PackageGen { } def codeWrapper: CodeWrapper - def surroundByPackage(innerCode: String) = + def surroundByPackage(innerCode: String): String = codeWrapper match { case NoWrapper => innerCode case PackageHeader(packageName) => { diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/gen/CodeGeneratorComponents.scala b/quill-codegen/src/main/scala/io/getquill/codegen/gen/CodeGeneratorComponents.scala index df8d624859..1f362a5e5e 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/gen/CodeGeneratorComponents.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/gen/CodeGeneratorComponents.scala @@ -21,7 +21,7 @@ trait CodeGeneratorComponents extends HasBasicMeta with QuerySchemaNaming { type QuerySchemaNaming = TableMeta => String type ColumnGetter = ColumnMeta => String - def defaultExcludedSchemas = Set[String]() + def defaultExcludedSchemas: Set[String] = Set.empty[String] def querySchemaImports = "" def nameParser: NameParser def unrecognizedTypeStrategy: UnrecognizedTypeStrategy diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/gen/Generator.scala b/quill-codegen/src/main/scala/io/getquill/codegen/gen/Generator.scala index fb8a1e3294..385ecd0669 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/gen/Generator.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/gen/Generator.scala @@ -31,7 +31,7 @@ trait Generator { /** * Instantiate the generator for a particular schema */ - def generatorMaker = new SingleGeneratorFactory[CodeEmitter] { + def generatorMaker: SingleGeneratorFactory[CodeEmitter] = new SingleGeneratorFactory[CodeEmitter] { override def apply(emitterSettings: EmitterSettings[TableMeta, ColumnMeta]): CodeEmitter = new CodeEmitter(emitterSettings) } @@ -50,7 +50,7 @@ trait Generator { emitters } } - def makeGenerators = new MultiGeneratorFactory(generatorMaker).apply + def makeGenerators: Seq[CodeEmitter] = new MultiGeneratorFactory(generatorMaker).apply def writeAllFiles(location: String): Future[Seq[Path]] = Future.sequence(writeFiles(location)) @@ -101,7 +101,7 @@ trait Generator { } val fileWithExtension = fileName.resolveSibling(fileName.getFileName.toString + ".scala") - val loc = Paths.get(location) + Paths.get(location) (gen, Paths.get(location, fileWithExtension.toString)) } @@ -120,7 +120,7 @@ trait Generator { } } - val renderMembers = nameParser match { + val renderMembers: Boolean = nameParser match { case CustomNames(_, _) => true case _ => false } @@ -130,7 +130,7 @@ trait Generator { * * @return */ - def writeStrings = makeGenerators.map(_.apply) + def writeStrings: Seq[String] = makeGenerators.map(_.apply) class CodeEmitter(emitterSettings: EmitterSettings[TableMeta, ColumnMeta]) extends AbstractCodeEmitter @@ -150,22 +150,22 @@ trait Generator { override def packagePrefix: String = Generator.this.packagePrefix - override def code = surroundByPackage(body) + override def code: String = surroundByPackage(body) def body: String = caseClassesCode + "\n\n" + tableSchemasCode def caseClassesCode: String = caseClassTables.map(CaseClass(_).code).mkString("\n\n") def tableSchemasCode: String = querySchemaTables.map(CombinedTableSchemas(_, querySchemaNaming).code).mkString("\n") - protected def ifMembers(str: String) = if (renderMembers) str else "" + protected def ifMembers(str: String): String = if (renderMembers) str else "" - def CaseClass = new CaseClassGen(_) + def CaseClass: TableStereotype[TableMeta,ColumnMeta] => CaseClassGen = new CaseClassGen(_) class CaseClassGen(val tableColumns: TableStereotype[TableMeta, ColumnMeta]) extends super.AbstractCaseClassGen with CaseClassNaming[TableMeta, ColumnMeta] { - def code = + def code: String = s"case class ${actualCaseClassName}(" + tableColumns.columns.map(Member(_).code).mkString(", ") + ")" - def Member = new MemberGen(_) + def Member: ColumnFusion[ColumnMeta] => MemberGen = new MemberGen(_) class MemberGen(val column: ColumnFusion[ColumnMeta]) extends super.AbstractMemberGen with FieldNaming[ColumnMeta] { @@ -177,7 +177,7 @@ trait Generator { } } - def CombinedTableSchemas = new CombinedTableSchemasGen(_, _) + def CombinedTableSchemas: (TableStereotype[TableMeta,ColumnMeta], QuerySchemaNaming) => CombinedTableSchemasGen = new CombinedTableSchemasGen(_, _) class CombinedTableSchemasGen( tableColumns: TableStereotype[TableMeta, ColumnMeta], querySchemaNaming: QuerySchemaNaming @@ -201,12 +201,12 @@ trait Generator { Seq(imports, schemas).pruneEmpty.mkString("\n\n") } - def QuerySchema = new QuerySchemaGen(_, _) + def QuerySchema: (TableStereotype[TableMeta,ColumnMeta], TableMeta) => QuerySchemaGen = new QuerySchemaGen(_, _) class QuerySchemaGen(val tableColumns: TableStereotype[TableMeta, ColumnMeta], schema: TableMeta) extends AbstractQuerySchemaGen with CaseClassNaming[TableMeta, ColumnMeta] { - def members = + def members: String = ifMembers( (tableColumns.columns.map(QuerySchemaMapping(_).code).mkString(",\n")) ) @@ -227,7 +227,7 @@ trait Generator { override def tableName: String = schema.tableName override def schemaName: Option[String] = schema.tableSchema - def QuerySchemaMapping = new QuerySchemaMappingGen(_) + def QuerySchemaMapping: ColumnFusion[ColumnMeta] => QuerySchemaMappingGen = new QuerySchemaMappingGen(_) class QuerySchemaMappingGen(val column: ColumnFusion[ColumnMeta]) extends AbstractQuerySchemaMappingGen with FieldNaming[ColumnMeta] { diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/gen/StereotypePackager.scala b/quill-codegen/src/main/scala/io/getquill/codegen/gen/StereotypePackager.scala index 24fded1cb3..a2004dcd9d 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/gen/StereotypePackager.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/gen/StereotypePackager.scala @@ -11,7 +11,7 @@ class StereotypePackager[Emitter, TableMeta, ColumnMeta] { emitterMaker: (EmitterSettings[TableMeta, ColumnMeta]) => Emitter, packagingStrategy: PackagingStrategy, tables: Seq[TableStereotype[TableMeta, ColumnMeta]] - ) = { + ): Seq[Emitter] = { import io.getquill.codegen.util.MapExtensions._ import packagingStrategy._ implicit class OptionSeqExtentions[T](optionalSeq: Option[Seq[T]]) { diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/model/CustomNameParser.scala b/quill-codegen/src/main/scala/io/getquill/codegen/model/CustomNameParser.scala index 05238dedb3..933fd5cef4 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/model/CustomNameParser.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/model/CustomNameParser.scala @@ -22,7 +22,7 @@ trait SnakeCaseNames extends NameParser { object LiteralNames extends LiteralNames object SnakeCaseNames extends SnakeCaseNames -case class CustomNames( +final case class CustomNames( columnParser: JdbcColumnMeta => String = cm => cm.columnName.snakeToLowerCamel, tableParser: JdbcTableMeta => String = tm => tm.tableName.snakeToUpperCamel ) extends NameParser { @@ -31,7 +31,7 @@ case class CustomNames( def parseTable(tm: JdbcTableMeta): String = tableParser(tm) } -case class SnakeCaseCustomTable( +final case class SnakeCaseCustomTable( tableParser: JdbcTableMeta => String ) extends NameParser { def generateQuerySchemas = true diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/model/Fuser.scala b/quill-codegen/src/main/scala/io/getquill/codegen/model/Fuser.scala index 362156f30c..810124c448 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/model/Fuser.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/model/Fuser.scala @@ -11,7 +11,7 @@ trait FuserBase[TableMeta, ColumnMeta] extends Fuser[TableMeta, ColumnMeta] { val ancestry: ClassAncestry - protected def unifyColumns(a: ColumnFusion[ColumnMeta], b: ColumnFusion[ColumnMeta]) = { + protected def unifyColumns(a: ColumnFusion[ColumnMeta], b: ColumnFusion[ColumnMeta]): ColumnFusion[ColumnMeta] = { val commonAncestor = ancestry(a.dataType, b.dataType) ColumnFusion( a.name, diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/model/Naming.scala b/quill-codegen/src/main/scala/io/getquill/codegen/model/Naming.scala index 87b0a784b1..73f36a942c 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/model/Naming.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/model/Naming.scala @@ -5,13 +5,13 @@ import io.getquill.codegen.util.ScalaLangUtil.escape trait ByName { def prefix: String def namespaceMaker: PackageNamingStrategy.NamespaceMaker - def byName(table: TableStereotype[_, _]) = namespaceMaker(table) + def byName(table: TableStereotype[_, _]): String = namespaceMaker(table) } sealed trait CodeWrapper -case class PackageHeader(packageName: String) extends CodeWrapper -case class PackageObject(packageName: String) extends CodeWrapper -case class SimpleObject(packageName: String) extends CodeWrapper +final case class PackageHeader(packageName: String) extends CodeWrapper +final case class PackageObject(packageName: String) extends CodeWrapper +final case class SimpleObject(packageName: String) extends CodeWrapper case object NoWrapper extends CodeWrapper sealed trait FileNamingStrategy @@ -37,7 +37,7 @@ case object ByPackageObjectStandardName extends FileNamingStrategy case object ByPackageName extends FileNamingStrategy case object ByDefaultName extends FileNamingStrategy -case class BySomeTableData[Gen](val namer: Gen => java.nio.file.Path)(implicit +final case class BySomeTableData[Gen](val namer: Gen => java.nio.file.Path)(implicit val tt: scala.reflect.runtime.universe.TypeTag[Gen] ) extends FileNamingStrategy @@ -50,5 +50,5 @@ trait CaseClassNaming[TableMeta, ColumnMeta] { trait FieldNaming[ColumnMeta] { def column: ColumnFusion[ColumnMeta] def rawFieldName: String = column.name - def fieldName = escape(rawFieldName) + def fieldName: String = escape(rawFieldName) } diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/model/PackagingStrategy.scala b/quill-codegen/src/main/scala/io/getquill/codegen/model/PackagingStrategy.scala index 4a7c3f8a6a..a0ce74efce 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/model/PackagingStrategy.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/model/PackagingStrategy.scala @@ -5,7 +5,7 @@ object PackagingStrategy { object ByPackageObject { private def packageByNamespace(prefix: String) = PackageObjectByNamespace(prefix, _.table.namespace) - def Simple(packagePrefix: String = "") = + def Simple(packagePrefix: String = ""): PackagingStrategy = PackagingStrategy( GroupByPackage, packageByNamespace(packagePrefix), @@ -24,7 +24,7 @@ object PackagingStrategy { * imports (i.e. since each file is a separate table you can be sure to just * imports the exact tables needed for every source file). */ - def TablePerFile(packagePrefix: String = "") = + def TablePerFile(packagePrefix: String = ""): PackagingStrategy = PackagingStrategy( DoNotGroup, packageByNamespace(packagePrefix), @@ -38,7 +38,7 @@ object PackagingStrategy { * per-schema for example the ComposeableTraitsGen that creates Traits * representing database schemas that can be composed with Contexts. */ - def TablePerSchema(packagePrefix: String = "") = + def TablePerSchema(packagePrefix: String = ""): PackagingStrategy = PackagingStrategy( GroupByPackage, packageByNamespace(packagePrefix), @@ -47,7 +47,7 @@ object PackagingStrategy { ) } - def NoPackageCombined = + def NoPackageCombined: PackagingStrategy = PackagingStrategy( GroupByPackage, NoPackage, @@ -55,7 +55,7 @@ object PackagingStrategy { ByPackageName ) - def NoPackageSeparate = + def NoPackageSeparate: PackagingStrategy = PackagingStrategy( DoNotGroup, NoPackage, @@ -64,7 +64,7 @@ object PackagingStrategy { ) } -case class PackagingStrategy( +final case class PackagingStrategy( packageGroupingStrategy: PackageGroupingStrategy, packageNamingStrategyForCaseClasses: PackageNamingStrategy, packageNamingStrategyForQuerySchemas: PackageNamingStrategy, @@ -80,17 +80,17 @@ sealed trait PackageNamingStrategy extends (TableStereotype[_, _] => CodeWrapper object PackageNamingStrategy { type NamespaceMaker = TableStereotype[_, _] => String } -case class PackageHeaderByNamespace(val prefix: String, val namespaceMaker: PackageNamingStrategy.NamespaceMaker) +final case class PackageHeaderByNamespace(val prefix: String, val namespaceMaker: PackageNamingStrategy.NamespaceMaker) extends PackageNamingStrategy with ByName { override def apply(table: TableStereotype[_, _]): CodeWrapper = PackageHeader(byName(table)) } -case class PackageObjectByNamespace(val prefix: String, val namespaceMaker: PackageNamingStrategy.NamespaceMaker) +final case class PackageObjectByNamespace(val prefix: String, val namespaceMaker: PackageNamingStrategy.NamespaceMaker) extends PackageNamingStrategy with ByName { override def apply(table: TableStereotype[_, _]): CodeWrapper = PackageObject(byName(table)) } -case class SimpleObjectByNamespace(val prefix: String, val namespaceMaker: PackageNamingStrategy.NamespaceMaker) +final case class SimpleObjectByNamespace(val prefix: String, val namespaceMaker: PackageNamingStrategy.NamespaceMaker) extends PackageNamingStrategy with ByName { override def apply(table: TableStereotype[_, _]): CodeWrapper = SimpleObject(byName(table)) diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/model/SchemaModel.scala b/quill-codegen/src/main/scala/io/getquill/codegen/model/SchemaModel.scala index 5ad0910c2c..4ea935f279 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/model/SchemaModel.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/model/SchemaModel.scala @@ -2,7 +2,7 @@ package io.getquill.codegen.model import java.sql.ResultSet -case class RawSchema[T, C](table: T, columns: Seq[C]) +final case class RawSchema[T, C](table: T, columns: Seq[C]) trait BasicTableMeta { def tableSchema: Option[String] @@ -13,7 +13,7 @@ trait BasicColumnMeta { def columnName: String } -case class JdbcTableMeta( +final case class JdbcTableMeta( tableCat: Option[String], tableSchema: Option[String], tableName: String, @@ -21,7 +21,7 @@ case class JdbcTableMeta( ) extends BasicTableMeta object JdbcTableMeta { - def fromResultSet(rs: ResultSet) = JdbcTableMeta( + def fromResultSet(rs: ResultSet): JdbcTableMeta = JdbcTableMeta( tableCat = Option(rs.getString("TABLE_CAT")), tableSchema = Option(rs.getString("TABLE_SCHEM")), tableName = rs.getString("TABLE_NAME"), @@ -29,7 +29,7 @@ object JdbcTableMeta { ) } -case class JdbcColumnMeta( +final case class JdbcColumnMeta( tableCat: Option[String], tableSchema: Option[String], tableName: String, @@ -41,7 +41,7 @@ case class JdbcColumnMeta( ) extends BasicColumnMeta object JdbcColumnMeta { - def fromResultSet(rs: ResultSet) = + def fromResultSet(rs: ResultSet): JdbcColumnMeta = JdbcColumnMeta( tableCat = Option(rs.getString("TABLE_CAT")), tableSchema = Option(rs.getString("TABLE_SCHEM")), diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/model/StereotypedModel.scala b/quill-codegen/src/main/scala/io/getquill/codegen/model/StereotypedModel.scala index 1451973507..91498345d2 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/model/StereotypedModel.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/model/StereotypedModel.scala @@ -8,18 +8,18 @@ import scala.reflect.ClassTag * with a given name or, if it has been combined with all other identically * named tables (in the same schema) that we wish to combine it with. */ -case class TableStereotype[TableMeta, ColumnMeta]( +final case class TableStereotype[TableMeta, ColumnMeta]( table: TableFusion[TableMeta], columns: Seq[ColumnFusion[ColumnMeta]] ) -case class TableFusion[TableMeta]( +final case class TableFusion[TableMeta]( namespace: String, name: String, meta: Seq[TableMeta] ) -case class ColumnFusion[ColumnMeta]( +final case class ColumnFusion[ColumnMeta]( name: String, dataType: ClassTag[_], nullable: Boolean, diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/util/MapExtensions.scala b/quill-codegen/src/main/scala/io/getquill/codegen/util/MapExtensions.scala index dbe05bdd6d..1e7c831593 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/util/MapExtensions.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/util/MapExtensions.scala @@ -5,8 +5,8 @@ import scala.collection.immutable.{ListMap, ListSet} object MapExtensions { implicit class MapOps[K, V](m: Map[K, V]) { - def zipOnKeys(o: Map[K, V]) = zipMapsOnKeys(m, o) - def zipOnKeysOrdered(o: Map[K, V]) = zipMapsOnKeysOrdered(m, o) + def zipOnKeys(o: Map[K, V]): Map[K,(Option[V], Option[V])] = zipMapsOnKeys(m, o) + def zipOnKeysOrdered(o: Map[K, V]): ListMap[K,(Option[V], Option[V])] = zipMapsOnKeysOrdered(m, o) } def zipMapsOnKeys[K, V](one: Map[K, V], two: Map[K, V]): Map[K, (Option[V], Option[V])] = diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/util/ScalaLangUtil.scala b/quill-codegen/src/main/scala/io/getquill/codegen/util/ScalaLangUtil.scala index c8ab41cba1..6f539636ec 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/util/ScalaLangUtil.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/util/ScalaLangUtil.scala @@ -1,10 +1,10 @@ package io.getquill.codegen.util object ScalaLangUtil { - def escape(str: String) = + def escape(str: String): String = if (isKeyword(str)) s"`${str}`" else str - def isKeyword(word: String) = keywords.contains(word.trim) + def isKeyword(word: String): Boolean = keywords.contains(word.trim) private val keywords = Set( "abstract", "case", diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/util/StringSeqUtil.scala b/quill-codegen/src/main/scala/io/getquill/codegen/util/StringSeqUtil.scala index db66a96e34..694e91766f 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/util/StringSeqUtil.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/util/StringSeqUtil.scala @@ -2,6 +2,6 @@ package io.getquill.codegen.util object StringSeqUtil { implicit class StringSeqExt(seq: Seq[String]) { - def pruneEmpty = seq.filterNot(_.trim == "") + def pruneEmpty: Seq[String] = seq.filterNot(_.trim == "") } } diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/util/StringUtil.scala b/quill-codegen/src/main/scala/io/getquill/codegen/util/StringUtil.scala index 414673497b..b0d458f315 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/util/StringUtil.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/util/StringUtil.scala @@ -11,9 +11,9 @@ object StringUtil { } implicit class StringExtensions(str: String) { - def snakeToUpperCamel = str.split("_").map(_.toLowerCase).map(_.capitalize).mkString + def snakeToUpperCamel: String = str.split("_").map(_.toLowerCase).map(_.capitalize).mkString def snakeToLowerCamel = str.split("_").map(_.toLowerCase).map(_.capitalize).mkString.uncapitalize - def lowerCamelToSnake = str.split("(?=[A-Z])").mkString("_").toLowerCase + def lowerCamelToSnake: String = str.split("(?=[A-Z])").mkString("_").toLowerCase def uncapitalize = new String( (str.toList match { @@ -21,15 +21,15 @@ object StringUtil { case Nil => Nil }).toArray ) - def unquote = str.replaceFirst("^\"", "").replaceFirst("\"$", "") - def trimFront = str.dropWhile(_ == '\n') - def notEmpty = if (str.trim == "") None else Some(str) - def inSetNocase(seq: String*) = + def unquote: String = str.replaceFirst("^\"", "").replaceFirst("\"$", "") + def trimFront: String = str.dropWhile(_ == '\n') + def notEmpty: Option[String] = if (str.trim == "") None else Some(str) + def inSetNocase(seq: String*): Boolean = seq.map(_.toLowerCase).toSeq.contains(str.toLowerCase) } implicit class OptionStringExtensions(str: Option[String]) { - def existsInSetNocase(seq: String*) = + def existsInSetNocase(seq: String*): Boolean = str.map(_.toLowerCase).exists(value => seq.map(_.toLowerCase).toSeq.contains(value)) } } diff --git a/quill-core/src/main/scala/io/getquill/AsyncMirrorContext.scala b/quill-core/src/main/scala/io/getquill/AsyncMirrorContext.scala index 63dc3d54ee..155b93b145 100644 --- a/quill-core/src/main/scala/io/getquill/AsyncMirrorContext.scala +++ b/quill-core/src/main/scala/io/getquill/AsyncMirrorContext.scala @@ -97,19 +97,19 @@ class AsyncMirrorContext[+Idiom <: BaseIdiom, +Naming <: NamingStrategy]( def executeQuery[T](string: String, prepare: Prepare = identityPrepare, extractor: Extractor[T] = identityExtractor)( executionInfo: ExecutionInfo, dc: Runner - )(implicit ec: ExecutionContext) = + )(implicit ec: ExecutionContext): Future[QueryMirror[T]] = Future(QueryMirror(string, prepare(Row(), session)._2, extractor, executionInfo)) def executeQuerySingle[T]( string: String, prepare: Prepare = identityPrepare, extractor: Extractor[T] = identityExtractor - )(executionInfo: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext) = + )(executionInfo: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext): Future[QueryMirror[T]] = Future(QueryMirror(string, prepare(Row(), session)._2, extractor, executionInfo)) def executeAction(string: String, prepare: Prepare = identityPrepare)(executionInfo: ExecutionInfo, dc: Runner)( implicit ec: ExecutionContext - ) = + ): Future[ActionMirror] = Future(ActionMirror(string, prepare(Row(), session)._2, executionInfo)) def executeActionReturning[O]( @@ -117,7 +117,7 @@ class AsyncMirrorContext[+Idiom <: BaseIdiom, +Naming <: NamingStrategy]( prepare: Prepare = identityPrepare, extractor: Extractor[O], returningBehavior: ReturnAction - )(executionInfo: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext) = + )(executionInfo: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext): Future[ActionReturningMirror[O,O]] = Future(ActionReturningMirror[O, O](string, prepare(Row(), session)._2, extractor, returningBehavior, executionInfo)) def executeActionReturningMany[O]( @@ -125,14 +125,14 @@ class AsyncMirrorContext[+Idiom <: BaseIdiom, +Naming <: NamingStrategy]( prepare: Prepare = identityPrepare, extractor: Extractor[O], returningBehavior: ReturnAction - )(executionInfo: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext) = + )(executionInfo: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext): Future[ActionReturningMirror[O,List[O]]] = Future( ActionReturningMirror[O, List[O]](string, prepare(Row(), session)._2, extractor, returningBehavior, executionInfo) ) def executeBatchAction( groups: List[BatchGroup] - )(executionInfo: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext) = + )(executionInfo: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext): Future[BatchActionMirror] = Future { BatchActionMirror( groups.map { case BatchGroup(string, prepare) => @@ -145,7 +145,7 @@ class AsyncMirrorContext[+Idiom <: BaseIdiom, +Naming <: NamingStrategy]( def executeBatchActionReturning[T]( groups: List[BatchGroupReturning], extractor: Extractor[T] - )(executionInfo: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext) = + )(executionInfo: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext): Future[BatchActionReturningMirror[T]] = Future { BatchActionReturningMirror[T]( groups.map { case BatchGroupReturning(string, returningBehavior, prepare) => diff --git a/quill-core/src/main/scala/io/getquill/FutureTests.scala b/quill-core/src/main/scala/io/getquill/FutureTests.scala index e0578ae591..6e03e639ad 100644 --- a/quill-core/src/main/scala/io/getquill/FutureTests.scala +++ b/quill-core/src/main/scala/io/getquill/FutureTests.scala @@ -1,9 +1,6 @@ package io.getquill -import io.getquill.context.mirror.{MirrorSession, Row} -import io.getquill.util.PrintMac -import scala.reflect.ClassTag //package io.getquill // @@ -28,7 +25,6 @@ import scala.reflect.ClassTag object FutureTests { val ctx = new MirrorContext(PostgresDialect, Literal) - import ctx._ // case class Person(id: Int, name: Option[String], age: Int) diff --git a/quill-core/src/main/scala/io/getquill/MirrorContext.scala b/quill-core/src/main/scala/io/getquill/MirrorContext.scala index 291a94ad2f..fd3e8e970e 100644 --- a/quill-core/src/main/scala/io/getquill/MirrorContext.scala +++ b/quill-core/src/main/scala/io/getquill/MirrorContext.scala @@ -10,8 +10,8 @@ import scala.util.{Failure, Success, Try} object mirrorContextWithQueryProbing extends MirrorContext(MirrorIdiom, Literal) with QueryProbing -case class BatchActionMirrorGeneric[A](groups: List[(String, List[A])], info: ExecutionInfo) -case class BatchActionReturningMirrorGeneric[T, PrepareRow, Extractor[_]]( +final case class BatchActionMirrorGeneric[A](groups: List[(String, List[A])], info: ExecutionInfo) +final case class BatchActionReturningMirrorGeneric[T, PrepareRow, Extractor[_]]( groups: List[(String, ReturnAction, List[PrepareRow])], extractor: Extractor[T], info: ExecutionInfo @@ -97,17 +97,17 @@ class MirrorContext[+Idiom <: BaseIdiom, +Naming <: NamingStrategy]( def executeQuery[T](string: String, prepare: Prepare = identityPrepare, extractor: Extractor[T] = identityExtractor)( info: ExecutionInfo, dc: Runner - ) = + ): Result[RunQueryResult[T]] = QueryMirror(string, prepare(Row(), session)._2, extractor, info) def executeQuerySingle[T]( string: String, prepare: Prepare = identityPrepare, extractor: Extractor[T] = identityExtractor - )(info: ExecutionInfo, dc: Runner) = + )(info: ExecutionInfo, dc: Runner): Result[RunQuerySingleResult[T]] = QueryMirror(string, prepare(Row(), session)._2, extractor, info) - def executeAction(string: String, prepare: Prepare = identityPrepare)(info: ExecutionInfo, dc: Runner) = + def executeAction(string: String, prepare: Prepare = identityPrepare)(info: ExecutionInfo, dc: Runner): ActionMirror = ActionMirror(string, prepare(Row(), session)._2, info) def executeActionReturning[O]( @@ -115,7 +115,7 @@ class MirrorContext[+Idiom <: BaseIdiom, +Naming <: NamingStrategy]( prepare: Prepare = identityPrepare, extractor: Extractor[O], returningBehavior: ReturnAction - )(info: ExecutionInfo, dc: Runner) = + )(info: ExecutionInfo, dc: Runner): Result[RunActionReturningResult[O]] = ActionReturningMirror[O, O](string, prepare(Row(), session)._2, extractor, returningBehavior, info) def executeActionReturningMany[O]( @@ -123,10 +123,10 @@ class MirrorContext[+Idiom <: BaseIdiom, +Naming <: NamingStrategy]( prepare: Prepare = identityPrepare, extractor: Extractor[O], returningBehavior: ReturnAction - )(info: ExecutionInfo, dc: Runner) = + )(info: ExecutionInfo, dc: Runner): ActionReturningMirror[O,List[O]] = ActionReturningMirror[O, List[O]](string, prepare(Row(), session)._2, extractor, returningBehavior, info) - def executeBatchAction(groups: List[BatchGroup])(info: ExecutionInfo, dc: Runner) = + def executeBatchAction(groups: List[BatchGroup])(info: ExecutionInfo, dc: Runner): BatchActionMirrorGeneric[Row] = BatchActionMirror( groups.map { case BatchGroup(string, prepare) => (string, prepare.map(_(Row(), session)._2)) @@ -146,10 +146,10 @@ class MirrorContext[+Idiom <: BaseIdiom, +Naming <: NamingStrategy]( info ) - def prepareAction(string: String, prepare: Prepare = identityPrepare)(info: ExecutionInfo, dc: Runner) = + def prepareAction(string: String, prepare: Prepare = identityPrepare)(info: ExecutionInfo, dc: Runner): Session => PrepareRow = (session: Session) => prepare(Row(), session)._2 - def prepareBatchAction(groups: List[BatchGroup])(info: ExecutionInfo, dc: Runner) = + def prepareBatchAction(groups: List[BatchGroup])(info: ExecutionInfo, dc: Runner): Session => List[PrepareRow] = (session: Session) => groups.flatMap { case BatchGroup(string, prepare) => prepare.map(_(Row(), session)._2) diff --git a/quill-core/src/main/scala/io/getquill/context/ActionMacro.scala b/quill-core/src/main/scala/io/getquill/context/ActionMacro.scala index 8085933581..9cf6c40955 100644 --- a/quill-core/src/main/scala/io/getquill/context/ActionMacro.scala +++ b/quill-core/src/main/scala/io/getquill/context/ActionMacro.scala @@ -291,7 +291,7 @@ class ActionMacro(val c: MacroContext) extends ContextMacro with ReifyLiftings { object ExtractLiftings { def of(ast: Ast): (Ast, List[(String, ScalarLift)]) = { - val (outputAst, extracted) = ExtractLiftings(List())(ast) + val (outputAst, extracted) = ExtractLiftings(List.empty)(ast) (outputAst, extracted.state.map { case (tag, lift) => (tag.uid, lift) }) } } diff --git a/quill-core/src/main/scala/io/getquill/context/Context.scala b/quill-core/src/main/scala/io/getquill/context/Context.scala index 2627386bd2..3b8e32c437 100644 --- a/quill-core/src/main/scala/io/getquill/context/Context.scala +++ b/quill-core/src/main/scala/io/getquill/context/Context.scala @@ -1,11 +1,9 @@ package io.getquill.context -import com.typesafe.scalalogging.Logger import scala.language.higherKinds import scala.language.experimental.macros import io.getquill.dsl.CoreDsl -import io.getquill.util.ContextLogger import io.getquill.util.Messages.fail import java.io.Closeable @@ -50,7 +48,7 @@ trait Context[+Idiom <: io.getquill.idiom.Idiom, +Naming <: NamingStrategy] numRows: Int ): Result[RunBatchActionReturningResult[T]] = macro ActionMacro.runBatchActionReturningRows[T] - protected def handleSingleResult[T](sql: String, list: List[T]) = + protected def handleSingleResult[T](sql: String, list: List[T]): T = list match { case Nil => fail(s"Expected a single result from the query: `${sql}` but got a empty result-set!") diff --git a/quill-core/src/main/scala/io/getquill/context/ContextMacro.scala b/quill-core/src/main/scala/io/getquill/context/ContextMacro.scala index a1163a5b00..f029f068ff 100644 --- a/quill-core/src/main/scala/io/getquill/context/ContextMacro.scala +++ b/quill-core/src/main/scala/io/getquill/context/ContextMacro.scala @@ -140,7 +140,7 @@ trait ContextMacro extends Quotation { (idiom, n) } - def idiomAndNamingDynamic = + def idiomAndNamingDynamic: Tree = q"(${c.prefix}.idiom, ${c.prefix}.naming)" private def idiomAndNamingStatic = { diff --git a/quill-core/src/main/scala/io/getquill/context/Expand.scala b/quill-core/src/main/scala/io/getquill/context/Expand.scala index 41013154ba..a5e880ae0a 100644 --- a/quill-core/src/main/scala/io/getquill/context/Expand.scala +++ b/quill-core/src/main/scala/io/getquill/context/Expand.scala @@ -4,7 +4,6 @@ import io.getquill.ast._ import io.getquill.NamingStrategy import io.getquill.idiom._ import io.getquill.IdiomContext -import io.getquill.quat.Quat object CanDoBatchedInsert { def apply(ast: Ast, idiom: Idiom, statement: Token, isReturning: Boolean, idiomContext: IdiomContext): Boolean = { @@ -101,7 +100,7 @@ object CanDoBatchedInsert { } } -case class Expand[C <: Context[_, _]]( +final case class Expand[C <: Context[_, _]]( val context: C, val ast: Ast, statement: Statement, @@ -118,11 +117,11 @@ case class Expand[C <: Context[_, _]]( forProbing = false ) - val liftings = externals.collect { case lift: ScalarLift => + val liftings: List[ScalarLift] = externals.collect { case lift: ScalarLift => lift } - val prepare = + val prepare: (context.PrepareRow, context.Session) => (List[Any], context.PrepareRow) = (row: context.PrepareRow, session: context.Session) => { val (_, values, prepare) = liftings.foldLeft((0, List.empty[Any], row)) { case ((idx, values, row), lift) => val encoder = lift.encoder.asInstanceOf[context.Encoder[Any]] @@ -133,7 +132,7 @@ case class Expand[C <: Context[_, _]]( } } -case class ExpandWithInjectables[T, C <: Context[_, _]]( +final case class ExpandWithInjectables[T, C <: Context[_, _]]( val context: C, val ast: Ast, statement: Statement, @@ -154,11 +153,11 @@ case class ExpandWithInjectables[T, C <: Context[_, _]]( injectables ) - val liftings = externals.collect { case lift: ScalarLift => + val liftings: List[ScalarLift] = externals.collect { case lift: ScalarLift => lift } - val prepare = + val prepare: (context.PrepareRow, context.Session) => (List[Any], context.PrepareRow) = (row: context.PrepareRow, session: context.Session) => { val (_, values, prepare) = liftings.foldLeft((0, List.empty[Any], row)) { case ((idx, values, row), lift) => val encoder = lift.encoder.asInstanceOf[context.Encoder[Any]] diff --git a/quill-core/src/main/scala/io/getquill/context/ProbeStatement.scala b/quill-core/src/main/scala/io/getquill/context/ProbeStatement.scala index 0824f31dff..01f5edc3e2 100644 --- a/quill-core/src/main/scala/io/getquill/context/ProbeStatement.scala +++ b/quill-core/src/main/scala/io/getquill/context/ProbeStatement.scala @@ -16,7 +16,7 @@ object ProbeStatement { private val cache = new Cache[Types#Type, Context[Idiom, NamingStrategy]] - def apply(statement: String, c: MacroContext) = { + def apply(statement: String, c: MacroContext): Unit = { import c.universe.{Try => _, _} def resolveContext(tpe: Type) = diff --git a/quill-core/src/main/scala/io/getquill/context/mirror/MirrorDecoders.scala b/quill-core/src/main/scala/io/getquill/context/mirror/MirrorDecoders.scala index d369fb2aa7..eed1c3a9da 100644 --- a/quill-core/src/main/scala/io/getquill/context/mirror/MirrorDecoders.scala +++ b/quill-core/src/main/scala/io/getquill/context/mirror/MirrorDecoders.scala @@ -14,12 +14,12 @@ trait MirrorDecoders { override type Decoder[T] = MirrorDecoder[T] case class MirrorDecoder[T](decoder: BaseDecoder[T]) extends BaseDecoder[T] { - override def apply(index: Index, row: ResultRow, session: Session) = + override def apply(index: Index, row: ResultRow, session: Session): T = decoder(index, row, session) } def decoder[T: ClassTag]: Decoder[T] = - MirrorDecoder { (index: Index, row: ResultRow, session: Session) => + MirrorDecoder { (index: Index, row: ResultRow, _: Session) => val cls = implicitly[ClassTag[T]].runtimeClass if (cls.isPrimitive && row.nullAt(index)) 0.asInstanceOf[T] @@ -30,7 +30,7 @@ trait MirrorDecoders { } def decoderUnsafe[T]: Decoder[T] = - MirrorDecoder((index: Index, row: ResultRow, session: Session) => row.data(index).asInstanceOf[T]) + MirrorDecoder((index: Index, row: ResultRow, _: Session) => row.data(index).asInstanceOf[T]) implicit def mappedDecoder[I, O](implicit mapped: MappedEncoding[I, O], d: Decoder[I]): Decoder[O] = MirrorDecoder((index: Index, row: ResultRow, session: Session) => mapped.f(d.apply(index, row, session))) diff --git a/quill-core/src/main/scala/io/getquill/context/mirror/MirrorEncoders.scala b/quill-core/src/main/scala/io/getquill/context/mirror/MirrorEncoders.scala index 97341e3884..cb1e0e5969 100644 --- a/quill-core/src/main/scala/io/getquill/context/mirror/MirrorEncoders.scala +++ b/quill-core/src/main/scala/io/getquill/context/mirror/MirrorEncoders.scala @@ -14,12 +14,12 @@ trait MirrorEncoders { override type Session = MirrorSession case class MirrorEncoder[T](encoder: BaseEncoder[T]) extends BaseEncoder[T] { - override def apply(index: Index, value: T, row: PrepareRow, session: Session) = + override def apply(index: Index, value: T, row: PrepareRow, session: Session): PrepareRow = encoder(index, value, row, session) } def encoder[T]: Encoder[T] = - MirrorEncoder((index: Index, value: T, row: PrepareRow, session: Session) => row.add(value)) + MirrorEncoder((_: Index, value: T, row: PrepareRow, _: Session) => row.add(value)) implicit def mappedEncoder[I, O](implicit mapped: MappedEncoding[I, O], e: Encoder[O]): Encoder[I] = MirrorEncoder((index: Index, value: I, row: PrepareRow, session: Session) => diff --git a/quill-core/src/main/scala/io/getquill/context/mirror/Row.scala b/quill-core/src/main/scala/io/getquill/context/mirror/Row.scala index 89446ab82c..2b7201737c 100644 --- a/quill-core/src/main/scala/io/getquill/context/mirror/Row.scala +++ b/quill-core/src/main/scala/io/getquill/context/mirror/Row.scala @@ -7,16 +7,16 @@ import scala.reflect.ClassTag * testing. (Note that this must not be in quill-engine or it will conflict with * the io.getquill.context.mirror.Row class in ProtoQuill.) */ -case class Row private (data: List[Any]) { +final case class Row private (data: List[Any]) { // Nulls need a special placeholder so they can be checked via `nullAt`. - def add(value: Any) = + def add(value: Any): Row = value match { case null => new Row((data :+ null)) case _ => new Row((data :+ value)) } def nullAt(index: Int): Boolean = data.apply(index) == null - def apply[T](index: Int)(implicit t: ClassTag[T]) = + def apply[T](index: Int)(implicit t: ClassTag[T]): T = data(index) match { case v: T => v case other => @@ -25,6 +25,6 @@ case class Row private (data: List[Any]) { } object Row { - def apply(data: Any*) = - data.foldLeft(new Row(List()))((r, value) => r.add(value)) + def apply(data: Any*): Row = + data.foldLeft(new Row(List.empty))((r, value) => r.add(value)) } diff --git a/quill-core/src/main/scala/io/getquill/dsl/DynamicQueryDSL.scala b/quill-core/src/main/scala/io/getquill/dsl/DynamicQueryDSL.scala index 4e1806613e..e594ea3572 100644 --- a/quill-core/src/main/scala/io/getquill/dsl/DynamicQueryDSL.scala +++ b/quill-core/src/main/scala/io/getquill/dsl/DynamicQueryDSL.scala @@ -33,7 +33,7 @@ class DynamicQueryDslMacro(val c: MacroContext) { trait DynamicQueryDsl { dsl: CoreDsl => - val quatMaking = new TypeTaggedQuatMaking() { + val quatMaking: TypeTaggedQuatMaking = new TypeTaggedQuatMaking() { import u.typeOf override def quatValueTypes: List[u.Type] = List( @@ -90,7 +90,7 @@ trait DynamicQueryDsl { val quat = quatMaking.inferQuat(t.tpe).probit DynamicEntityQuery( splice[EntityQuery[T]]( - Entity(quat.name, Nil, quat) + Entity(quat.name, List.empty, quat) ) ) } @@ -145,7 +145,7 @@ trait DynamicQueryDsl { )(implicit t: u.TypeTag[T]): DynamicEntityQuery[T] = { val aliases = columns.map { alias => - @tailrec def path(ast: Ast, acc: List[String] = Nil): List[String] = + @tailrec def path(ast: Ast, acc: List[String] = List.empty): List[String] = ast match { case Property(a, name) => path(a, name :: acc) @@ -180,11 +180,11 @@ trait DynamicQueryDsl { override def ast = a } - protected def spliceLift[O](o: O)(implicit enc: Encoder[O]) = + protected def spliceLift[O](o: O)(implicit enc: Encoder[O]): Quoted[O] = splice[O](ScalarValueLift("o", External.Source.Parser, o, enc, Quat.Value)) object DynamicQuery { - def apply[T](p: Quoted[Query[T]]) = + def apply[T](p: Quoted[Query[T]]): DynamicQuery[T] = new DynamicQuery[T] { override def q = p } @@ -198,7 +198,7 @@ trait DynamicQueryDsl { f: Quoted[U] => Quoted[V], t: (Ast, Ident, Ast) => Ast, r: Ast => R = dyn _ - ) = + ): R = withFreshIdent { v => r(t(q.ast, v, f(splice(v)).ast)) }(Quat.Generic) @@ -208,7 +208,7 @@ trait DynamicQueryDsl { f: (Quoted[T], Quoted[O]) => Quoted[R], t: (Quoted[T] => Quoted[R]) => D, thiz: D - )(implicit enc: Encoder[O]) = + )(implicit enc: Encoder[O]): D = opt match { case Some(o) => t(v => f(v, spliceLift(o))) @@ -433,7 +433,7 @@ trait DynamicQueryDsl { } object DynamicAction { - def apply[A <: DslAction[_]](p: Quoted[A]) = + def apply[A <: DslAction[_]](p: Quoted[A]): DynamicAction[A] = new DynamicAction[A] { override val q = p } @@ -446,7 +446,7 @@ trait DynamicQueryDsl { } object DynamicInsert { - def apply[E](p: Quoted[Insert[E]]) = + def apply[E](p: Quoted[Insert[E]]): DynamicInsert[E] = new DynamicInsert[E] { override val q = p } diff --git a/quill-core/src/main/scala/io/getquill/dsl/MetaDslMacro.scala b/quill-core/src/main/scala/io/getquill/dsl/MetaDslMacro.scala index 5b8e5463fe..442fb78556 100644 --- a/quill-core/src/main/scala/io/getquill/dsl/MetaDslMacro.scala +++ b/quill-core/src/main/scala/io/getquill/dsl/MetaDslMacro.scala @@ -92,7 +92,7 @@ class MetaDslMacro(val c: MacroContext) extends ValueComputation { ) } - case class FieldExpansion(lookup: Tree, nullChecker: Tree) + final case class FieldExpansion(lookup: Tree, nullChecker: Tree) def expandRecurse(value: Value): FieldExpansion = value match { diff --git a/quill-core/src/main/scala/io/getquill/dsl/QueryDsl.scala b/quill-core/src/main/scala/io/getquill/dsl/QueryDsl.scala index cad9a25d01..5b3abd0c9f 100644 --- a/quill-core/src/main/scala/io/getquill/dsl/QueryDsl.scala +++ b/quill-core/src/main/scala/io/getquill/dsl/QueryDsl.scala @@ -4,7 +4,6 @@ import scala.language.experimental.macros import io.getquill.quotation.NonQuotedException import io.getquill.EntityQuery -import java.time.{OffsetDateTime, ZonedDateTime} import scala.annotation.compileTimeOnly private[getquill] trait QueryDsl { diff --git a/quill-core/src/main/scala/io/getquill/dsl/ValueComputation.scala b/quill-core/src/main/scala/io/getquill/dsl/ValueComputation.scala index 66a8535802..be00fb71ff 100644 --- a/quill-core/src/main/scala/io/getquill/dsl/ValueComputation.scala +++ b/quill-core/src/main/scala/io/getquill/dsl/ValueComputation.scala @@ -1,7 +1,6 @@ package io.getquill.dsl import scala.reflect.macros.whitebox.{Context => MacroContext} -import io.getquill.Embedded import io.getquill.util.OptionalTypecheck import io.getquill.util.MacroContextExt._ @@ -83,7 +82,7 @@ trait ValueComputation { path(f.body) } - def filter(value: Value, path: List[TermName] = Nil): Option[Value] = + def filter(value: Value, path: List[TermName] = List.empty): Option[Value] = value match { case value if paths.contains(path ++ value.term) => None diff --git a/quill-core/src/main/scala/io/getquill/log/ContextLog.scala b/quill-core/src/main/scala/io/getquill/log/ContextLog.scala index 5bc439c42f..55e39382eb 100644 --- a/quill-core/src/main/scala/io/getquill/log/ContextLog.scala +++ b/quill-core/src/main/scala/io/getquill/log/ContextLog.scala @@ -5,6 +5,6 @@ import io.getquill.util.ContextLogger object ContextLog { private val logger = ContextLogger(this.getClass) - def apply(str: String) = + def apply(str: String): Unit = logger.underlying.error(str) } diff --git a/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala b/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala index 442c6af719..988ccc8ae8 100644 --- a/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala +++ b/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala @@ -78,7 +78,7 @@ trait IOMonad { IO.fromTry(f(r)) } - def lowerFromTry[U](implicit ev: T => Try[U]) = + def lowerFromTry[U](implicit ev: T => Try[U]): IO[U,E] = transform(_.flatMap(ev)) def liftToTry: IO[Try[T], E] = diff --git a/quill-core/src/main/scala/io/getquill/monad/ScalaFutureIOMonad.scala b/quill-core/src/main/scala/io/getquill/monad/ScalaFutureIOMonad.scala index fd6f5bb3cf..7925d0bb74 100644 --- a/quill-core/src/main/scala/io/getquill/monad/ScalaFutureIOMonad.scala +++ b/quill-core/src/main/scala/io/getquill/monad/ScalaFutureIOMonad.scala @@ -33,7 +33,7 @@ trait ScalaFutureIOMonad extends IOMonad { def flatten[Y, M[X] <: IterableOnce[X]]( seq: Sequence[Y, M, Effect] - )(implicit ec: ExecutionContext) = { + )(implicit ec: ExecutionContext): Future[M[Y]] = { val builder = seq.cbfResultToValue.newBuilder seq.in.iterator .foldLeft(Future.successful(builder)) { (fr, ioa) => diff --git a/quill-core/src/main/scala/io/getquill/quat/QuatMaking.scala b/quill-core/src/main/scala/io/getquill/quat/QuatMaking.scala index 7b5adcd0bf..442e4726f9 100644 --- a/quill-core/src/main/scala/io/getquill/quat/QuatMaking.scala +++ b/quill-core/src/main/scala/io/getquill/quat/QuatMaking.scala @@ -94,7 +94,7 @@ object RuntimeEntityQuat { object CaseClass { // Common methods to exclude from object fields - val exclude = classOf[Product].getMethods.map(_.getName).toSet ++ classOf[Object].getMethods.map(_.getName).toSet + val exclude: Set[String] = classOf[Product].getMethods.map(_.getName).toSet ++ classOf[Object].getMethods.map(_.getName).toSet def unapply(cls: Class[_]): Option[List[Method]] = if (cls.getInterfaces.contains(classOf[Product])) { @@ -374,13 +374,13 @@ trait QuatMakingBase extends MacroUtilUniverse { case other => other } - def isNone(tpe: Type) = { + def isNone(tpe: Type): Boolean = { val era = tpe.erasure era =:= typeOf[None.type] } // Note. Used in other places beside here where None needs to be included in option type. - def isOptionType(tpe: Type) = { + def isOptionType(tpe: Type): Boolean = { val era = tpe.erasure era =:= typeOf[Option[Any]] || era =:= typeOf[Some[Any]] || era =:= typeOf[None.type] } diff --git a/quill-core/src/main/scala/io/getquill/quotation/IsDynamic.scala b/quill-core/src/main/scala/io/getquill/quotation/IsDynamic.scala index dabc36ae82..bc047b418b 100644 --- a/quill-core/src/main/scala/io/getquill/quotation/IsDynamic.scala +++ b/quill-core/src/main/scala/io/getquill/quotation/IsDynamic.scala @@ -5,6 +5,6 @@ import io.getquill.ast.CollectAst import io.getquill.ast.Dynamic object IsDynamic { - def apply(a: Ast) = + def apply(a: Ast): Boolean = CollectAst(a) { case d: Dynamic => d }.nonEmpty } diff --git a/quill-core/src/main/scala/io/getquill/quotation/MacroUtilUniverse.scala b/quill-core/src/main/scala/io/getquill/quotation/MacroUtilUniverse.scala index 231ed48b86..a922b5282a 100644 --- a/quill-core/src/main/scala/io/getquill/quotation/MacroUtilUniverse.scala +++ b/quill-core/src/main/scala/io/getquill/quotation/MacroUtilUniverse.scala @@ -18,32 +18,32 @@ trait MacroUtilUniverse { import u.{Block => _, Constant => _, Function => _, Ident => _, If => _, _} object QuotedType { - def unapply(tpe: Type) = + def unapply(tpe: Type): Option[Type] = paramOf(tpe, typeOf[Quoted[Any]]) } object QueryType { - def unapply(tpe: Type) = + def unapply(tpe: Type): Option[Type] = paramOf(tpe, typeOf[io.getquill.Query[Any]]) } object BatchType { - def unapply(tpe: Type) = + def unapply(tpe: Type): Option[Type] = paramOf(tpe, typeOf[io.getquill.BatchAction[_]]) } // Note: These will not match if they are not existential object ActionType { object Insert { - def unapply(tpe: Type) = + def unapply(tpe: Type): Option[Type] = paramOf(tpe, typeOf[io.getquill.Insert[_]]) } object Update { - def unapply(tpe: Type) = + def unapply(tpe: Type): Option[Type] = paramOf(tpe, typeOf[io.getquill.Update[_]]) } object Delete { - def unapply(tpe: Type) = + def unapply(tpe: Type): Option[Type] = paramOf(tpe, typeOf[io.getquill.Delete[_]]) } } diff --git a/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala b/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala index e4b964309e..c0b4a66334 100644 --- a/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala +++ b/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala @@ -2,7 +2,6 @@ package io.getquill.quotation import scala.reflect.ClassTag import io.getquill.ast._ -import io.getquill.Embedded import io.getquill.context._ import io.getquill.norm.{BetaReduction, TypeBehavior} import io.getquill.util.MacroContextExt.RichContext @@ -31,7 +30,7 @@ trait Parsing extends ValueComputation with QuatMaking with MacroUtilBase { case class Parser[T](p: PartialFunction[Tree, T])(implicit ct: ClassTag[T]) { - def apply(tree: Tree) = + def apply(tree: Tree): T = unapply(tree).getOrElse { lazy val errorDetail = if (Messages.errorDetail) @@ -103,7 +102,7 @@ trait Parsing extends ValueComputation with QuatMaking with MacroUtilBase { path.foldLeft(tuple) { case (t, i) => Property(t, s"_${i + 1}") } - def reductions(ast: Ast, path: List[Int] = List()): List[(Ident, Ast)] = + def reductions(ast: Ast, path: List[Int] = List.empty): List[(Ident, Ast)] = ast match { case ident: Ident => List(ident -> property(path)) case Tuple(elems) => @@ -200,8 +199,8 @@ trait Parsing extends ValueComputation with QuatMaking with MacroUtilBase { Entity("unused", Nil, quat) case q"$pack.querySchema[$t](${name: String}, ..$properties)" => - val ttpe = q"$t".tpe - val inferred = inferQuat(q"$t".tpe) + q"$t".tpe + inferQuat(q"$t".tpe) val quat = inferQuat(q"$t".tpe).probit c.warn(VerifyNoBranches.in(quat)) Entity.Opinionated(name, properties.map(propertyAliasParser(_)), quat, Fixed) @@ -378,10 +377,10 @@ trait Parsing extends ValueComputation with QuatMaking with MacroUtilBase { Quat.improveInfixQuat(value) } - val impureInfixParser = combinedInfixParser(false, Quat.Value) // TODO Verify Quat in what cases does this come up? + val impureInfixParser: Parser[Ast] = combinedInfixParser(false, Quat.Value) // TODO Verify Quat in what cases does this come up? object InfixMatch { - def unapply(tree: Tree) = + def unapply(tree: Tree): Option[(List[String], List[Tree])] = tree match { case q"$pack.InfixInterpolator(scala.StringContext.apply(..${parts: List[String]})).infix(..$params)" => Some((parts, params)) @@ -411,7 +410,7 @@ trait Parsing extends ValueComputation with QuatMaking with MacroUtilBase { val fused = (elements - .foldLeft(List[Either[Tree, Tree]]()) { + .foldLeft(List.empty[Either[Tree, Tree]]) { case (Left(a) :: tail, Left(b)) => Left(q"$a + $b") :: tail case (list, b) => @@ -759,7 +758,7 @@ trait Parsing extends ValueComputation with QuatMaking with MacroUtilBase { } private object operator { - def unapply(t: TermName) = + def unapply(t: TermName): Option[BinaryOperator] = t.decodedName.toString match { case ">" => Some(NumericOperator.`>`) case ">=" => Some(NumericOperator.`>=`) @@ -770,7 +769,7 @@ trait Parsing extends ValueComputation with QuatMaking with MacroUtilBase { } private object IsExtensionClass { - def unapply(tree: Tree) = + def unapply(tree: Tree): Option[(Tree, Tree)] = tree match { case cls @ q"$extension($a)" if (cls.tpe.baseClasses.contains(typeOf[Ordered[Any]].typeSymbol)) => Some((extension, a)) @@ -836,11 +835,10 @@ trait Parsing extends ValueComputation with QuatMaking with MacroUtilBase { symbol.isClass && symbol.asClass.isCaseClass } - private def isTypeTuple(tpe: Type) = - tpe.typeSymbol.fullName startsWith "scala.Tuple" + object ClassTypeRefMatch { - def unapply(tpe: Type) = tpe match { + def unapply(tpe: Type): Option[(ClassSymbol, List[Type])] = tpe match { case TypeRef(_, cls, args) if (cls.isClass) => Some((cls.asClass, args)) case _ => None } @@ -963,7 +961,7 @@ trait Parsing extends ValueComputation with QuatMaking with MacroUtilBase { } implicit class InsertReturnCapabilityExtension(capability: ReturningCapability) { - def verifyAst(returnBody: Ast) = capability match { + def verifyAst(returnBody: Ast): Unit = capability match { case OutputClauseSupported => returnBody match { case _: Query => @@ -1231,7 +1229,7 @@ trait Parsing extends ValueComputation with QuatMaking with MacroUtilBase { case false => maybeQuoted case true => q"unquote($maybeQuoted)" } - val t = TypeName(c.freshName("T")) + TypeName(c.freshName("T")) try c.typecheck(unquoted(tree), c.TYPEmode) catch { diff --git a/quill-core/src/main/scala/io/getquill/quotation/QuatUnliftable.scala b/quill-core/src/main/scala/io/getquill/quotation/QuatUnliftable.scala index 76f9fc5c9b..f3b272fdf9 100644 --- a/quill-core/src/main/scala/io/getquill/quotation/QuatUnliftable.scala +++ b/quill-core/src/main/scala/io/getquill/quotation/QuatUnliftable.scala @@ -9,10 +9,10 @@ trait QuatUnliftable { val mctx: Context import mctx.universe.{Constant => _, Function => _, Ident => _, If => _, _} - def unliftQuat(v: Tree) = quatUnliftable.unapply(v).getOrElse(mctx.fail(s"Can't unlift $v")) - def unliftQuats(v: Seq[Tree]) = v.map(unliftQuat(_)) - def unliftString(v: Tree)(implicit u: Unliftable[String]) = u.unapply(v).getOrElse(mctx.fail(s"Can't unlift $v")) - def unliftStrings(v: Seq[Tree])(implicit u: Unliftable[String]) = v.map(unliftString(_)) + def unliftQuat(v: Tree): Quat = quatUnliftable.unapply(v).getOrElse(mctx.fail(s"Can't unlift $v")) + def unliftQuats(v: Seq[Tree]): Seq[Quat] = v.map(unliftQuat(_)) + def unliftString(v: Tree)(implicit u: Unliftable[String]): String = u.unapply(v).getOrElse(mctx.fail(s"Can't unlift $v")) + def unliftStrings(v: Seq[Tree])(implicit u: Unliftable[String]): Seq[String] = v.map(unliftString(_)) implicit val quatProductUnliftable: Unliftable[Quat.Product] = Unliftable[Quat.Product] { // On JVM, a Quat must be serialized and then lifted from the serialized state i.e. as a FromSerialized using JVM (due to 64KB method limit) diff --git a/quill-core/src/main/scala/io/getquill/quotation/Quotation.scala b/quill-core/src/main/scala/io/getquill/quotation/Quotation.scala index 47d8eb1960..7cea52f3ef 100644 --- a/quill-core/src/main/scala/io/getquill/quotation/Quotation.scala +++ b/quill-core/src/main/scala/io/getquill/quotation/Quotation.scala @@ -9,7 +9,7 @@ import io.getquill.norm.BetaReduction import io.getquill.util.Messages.TraceType import io.getquill.util.{EnableReflectiveCalls, Interpolator, Messages} -case class QuotedAst(ast: Ast) extends StaticAnnotation +final case class QuotedAst(ast: Ast) extends StaticAnnotation abstract class LiftUnlift(numQuatFields: Int) extends Liftables with Unliftables { lazy val serializeQuats: Boolean = numQuatFields > Messages.maxQuatFields @@ -21,7 +21,7 @@ trait Quotation extends Parsing with ReifyLiftings { private val quoted = TermName("quoted") - def quote[T](body: Tree)(implicit t: WeakTypeTag[T]) = { + def quote[T](body: Tree)(implicit t: WeakTypeTag[T]): Tree = { val interp = new Interpolator(TraceType.Quotation, transpileConfig.traceConfig, 1) import interp._ @@ -61,18 +61,18 @@ trait Quotation extends Parsing with ReifyLiftings { } } - def doubleQuote[T: WeakTypeTag](body: Expr[Any]) = + def doubleQuote[T: WeakTypeTag](body: Expr[Any]): Tree = body.tree match { case q"null" => c.fail("Can't quote null") case tree => q"${c.prefix}.unquote($tree)" } - def quotedFunctionBody(func: Expr[Any]) = + def quotedFunctionBody(func: Expr[Any]): Tree = func.tree match { case q"(..$p) => $b" => q"${c.prefix}.quote((..$p) => ${c.prefix}.unquote($b))" } - protected def unquote[T](tree: Tree)(implicit ct: ClassTag[T]) = { + protected def unquote[T](tree: Tree)(implicit ct: ClassTag[T]): Option[T] = { val unlift = new { override val mctx: c.type = c } with Unliftables import unlift._ astTree(tree).flatMap(astUnliftable.unapply).map { case ast: T => diff --git a/quill-core/src/main/scala/io/getquill/quotation/ReifyLiftings.scala b/quill-core/src/main/scala/io/getquill/quotation/ReifyLiftings.scala index f9efa5b306..ac510aba14 100644 --- a/quill-core/src/main/scala/io/getquill/quotation/ReifyLiftings.scala +++ b/quill-core/src/main/scala/io/getquill/quotation/ReifyLiftings.scala @@ -12,8 +12,8 @@ import io.getquill.util.{Interpolator, OptionalTypecheck} import io.getquill.util.MacroContextExt._ import io.getquill.util.Messages.TraceType -case class ScalarValueLifting[T, U](value: T, encoder: EncodingDsl#Encoder[U]) -case class CaseClassValueLifting[T](value: T) +final case class ScalarValueLifting[T, U](value: T, encoder: EncodingDsl#Encoder[U]) +final case class CaseClassValueLifting[T](value: T) trait ReifyLiftings extends QuatMaking with TranspileConfigSummoning { val c: MacroContext @@ -80,7 +80,7 @@ trait ReifyLiftings extends QuatMaking with TranspileConfigSummoning { } } - override def apply(ast: Ast) = + override def apply(ast: Ast): (Ast, StatefulTransformer[Map[TermName,Reified]]) = ast match { case ast: Lift => diff --git a/quill-core/src/main/scala/io/getquill/quotation/TranspileConfigSummoning.scala b/quill-core/src/main/scala/io/getquill/quotation/TranspileConfigSummoning.scala index d7c361b26e..a6e2d5372f 100644 --- a/quill-core/src/main/scala/io/getquill/quotation/TranspileConfigSummoning.scala +++ b/quill-core/src/main/scala/io/getquill/quotation/TranspileConfigSummoning.scala @@ -41,7 +41,7 @@ trait TranspileConfigSummoning { foundMemberNames.contains(simpleName) } case None => - List() + List.empty } } @@ -60,21 +60,21 @@ trait TranspileConfigSummoning { foundMemberNames.contains(simpleName) } case None => - List() + List.empty } } private[getquill] def getConfigListMembers(consMember: Type): List[Type] = { val isNil = consMember <:< typeOf[io.getquill.norm.ConfigList.HNil] val isCons = consMember <:< typeOf[io.getquill.norm.ConfigList.::[_, _]] - if (isNil) Nil + if (isNil) List.empty else if (isCons) { val member = consMember.typeArgs(0) val next = consMember.typeArgs(1) member :: getConfigListMembers(next) } else { c.warn(s"Unknown parameter of ConfigList ${consMember} is not a HList Cons or Nil. Ignoring it.") - Nil + List.empty } } diff --git a/quill-core/src/main/scala/io/getquill/util/EnableReflectiveCalls.scala b/quill-core/src/main/scala/io/getquill/util/EnableReflectiveCalls.scala index b4d1484db2..998e99b7ac 100644 --- a/quill-core/src/main/scala/io/getquill/util/EnableReflectiveCalls.scala +++ b/quill-core/src/main/scala/io/getquill/util/EnableReflectiveCalls.scala @@ -1,13 +1,14 @@ package io.getquill.util import scala.reflect.macros.blackbox.Context +import scala.reflect.api.Trees object EnableReflectiveCalls { - def apply(c: Context) = { + def apply(c: Context): List[c.universe.SymTree with Trees.``] = { import c.universe._ q"import _root_.scala.language.reflectiveCalls" :: q"Nil.asInstanceOf[{ def size }].size" :: - Nil + List.empty } } diff --git a/quill-core/src/main/scala/io/getquill/util/NullCheck.scala b/quill-core/src/main/scala/io/getquill/util/NullCheck.scala index 3192a44f80..4eef3835d4 100644 --- a/quill-core/src/main/scala/io/getquill/util/NullCheck.scala +++ b/quill-core/src/main/scala/io/getquill/util/NullCheck.scala @@ -1,5 +1,5 @@ package io.getquill.util object NullCheck { - def product(v: AnyRef) = v == null || v == None + def product(v: AnyRef): Boolean = v == null || v == None } diff --git a/quill-core/src/main/scala/io/getquill/util/OrderedGroupByExt.scala b/quill-core/src/main/scala/io/getquill/util/OrderedGroupByExt.scala index b6943dbec9..245b3c0628 100644 --- a/quill-core/src/main/scala/io/getquill/util/OrderedGroupByExt.scala +++ b/quill-core/src/main/scala/io/getquill/util/OrderedGroupByExt.scala @@ -5,7 +5,7 @@ import collection.mutable.{LinkedHashMap => MMap, Builder} import scala.language.higherKinds object OrderedGroupByExt { - implicit class GroupByOrderedImplicitImpl[A](val t: Traversable[A]) extends AnyVal { + implicit class GroupByOrderedImplicitImpl[A](private val t: Traversable[A]) extends AnyVal { def groupByOrderedUnique[K](f: A => K): Map[K, ListSet[A]] = groupByGen(ListSet.newBuilder[A])(f) diff --git a/quill-core/src/main/scala/io/getquill/util/QueryLogger.scala b/quill-core/src/main/scala/io/getquill/util/QueryLogger.scala index ef3dd20f7e..9acda674c7 100644 --- a/quill-core/src/main/scala/io/getquill/util/QueryLogger.scala +++ b/quill-core/src/main/scala/io/getquill/util/QueryLogger.scala @@ -10,7 +10,7 @@ import java.time.format.DateTimeFormatter class QueryLogger(logToFile: LogToFile) { - val runtime = + val runtime: Option[Runtime.Scoped[Unit]] = Unsafe.unsafe { implicit u => logToFile match { case LogToFile.Enabled(logFile) => diff --git a/quill-doobie/src/main/scala/io/getquill/doobie/DoobieContextBase.scala b/quill-doobie/src/main/scala/io/getquill/doobie/DoobieContextBase.scala index d07f2b5252..481e49e84d 100644 --- a/quill-doobie/src/main/scala/io/getquill/doobie/DoobieContextBase.scala +++ b/quill-doobie/src/main/scala/io/getquill/doobie/DoobieContextBase.scala @@ -206,7 +206,7 @@ trait DoobieContextBase[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] ex: Extractor[A] )(implicit connection: Connection - ): Read[A] = new Read[A](Nil, (rs, _) => ex(rs, connection)) + ): Read[A] = new Read[A](List.empty, (rs, _) => ex(rs, connection)) // Nothing to do here. override def close(): Unit = () diff --git a/quill-engine/src/main/scala/io/getquill/AstPrinter.scala b/quill-engine/src/main/scala/io/getquill/AstPrinter.scala index f6a13a6897..be65f4c268 100644 --- a/quill-engine/src/main/scala/io/getquill/AstPrinter.scala +++ b/quill-engine/src/main/scala/io/getquill/AstPrinter.scala @@ -27,7 +27,7 @@ class AstPrinter(traceOpinions: Boolean, traceAstSimple: Boolean, traceQuats: Qu val escapeUnicode = false val showFieldNames = false - val traceAllQuats = traceQuats == QuatTrace.All + val traceAllQuats: Boolean = traceQuats == QuatTrace.All private def printRenameable(r: Renameable) = r match { @@ -60,7 +60,7 @@ class AstPrinter(traceOpinions: Boolean, traceAstSimple: Boolean, traceQuats: Qu traceQuats match { case QuatTrace.Full | QuatTrace.All => List(Tree.Literal(e.q.shortString)) case QuatTrace.Short => List(Tree.Literal(e.q.shortString.take(10))) - case QuatTrace.None => List() + case QuatTrace.None => List.empty } case treemake.Elem(value) => List(treeify(value, escapeUnicode, showFieldNames)) case treemake.Tree(value) => List(value) @@ -73,7 +73,7 @@ class AstPrinter(traceOpinions: Boolean, traceAstSimple: Boolean, traceQuats: Qu private case class Elem(any: Any) extends treemake private case class Tree(any: pprint.Tree) extends treemake private case class Content(list: List[treemake]) extends treemake { - def andWith(elem: treemake) = + def andWith(elem: treemake): Content = elem match { case c: Content => Content(list ++ c.list) case other => Content(list :+ other) @@ -98,15 +98,15 @@ class AstPrinter(traceOpinions: Boolean, traceAstSimple: Boolean, traceQuats: Qu if (traceOpinions) List(printVisibility(i.visibility)) else - List() + List.empty )).iterator ) case i: Infix => val content = - List(i.parts.toList, i.params.toList) ++ (if (i.pure) List("pure") else List()) ++ (if (i.transparent) + List(i.parts.toList, i.params.toList) ++ (if (i.pure) List("pure") else List.empty) ++ (if (i.transparent) List("transparent") - else List()) + else List.empty) Tree.Apply("Infix", treemake(content: _*).withQuat(i.bestQuat).make) case e: Entity if (!traceOpinions) => diff --git a/quill-engine/src/main/scala/io/getquill/H2Dialect.scala b/quill-engine/src/main/scala/io/getquill/H2Dialect.scala index 8d2476645d..1c7858bfb3 100644 --- a/quill-engine/src/main/scala/io/getquill/H2Dialect.scala +++ b/quill-engine/src/main/scala/io/getquill/H2Dialect.scala @@ -20,7 +20,7 @@ trait H2Dialect private[getquill] val preparedStatementId = new AtomicInteger - override def prepareForProbing(string: String) = + override def prepareForProbing(string: String): String = s"PREPARE p${preparedStatementId.incrementAndGet.toString.token} AS $string}" override def astTokenizer(implicit diff --git a/quill-engine/src/main/scala/io/getquill/IdiomContext.scala b/quill-engine/src/main/scala/io/getquill/IdiomContext.scala index 3f9aced955..3d934439e3 100644 --- a/quill-engine/src/main/scala/io/getquill/IdiomContext.scala +++ b/quill-engine/src/main/scala/io/getquill/IdiomContext.scala @@ -4,12 +4,12 @@ import io.getquill.ast.{Ast, CollectAst} import io.getquill.norm.TranspileConfig import io.getquill.ast -case class IdiomContext(config: TranspileConfig, queryType: IdiomContext.QueryType) { +final case class IdiomContext(config: TranspileConfig, queryType: IdiomContext.QueryType) { def traceConfig = config.traceConfig } object IdiomContext { - def Empty = IdiomContext(TranspileConfig.Empty, QueryType.Insert) + def Empty: IdiomContext = IdiomContext(TranspileConfig.Empty, QueryType.Insert) sealed trait QueryType { def isBatch: Boolean def batchAlias: Option[String] @@ -20,8 +20,8 @@ object IdiomContext { case object Update extends Regular case object Delete extends Regular - case class BatchInsert(foreachAlias: String) extends Batch { val batchAlias = Some(foreachAlias) } - case class BatchUpdate(foreachAlias: String) extends Batch { val batchAlias = Some(foreachAlias) } + final case class BatchInsert(foreachAlias: String) extends Batch { val batchAlias: Some[String] = Some(foreachAlias) } + final case class BatchUpdate(foreachAlias: String) extends Batch { val batchAlias: Some[String] = Some(foreachAlias) } sealed trait Regular extends QueryType { val isBatch = false; val batchAlias = None } sealed trait Batch extends QueryType { val isBatch = true } @@ -35,7 +35,7 @@ object IdiomContext { } object Batch { - def unapply(qt: QueryType) = + def unapply(qt: QueryType): Option[String] = qt match { case BatchInsert(foreachAlias) => Some(foreachAlias) case BatchUpdate(foreachAlias) => Some(foreachAlias) diff --git a/quill-engine/src/main/scala/io/getquill/MappedEncoding.scala b/quill-engine/src/main/scala/io/getquill/MappedEncoding.scala index f11638a89b..7d791458e1 100644 --- a/quill-engine/src/main/scala/io/getquill/MappedEncoding.scala +++ b/quill-engine/src/main/scala/io/getquill/MappedEncoding.scala @@ -1,3 +1,3 @@ package io.getquill -case class MappedEncoding[I, O](f: I => O) +final case class MappedEncoding[I, O](f: I => O) diff --git a/quill-engine/src/main/scala/io/getquill/MirrorIdiom.scala b/quill-engine/src/main/scala/io/getquill/MirrorIdiom.scala index 2004e6deef..e29265db0e 100644 --- a/quill-engine/src/main/scala/io/getquill/MirrorIdiom.scala +++ b/quill-engine/src/main/scala/io/getquill/MirrorIdiom.scala @@ -215,13 +215,13 @@ trait MirrorIdiomBase extends Idiom { case o => stmt"${o.toString.token}" } - def tokenizeName(name: String, renameable: Renameable) = + def tokenizeName(name: String, renameable: Renameable): String = renameable match { case ByStrategy => name case Fixed => s"`${name}`" } - def bracketIfHidden(name: String, visibility: Visibility) = + def bracketIfHidden(name: String, visibility: Visibility): String = (distinguishHidden, visibility) match { case (true, Hidden) => s"[$name]" case _ => name diff --git a/quill-engine/src/main/scala/io/getquill/Model.scala b/quill-engine/src/main/scala/io/getquill/Model.scala index 74455be279..9a3d2d2ebe 100644 --- a/quill-engine/src/main/scala/io/getquill/Model.scala +++ b/quill-engine/src/main/scala/io/getquill/Model.scala @@ -1,6 +1,5 @@ package io.getquill -import io.getquill.ast.Ast import io.getquill.quotation.NonQuotedException import scala.annotation.compileTimeOnly diff --git a/quill-engine/src/main/scala/io/getquill/MySQLDialect.scala b/quill-engine/src/main/scala/io/getquill/MySQLDialect.scala index 5935220f3f..14130d049d 100644 --- a/quill-engine/src/main/scala/io/getquill/MySQLDialect.scala +++ b/quill-engine/src/main/scala/io/getquill/MySQLDialect.scala @@ -19,12 +19,12 @@ trait MySQLDialect override def useActionTableAliasAs: ActionTableAliasBehavior = ActionTableAliasBehavior.SkipAs - override def prepareForProbing(string: String) = { + override def prepareForProbing(string: String): String = { val quoted = string.replace("'", "\\'") s"PREPARE p${quoted.hashCode.abs.toString.token} FROM '$quoted'" } - override def defaultAutoGeneratedToken(field: Token) = stmt"($field) VALUES (DEFAULT)" + override def defaultAutoGeneratedToken(field: Token): Statement = stmt"($field) VALUES (DEFAULT)" override def astTokenizer(implicit astTokenizer: Tokenizer[Ast], @@ -100,7 +100,7 @@ trait MySQLDialect override protected def limitOffsetToken( query: Statement - )(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy) = + )(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy): Tokenizer[(Option[Ast], Option[Ast])] = Tokenizer[(Option[Ast], Option[Ast])] { case (None, Some(offset)) => stmt"$query LIMIT 18446744073709551610 OFFSET ${offset.token}" case other => super.limitOffsetToken(query).token(other) diff --git a/quill-engine/src/main/scala/io/getquill/NamingStrategy.scala b/quill-engine/src/main/scala/io/getquill/NamingStrategy.scala index 6c0c726725..27d951f7ab 100644 --- a/quill-engine/src/main/scala/io/getquill/NamingStrategy.scala +++ b/quill-engine/src/main/scala/io/getquill/NamingStrategy.scala @@ -9,32 +9,32 @@ trait NamingStrategy { trait CompositeNamingStrategy extends NamingStrategy { protected val elements: List[NamingStrategy] - override def default(s: String) = + override def default(s: String): String = elements.foldLeft(s)((s, n) => n.default(s)) - override def table(s: String) = + override def table(s: String): String = elements.foldLeft(s)((s, n) => n.table(s)) - override def column(s: String) = + override def column(s: String): String = elements.foldLeft(s)((s, n) => n.column(s)) } -case class CompositeNamingStrategy2[N1 <: NamingStrategy, N2 <: NamingStrategy]( +final case class CompositeNamingStrategy2[N1 <: NamingStrategy, N2 <: NamingStrategy]( n1: N1, n2: N2 ) extends CompositeNamingStrategy { - override protected val elements = List(n1, n2) + override protected val elements: List[NamingStrategy] = List(n1, n2) } -case class CompositeNamingStrategy3[N1 <: NamingStrategy, N2 <: NamingStrategy, N3 <: NamingStrategy]( +final case class CompositeNamingStrategy3[N1 <: NamingStrategy, N2 <: NamingStrategy, N3 <: NamingStrategy]( n1: N1, n2: N2, n3: N3 ) extends CompositeNamingStrategy { - override protected val elements = List(n1, n2, n3) + override protected val elements: List[NamingStrategy] = List(n1, n2, n3) } -case class CompositeNamingStrategy4[ +final case class CompositeNamingStrategy4[ N1 <: NamingStrategy, N2 <: NamingStrategy, N3 <: NamingStrategy, @@ -45,7 +45,7 @@ case class CompositeNamingStrategy4[ n3: N3, n4: N4 ) extends CompositeNamingStrategy { - override protected val elements = List(n1, n2, n3, n4) + override protected val elements: List[NamingStrategy] = List(n1, n2, n3, n4) } object NamingStrategy { @@ -86,7 +86,7 @@ trait Literal extends NamingStrategy { object Literal extends Literal trait Escape extends NamingStrategy { - override def default(s: String) = + override def default(s: String): String = s""""$s"""" } object Escape extends Escape @@ -105,7 +105,7 @@ object LowerCase extends LowerCase trait SnakeCase extends NamingStrategy { - override def default(s: String) = + override def default(s: String): String = (s.toList match { case c :: tail => c.toLower +: snakeCase(tail) case Nil => Nil @@ -122,7 +122,7 @@ object SnakeCase extends SnakeCase trait CamelCase extends NamingStrategy { - override def default(s: String) = + override def default(s: String): String = camelCase(s.toList).mkString private def camelCase(s: List[Char]): List[Char] = @@ -138,20 +138,20 @@ object CamelCase extends CamelCase trait PluralizedTableNames extends NamingStrategy { override def default(s: String) = s - override def table(s: String) = + override def table(s: String): String = if (s.endsWith("s")) s else s + "s" } object PluralizedTableNames extends PluralizedTableNames trait PostgresEscape extends Escape { - override def column(s: String) = if (s.startsWith("$")) s else super.column(s) + override def column(s: String): String = if (s.startsWith("$")) s else super.column(s) } object PostgresEscape extends PostgresEscape trait MysqlEscape extends NamingStrategy { - override def table(s: String) = quote(s) - override def column(s: String) = quote(s) + override def table(s: String): String = quote(s) + override def column(s: String): String = quote(s) override def default(s: String) = s private def quote(s: String) = s"`$s`" } diff --git a/quill-engine/src/main/scala/io/getquill/OracleDialect.scala b/quill-engine/src/main/scala/io/getquill/OracleDialect.scala index efff0fb629..29ae5c50b7 100644 --- a/quill-engine/src/main/scala/io/getquill/OracleDialect.scala +++ b/quill-engine/src/main/scala/io/getquill/OracleDialect.scala @@ -50,11 +50,11 @@ trait OracleDialect override def concatBehavior: ConcatBehavior = NonAnsiConcat - override def emptySetContainsToken(field: Token) = StringToken("1 <> 1") + override def emptySetContainsToken(field: Token): StringToken = StringToken("1 <> 1") override protected def limitOffsetToken( query: Statement - )(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy) = + )(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy): Tokenizer[(Option[Ast], Option[Ast])] = Tokenizer[(Option[Ast], Option[Ast])] { case (Some(limit), None) => stmt"$query FETCH FIRST ${limit.token} ROWS ONLY" case (Some(limit), Some(offset)) => stmt"$query OFFSET ${offset.token} ROWS FETCH NEXT ${limit.token} ROWS ONLY" @@ -96,7 +96,7 @@ trait OracleDialect case None => strategy.column(columnOrTable) } - override def defaultAutoGeneratedToken(field: Token) = stmt"($field) VALUES (DEFAULT)" + override def defaultAutoGeneratedToken(field: Token): Statement = stmt"($field) VALUES (DEFAULT)" override def prepareForProbing(string: String) = string } diff --git a/quill-engine/src/main/scala/io/getquill/OrdModel.scala b/quill-engine/src/main/scala/io/getquill/OrdModel.scala index 6a7bea65d0..e9497494cf 100644 --- a/quill-engine/src/main/scala/io/getquill/OrdModel.scala +++ b/quill-engine/src/main/scala/io/getquill/OrdModel.scala @@ -2,7 +2,7 @@ package io.getquill import io.getquill.ast.{Asc, AscNullsFirst, AscNullsLast, Desc, DescNullsFirst, DescNullsLast, Ordering, TupleOrdering} -case class Ord[T](ord: Ordering) +final case class Ord[T](ord: Ordering) object Ord { diff --git a/quill-engine/src/main/scala/io/getquill/PostgresDialect.scala b/quill-engine/src/main/scala/io/getquill/PostgresDialect.scala index 71fac8ea39..8ba25431dd 100644 --- a/quill-engine/src/main/scala/io/getquill/PostgresDialect.scala +++ b/quill-engine/src/main/scala/io/getquill/PostgresDialect.scala @@ -1,21 +1,19 @@ package io.getquill import java.util.concurrent.atomic.AtomicInteger -import io.getquill.ast.{Action, Query, _} +import io.getquill.ast._ import io.getquill.ast -import io.getquill.context.sql.idiom -import io.getquill.context.sql.idiom.SqlIdiom.{InsertUpdateStmt, copyIdiom} import io.getquill.context.{CanInsertReturningWithMultiValues, CanInsertWithMultiValues, CanReturnClause} import io.getquill.context.sql.idiom._ -import io.getquill.idiom.{ScalarTagToken, Statement, Token, ValuesClauseToken} +import io.getquill.idiom.{Statement, ValuesClauseToken} import io.getquill.idiom.StatementInterpolator._ -import io.getquill.norm.{BetaReduction, ExpandReturning, ProductAggregationToken} -import io.getquill.quat.Quat +import io.getquill.norm.{BetaReduction, ProductAggregationToken} import io.getquill.sql.norm.NormalizeFilteredActionAliases import io.getquill.util.Messages.fail import scala.annotation.tailrec -import scala.collection.immutable.{ListMap, ListSet, Queue} +import scala.collection.immutable.ListMap +import scala.collection.immutable trait PostgresDialect extends SqlIdiom @@ -51,7 +49,7 @@ trait PostgresDialect private[getquill] val preparedStatementId = new AtomicInteger - override def prepareForProbing(string: String) = { + override def prepareForProbing(string: String): String = { var i = 0 val query = string.flatMap(x => if (x != '?') s"$x" @@ -112,7 +110,7 @@ trait PostgresDialect astTokenizer: Tokenizer[Ast], strategy: NamingStrategy, idiomContext: IdiomContext - ) = + ): Tokenizer[Ast] = Tokenizer.withFallback[Ast](this.astTokenizer(_, strategy, idiomContext)) { case p: Property => this.propertyTokenizer.token(p) } @@ -178,7 +176,7 @@ trait PostgresDialect // Originally was `WHERE ps.id = STag(uid:3)` // (replacedWhere: `WHERE ps.id = p.id1`, additionalColumns: [id] /*and any other column names of STags in WHERE*/, additionalLifts: [STag(uid:3)]) val (Update(Filter(table: Entity, tableAlias, replacedWhere), assignments), valuesColumns, valuesLifts) = - ReplaceLiftings.of(clause)(batchAlias, List()) + ReplaceLiftings.of(clause)(batchAlias, List.empty) if (valuesLifts.nonEmpty) { // The SET columns/values i.e. ([name, id], [STag(uid:1), STag(uid:2)] val columnsAndValues = columnsAndValuesTogether(assignments) @@ -197,7 +195,7 @@ trait PostgresDialect case (clause @ Update(_: Entity, _), IdiomContext.QueryType.Batch(batchAlias)) => val (Update(table: Entity, assignments), valuesColumns, valuesLifts) = - ReplaceLiftings.of(clause)(batchAlias, List()) + ReplaceLiftings.of(clause)(batchAlias, List.empty) // Choose table alias based on how assignments clauses were realized. Batch-Alias should mean the same thing as when NormalizeFilteredActionAliases was run in Idiom should the // value should be the same thing as the clauses that were realiased. @@ -222,12 +220,12 @@ trait PostgresDialect object PostgresDialect extends PostgresDialect -case class ReplaceAssignmentAliases(newAlias: Ident) extends StatelessTransformer { +final case class ReplaceAssignmentAliases(newAlias: Ident) extends StatelessTransformer { override def apply(e: Assignment): Assignment = Assignment(newAlias, BetaReduction(e.property, e.alias -> newAlias), BetaReduction(e.value, e.alias -> newAlias)) } -case class ReplaceLiftings( +final case class ReplaceLiftings( foreachIdentName: String, existingColumnNames: List[String], state: ListMap[String, ScalarTag] @@ -236,7 +234,7 @@ case class ReplaceLiftings( private def columnExists(col: String) = existingColumnNames.contains(col) || state.keySet.contains(col) - def freshIdent(newCol: String) = { + def freshIdent(newCol: String): String = { @tailrec def loop(id: String, n: Int): String = { val fresh = s"${id}${n}" @@ -251,8 +249,7 @@ case class ReplaceLiftings( loop(newCol, 1) } - private def parseName(name: String) = - name.replace(".", "_") + override def apply(e: Ast): (Ast, StatefulTransformer[ListMap[String, ScalarTag]]) = e match { @@ -267,7 +264,7 @@ case class ReplaceLiftings( } } object ReplaceLiftings { - def of(ast: Ast)(foreachIdent: String, existingColumnNames: List[String]) = { + def of(ast: Ast)(foreachIdent: String, existingColumnNames: List[String]): (Ast, immutable.Iterable[String], immutable.Iterable[ScalarTag]) = { val (newAst, transform) = new ReplaceLiftings(foreachIdent, existingColumnNames, ListMap()).apply(ast) (newAst, transform.state.map(_._1), transform.state.map(_._2)) } diff --git a/quill-engine/src/main/scala/io/getquill/ReturnAction.scala b/quill-engine/src/main/scala/io/getquill/ReturnAction.scala index bb6d09d129..f17a3c6ab0 100644 --- a/quill-engine/src/main/scala/io/getquill/ReturnAction.scala +++ b/quill-engine/src/main/scala/io/getquill/ReturnAction.scala @@ -3,6 +3,6 @@ package io.getquill sealed trait ReturnAction object ReturnAction { case object ReturnNothing extends ReturnAction - case class ReturnColumns(columns: List[String]) extends ReturnAction + final case class ReturnColumns(columns: List[String]) extends ReturnAction case object ReturnRecord extends ReturnAction } diff --git a/quill-engine/src/main/scala/io/getquill/SQLServerDialect.scala b/quill-engine/src/main/scala/io/getquill/SQLServerDialect.scala index 4e3b5bdde9..cdee4215e4 100644 --- a/quill-engine/src/main/scala/io/getquill/SQLServerDialect.scala +++ b/quill-engine/src/main/scala/io/getquill/SQLServerDialect.scala @@ -25,11 +25,11 @@ trait SQLServerDialect override def useActionTableAliasAs: ActionTableAliasBehavior = ActionTableAliasBehavior.Hide - override def querifyAst(ast: Ast, idiomContext: TraceConfig) = AddDropToNestedOrderBy( + override def querifyAst(ast: Ast, idiomContext: TraceConfig): SqlQuery = AddDropToNestedOrderBy( new SqlQueryApply(idiomContext)(ast) ) - override def emptySetContainsToken(field: Token) = StringToken("1 <> 1") + override def emptySetContainsToken(field: Token): StringToken = StringToken("1 <> 1") override def prepareForProbing(string: String) = string @@ -39,7 +39,7 @@ trait SQLServerDialect override protected def limitOffsetToken( query: Statement - )(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy) = + )(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy): Tokenizer[(Option[Ast], Option[Ast])] = Tokenizer[(Option[Ast], Option[Ast])] { case (Some(limit), None) => stmt"TOP (${limit.token}) $query" case (Some(limit), Some(offset)) => stmt"$query OFFSET ${offset.token} ROWS FETCH FIRST ${limit.token} ROWS ONLY" diff --git a/quill-engine/src/main/scala/io/getquill/SqliteDialect.scala b/quill-engine/src/main/scala/io/getquill/SqliteDialect.scala index d66220abe2..f773fee281 100644 --- a/quill-engine/src/main/scala/io/getquill/SqliteDialect.scala +++ b/quill-engine/src/main/scala/io/getquill/SqliteDialect.scala @@ -17,9 +17,9 @@ trait SqliteDialect with CanInsertWithMultiValues with CanInsertReturningWithSingleValue { - override def emptySetContainsToken(field: Token) = StringToken("0") + override def emptySetContainsToken(field: Token): StringToken = StringToken("0") - override def prepareForProbing(string: String) = s"sqlite3_prepare_v2($string)" + override def prepareForProbing(string: String): String = s"sqlite3_prepare_v2($string)" override def astTokenizer(implicit astTokenizer: Tokenizer[Ast], diff --git a/quill-engine/src/main/scala/io/getquill/ast/Ast.scala b/quill-engine/src/main/scala/io/getquill/ast/Ast.scala index 9ae9a5715e..1a0b423f7b 100644 --- a/quill-engine/src/main/scala/io/getquill/ast/Ast.scala +++ b/quill-engine/src/main/scala/io/getquill/ast/Ast.scala @@ -22,7 +22,7 @@ sealed trait Ast { case l: CaseClassQueryLift => l.quat.countFields }.sum - override def toString = { + override def toString: String = { import io.getquill.MirrorIdiom._ import io.getquill.idiom.StatementInterpolator._ implicit def externalTokenizer: Tokenizer[External] = @@ -34,7 +34,7 @@ sealed trait Ast { object Ast { object LeafQuat { - def unapply(ast: Ast) = + def unapply(ast: Ast): Option[Ast] = if (!ast.quat.isInstanceOf[Quat.Product]) Some(ast) else @@ -95,16 +95,16 @@ final class Entity(val name: String, val properties: List[PropertyAlias])(theQua name: String = this.name, properties: List[PropertyAlias] = this.properties, quat: Quat.Product = this.quat - ) = + ): Entity = Entity.Opinionated(name, properties, quat, this.renameable) - override def equals(that: Any) = + override def equals(that: Any): Boolean = that match { case e: Entity => this.id == e.id case _ => false } - override def hashCode = id.hashCode() + override def hashCode: Int = id.hashCode() def syncToQuat: Entity = { import io.getquill.quat.QuatOps.Implicits._ @@ -130,12 +130,12 @@ final class Entity(val name: String, val properties: List[PropertyAlias])(theQua } object Entity { - private case class Id(name: String, properties: List[PropertyAlias]) + final private case class Id(name: String, properties: List[PropertyAlias]) def apply(name: String, properties: List[PropertyAlias], quat: => Quat.Product): Entity = new Entity(name, properties)(quat)(Renameable.neutral) - def unapply(e: Entity) = Some((e.name, e.properties, e.quat)) + def unapply(e: Entity): Some[(String, List[PropertyAlias], Quat.Product)] = Some((e.name, e.properties, e.quat)) object Opinionated { def apply( @@ -146,34 +146,34 @@ object Entity { ): Entity = new Entity(name, properties)(quat)(renameableNew) - def unapply(e: Entity) = + def unapply(e: Entity): Some[(String, List[PropertyAlias], Quat.Product, Renameable)] = Some((e.name, e.properties, e.quat, e.renameable)) } } -case class PropertyAlias(path: List[String], alias: String) +final case class PropertyAlias(path: List[String], alias: String) -case class Filter(query: Ast, alias: Ident, body: Ast) extends Query { +final case class Filter(query: Ast, alias: Ident, body: Ast) extends Query { def quat = query.quat def bestQuat: Quat = query.bestQuat } -case class Map(query: Ast, alias: Ident, body: Ast) extends Query { +final case class Map(query: Ast, alias: Ident, body: Ast) extends Query { def quat = body.quat def bestQuat: Quat = body.bestQuat } -case class FlatMap(query: Ast, alias: Ident, body: Ast) extends Query { +final case class FlatMap(query: Ast, alias: Ident, body: Ast) extends Query { def quat = body.quat def bestQuat: Quat = body.bestQuat } -case class ConcatMap(query: Ast, alias: Ident, body: Ast) extends Query { +final case class ConcatMap(query: Ast, alias: Ident, body: Ast) extends Query { def quat = body.quat def bestQuat: Quat = body.bestQuat } -case class SortBy(query: Ast, alias: Ident, criteria: Ast, ordering: Ast) extends Query { +final case class SortBy(query: Ast, alias: Ident, criteria: Ast, ordering: Ast) extends Query { def quat = query.quat def bestQuat: Quat = query.bestQuat } @@ -182,7 +182,7 @@ sealed trait Ordering extends Ast { def quat = Quat.Value def bestQuat: Quat = quat } -case class TupleOrdering(elems: List[Ordering]) extends Ordering +final case class TupleOrdering(elems: List[Ordering]) extends Ordering sealed trait PropertyOrdering extends Ordering case object Asc extends PropertyOrdering @@ -192,18 +192,18 @@ case object DescNullsFirst extends PropertyOrdering case object AscNullsLast extends PropertyOrdering case object DescNullsLast extends PropertyOrdering -case class GroupBy(query: Ast, alias: Ident, body: Ast) extends Query { - def quat = Quat.Tuple(body.quat, query.quat) +final case class GroupBy(query: Ast, alias: Ident, body: Ast) extends Query { + def quat: Quat.Product = Quat.Tuple(body.quat, query.quat) def bestQuat: Quat = Quat.Tuple(body.bestQuat, query.bestQuat) } -case class GroupByMap(query: Ast, byAlias: Ident, byBody: Ast, mapAlias: Ident, mapBody: Ast) extends Query { +final case class GroupByMap(query: Ast, byAlias: Ident, byBody: Ast, mapAlias: Ident, mapBody: Ast) extends Query { def quat = mapBody.quat def bestQuat: Quat = mapBody.bestQuat } -case class Aggregation(operator: AggregationOperator, ast: Ast) extends Query { - def quat = +final case class Aggregation(operator: AggregationOperator, ast: Ast) extends Query { + def quat: Quat = operator match { case AggregationOperator.`min` => ast.quat case AggregationOperator.`max` => ast.quat @@ -221,27 +221,27 @@ case class Aggregation(operator: AggregationOperator, ast: Ast) extends Query { } } -case class Take(query: Ast, n: Ast) extends Query { +final case class Take(query: Ast, n: Ast) extends Query { def quat = query.quat def bestQuat: Quat = query.bestQuat } -case class Drop(query: Ast, n: Ast) extends Query { +final case class Drop(query: Ast, n: Ast) extends Query { def quat = query.quat def bestQuat: Quat = query.bestQuat } -case class Union(a: Ast, b: Ast) extends Query { +final case class Union(a: Ast, b: Ast) extends Query { def quat = a.quat def bestQuat: Quat = a.bestQuat } // a and b quats should be same -case class UnionAll(a: Ast, b: Ast) extends Query { +final case class UnionAll(a: Ast, b: Ast) extends Query { def quat = a.quat def bestQuat: Quat = a.bestQuat } // a and b quats should be same -case class Join( +final case class Join( typ: JoinType, a: Ast, b: Ast, @@ -249,26 +249,26 @@ case class Join( aliasB: Ident, on: Ast ) extends Query { - def quat = Quat.Tuple(a.quat, b.quat) + def quat: Quat.Product = Quat.Tuple(a.quat, b.quat) def bestQuat: Quat = Quat.Tuple(a.bestQuat, b.bestQuat) } -case class FlatJoin(typ: JoinType, a: Ast, aliasA: Ident, on: Ast) extends Query { +final case class FlatJoin(typ: JoinType, a: Ast, aliasA: Ident, on: Ast) extends Query { def quat = a.quat def bestQuat: Quat = a.bestQuat } -case class Distinct(a: Ast) extends Query { +final case class Distinct(a: Ast) extends Query { def quat = a.quat def bestQuat: Quat = a.bestQuat } -case class DistinctOn(query: Ast, alias: Ident, body: Ast) extends Query { +final case class DistinctOn(query: Ast, alias: Ident, body: Ast) extends Query { def quat = query.quat def bestQuat: Quat = query.bestQuat } -case class Nested(a: Ast) extends Query { +final case class Nested(a: Ast) extends Query { def quat = a.quat def bestQuat: Quat = a.bestQuat } @@ -284,32 +284,32 @@ final class Infix(val parts: List[String], val params: List[Ast], val pure: Bool def asTransparent = new Infix(this.parts, this.params, this.pure, true)(theQuat) - override def equals(that: Any) = + override def equals(that: Any): Boolean = that match { case p: Infix => this.id == p.id case _ => false } - override def hashCode = id.hashCode() + override def hashCode: Int = id.hashCode() def copy( parts: List[String] = this.parts, params: List[Ast] = this.params, pure: Boolean = this.pure, transparent: Boolean = this.transparent, quat: Quat = this.quat - ) = + ): Infix = Infix(parts, params, pure, transparent, quat) } object Infix { - private case class Id(val parts: List[String], val params: List[Ast], val pure: Boolean, val transparent: Boolean) + final private case class Id(val parts: List[String], val params: List[Ast], val pure: Boolean, val transparent: Boolean) def apply(parts: List[String], params: List[Ast], pure: Boolean, transparent: Boolean, quat: => Quat) = new Infix(parts, params, pure, transparent)(quat) - def unapply(i: Infix) = Some((i.parts, i.params, i.pure, i.transparent, i.quat)) + def unapply(i: Infix): Some[(List[String], List[Ast], Boolean, Boolean, Quat)] = Some((i.parts, i.params, i.pure, i.transparent, i.quat)) } -case class Function(params: List[Ident], body: Ast) extends Ast { +final case class Function(params: List[Ident], body: Ast) extends Ast { def quat = body.quat def bestQuat: Quat = body.bestQuat } @@ -321,13 +321,13 @@ final class Ident private (val name: String)(theQuat: => Quat)(val visibility: V private val id = Ident.Id(name) - override def equals(that: Any) = + override def equals(that: Any): Boolean = that match { case p: Ident => this.id == p.id case _ => false } - override def hashCode = id.hashCode() + override def hashCode: Int = id.hashCode() override def withQuat(quat: => Quat): Ident = Ident.Opinionated(this.name, quat, this.visibility) @@ -352,14 +352,14 @@ final class Ident private (val name: String)(theQuat: => Quat)(val visibility: V * ExpandNestedQueries phase, needs to be marked invisible. */ object Ident { - private case class Id(name: String) + final private case class Id(name: String) def apply(name: String, quat: => Quat = Quat.Value) = new Ident(name)(quat)(Visibility.Visible) - def unapply(p: Ident) = Some((p.name, p.quat)) + def unapply(p: Ident): Some[(String, Quat)] = Some((p.name, p.quat)) object Opinionated { def apply(name: String, quatNew: => Quat, visibilityNew: Visibility) = new Ident(name)(quatNew)(visibilityNew) - def unapply(p: Ident) = + def unapply(p: Ident): Some[(String, Quat, Visibility)] = Some((p.name, p.quat, p.visibility)) } } @@ -371,13 +371,13 @@ final class ExternalIdent private (val name: String)(theQuat: => Quat)(val renam def bestQuat: Quat = quat private def id = ExternalIdent.Id(name) - override def equals(that: Any) = + override def equals(that: Any): Boolean = that match { case e: ExternalIdent => this.id == e.id case _ => false } - override def hashCode = id.hashCode() + override def hashCode: Int = id.hashCode() // need to define a copy which will propagate current value of visibility into the copy def copy(name: String = this.name, quat: => Quat = this.quat): ExternalIdent = @@ -385,16 +385,16 @@ final class ExternalIdent private (val name: String)(theQuat: => Quat)(val renam } object ExternalIdent { - private case class Id(name: String) + final private case class Id(name: String) def apply(name: String, quat: => Quat) = new ExternalIdent(name)(quat)(Renameable.neutral) - def unapply(e: ExternalIdent) = Some((e.name, e.quat)) + def unapply(e: ExternalIdent): Some[(String, Quat)] = Some((e.name, e.quat)) object Opinionated { def apply(name: String, quat: => Quat, rename: Renameable) = new ExternalIdent(name)(quat)(rename) - def unapply(e: ExternalIdent) = Some((e.name, e.quat, e.renameable)) + def unapply(e: ExternalIdent): Some[(String, Quat, Renameable)] = Some((e.name, e.quat, e.renameable)) } } @@ -422,7 +422,7 @@ object Visibility extends OpinionValues[Visibility] { } sealed trait Renameable extends Opinion[Renameable] { - def fixedOr[T](plain: T)(otherwise: T) = + def fixedOr[T](plain: T)(otherwise: T): T = this match { case Renameable.Fixed => plain case _ => otherwise @@ -450,9 +450,9 @@ object Renameable extends OpinionValues[Renameable] { */ 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 quat: Quat = ast.quat.lookup(name, Messages.strictQuatChecking) def bestQuat: Quat = ast.quat.lookup(name, false) - def prevName = ast.quat.beforeRenamed(name) + def prevName: Option[String] = ast.quat.beforeRenamed(name) private def id = Property.Id(ast, name) @@ -467,22 +467,22 @@ final class Property(val ast: Ast, val name: String)(val renameable: Renameable, ): Property = Property.Opinionated(ast, name, renameable, visibility) - override def equals(that: Any) = + override def equals(that: Any): Boolean = that match { case e: Property => this.id == e.id case _ => false } - override def hashCode = id.hashCode() + override def hashCode: Int = id.hashCode() } object Property { - case class Id(ast: Ast, name: String) + final 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)) + def unapply(p: Property): Some[(Ast, String)] = Some((p.ast, p.name)) object Opinionated { def apply( @@ -492,50 +492,50 @@ object Property { visibilityNew: Visibility ) = new Property(ast, name)(renameableNew, visibilityNew) - def unapply(p: Property) = + def unapply(p: Property): Some[(Ast, String, Renameable, Visibility)] = Some((p.ast, p.name, p.renameable, p.visibility)) } } sealed trait OptionOperation extends Ast -case class OptionFlatten(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } -case class OptionGetOrElse(ast: Ast, body: Ast) extends OptionOperation { +final case class OptionFlatten(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } +final case class OptionGetOrElse(ast: Ast, body: Ast) extends OptionOperation { def quat = body.quat; def bestQuat = body.bestQuat } -case class OptionOrElse(ast: Ast, body: Ast) extends OptionOperation { +final case class OptionOrElse(ast: Ast, body: Ast) extends OptionOperation { def quat = body.quat; def bestQuat = body.bestQuat } -case class OptionFlatMap(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { +final case class OptionFlatMap(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { def quat = body.quat; def bestQuat = body.bestQuat } -case class OptionMap(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { +final case class OptionMap(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { def quat = body.quat; def bestQuat = body.bestQuat } -case class OptionForall(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { +final case class OptionForall(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { def quat = body.quat; def bestQuat = body.bestQuat } -case class OptionExists(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { +final case class OptionExists(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { def quat = body.quat; def bestQuat = body.bestQuat } -case class OptionContains(ast: Ast, body: Ast) extends OptionOperation { +final case class OptionContains(ast: Ast, body: Ast) extends OptionOperation { def quat = body.quat; def bestQuat = body.bestQuat } -case class OptionIsEmpty(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } -case class OptionNonEmpty(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } -case class OptionIsDefined(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } -case class OptionTableFlatMap(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { +final case class OptionIsEmpty(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } +final case class OptionNonEmpty(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } +final case class OptionIsDefined(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } +final case class OptionTableFlatMap(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { def quat = body.quat; def bestQuat = body.bestQuat } -case class OptionTableMap(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { +final case class OptionTableMap(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { def quat = body.quat; def bestQuat = body.bestQuat } -case class OptionTableExists(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { +final case class OptionTableExists(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { def quat = body.quat; def bestQuat = body.bestQuat } -case class OptionTableForall(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { +final case class OptionTableForall(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { def quat = body.quat; def bestQuat = body.bestQuat } -case class FilterIfDefined(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { +final case class FilterIfDefined(ast: Ast, alias: Ident, body: Ast) extends OptionOperation { def quat = body.quat; def bestQuat: Quat = body.bestQuat } case object OptionNoneId @@ -544,44 +544,44 @@ final class OptionNone(theQuat: => Quat) extends OptionOperation with Terminal { def quat = computedQuat def bestQuat = quat - override def withQuat(quat: => Quat) = this.copy(quat = quat) + override def withQuat(quat: => Quat): OptionNone = this.copy(quat = quat) override def equals(obj: Any): Boolean = obj match { case e: OptionNone => true case _ => false } override def hashCode(): Int = OptionNoneId.hashCode() - def copy(quat: => Quat = this.quat) = OptionNone(quat) + def copy(quat: => Quat = this.quat): OptionNone = OptionNone(quat) } object OptionNone { def apply(quat: => Quat): OptionNone = new OptionNone(quat) - def unapply(on: OptionNone) = Some(on.quat) + def unapply(on: OptionNone): Some[Quat] = Some(on.quat) } -case class OptionSome(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } -case class OptionApply(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } -case class OptionOrNull(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } -case class OptionGetOrNull(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } +final case class OptionSome(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } +final case class OptionApply(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } +final case class OptionOrNull(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } +final case class OptionGetOrNull(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } sealed trait IterableOperation extends Ast -case class MapContains(ast: Ast, body: Ast) extends IterableOperation { +final case class MapContains(ast: Ast, body: Ast) extends IterableOperation { def quat = body.quat; def bestQuat = body.bestQuat } -case class SetContains(ast: Ast, body: Ast) extends IterableOperation { +final case class SetContains(ast: Ast, body: Ast) extends IterableOperation { def quat = body.quat; def bestQuat = body.bestQuat } -case class ListContains(ast: Ast, body: Ast) extends IterableOperation { +final case class ListContains(ast: Ast, body: Ast) extends IterableOperation { def quat = body.quat; def bestQuat = body.bestQuat } -case class If(condition: Ast, `then`: Ast, `else`: Ast) extends Ast { +final case class If(condition: Ast, `then`: Ast, `else`: Ast) extends Ast { def quat = `then`.quat; def bestQuat = `then`.bestQuat } // then and else clauses should have identical quats -case class Assignment(alias: Ident, property: Ast, value: Ast) extends Ast { +final case class Assignment(alias: Ident, property: Ast, value: Ast) extends Ast { def quat = Quat.Value; def bestQuat = quat } -case class AssignmentDual(alias1: Ident, alias2: Ident, property: Ast, value: Ast) extends Ast { +final case class AssignmentDual(alias1: Ident, alias2: Ident, property: Ast, value: Ast) extends Ast { def quat = Quat.Value; def bestQuat = quat } @@ -589,17 +589,17 @@ case class AssignmentDual(alias1: Ident, alias2: Ident, property: Ast, value: As sealed trait Operation extends Ast -case class UnaryOperation(operator: UnaryOperator, ast: Ast) extends Operation { +final case class UnaryOperation(operator: UnaryOperator, ast: Ast) extends Operation { def quat = Quat.BooleanExpression; def bestQuat = quat } -case class BinaryOperation(a: Ast, operator: BinaryOperator, b: Ast) extends Operation { +final case class BinaryOperation(a: Ast, operator: BinaryOperator, b: Ast) extends Operation { import BooleanOperator._ import NumericOperator._ import StringOperator.`startsWith` import SetOperator.`contains` - def quat = operator match { + def quat: Quat = operator match { case EqualityOperator.`_==` | EqualityOperator.`_!=` | `&&` | `||` | `>` | `>=` | `<` | `<=` | `startsWith` | `contains` => Quat.BooleanExpression @@ -609,7 +609,7 @@ case class BinaryOperation(a: Ast, operator: BinaryOperator, b: Ast) extends Ope def bestQuat = quat } -case class FunctionApply(function: Ast, values: List[Ast]) extends Operation { +final case class FunctionApply(function: Ast, values: List[Ast]) extends Operation { def quat = function.quat; def bestQuat = function.bestQuat } @@ -632,10 +632,10 @@ final class Constant(val v: Any)(theQuat: => Quat) extends Value { } object Constant { - private case class Id(v: Any) + final private case class Id(v: Any) def apply(v: Any, quat: => Quat): Constant = new Constant(v)(quat) - def unapply(const: Constant) = Some((const.v, const.quat)) + def unapply(const: Constant): Some[(Any, Quat)] = Some((const.v, const.quat)) def auto(v: Any): Constant = { lazy val theQuat = if (v.isInstanceOf[Boolean]) Quat.BooleanValue else Quat.Value @@ -645,14 +645,14 @@ object Constant { case object NullValue extends Value { def quat = Quat.Null; def bestQuat = quat } -case class Tuple(values: List[Ast]) extends Value { +final case class Tuple(values: List[Ast]) extends Value { private lazy val computedQuat = Quat.Tuple(values.map(_.quat)) def quat = computedQuat private lazy val bestComputedQuat = Quat.Tuple(values.map(_.bestQuat)) def bestQuat = bestComputedQuat } -case class CaseClass(name: String, values: List[(String, Ast)]) extends Value { +final case class CaseClass(name: String, values: List[(String, Ast)]) extends Value { private lazy val computedQuat = Quat.Product(name, values.map { case (k, v) => (k, v.quat) }) def quat = computedQuat private lazy val bestComputedQuat = Quat.Product(name, values.map { case (k, v) => (k, v.bestQuat) }) @@ -669,7 +669,7 @@ case class CaseClass(name: String, values: List[(String, Ast)]) extends Value { } object CaseClass { - case class Id(values: List[(String, Ast)]) + final case class Id(values: List[(String, Ast)]) val GeneratedName = "" object Single { def apply(tup: (String, Ast)) = new CaseClass(GeneratedName, List(tup)) @@ -683,14 +683,14 @@ object CaseClass { //************************************************************ -case class Block(statements: List[Ast]) extends Ast { +final case class Block(statements: List[Ast]) extends Ast { private lazy val computedQuat = statements.last.quat def quat = computedQuat - private lazy val bestComputedQuat = statements.last.bestQuat + statements.last.bestQuat def bestQuat = computedQuat } // Note. Assuming Block is not Empty -case class Val(name: Ident, body: Ast) extends Ast { +final case class Val(name: Ident, body: Ast) extends Ast { def quat = body.quat def bestQuat = body.bestQuat } @@ -700,13 +700,13 @@ case class Val(name: Ident, body: Ast) extends Ast { sealed trait Action extends Ast // Note, technically return type of Actions for most Actions is a Int value but Quat here is used for Returning Quat types -case class Update(query: Ast, assignments: List[Assignment]) extends Action { +final case class Update(query: Ast, assignments: List[Assignment]) extends Action { def quat = query.quat; def bestQuat = query.bestQuat } -case class Insert(query: Ast, assignments: List[Assignment]) extends Action { +final case class Insert(query: Ast, assignments: List[Assignment]) extends Action { def quat = query.quat; def bestQuat = query.bestQuat } -case class Delete(query: Ast) extends Action { def quat = query.quat; def bestQuat = query.bestQuat } +final case class Delete(query: Ast) extends Action { def quat = query.quat; def bestQuat = query.bestQuat } sealed trait ReturningAction extends Action { def action: Ast @@ -723,18 +723,18 @@ object ReturningAction { } } -case class Returning(action: Ast, alias: Ident, property: Ast) extends ReturningAction { +final case class Returning(action: Ast, alias: Ident, property: Ast) extends ReturningAction { def quat = property.quat; def bestQuat = property.bestQuat } -case class ReturningGenerated(action: Ast, alias: Ident, property: Ast) extends ReturningAction { +final case class ReturningGenerated(action: Ast, alias: Ident, property: Ast) extends ReturningAction { def quat = property.quat; def bestQuat = property.bestQuat } -case class Foreach(query: Ast, alias: Ident, body: Ast) extends Action { +final case class Foreach(query: Ast, alias: Ident, body: Ast) extends Action { def quat = body.quat; def bestQuat = body.bestQuat } -case class OnConflict( +final case class OnConflict( insert: Ast, target: OnConflict.Target, action: OnConflict.Action @@ -742,22 +742,22 @@ case class OnConflict( object OnConflict { - case class Excluded(alias: Ident) extends Ast { + final case class Excluded(alias: Ident) extends Ast { def quat = alias.quat def bestQuat = alias.bestQuat } - case class Existing(alias: Ident) extends Ast { + final case class Existing(alias: Ident) extends Ast { def quat = alias.quat def bestQuat = alias.bestQuat } sealed trait Target case object NoTarget extends Target - case class Properties(props: List[Property]) extends Target + final case class Properties(props: List[Property]) extends Target sealed trait Action case object Ignore extends Action - case class Update(assignments: List[AssignmentDual]) extends Action + final case class Update(assignments: List[AssignmentDual]) extends Action } //************************************************************ @@ -770,7 +770,7 @@ final class Dynamic(val tree: Any)(theQuat: => Quat) extends Ast { object Dynamic { def apply(tree: Any, quat: => Quat): Dynamic = new Dynamic(tree)(quat) - def unapply(d: Dynamic) = Some((d.tree, d.quat)) + def unapply(d: Dynamic): Some[(Any, Quat)] = Some((d.tree, d.quat)) def apply(v: Any): Dynamic = { lazy val theQuat = if (v.isInstanceOf[Boolean]) Quat.BooleanValue else Quat.Value @@ -778,13 +778,13 @@ object Dynamic { } } -case class QuotedReference(tree: Any, ast: Ast) extends Ast { def quat = ast.quat; def bestQuat = ast.bestQuat; } +final case class QuotedReference(tree: Any, ast: Ast) extends Ast { def quat = ast.quat; def bestQuat = ast.bestQuat; } sealed trait External extends Ast object External { sealed trait Source object Source { - case class UnparsedProperty(name: String) extends Source + final case class UnparsedProperty(name: String) extends Source case object Parser extends Source } } @@ -811,7 +811,7 @@ final class ScalarValueLift(val name: String, val source: External.Source, val v ) extends ScalarLift { def quat: Quat = theQuat def bestQuat = quat - override def withQuat(quat: => Quat) = this.copy(quat = quat) + override def withQuat(quat: => Quat): ScalarValueLift = this.copy(quat = quat) private val id = ScalarValueLift.Id(name, source, value, encoder) override def hashCode(): Int = id.hashCode() @@ -826,20 +826,20 @@ final class ScalarValueLift(val name: String, val source: External.Source, val v value: Any = this.value, encoder: Any = this.encoder, quat: => Quat = this.quat - ) = + ): ScalarValueLift = ScalarValueLift(name, source, value, encoder, quat) } object ScalarValueLift { - private case class Id(name: String, source: External.Source, value: Any, encoder: Any) + final private case class Id(name: String, source: External.Source, value: Any, encoder: Any) def apply(name: String, source: External.Source, value: Any, encoder: Any, quat: => Quat): ScalarValueLift = new ScalarValueLift(name, source, value, encoder)(quat) - def unapply(svl: ScalarValueLift) = Some((svl.name, svl.source, svl.value, svl.encoder, svl.quat)) + def unapply(svl: ScalarValueLift): Some[(String, External.Source, Any, Any, Quat)] = Some((svl.name, svl.source, svl.value, svl.encoder, svl.quat)) } final class ScalarQueryLift(val name: String, val value: Any, val encoder: Any)(theQuat: => Quat) extends ScalarLift { def quat: Quat = theQuat def bestQuat = quat - override def withQuat(quat: => Quat) = this.copy(quat = quat) + override def withQuat(quat: => Quat): ScalarQueryLift = this.copy(quat = quat) private val id = ScalarQueryLift.Id(name, value, encoder) override def hashCode(): Int = id.hashCode() @@ -849,14 +849,14 @@ final class ScalarQueryLift(val name: String, val value: Any, val encoder: Any)( case _ => false } - def copy(name: String = this.name, value: Any = this.value, encoder: Any = this.encoder, quat: => Quat = this.quat) = + def copy(name: String = this.name, value: Any = this.value, encoder: Any = this.encoder, quat: => Quat = this.quat): ScalarQueryLift = ScalarQueryLift(name, value, encoder, quat) } object ScalarQueryLift { - private case class Id(name: String, value: Any, encoder: Any) + final private case class Id(name: String, value: Any, encoder: Any) def apply(name: String, value: Any, encoder: Any, quat: => Quat): ScalarQueryLift = new ScalarQueryLift(name, value, encoder)(quat) - def unapply(l: ScalarQueryLift) = Some((l.name, l.value, l.encoder, l.quat)) + def unapply(l: ScalarQueryLift): Some[(String, Any, Any, Quat)] = Some((l.name, l.value, l.encoder, l.quat)) } sealed trait CaseClassLift extends Lift @@ -865,7 +865,7 @@ final class CaseClassValueLift(val name: String, val simpleName: String, val val extends CaseClassLift { def quat: Quat = theQuat def bestQuat = quat - override def withQuat(quat: => Quat) = this.copy(quat = quat) + override def withQuat(quat: => Quat): CaseClassValueLift = this.copy(quat = quat) private val id = CaseClassValueLift.Id(name, simpleName, value) override def hashCode(): Int = id.hashCode() @@ -879,20 +879,20 @@ final class CaseClassValueLift(val name: String, val simpleName: String, val val simpleName: String = this.simpleName, value: Any = this.value, quat: => Quat = this.quat - ) = + ): CaseClassValueLift = CaseClassValueLift(name, simpleName, value, quat) } object CaseClassValueLift { - private case class Id(name: String, simpleName: String, value: Any) + final private case class Id(name: String, simpleName: String, value: Any) def apply(name: String, simpleName: String, value: Any, quat: => Quat): CaseClassValueLift = new CaseClassValueLift(name, simpleName, value)(quat) - def unapply(l: CaseClassValueLift) = Some((l.name, l.simpleName, l.value, l.quat)) + def unapply(l: CaseClassValueLift): Some[(String, String, Any, Quat)] = Some((l.name, l.simpleName, l.value, l.quat)) } final class CaseClassQueryLift(val name: String, val value: Any)(theQuat: => Quat) extends CaseClassLift { def quat: Quat = theQuat def bestQuat = quat - override def withQuat(quat: => Quat) = this.copy(quat = quat) + override def withQuat(quat: => Quat): CaseClassQueryLift = this.copy(quat = quat) private val id = CaseClassQueryLift.Id(name, value) override def hashCode(): Int = id.hashCode() @@ -902,14 +902,14 @@ final class CaseClassQueryLift(val name: String, val value: Any)(theQuat: => Qua case _ => false } - def copy(name: String = this.name, value: Any = this.value, quat: => Quat = this.quat) = + def copy(name: String = this.name, value: Any = this.value, quat: => Quat = this.quat): CaseClassQueryLift = CaseClassQueryLift(name, value, quat) } object CaseClassQueryLift { - private case class Id(name: String, value: Any) + final private case class Id(name: String, value: Any) def apply(name: String, value: Any, quat: => Quat): CaseClassQueryLift = new CaseClassQueryLift(name, value)(quat) - def unapply(l: CaseClassQueryLift) = Some((l.name, l.value, l.quat)) + def unapply(l: CaseClassQueryLift): Some[(String, Any, Quat)] = Some((l.name, l.value, l.quat)) } /** @@ -924,8 +924,8 @@ sealed trait Tag extends External { val uid: String } -case class ScalarTagId(uid: String) -case class ScalarTag(uid: String, source: External.Source) extends Tag { +final case class ScalarTagId(uid: String) +final case class ScalarTag(uid: String, source: External.Source) extends Tag { def quat = Quat.Value def bestQuat = quat @@ -938,8 +938,8 @@ case class ScalarTag(uid: String, source: External.Source) extends Tag { } } -case class QuotationTagId(uid: String) -case class QuotationTag(uid: String) extends Tag { +final case class QuotationTagId(uid: String) +final case class QuotationTag(uid: String) extends Tag { def quat = Quat.Value def bestQuat = quat diff --git a/quill-engine/src/main/scala/io/getquill/ast/AstOps.scala b/quill-engine/src/main/scala/io/getquill/ast/AstOps.scala index 86e2636b4d..bf07b58fc4 100644 --- a/quill-engine/src/main/scala/io/getquill/ast/AstOps.scala +++ b/quill-engine/src/main/scala/io/getquill/ast/AstOps.scala @@ -1,11 +1,11 @@ package io.getquill.ast // Represents an Ident without a Quat -case class IdentName(name: String) +final case class IdentName(name: String) object Implicits { implicit class IdentOps(id: Ident) { - def idName = IdentName(id.name) + def idName: IdentName = IdentName(id.name) } implicit class AstOpsExt(body: Ast) { @@ -49,7 +49,7 @@ object +!=+ { } object IsNotNullCheck { - def apply(ast: Ast) = BinaryOperation(ast, EqualityOperator.`_!=`, NullValue) + def apply(ast: Ast): BinaryOperation = BinaryOperation(ast, EqualityOperator.`_!=`, NullValue) def unapply(ast: Ast): Option[Ast] = ast match { @@ -59,7 +59,7 @@ object IsNotNullCheck { } object IsNullCheck { - def apply(ast: Ast) = BinaryOperation(ast, EqualityOperator.`_==`, NullValue) + def apply(ast: Ast): BinaryOperation = BinaryOperation(ast, EqualityOperator.`_==`, NullValue) def unapply(ast: Ast): Option[Ast] = ast match { @@ -69,20 +69,20 @@ object IsNullCheck { } object IfExistElseNull { - def apply(exists: Ast, `then`: Ast) = + def apply(exists: Ast, `then`: Ast): If = If(IsNotNullCheck(exists), `then`, NullValue) - def unapply(ast: Ast) = ast match { + def unapply(ast: Ast): Option[(Ast, Ast)] = ast match { case If(IsNotNullCheck(exists), t, NullValue) => Some((exists, t)) case _ => None } } object IfExist { - def apply(exists: Ast, `then`: Ast, otherwise: Ast) = + def apply(exists: Ast, `then`: Ast, otherwise: Ast): If = If(IsNotNullCheck(exists), `then`, otherwise) - def unapply(ast: Ast) = ast match { + def unapply(ast: Ast): Option[(Ast, Ast, Ast)] = ast match { case If(IsNotNullCheck(exists), t, e) => Some((exists, t, e)) case _ => None } diff --git a/quill-engine/src/main/scala/io/getquill/ast/CollectAst.scala b/quill-engine/src/main/scala/io/getquill/ast/CollectAst.scala index 3f217d9844..9283280806 100644 --- a/quill-engine/src/main/scala/io/getquill/ast/CollectAst.scala +++ b/quill-engine/src/main/scala/io/getquill/ast/CollectAst.scala @@ -10,7 +10,7 @@ import scala.reflect.ClassTag */ class CollectAst[T](p: PartialFunction[Ast, T], val state: Queue[T]) extends StatefulTransformer[Queue[T]] { - override def apply(a: Ast) = + override def apply(a: Ast): (Ast, StatefulTransformer[Queue[T]]) = a match { case d if (p.isDefinedAt(d)) => (d, new CollectAst(p, state :+ p(d))) case other => super.apply(other) @@ -19,12 +19,12 @@ class CollectAst[T](p: PartialFunction[Ast, T], val state: Queue[T]) extends Sta object CollectAst { - def byType[T: ClassTag](a: Ast) = + def byType[T: ClassTag](a: Ast): Queue[T] = apply[T](a) { case t: T => t } - def apply[T](a: Ast)(p: PartialFunction[Ast, T]) = + def apply[T](a: Ast)(p: PartialFunction[Ast, T]): Queue[T] = (new CollectAst(p, Queue[T]()).apply(a)) match { case (_, transformer) => transformer.state diff --git a/quill-engine/src/main/scala/io/getquill/ast/StatefulTransformer.scala b/quill-engine/src/main/scala/io/getquill/ast/StatefulTransformer.scala index eaeafe3520..a4548fadb5 100644 --- a/quill-engine/src/main/scala/io/getquill/ast/StatefulTransformer.scala +++ b/quill-engine/src/main/scala/io/getquill/ast/StatefulTransformer.scala @@ -317,8 +317,8 @@ trait StatefulTransformer[T] { (OnConflict.Update(at), att) } - def apply[U, R](list: List[U])(f: StatefulTransformer[T] => U => (R, StatefulTransformer[T])) = - list.foldLeft((List[R](), this)) { case ((values, t), v) => + def apply[U, R](list: List[U])(f: StatefulTransformer[T] => U => (R, StatefulTransformer[T])): (List[R], StatefulTransformer[T]) = + list.foldLeft((List.empty[R], this)) { case ((values, t), v) => val (vt, vtt) = f(t)(v) (values :+ vt, vtt) } diff --git a/quill-engine/src/main/scala/io/getquill/ast/StatefulTransformerWithStack.scala b/quill-engine/src/main/scala/io/getquill/ast/StatefulTransformerWithStack.scala index efebc4a0a0..ea93f5afe3 100644 --- a/quill-engine/src/main/scala/io/getquill/ast/StatefulTransformerWithStack.scala +++ b/quill-engine/src/main/scala/io/getquill/ast/StatefulTransformerWithStack.scala @@ -6,8 +6,8 @@ object StatefulTransformerWithStack { } object History { case object Root extends History { val ast = None } - case class Child(clause: Ast, prev: History) extends History { - def ast = Some(clause) + final case class Child(clause: Ast, prev: History) extends History { + def ast: Some[Ast] = Some(clause) } def apply(ast: Ast)(implicit prev: History): Child = @@ -335,8 +335,8 @@ trait StatefulTransformerWithStack[T] { def apply[U, R](list: List[U])(f: StatefulTransformerWithStack[T] => U => (R, StatefulTransformerWithStack[T]))( implicit parent: History - ) = - list.foldLeft((List[R](), this)) { case ((values, t), v) => + ): (List[R], StatefulTransformerWithStack[T]) = + list.foldLeft((List.empty[R], this)) { case ((values, t), v) => val (vt, vtt) = f(t)(v) (values :+ vt, vtt) } diff --git a/quill-engine/src/main/scala/io/getquill/ast/Transform.scala b/quill-engine/src/main/scala/io/getquill/ast/Transform.scala index 9bfd50e08f..2e7adaed52 100644 --- a/quill-engine/src/main/scala/io/getquill/ast/Transform.scala +++ b/quill-engine/src/main/scala/io/getquill/ast/Transform.scala @@ -2,7 +2,7 @@ package io.getquill.ast class Transform[T](p: PartialFunction[Ast, Ast]) extends StatelessTransformer { - override def apply(a: Ast) = + override def apply(a: Ast): Ast = a match { case a if (p.isDefinedAt(a)) => p(a) case other => super.apply(other) diff --git a/quill-engine/src/main/scala/io/getquill/context/ProtoContext.scala b/quill-engine/src/main/scala/io/getquill/context/ProtoContext.scala index d97be646b7..d405dcc133 100644 --- a/quill-engine/src/main/scala/io/getquill/context/ProtoContext.scala +++ b/quill-engine/src/main/scala/io/getquill/context/ProtoContext.scala @@ -79,7 +79,7 @@ class ExecutionInfo(val executionType: ExecutionType, queryAst: => Ast, queryTop object ExecutionInfo { def apply(executionType: ExecutionType, ast: => Ast, topLevelQuat: => Quat) = new ExecutionInfo(executionType, ast, topLevelQuat) - val unknown = ExecutionInfo(ExecutionType.Unknown, io.getquill.ast.NullValue, Quat.Unknown) + val unknown: ExecutionInfo = ExecutionInfo(ExecutionType.Unknown, io.getquill.ast.NullValue, Quat.Unknown) } trait AstSplicing diff --git a/quill-engine/src/main/scala/io/getquill/context/RowContext.scala b/quill-engine/src/main/scala/io/getquill/context/RowContext.scala index 48a85befa2..163822d07d 100644 --- a/quill-engine/src/main/scala/io/getquill/context/RowContext.scala +++ b/quill-engine/src/main/scala/io/getquill/context/RowContext.scala @@ -6,8 +6,8 @@ trait RowContext { type PrepareRow type ResultRow - protected val identityPrepare: Prepare = (p: PrepareRow, s: Session) => (Nil, p) - protected val identityExtractor = (rr: ResultRow, s: Session) => rr + protected val identityPrepare: Prepare = (p: PrepareRow, _: Session) => (List.empty, p) + protected val identityExtractor: (ResultRow, Session) => ResultRow = (rr: ResultRow, _: Session) => rr case class BatchGroup(string: String, prepare: List[Prepare]) case class BatchGroupReturning(string: String, returningBehavior: ReturnAction, prepare: List[Prepare]) diff --git a/quill-engine/src/main/scala/io/getquill/context/cassandra/CqlIdiom.scala b/quill-engine/src/main/scala/io/getquill/context/cassandra/CqlIdiom.scala index 832b6d4078..32d6dd5ee4 100644 --- a/quill-engine/src/main/scala/io/getquill/context/cassandra/CqlIdiom.scala +++ b/quill-engine/src/main/scala/io/getquill/context/cassandra/CqlIdiom.scala @@ -20,13 +20,13 @@ trait CqlIdiom extends Idiom { override def liftingPlaceholder(idx: Int) = "?" - override def emptySetContainsToken(field: Token) = stmt"$field IN ()" + override def emptySetContainsToken(field: Token): Statement = stmt"$field IN ()" override def prepareForProbing(string: String) = string override def translate(ast: Ast, topLevelQuat: Quat, executionType: ExecutionType, idiomContext: IdiomContext)( implicit naming: NamingStrategy - ) = { + ): (Ast, Statement, ExecutionType) = { val cqlNormalize = new CqlNormalize(idiomContext.config) val normalizedAst = cqlNormalize(ast) (normalizedAst, stmt"${normalizedAst.token}", executionType) @@ -34,7 +34,7 @@ trait CqlIdiom extends Idiom { override def translateCached(ast: Ast, topLevelQuat: Quat, executionType: ExecutionType, idiomContext: IdiomContext)( implicit naming: NamingStrategy - ) = { + ): (Ast, Statement, ExecutionType) = { val cqlNormalize = new CqlNormalize(idiomContext.config) val normalizedAst = NormalizeCaching(cqlNormalize.apply)(ast) (normalizedAst, stmt"${normalizedAst.token}", executionType) diff --git a/quill-engine/src/main/scala/io/getquill/context/cassandra/CqlNormalize.scala b/quill-engine/src/main/scala/io/getquill/context/cassandra/CqlNormalize.scala index d207728635..e5627d6342 100644 --- a/quill-engine/src/main/scala/io/getquill/context/cassandra/CqlNormalize.scala +++ b/quill-engine/src/main/scala/io/getquill/context/cassandra/CqlNormalize.scala @@ -10,7 +10,7 @@ import io.getquill.quat.Quat class CqlNormalize(transpileConfig: TranspileConfig) { val NormalizePhase = new Normalize(transpileConfig) - def apply(ast: Ast) = + def apply(ast: Ast): Ast = normalize(ast) /** diff --git a/quill-engine/src/main/scala/io/getquill/context/cassandra/CqlQuery.scala b/quill-engine/src/main/scala/io/getquill/context/cassandra/CqlQuery.scala index 3dbf85009a..2faaf688fd 100644 --- a/quill-engine/src/main/scala/io/getquill/context/cassandra/CqlQuery.scala +++ b/quill-engine/src/main/scala/io/getquill/context/cassandra/CqlQuery.scala @@ -3,7 +3,7 @@ package io.getquill.context.cassandra import io.getquill.ast._ import io.getquill.util.Messages.fail -case class CqlQuery( +final case class CqlQuery( entity: Entity, filter: Option[Ast], orderBy: List[OrderByCriteria], @@ -12,7 +12,7 @@ case class CqlQuery( distinct: Boolean ) -case class OrderByCriteria( +final case class OrderByCriteria( property: Property, ordering: PropertyOrdering ) @@ -34,7 +34,7 @@ object CqlQuery { case Aggregation(AggregationOperator.`size`, q: Query) => apply(q, List(Aggregation(AggregationOperator.`size`, Constant.auto(1))), distinct) case other => - apply(q, List(), distinct) + apply(q, List.empty, distinct) } private def apply(q: Query, select: List[Ast], distinct: Boolean): CqlQuery = @@ -50,7 +50,7 @@ object CqlQuery { case SortBy(q: Query, x, p, o) => apply(q, orderByCriteria(p, o), limit, select, distinct) case other => - apply(q, List(), limit, select, distinct) + apply(q, List.empty, limit, select, distinct) } private def apply( @@ -95,7 +95,7 @@ object CqlQuery { case Tuple(values) => values.flatMap(select) case CaseClass(_, values) => values.flatMap(v => select(v._2)) case p: Property => List(p) - case i: Ident => List() + case i: Ident => List.empty case l: Lift => List(l) case l: ScalarTag => List(l) case other => fail(s"Cql supports only properties as select elements. Found: $other") diff --git a/quill-engine/src/main/scala/io/getquill/context/cassandra/ExpandMappedInfixCassandra.scala b/quill-engine/src/main/scala/io/getquill/context/cassandra/ExpandMappedInfixCassandra.scala index d056960483..c9fb9086c7 100644 --- a/quill-engine/src/main/scala/io/getquill/context/cassandra/ExpandMappedInfixCassandra.scala +++ b/quill-engine/src/main/scala/io/getquill/context/cassandra/ExpandMappedInfixCassandra.scala @@ -5,7 +5,7 @@ import io.getquill.ast._ object ExpandMappedInfixCassandra extends StatelessTransformer { - override def apply(q: Ast) = + override def apply(q: Ast): Ast = q match { case Map(q: Infix, x, p) if (x == p) => q diff --git a/quill-engine/src/main/scala/io/getquill/context/mirror/MirrorSession.scala b/quill-engine/src/main/scala/io/getquill/context/mirror/MirrorSession.scala index 9e887dce28..cbc3f8afab 100644 --- a/quill-engine/src/main/scala/io/getquill/context/mirror/MirrorSession.scala +++ b/quill-engine/src/main/scala/io/getquill/context/mirror/MirrorSession.scala @@ -1,6 +1,6 @@ package io.getquill.context.mirror -case class MirrorSession(name: String) +final case class MirrorSession(name: String) object MirrorSession { - def default = MirrorSession("DefaultMirrorSession") + def default: MirrorSession = MirrorSession("DefaultMirrorSession") } diff --git a/quill-engine/src/main/scala/io/getquill/idiom/Statement.scala b/quill-engine/src/main/scala/io/getquill/idiom/Statement.scala index fa4b573e29..47af6f80b4 100644 --- a/quill-engine/src/main/scala/io/getquill/idiom/Statement.scala +++ b/quill-engine/src/main/scala/io/getquill/idiom/Statement.scala @@ -5,30 +5,30 @@ import io.getquill.ast._ sealed trait Token sealed trait TagToken extends Token -case class StringToken(string: String) extends Token { +final case class StringToken(string: String) extends Token { override def toString = string } -case class ScalarTagToken(tag: ScalarTag) extends TagToken { - override def toString = s"lift(${tag.uid})" +final case class ScalarTagToken(tag: ScalarTag) extends TagToken { + override def toString: String = s"lift(${tag.uid})" } -case class QuotationTagToken(tag: QuotationTag) extends TagToken { - override def toString = s"quoted(${tag.uid})" +final case class QuotationTagToken(tag: QuotationTag) extends TagToken { + override def toString: String = s"quoted(${tag.uid})" } -case class ScalarLiftToken(lift: ScalarLift) extends Token { - override def toString = s"lift(${lift.name})" +final case class ScalarLiftToken(lift: ScalarLift) extends Token { + override def toString: String = s"lift(${lift.name})" } -case class ValuesClauseToken(statement: Statement) extends Token { +final case class ValuesClauseToken(statement: Statement) extends Token { override def toString = statement.toString } -case class Statement(tokens: List[Token]) extends Token { +final case class Statement(tokens: List[Token]) extends Token { override def toString = tokens.mkString } -case class SetContainsToken(a: Token, op: Token, b: Token) extends Token { - override def toString = s"${a.toString} ${op.toString} (${b.toString})" +final case class SetContainsToken(a: Token, op: Token, b: Token) extends Token { + override def toString: String = s"${a.toString} ${op.toString} (${b.toString})" } diff --git a/quill-engine/src/main/scala/io/getquill/idiom/StatementInterpolator.scala b/quill-engine/src/main/scala/io/getquill/idiom/StatementInterpolator.scala index 9bf9204a9b..bb6ee69167 100644 --- a/quill-engine/src/main/scala/io/getquill/idiom/StatementInterpolator.scala +++ b/quill-engine/src/main/scala/io/getquill/idiom/StatementInterpolator.scala @@ -13,12 +13,12 @@ object StatementInterpolator { } object Tokenizer { - def apply[T](f: T => Token) = new Tokenizer[T] { + def apply[T](f: T => Token): Tokenizer[T] = new Tokenizer[T] { def token(v: T) = f(v) } def withFallback[T]( fallback: Tokenizer[T] => Tokenizer[T] - )(pf: PartialFunction[T, Token]) = + )(pf: PartialFunction[T, Token]): Tokenizer[T] = new Tokenizer[T] { private val stable = fallback(this) override def token(v: T) = pf.applyOrElse(v, stable.token) @@ -26,7 +26,7 @@ object StatementInterpolator { } implicit class TokenImplicit[T](v: T)(implicit tokenizer: Tokenizer[T]) { - def token = tokenizer.token(v) + def token: Token = tokenizer.token(v) } implicit def stringTokenizer: Tokenizer[String] = @@ -102,7 +102,7 @@ object StatementInterpolator { Tokenizer[ScalarLiftToken](identity) implicit class TokenList[T](list: List[T]) { - def mkStmt(sep: String = ", ")(implicit tokenize: Tokenizer[T]) = { + def mkStmt(sep: String = ", ")(implicit tokenize: Tokenizer[T]): Statement = { val l1 = list.map(_.token) val l2 = List.fill(l1.size - 1)(StringToken(sep)) Statement(Interleave(l1, l2)) diff --git a/quill-engine/src/main/scala/io/getquill/norm/AdHocReduction.scala b/quill-engine/src/main/scala/io/getquill/norm/AdHocReduction.scala index 800aee833b..09ae225feb 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/AdHocReduction.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/AdHocReduction.scala @@ -12,7 +12,7 @@ import io.getquill.util.TraceConfig class AdHocReduction(traceConfig: TraceConfig) { - def unapply(q: Query) = + def unapply(q: Query): Option[Query] = q match { // --------------------------- diff --git a/quill-engine/src/main/scala/io/getquill/norm/ApplyMap.scala b/quill-engine/src/main/scala/io/getquill/norm/ApplyMap.scala index b0f76c7fa0..e0d21df808 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/ApplyMap.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/ApplyMap.scala @@ -28,7 +28,7 @@ class ApplyMap(traceConfig: TraceConfig) { object InfixedTailOperation { - def hasImpureInfix(ast: Ast) = + def hasImpureInfix(ast: Ast): Boolean = CollectAst(ast) { case i @ Infix(_, _, false, _, _) => i }.nonEmpty diff --git a/quill-engine/src/main/scala/io/getquill/norm/BetaReduction.scala b/quill-engine/src/main/scala/io/getquill/norm/BetaReduction.scala index c4dedabd13..1cbe0370b8 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/BetaReduction.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/BetaReduction.scala @@ -38,7 +38,7 @@ object EmptyProductQuatBehavior { case object Ignore extends EmptyProductQuatBehavior } -case class BetaReduction(map: IMap[Ast, Ast], typeBehavior: TypeBehavior, emptyBehavior: EmptyProductQuatBehavior) +final case class BetaReduction(map: IMap[Ast, Ast], typeBehavior: TypeBehavior, emptyBehavior: EmptyProductQuatBehavior) extends StatelessTransformer { override def apply(ast: Ast): Ast = diff --git a/quill-engine/src/main/scala/io/getquill/norm/DisablePhase.scala b/quill-engine/src/main/scala/io/getquill/norm/DisablePhase.scala index a5b6e7d06c..faf4e4d9c3 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/DisablePhase.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/DisablePhase.scala @@ -4,9 +4,9 @@ import io.getquill.norm.ConfigList._ import io.getquill.util.Messages.TraceType import io.getquill.util.TraceConfig -case class TranspileConfig(disablePhases: List[OptionalPhase], traceConfig: TraceConfig) +final case class TranspileConfig(disablePhases: List[OptionalPhase], traceConfig: TraceConfig) object TranspileConfig { - val Empty = TranspileConfig(List(), TraceConfig(List())) + val Empty: TranspileConfig = TranspileConfig(List.empty, TraceConfig(List.empty)) } sealed trait OptionalPhase @@ -14,7 +14,7 @@ object OptionalPhase { sealed trait ApplyMap extends OptionalPhase case object ApplyMap extends ApplyMap - val all = List(ApplyMap) + val all: List[ApplyMap.type] = List(ApplyMap) } trait DisablePhase { diff --git a/quill-engine/src/main/scala/io/getquill/norm/ExpandReturning.scala b/quill-engine/src/main/scala/io/getquill/norm/ExpandReturning.scala index 4097c7a8f5..ed3c0c1684 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/ExpandReturning.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/ExpandReturning.scala @@ -16,7 +16,7 @@ object ExpandReturning { def applyMap( returning: ReturningAction - )(f: (Ast, Statement) => String)(idiom: Idiom, naming: NamingStrategy, idiomContext: IdiomContext) = + )(f: (Ast, Statement) => String)(idiom: Idiom, naming: NamingStrategy, idiomContext: IdiomContext): ReturnAction = idiom.idiomReturningCapability match { case ReturningClauseSupported | OutputClauseSupported => ReturnAction.ReturnRecord diff --git a/quill-engine/src/main/scala/io/getquill/norm/FlattenOptionOperation.scala b/quill-engine/src/main/scala/io/getquill/norm/FlattenOptionOperation.scala index ca9bd28242..5863d41b91 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/FlattenOptionOperation.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/FlattenOptionOperation.scala @@ -12,14 +12,13 @@ class FlattenOptionOperation(concatBehavior: ConcatBehavior, traceConfig: TraceC val interp = new Interpolator(TraceType.FlattenOptionOperation, traceConfig, 2) import interp._ - private def emptyOrNot(b: Boolean, ast: Ast) = - if (b) OptionIsEmpty(ast) else OptionNonEmpty(ast) + - def validateContainsOrElse(containsNon: Boolean, succeedWith: () => Ast, orElse: () => Ast) = + def validateContainsOrElse(containsNon: Boolean, succeedWith: () => Ast, orElse: () => Ast): Ast = if (containsNon) succeedWith() else orElse() - def uncheckedReduction(ast: Ast, alias: Ident, body: Ast, validateBody: Ast => Boolean) = + def uncheckedReduction(ast: Ast, alias: Ident, body: Ast, validateBody: Ast => Boolean): Ast = validateContainsOrElse( validateBody(body), () => { @@ -29,7 +28,7 @@ class FlattenOptionOperation(concatBehavior: ConcatBehavior, traceConfig: TraceC () => apply(BetaReduction(body, alias -> ast)) ) - def uncheckedForall(ast: Ast, alias: Ident, body: Ast, validateBody: Ast => Boolean) = + def uncheckedForall(ast: Ast, alias: Ident, body: Ast, validateBody: Ast => Boolean): Ast = validateContainsOrElse( validateBody(body), () => { @@ -42,7 +41,7 @@ class FlattenOptionOperation(concatBehavior: ConcatBehavior, traceConfig: TraceC } ) - def containsNonFallthroughElement(ast: Ast) = + def containsNonFallthroughElement(ast: Ast): Boolean = CollectAst(ast) { case If(_, _, _) => true case Infix(_, _, _, _, _) => true diff --git a/quill-engine/src/main/scala/io/getquill/norm/Normalize.scala b/quill-engine/src/main/scala/io/getquill/norm/Normalize.scala index 05d97cf020..301062baef 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/Normalize.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/Normalize.scala @@ -36,8 +36,7 @@ class Normalize(config: TranspileConfig) extends StatelessTransformer { trace"Avoid Capture and Normalize $q into:" andReturn norm(DealiasPhase(AvoidAliasConflictPhase(q, false))) - private def traceNorm[T](label: String) = - trace[T](s"${label} (Normalize)", 1, Normalizations) + private def demarcate(heading: String) = ((ast: Query) => title(s"(Normalize) $heading", TraceType.Normalizations)(ast)) diff --git a/quill-engine/src/main/scala/io/getquill/norm/OrderTerms.scala b/quill-engine/src/main/scala/io/getquill/norm/OrderTerms.scala index 1b371a082c..5ef362970e 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/OrderTerms.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/OrderTerms.scala @@ -5,7 +5,7 @@ import io.getquill.util.TraceConfig class OrderTerms(traceConfig: TraceConfig) { - def unapply(q: Query) = + def unapply(q: Query): Option[Query] = q match { case Take(Map(a: GroupBy, b, c), d) => None diff --git a/quill-engine/src/main/scala/io/getquill/norm/RenameProperties.scala b/quill-engine/src/main/scala/io/getquill/norm/RenameProperties.scala index 1aa5908d70..a1ffb36887 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/RenameProperties.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/RenameProperties.scala @@ -36,7 +36,7 @@ class RenameProperties(traceConfig: TraceConfig) { val ApplyRenamesToPropsPhase = new ApplyRenamesToProps(traceConfig) val RepropagateQuatsPhase = new RepropagateQuats(traceConfig) - def apply(ast: Ast) = + def apply(ast: Ast): Ast = (identity[Ast] _) .andThen(SeedRenames.apply(_: Ast)) // Stage field renames into the Quats of entities .andThen(demarcate("SeedRenames")) @@ -82,7 +82,7 @@ class ApplyRenamesToProps(traceConfig: TraceConfig) extends StatelessTransformer override def apply(p: Property): Property = applyProperty(p) - def applyProperty(p: Property) = + def applyProperty(p: Property): Property = p match { case p @ Property.Opinionated(ast, name, renameable, visibility) => val newAst = apply(ast) diff --git a/quill-engine/src/main/scala/io/getquill/norm/RepropagateQuats.scala b/quill-engine/src/main/scala/io/getquill/norm/RepropagateQuats.scala index 93bacd7d9a..4d65f11697 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/RepropagateQuats.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/RepropagateQuats.scala @@ -77,11 +77,11 @@ class RepropagateQuats(traceConfig: TraceConfig) extends StatelessTransformer { } implicit class IdentExt(id: Ident) { - def retypeQuatFrom(from: Quat) = + def retypeQuatFrom(from: Quat): Ident = id.copy(quat = id.quat.retypeFrom(from)) } - def applyBody(a: Ast, b: Ident, c: Ast)(f: (Ast, Ident, Ast) => Query) = { + def applyBody(a: Ast, b: Ident, c: Ast)(f: (Ast, Ident, Ast) => Query): Query = { val ar = apply(a) val br = b.retypeQuatFrom(ar.quat) val cr = BetaReduction(c, RWR, b -> br) @@ -136,7 +136,7 @@ class RepropagateQuats(traceConfig: TraceConfig) extends StatelessTransformer { super.apply(other) } - def reassign(assignments: List[Assignment], quat: Quat) = + def reassign(assignments: List[Assignment], quat: Quat): List[Assignment] = assignments.map { case Assignment(alias, property, value) => val aliasR = alias.retypeQuatFrom(quat) diff --git a/quill-engine/src/main/scala/io/getquill/norm/SheathLeafClauses.scala b/quill-engine/src/main/scala/io/getquill/norm/SheathLeafClauses.scala index 89aaff0516..c7e8e37d06 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/SheathLeafClauses.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/SheathLeafClauses.scala @@ -36,20 +36,20 @@ import io.getquill.util.Messages.TraceType * Typically this is a query-ast clause that results in a scalar type. It could * be M(ent,e,e.v) or an `sql"stuff".as[Query[Int/String/Boolean/etc...] ]` */ -case class SheathLeafClauses(state: Option[String], traceConfig: TraceConfig) +final case class SheathLeafClauses(state: Option[String], traceConfig: TraceConfig) extends StatefulTransformerWithStack[Option[String]] { val interp = new Interpolator(TraceType.ShealthLeaf, traceConfig, 3) import interp._ - def sheathLeaf(ast: Ast) = + def sheathLeaf(ast: Ast): (Ast, Option[String]) = ast match { case LeafQuat(p: Property) => (CaseClass.Single(p.name -> p), Some(p.name)) case LeafQuat(body) => (CaseClass.Single("x" -> body), Some("x")) case other => (other, None) } - def elaborateSheath(ast: Ast)(state: Option[String], e: Ident, newIdent: Ident) = + def elaborateSheath(ast: Ast)(state: Option[String], e: Ident, newIdent: Ident): Ast = state match { case Some(v) => val e1 = newIdent @@ -63,7 +63,7 @@ case class SheathLeafClauses(state: Option[String], traceConfig: TraceConfig) ast } - def elaborateGroupSheath(ast: Ast)(state: Option[String], replace: Ident, newIdent: Ident) = { + def elaborateGroupSheath(ast: Ast)(state: Option[String], replace: Ident, newIdent: Ident): Ast = { val e = replace val e1 = newIdent state match { @@ -80,7 +80,7 @@ case class SheathLeafClauses(state: Option[String], traceConfig: TraceConfig) } object NotGroupBy { - def unapply(ast: Ast) = + def unapply(ast: Ast): Option[Ast] = ast match { case p: GroupBy => None case _ => Some(ast) @@ -100,7 +100,7 @@ case class SheathLeafClauses(state: Option[String], traceConfig: TraceConfig) case MapClauseType.ConcatMap => ConcatMap(a, b, c) } } - def unapply(ast: Ast) = + def unapply(ast: Ast): Option[(Ast, Ident, Ast, Remaker)] = ast match { case Map(a, b, c) => Some((a, b, c, new Remaker(MapClauseType.Map))) case ConcatMap(a, b, c) => Some((a, b, c, new Remaker(MapClauseType.ConcatMap))) @@ -121,7 +121,7 @@ case class SheathLeafClauses(state: Option[String], traceConfig: TraceConfig) case UnionClauseType.UnionAll => UnionAll(a, b) } } - def unapply(ast: Ast) = + def unapply(ast: Ast): Option[(Ast, Ast, Remaker)] = ast match { case Union(a, b) => Some((a, b, new Remaker(UnionClauseType.Union))) case UnionAll(a, b) => Some((a, b, new Remaker(UnionClauseType.UnionAll))) @@ -372,5 +372,5 @@ case class SheathLeafClauses(state: Option[String], traceConfig: TraceConfig) } private[getquill] class SheathLeafClausesApply(traceConfig: TraceConfig) { - def apply(q: Ast) = new SheathLeafClauses(None, traceConfig).apply(q)(History.Root)._1 + def apply(q: Ast): Ast = new SheathLeafClauses(None, traceConfig).apply(q)(History.Root)._1 } diff --git a/quill-engine/src/main/scala/io/getquill/norm/StabilizeLifts.scala b/quill-engine/src/main/scala/io/getquill/norm/StabilizeLifts.scala index 84a73345ec..a9eb80f646 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/StabilizeLifts.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/StabilizeLifts.scala @@ -13,7 +13,7 @@ private[getquill] object StabilizeLifts { def revert(ast: Ast, state: State): Ast = RevertLiftValues(state).apply(ast) - case class State( + final case class State( replaceTable: IMap[Token, Any], nextToken: Token ) { @@ -24,15 +24,15 @@ private[getquill] object StabilizeLifts { ) } - case class Token(id: Long) + final case class Token(id: Long) - case class RevertLiftValues(state: State) extends StatelessTransformer { + final case class RevertLiftValues(state: State) extends StatelessTransformer { override def apply(ast: Ast): Ast = ast match { case l: Lift => applyLift(l) case others => super.apply(others) } - def applyLift(ast: Lift) = ast match { + def applyLift(ast: Lift): Lift = ast match { case l: ScalarValueLift => val value = state.replaceTable(l.value.asInstanceOf[Token]) l.copy(value = value) @@ -49,7 +49,7 @@ private[getquill] object StabilizeLifts { } } - case class StubLiftValues(state: State) extends StatefulTransformer[State] { + final case class StubLiftValues(state: State) extends StatefulTransformer[State] { override def apply(e: Ast): (Ast, StatefulTransformer[State]) = e match { case l: Lift => val (ast, ss) = applyLift(l) diff --git a/quill-engine/src/main/scala/io/getquill/norm/SymbolicReduction.scala b/quill-engine/src/main/scala/io/getquill/norm/SymbolicReduction.scala index 29c14768d5..7fba20d388 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/SymbolicReduction.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/SymbolicReduction.scala @@ -16,7 +16,7 @@ import io.getquill.util.TraceConfig */ class SymbolicReduction(traceConfig: TraceConfig) { - def unapply(q: Query) = + def unapply(q: Query): Option[Query] = q match { /* diff --git a/quill-engine/src/main/scala/io/getquill/norm/capture/AvoidAliasConflict.scala b/quill-engine/src/main/scala/io/getquill/norm/capture/AvoidAliasConflict.scala index 5b9424ca36..9dadecb243 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/capture/AvoidAliasConflict.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/capture/AvoidAliasConflict.scala @@ -57,7 +57,7 @@ import scala.collection.immutable.Set * called once from the top-level inside `SqlNormalize` at the very end of the * transformation pipeline. */ -private[getquill] case class AvoidAliasConflict(state: Set[IdentName], detemp: Boolean, traceConfig: TraceConfig) +final private[getquill] case class AvoidAliasConflict(state: Set[IdentName], detemp: Boolean, traceConfig: TraceConfig) extends StatefulTransformer[Set[IdentName]] { val interp = new Interpolator(TraceType.AvoidAliasConflict, traceConfig, 3) @@ -284,7 +284,7 @@ private[getquill] case class AvoidAliasConflict(state: Set[IdentName], detemp: B */ private def applyFunction(f: Function): Function = { val (newBody, _, newParams) = - f.params.foldLeft((f.body, state, List[Ident]())) { + f.params.foldLeft((f.body, state, List.empty[Ident])) { case ((body, state, newParams), param) => { val fresh = freshIdent(param) val pr = BetaReduction(body, param -> fresh) @@ -305,7 +305,7 @@ private[getquill] case class AvoidAliasConflict(state: Set[IdentName], detemp: B private[getquill] class AvoidAliasConflictApply(traceConfig: TraceConfig) { def apply(q: Query, detemp: Boolean = false): Query = - AvoidAliasConflict(Set[IdentName](), detemp, traceConfig)(q) match { + AvoidAliasConflict(Set.empty[IdentName], detemp, traceConfig)(q) match { case (q, _) => q } } @@ -313,12 +313,12 @@ private[getquill] class AvoidAliasConflictApply(traceConfig: TraceConfig) { private[getquill] object AvoidAliasConflict { def Ast(q: Ast, detemp: Boolean = false, traceConfig: TraceConfig): Ast = - new AvoidAliasConflict(Set[IdentName](), detemp, traceConfig)(q) match { + new AvoidAliasConflict(Set.empty[IdentName], detemp, traceConfig)(q) match { case (q, _) => q } def apply(q: Query, detemp: Boolean = false, traceConfig: TraceConfig): Query = - AvoidAliasConflict(Set[IdentName](), detemp, traceConfig)(q) match { + AvoidAliasConflict(Set.empty[IdentName], detemp, traceConfig)(q) match { case (q, _) => q } diff --git a/quill-engine/src/main/scala/io/getquill/norm/capture/Dealias.scala b/quill-engine/src/main/scala/io/getquill/norm/capture/Dealias.scala index 5426511852..2da23d42d9 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/capture/Dealias.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/capture/Dealias.scala @@ -5,7 +5,7 @@ import io.getquill.norm.BetaReduction import io.getquill.util.{Interpolator, TraceConfig} import io.getquill.util.Messages.TraceType -case class Dealias(state: Option[Ident], traceConfig: TraceConfig) extends StatefulTransformer[Option[Ident]] { +final case class Dealias(state: Option[Ident], traceConfig: TraceConfig) extends StatefulTransformer[Option[Ident]] { val interp = new Interpolator(TraceType.Standard, traceConfig, 3) import interp._ @@ -80,14 +80,14 @@ case class Dealias(state: Option[Ident], traceConfig: TraceConfig) extends State } object Dealias { - def apply(query: Query)(traceConfig: TraceConfig) = + def apply(query: Query)(traceConfig: TraceConfig): Query = new Dealias(None, traceConfig)(query) match { case (q, _) => q } } class DealiasApply(traceConfig: TraceConfig) { - def apply(query: Query) = + def apply(query: Query): Query = new Dealias(None, traceConfig)(query) match { case (q, _) => q } diff --git a/quill-engine/src/main/scala/io/getquill/norm/capture/DemarcateExternalAliases.scala b/quill-engine/src/main/scala/io/getquill/norm/capture/DemarcateExternalAliases.scala index 5c96d3b7d9..f02be61de9 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/capture/DemarcateExternalAliases.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/capture/DemarcateExternalAliases.scala @@ -20,9 +20,9 @@ import io.getquill.ast._ * body. Other places where this needs to be done (e.g. in a Tuple that * `Returning` returns) are done in `ExpandReturning`. */ -private[getquill] case class DemarcateExternalAliases(externalIdent: Ident) extends StatelessTransformer { +final private[getquill] case class DemarcateExternalAliases(externalIdent: Ident) extends StatelessTransformer { - def applyNonOverride(idents: Ident*)(ast: Ast) = + def applyNonOverride(idents: Ident*)(ast: Ast): Ast = if (idents.forall(_ != externalIdent)) apply(ast) else ast @@ -81,7 +81,7 @@ object DemarcateExternalAliases { case Returning(a, id, body) => Returning(a, id, demarcateQueriesInBody(id, body)) case ReturningGenerated(a, id, body) => - val d = demarcateQueriesInBody(id, body) + demarcateQueriesInBody(id, body) ReturningGenerated(a, id, demarcateQueriesInBody(id, body)) case other => other diff --git a/quill-engine/src/main/scala/io/getquill/norm/capture/TemporaryIdent.scala b/quill-engine/src/main/scala/io/getquill/norm/capture/TemporaryIdent.scala index dbf84faf27..45a43776cf 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/capture/TemporaryIdent.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/capture/TemporaryIdent.scala @@ -3,7 +3,7 @@ package io.getquill.norm.capture import io.getquill.ast.Ident object TemporaryIdent { - def unapply(id: Ident) = + def unapply(id: Ident): Option[Ident] = if (id.name.matches("\\[tmp_[0-9A-Za-z]+\\]")) Some(id) else diff --git a/quill-engine/src/main/scala/io/getquill/quat/BooQuatSerializer.scala b/quill-engine/src/main/scala/io/getquill/quat/BooQuatSerializer.scala index 05bcfbfaa6..95532b9ff3 100644 --- a/quill-engine/src/main/scala/io/getquill/quat/BooQuatSerializer.scala +++ b/quill-engine/src/main/scala/io/getquill/quat/BooQuatSerializer.scala @@ -8,7 +8,7 @@ import boopickle.Default._ import scala.collection.mutable.LinkedHashMap object BooQuatSerializer { - case class ProductWithRenames(data: LinkedHashMap[String, Quat], renames: List[(String, String)]) + final case class ProductWithRenames(data: LinkedHashMap[String, Quat], renames: List[(String, String)]) implicit object productPickler extends Pickler[Quat.Product] { override def pickle(value: Quat.Product)(implicit state: PickleState): Unit = { diff --git a/quill-engine/src/main/scala/io/getquill/quat/FindBranches.scala b/quill-engine/src/main/scala/io/getquill/quat/FindBranches.scala index 6900225989..d99d3d1616 100644 --- a/quill-engine/src/main/scala/io/getquill/quat/FindBranches.scala +++ b/quill-engine/src/main/scala/io/getquill/quat/FindBranches.scala @@ -6,19 +6,19 @@ import io.getquill.quat.FindBranches.Result.ProductWithBranches object VerifyNoBranches { private implicit class DotsExt(list: List[String]) { - def dots = list.mkString(".") + def dots: String = list.mkString(".") } private implicit class StringExt(str: String) { - def appendIfNotEmpty(value: String) = + def appendIfNotEmpty(value: String): String = str.trim match { case "" => "" case other => other + value } - def isNonEmpty = str.trim != "" + def isNonEmpty: Boolean = str.trim != "" } - case class BranchFound( + final case class BranchFound( outerClass: Option[String], pathToInnerField: String, innerField: String, @@ -54,7 +54,7 @@ object VerifyNoBranches { children.flatMap(child => recurse(child, classesToHere :+ name)) } - val foundBranches = recurse(result, List()) + val foundBranches = recurse(result, List.empty) // In some situations e.g. CCOuter(a: CCFoo(bar: CCBar(baz), b: CCFoo(bar: CCBar(baz)) we will have two messages: // field 'baz' will be used instead of a in Outer.a // and: @@ -75,9 +75,9 @@ object VerifyNoBranches { } // TODO What about a a top-level branch, what's the text for that? - case class BranchFoundMessage(msg: String) + final case class BranchFoundMessage(msg: String) object BranchFoundMessage { - def makeFrom(found: BranchFound) = { + def makeFrom(found: BranchFound): BranchFoundMessage = { val link = "https://getquill.io/#extending-quill-custom-encoding" // The field 'value' in Person.Name.First will be use in the query[Person] instead of Person.name or Person.Name.first. // Are you sure this is the intended behavior? Perhaps you meant to write an encoder/decoder for Person.Name.First? @@ -95,10 +95,10 @@ object VerifyNoBranches { } } - case class Output(messages: List[BranchFoundMessage]) - def in(quat: Quat) = { + final case class Output(messages: List[BranchFoundMessage]) + def in(quat: Quat): Output = { val foundBranchResults = FindBranches.in(quat) - val foundBranches = foundBranchResults.map(BranchFound.constructFrom(_)).getOrElse(List()) + val foundBranches = foundBranchResults.map(BranchFound.constructFrom(_)).getOrElse(List.empty) Output(foundBranches.map(BranchFoundMessage.makeFrom(_))) } } @@ -107,11 +107,11 @@ private[getquill] object FindBranches { sealed trait Result object Result { - case class SingleBranch private[quat] (path: List[PathElement], innermostField: String) extends Result - case class ProductWithBranches(name: String, children: List[Result]) extends Result + final case class SingleBranch private[quat] (path: List[PathElement], innermostField: String) extends Result + final case class ProductWithBranches(name: String, children: List[Result]) extends Result } - def in(quat: Quat) = recurseFind("root", quat) + def in(quat: Quat): Option[Result] = recurseFind("root", quat) private def recurseFind(currentPropName: String, quat: Quat): Option[Result] = quat match { @@ -145,11 +145,11 @@ private[getquill] object FindBranches { None } - case class AccumPath private[quat] (first: RootElement, rest: List[PathElement]) { + final case class AccumPath private[quat] (first: RootElement, rest: List[PathElement]) { def :+(elem: PathElement) = this.copy(rest = rest :+ elem) } object AccumPath { - def make(firstClassName: String) = new AccumPath(RootElement(firstClassName), List()) + def make(firstClassName: String) = new AccumPath(RootElement(firstClassName), List.empty) } def recurse(thisField: String, thisQuat: Quat, path: AccumPath): Option[Branch] = thisQuat match { @@ -163,20 +163,20 @@ private[getquill] object FindBranches { } object SingletonProduct { - def unapply(quat: Quat) = + def unapply(quat: Quat): Option[(String, (String, Quat))] = quat match { case p: Quat.Product if (p.fields.size == 1) => Some((p.name, p.fields.head)) case _ => None } } - case class RootElement(fieldClassName: String) - case class PathElement(field: String, fieldClassName: String) + final case class RootElement(fieldClassName: String) + final case class PathElement(field: String, fieldClassName: String) - case class Branch(first: RootElement, tailPath: List[PathElement], innermostField: String) { + final case class Branch(first: RootElement, tailPath: List[PathElement], innermostField: String) { // field name originally given to a branch will always be "root" but this allows a higher level mechanism to set it since // the higher level mechanism should know the parent-product of the whole branch - def pathWithRootField(fieldName: String) = + def pathWithRootField(fieldName: String): List[PathElement] = PathElement(fieldName, first.fieldClassName) +: tailPath } } diff --git a/quill-engine/src/main/scala/io/getquill/quat/Quat.scala b/quill-engine/src/main/scala/io/getquill/quat/Quat.scala index c16f46b861..a944830567 100644 --- a/quill-engine/src/main/scala/io/getquill/quat/Quat.scala +++ b/quill-engine/src/main/scala/io/getquill/quat/Quat.scala @@ -8,10 +8,10 @@ import scala.collection.mutable object LinkedHashMapOps { implicit class LinkedHashMapExt[K, V](m1: mutable.LinkedHashMap[K, V]) { - def zipWith[R](m2: mutable.LinkedHashMap[K, V])(f: PartialFunction[(K, V, Option[V]), R]) = + def zipWith[R](m2: mutable.LinkedHashMap[K, V])(f: PartialFunction[(K, V, Option[V]), R]): List[R] = LinkedHashMapOps.zipWith(m1, m2, f) - def outerZipWith[R](m2: mutable.LinkedHashMap[K, V])(f: PartialFunction[(K, Option[V], Option[V]), R]) = + def outerZipWith[R](m2: mutable.LinkedHashMap[K, V])(f: PartialFunction[(K, Option[V], Option[V]), R]): mutable.LinkedHashSet[R] = LinkedHashMapOps.outerZipWith(m1, m2, f) } @@ -19,14 +19,14 @@ object LinkedHashMapOps { m1: mutable.LinkedHashMap[K, V], m2: mutable.LinkedHashMap[K, V], f: PartialFunction[(K, V, Option[V]), R] - ) = + ): List[R] = m1.toList.map(r => (r._1, r._2, m2.get(r._1))).collect(f) def outerZipWith[K, V, R]( m1: mutable.LinkedHashMap[K, V], m2: mutable.LinkedHashMap[K, V], f: PartialFunction[(K, Option[V], Option[V]), R] - ) = + ): mutable.LinkedHashSet[R] = mutable.LinkedHashSet((m1.keySet.toList ++ m2.keySet.toList): _*).map(k => (k, m1.get(k), m2.get(k))).collect(f) } @@ -48,7 +48,7 @@ object LinkedHashMapOps { * assumed that all operations Quats have referential transparency. */ sealed trait Quat { - def isAbstract = + def isAbstract: Boolean = this match { case Quat.Generic => true case Quat.Unknown => true @@ -62,7 +62,7 @@ sealed trait Quat { def withRenames(renames: List[(String, String)]): Quat = withRenames(mutable.LinkedHashMap(renames: _*)) - def serialize = BooQuatSerializer.serialize(this) + def serialize: String = BooQuatSerializer.serialize(this) /** Recursively count the fields of the Quat */ def countFields: Int = @@ -77,7 +77,7 @@ sealed trait Quat { * Either convert to a Product or make the Quat into an error if it is * anything else. */ - def probit = + def probit: Quat.Product = this match { case p: Quat.Product => p case other => QuatException(s"Was expecting SQL-level type must be a Product but found `${other}`") @@ -177,7 +177,7 @@ sealed trait Quat { object Quat { object Is { - def unapply(ast: Ast) = Some(ast.quat) + def unapply(ast: Ast): Some[Quat] = Some(ast.quat) } object IsAbstract { @@ -191,7 +191,7 @@ object Quat { * This is needed to propagate the Quat of an Infix param to the infix quat itself. * See here for more details: https://github.com/zio/zio-quill/pull/2420 */ - def improveInfixQuat(ast: Ast) = + def improveInfixQuat(ast: Ast): Ast = ast match { // Possibly improve the quat if an infix clause if it has exactly one inner Ast element and the type of it's quat is Generic case i @ Infix(parts, List(param), pure, transparent, _) if (transparent) => @@ -221,13 +221,13 @@ object Quat { override def isProduct = true private val id = Product.Id(fields) - override def equals(that: Any) = + override def equals(that: Any): scala.Boolean = that match { case e: Quat.Product => this.id == e.id case _ => false } - override def hashCode = id.hashCode() + override def hashCode: Int = id.hashCode() def copy( name: String = this.name, @@ -285,7 +285,7 @@ object Quat { override def withRenames(renames: mutable.LinkedHashMap[String, String]): Quat.Product = Product.WithRenames(name, tpe, fields, renames) - def withType(tpe: Quat.Product.Type) = + def withType(tpe: Quat.Product.Type): Product = this.copy(tpe = tpe) override def withRenames(renames: List[(String, String)]): Quat.Product = @@ -312,11 +312,11 @@ object Quat { Product.WithRenames(name, tpe, newFields, renames) } } - def LeafProduct(name: String, list: String*) = Quat.Product(name, list.map(e => (e, Quat.Value))) - def LeafTuple(numElems: Int) = Quat.Tuple((1 to numElems).map(_ => Quat.Value)) + def LeafProduct(name: String, list: String*): Product = Quat.Product(name, list.map(e => (e, Quat.Value))) + def LeafTuple(numElems: Int): Product = Quat.Tuple((1 to numElems).map(_ => Quat.Value)) object Product { - case class Id(fields: mutable.LinkedHashMap[String, Quat]) + final case class Id(fields: mutable.LinkedHashMap[String, Quat]) def fromSerialized(serial: String): Quat.Product = BooQuatSerializer.deserialize(serial).probit @@ -392,7 +392,7 @@ object Quat { tpe: Quat.Product.Type, list: Iterator[(String, Quat)], renames: Iterator[(String, String)] - ) = + ): Product = WithRenames.apply( name, tpe, @@ -400,14 +400,14 @@ object Quat { (mutable.LinkedHashMap[String, String]() ++ renames): mutable.LinkedHashMap[String, String] ) - def unapply(p: Quat.Product) = + def unapply(p: Quat.Product): Some[(mutable.LinkedHashMap[String,Quat], mutable.LinkedHashMap[String,String])] = Some((p.fields, p.renames)) } object WithRenamesCompact { def apply(name: String, tpe: Quat.Product.Type)( fields: String* - )(values: Quat*)(renamesFrom: String*)(renamesTo: String*) = { + )(values: Quat*)(renamesFrom: String*)(renamesTo: String*): Product = { if (fields.length != values.length) throw new IllegalArgumentException( s"Property Re-creation failed because fields length ${fields.length} was not same as values length ${values.length}." + @@ -421,7 +421,7 @@ object Quat { Product.WithRenames.iterated(name, tpe, fields.zip(values).iterator, renamesFrom.zip(renamesTo).iterator) } - def unapply(p: Quat.Product) = { + def unapply(p: Quat.Product): Some[(String, Type, mutable.Iterable[String], mutable.Iterable[Quat], mutable.Iterable[String], mutable.Iterable[String])] = { val (fields, values) = p.fields.unzip val (renamesFrom, renamesTo) = p.renames.unzip Some((p.name, p.tpe, fields, values, renamesFrom, renamesTo)) @@ -439,13 +439,13 @@ object Quat { } } case object Null extends Quat { - override def withRenames(renames: mutable.LinkedHashMap[String, String]) = this + override def withRenames(renames: mutable.LinkedHashMap[String, String]): io.getquill.quat.Quat.Null.type = this } case object Generic extends Quat { - override def withRenames(renames: mutable.LinkedHashMap[String, String]) = this + override def withRenames(renames: mutable.LinkedHashMap[String, String]): io.getquill.quat.Quat.Generic.type = this } case object Unknown extends Quat { - override def withRenames(renames: mutable.LinkedHashMap[String, String]) = this + override def withRenames(renames: mutable.LinkedHashMap[String, String]): io.getquill.quat.Quat.Unknown.type = this } object Placeholder { diff --git a/quill-engine/src/main/scala/io/getquill/quat/QuatOps.scala b/quill-engine/src/main/scala/io/getquill/quat/QuatOps.scala index a076f0c9a2..9d9cde16be 100644 --- a/quill-engine/src/main/scala/io/getquill/quat/QuatOps.scala +++ b/quill-engine/src/main/scala/io/getquill/quat/QuatOps.scala @@ -6,14 +6,14 @@ import io.getquill.quotation.QuatException private[getquill] object QuatOps { object Implicits { implicit class QuatOpsExt(quat: Quat.Product) { - def renameAtPath(path: List[String], renames: List[(String, String)]) = + def renameAtPath(path: List[String], renames: List[(String, String)]): Quat.Product = QuatOps.renameQuatAtPath(path, renames, quat) } } // Grouping renames at particular paths allows us to // Apply a set of renames in a particular path to a Quat - def renameQuatAtPath(path: List[String], renames: List[(String, String)], rootQuat: Quat.Product) = { + def renameQuatAtPath(path: List[String], renames: List[(String, String)], rootQuat: Quat.Product): Quat.Product = { def renameQuatAtPathRecurse(path: List[String], curr: List[String], quat: Quat.Product): Quat.Product = path match { case Nil => @@ -40,7 +40,7 @@ private[getquill] object QuatOps { Quat.Product.WithRenames(quat.name, quat.tpe, newFields, quat.renames) } - renameQuatAtPathRecurse(path, List(), rootQuat) + renameQuatAtPathRecurse(path, List.empty, rootQuat) } object HasBooleanQuat { diff --git a/quill-engine/src/main/scala/io/getquill/quotation/FreeVariables.scala b/quill-engine/src/main/scala/io/getquill/quotation/FreeVariables.scala index 4d640d6de2..a5561beb2d 100644 --- a/quill-engine/src/main/scala/io/getquill/quotation/FreeVariables.scala +++ b/quill-engine/src/main/scala/io/getquill/quotation/FreeVariables.scala @@ -4,9 +4,9 @@ import io.getquill.ast._ import io.getquill.ast.Implicits._ import collection.immutable.Set -case class State(seen: Set[IdentName], free: Set[IdentName]) +final case class State(seen: Set[IdentName], free: Set[IdentName]) -case class FreeVariables(state: State) extends StatefulTransformer[State] { +final case class FreeVariables(state: State) extends StatefulTransformer[State] { override def apply(ast: Ast): (Ast, StatefulTransformer[State]) = ast match { diff --git a/quill-engine/src/main/scala/io/getquill/quotation/NonQuotedException.scala b/quill-engine/src/main/scala/io/getquill/quotation/NonQuotedException.scala index 9348856c8c..a60df52689 100644 --- a/quill-engine/src/main/scala/io/getquill/quotation/NonQuotedException.scala +++ b/quill-engine/src/main/scala/io/getquill/quotation/NonQuotedException.scala @@ -4,5 +4,5 @@ class NonQuotedException extends Exception(NonQuotedException.message) object NonQuotedException { final val message = "The query definition must happen within a `quote` block." - def apply() = throw new NonQuotedException + def apply(): Nothing = throw new NonQuotedException } diff --git a/quill-engine/src/main/scala/io/getquill/quotation/QuatException.scala b/quill-engine/src/main/scala/io/getquill/quotation/QuatException.scala index 50df80103a..fd07ec041b 100644 --- a/quill-engine/src/main/scala/io/getquill/quotation/QuatException.scala +++ b/quill-engine/src/main/scala/io/getquill/quotation/QuatException.scala @@ -5,12 +5,12 @@ import io.getquill.quat.Quat class QuatException(message: String) extends IllegalArgumentException(message) object QuatException { - def apply(message: String) = throw new QuatException(message) + def apply(message: String): Nothing = throw new QuatException(message) } object QuatExceptionOps { implicit class QuatExceptionOpsExt(quat: => Quat) { - def suppress(additionalMessage: String = "") = + def suppress(additionalMessage: String = ""): String = try { quat.shortString } catch { case e: QuatException => diff --git a/quill-engine/src/main/scala/io/getquill/sql/Common.scala b/quill-engine/src/main/scala/io/getquill/sql/Common.scala index dde1a8bf04..10af8c43ca 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/Common.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/Common.scala @@ -4,7 +4,7 @@ import io.getquill.ast.{Aggregation, Ast, CollectAst, Infix} object Common { object ContainsImpurities { - def unapply(ast: Ast) = + def unapply(ast: Ast): Boolean = CollectAst(ast) { case agg: Aggregation => agg case inf: Infix if (!inf.pure) => inf diff --git a/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala b/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala index df0ce67d9a..86d492fdcf 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala @@ -9,21 +9,21 @@ import io.getquill.util.Messages.{TraceType, fail} import io.getquill.{Literal, PseudoAst, IdiomContext} import io.getquill.sql.Common.ContainsImpurities -case class OrderByCriteria(ast: Ast, ordering: PropertyOrdering) +final case class OrderByCriteria(ast: Ast, ordering: PropertyOrdering) sealed trait FromContext { def quat: Quat } -case class TableContext(entity: Entity, alias: String) extends FromContext { def quat = entity.quat } -case class QueryContext(query: SqlQuery, alias: String) extends FromContext { def quat = query.quat } -case class InfixContext(infix: Infix, alias: String) extends FromContext { def quat = infix.quat } -case class JoinContext(t: JoinType, a: FromContext, b: FromContext, on: Ast) extends FromContext { - def quat = Quat.Tuple(a.quat, b.quat) +final case class TableContext(entity: Entity, alias: String) extends FromContext { def quat = entity.quat } +final case class QueryContext(query: SqlQuery, alias: String) extends FromContext { def quat = query.quat } +final case class InfixContext(infix: Infix, alias: String) extends FromContext { def quat = infix.quat } +final case class JoinContext(t: JoinType, a: FromContext, b: FromContext, on: Ast) extends FromContext { + def quat: Quat.Product = Quat.Tuple(a.quat, b.quat) } -case class FlatJoinContext(t: JoinType, a: FromContext, on: Ast) extends FromContext { def quat = a.quat } +final case class FlatJoinContext(t: JoinType, a: FromContext, on: Ast) extends FromContext { def quat = a.quat } sealed trait SqlQuery { def quat: Quat - override def toString = { + override def toString: String = { import io.getquill.MirrorSqlDialect._ import io.getquill.idiom.StatementInterpolator._ implicit val idiomContext = IdiomContext.Empty @@ -40,11 +40,11 @@ case object UnionAllOperation extends SetOperation sealed trait DistinctKind { def isDistinct: Boolean } case object DistinctKind { case object Distinct extends DistinctKind { val isDistinct: Boolean = true } - case class DistinctOn(props: List[Ast]) extends DistinctKind { val isDistinct: Boolean = true } + final case class DistinctOn(props: List[Ast]) extends DistinctKind { val isDistinct: Boolean = true } case object None extends DistinctKind { val isDistinct: Boolean = false } } -case class SetOperationSqlQuery( +final case class SetOperationSqlQuery( a: SqlQuery, op: SetOperation, b: SqlQuery @@ -53,7 +53,7 @@ case class SetOperationSqlQuery( def quat = quatType } -case class UnaryOperationSqlQuery( +final case class UnaryOperationSqlQuery( op: UnaryOperator, q: SqlQuery )(quatType: Quat) @@ -61,15 +61,15 @@ case class UnaryOperationSqlQuery( def quat = quatType } -case class SelectValue(ast: Ast, alias: Option[String] = None, concat: Boolean = false) extends PseudoAst { +final case class SelectValue(ast: Ast, alias: Option[String] = None, concat: Boolean = false) extends PseudoAst { override def toString: String = s"${ast.toString}${alias.map("->" + _).getOrElse("")}" } -case class FlattenSqlQuery( - from: List[FromContext] = List(), +final case class FlattenSqlQuery( + from: List[FromContext] = List.empty, where: Option[Ast] = None, groupBy: Option[Ast] = None, - orderBy: List[OrderByCriteria] = Nil, + orderBy: List[OrderByCriteria] = List.empty, limit: Option[Ast] = None, offset: Option[Ast] = None, select: List[SelectValue], @@ -88,7 +88,7 @@ object TakeDropFlatten { } object CaseClassMake { - def fromQuat(quat: Quat)(idName: String) = + def fromQuat(quat: Quat)(idName: String): CaseClass = quat match { case p @ Quat.Product(fields) => CaseClass(p.name, fields.toList.map { case (name, _) => (name, Property(Ident(idName, quat), name)) }) @@ -180,7 +180,7 @@ class SqlQueryApply(traceConfig: TraceConfig) { nestNextMap: Boolean ): FlattenSqlQuery = { - def select(alias: String, quat: Quat) = SelectValue(Ident(alias, quat), None) :: Nil + def select(alias: String, quat: Quat) = SelectValue(Ident(alias, quat), None) :: List.empty def base(q: Ast, alias: String, nestNextMap: Boolean): FlattenSqlQuery = trace"Computing Base (nestingMaps=${nestNextMap}) for Query: $q" andReturn { @@ -190,8 +190,7 @@ class SqlQueryApply(traceConfig: TraceConfig) { q match { case _: GroupByMap => trace"base| Nesting GroupByMap $q" andReturn nest(source(q, alias)) case Map(GroupBy(input, id, _), _, _) => - val innerContext = - input match { + input match { case _: Map => nest(source(input, id.name)) case _ => @@ -529,13 +528,6 @@ class SqlQueryApply(traceConfig: TraceConfig) { case FlatJoinContext(_, from, _) => collectAliases(List(from)) } - private def collectTableAliases(contexts: List[FromContext]): List[String] = - contexts.flatMap { - case c: TableContext => List(c.alias) - case c: QueryContext => List() - case c: InfixContext => List() - case JoinContext(_, a, b, _) => collectAliases(List(a)) ++ collectAliases(List(b)) - case FlatJoinContext(_, from, _) => collectAliases(List(from)) - } + List.emptyList.empty } diff --git a/quill-engine/src/main/scala/io/getquill/sql/idiom/BooleanLiteralSupport.scala b/quill-engine/src/main/scala/io/getquill/sql/idiom/BooleanLiteralSupport.scala index 48537d4196..2898f77021 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/idiom/BooleanLiteralSupport.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/idiom/BooleanLiteralSupport.scala @@ -19,7 +19,7 @@ trait BooleanLiteralSupport extends SqlIdiom { concatBehavior: ConcatBehavior, equalityBehavior: EqualityBehavior, idiomContext: IdiomContext - ) = { + ): Ast = { val norm = SqlNormalize(ast, idiomContext.config, concatBehavior, equalityBehavior) if (Messages.smartBooleans) VendorizeBooleans(norm) diff --git a/quill-engine/src/main/scala/io/getquill/sql/idiom/ConcatSupport.scala b/quill-engine/src/main/scala/io/getquill/sql/idiom/ConcatSupport.scala index aacb8efa3b..e69a974117 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/idiom/ConcatSupport.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/idiom/ConcatSupport.scala @@ -11,5 +11,5 @@ trait ConcatSupport { trait NoConcatSupport { this: SqlIdiom => - override def concatFunction = Messages.fail(s"`concatMap` not supported by ${this.getClass.getSimpleName}") + override def concatFunction: Nothing = Messages.fail(s"`concatMap` not supported by ${this.getClass.getSimpleName}") } diff --git a/quill-engine/src/main/scala/io/getquill/sql/idiom/SqlIdiom.scala b/quill-engine/src/main/scala/io/getquill/sql/idiom/SqlIdiom.scala index 2fea936a4b..14bc43da78 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/idiom/SqlIdiom.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/idiom/SqlIdiom.scala @@ -24,7 +24,7 @@ import io.getquill.sql.norm.{ RemoveUnusedSelects } import io.getquill.util.{Interleave, Interpolator, Messages, TraceConfig} -import io.getquill.util.Messages.{TraceType, fail, trace} +import io.getquill.util.Messages.{TraceType, fail} trait SqlIdiom extends Idiom { @@ -46,13 +46,13 @@ trait SqlIdiom extends Idiom { concatBehavior: ConcatBehavior, equalityBehavior: EqualityBehavior, idiomContext: IdiomContext - ) = + ): Ast = SqlNormalize(ast, idiomContext.config, concatBehavior, equalityBehavior) def querifyAst(ast: Ast, traceConfig: TraceConfig) = new SqlQueryApply(traceConfig)(ast) // See HideTopLevelFilterAlias for more detail on how this works - def querifyAction(ast: Action, batchAlias: Option[String]) = { + def querifyAction(ast: Action, batchAlias: Option[String]): Action = { val norm1 = new NormalizeFilteredActionAliases(batchAlias)(ast) val norm2 = io.getquill.sql.norm.HideInnerProperties(norm1) useActionTableAliasAs match { @@ -172,7 +172,7 @@ trait SqlIdiom extends Idiom { val (l, e) = flatten(b) ((cond, a) +: l, e) case other => - (List(), other) + (List.empty, other) } val (l, e) = flatten(ast) @@ -196,13 +196,13 @@ trait SqlIdiom extends Idiom { import q._ - def selectTokenizer = + def selectTokenizer: Token = select match { case Nil => stmt"*" case _ => select.token } - def distinctTokenizer = ( + def distinctTokenizer = (: Statement distinct match { case DistinctKind.Distinct => stmt"DISTINCT " case DistinctKind.DistinctOn(props) => stmt"DISTINCT ON (${props.token}) " @@ -210,9 +210,9 @@ trait SqlIdiom extends Idiom { } ) - def withDistinct = stmt"$distinctTokenizer${selectTokenizer}" + def withDistinct: Statement = stmt"$distinctTokenizer${selectTokenizer}" - def withFrom = + def withFrom: Statement = from match { case Nil => withDistinct case head :: tail => @@ -226,27 +226,27 @@ trait SqlIdiom extends Idiom { stmt"$withDistinct FROM $t" } - def withWhere = + def withWhere: Statement = where match { case None => withFrom case Some(where) => stmt"$withFrom WHERE ${where.token}" } - def withGroupBy = + def withGroupBy: Statement = groupBy match { case None => withWhere case Some(groupBy) => stmt"$withWhere GROUP BY ${tokenizeGroupBy(groupBy)}" } - def withOrderBy = + def withOrderBy: Statement = orderBy match { case Nil => withGroupBy case orderBy => stmt"$withGroupBy ${tokenOrderBy(orderBy)}" } - def withLimitOffset = limitOffsetToken(withOrderBy).token((limit, offset)) + def withLimitOffset: Token = limitOffsetToken(withOrderBy).token((limit, offset)) - def apply = stmt"SELECT $withLimitOffset" + def apply: Statement = stmt"SELECT $withLimitOffset" } implicit def sqlQueryTokenizer(implicit @@ -262,13 +262,13 @@ trait SqlIdiom extends Idiom { stmt"SELECT ${op.token} (${q.token})" } - protected def tokenizeColumn(strategy: NamingStrategy, column: String, renameable: Renameable) = + protected def tokenizeColumn(strategy: NamingStrategy, column: String, renameable: Renameable): String = renameable match { case Fixed => tokenizeFixedColumn(strategy, column) case _ => strategy.column(column) } - protected def tokenizeTable(strategy: NamingStrategy, table: String, renameable: Renameable) = + protected def tokenizeTable(strategy: NamingStrategy, table: String, renameable: Renameable): String = renameable match { case Fixed => table case _ => strategy.table(table) @@ -389,7 +389,7 @@ trait SqlIdiom extends Idiom { case UnionAllOperation => stmt"UNION ALL" } - protected def limitOffsetToken(query: Statement)(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy) = + protected def limitOffsetToken(query: Statement)(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy): Tokenizer[(Option[Ast], Option[Ast])] = Tokenizer[(Option[Ast], Option[Ast])] { case (None, None) => query case (Some(limit), None) => stmt"$query LIMIT ${limit.token}" @@ -399,7 +399,7 @@ trait SqlIdiom extends Idiom { protected def tokenOrderBy( criteria: List[OrderByCriteria] - )(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy) = + )(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy): Statement = stmt"ORDER BY ${criteria.token}" implicit def sourceTokenizer(implicit @@ -536,7 +536,7 @@ trait SqlIdiom extends Idiom { strategy: NamingStrategy, renameable: Renameable, prefixRenameable: Renameable = Renameable.neutral - ) = + ): Token = prefixRenameable match { case Renameable.Fixed => // Typically this happens in a nested query on an multi-level select e.g. @@ -615,7 +615,7 @@ trait SqlIdiom extends Idiom { astTokenizer: Tokenizer[Ast], strategy: NamingStrategy, idiomContext: IdiomContext - ) = + ): Tokenizer[Ast] = Tokenizer.withFallback[Ast](SqlIdiom.this.astTokenizer(_, strategy, idiomContext)) { case q: Query => astTokenizer.token(q) case Property(Property.Opinionated(_, name, renameable, _), "isEmpty") => @@ -736,7 +736,7 @@ trait SqlIdiom extends Idiom { astTokenizer: Tokenizer[Ast], strategy: NamingStrategy, idiomContext: IdiomContext - ) = + ): Token = returnListTokenizer.token(ExpandReturning(r, alias)(this, strategy, idiomContext).map(_._1)) private def insertInfo( @@ -768,7 +768,7 @@ trait SqlIdiom extends Idiom { tokenizeTable(strategy, name, renameable).token } - protected def scopedTokenizer(ast: Ast)(implicit tokenizer: Tokenizer[Ast]) = + protected def scopedTokenizer(ast: Ast)(implicit tokenizer: Tokenizer[Ast]): Token = ast match { case _: Query => stmt"(${ast.token})" case _: BinaryOperation => stmt"(${ast.token})" @@ -801,7 +801,7 @@ object SqlIdiom { override def productAggregationToken: ProductAggregationToken = parent.productAggregationToken } - case class InsertUpdateStmt(action: Statement, where: Statement) + final case class InsertUpdateStmt(action: Statement, where: Statement) private[getquill] def withActionAlias(parentIdiom: SqlIdiom, action: Action, alias: Ident)(implicit strategy: NamingStrategy, idiomContext: IdiomContext diff --git a/quill-engine/src/main/scala/io/getquill/sql/idiom/VerifySqlQuery.scala b/quill-engine/src/main/scala/io/getquill/sql/idiom/VerifySqlQuery.scala index 3c33064475..60eb8cb5e0 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/idiom/VerifySqlQuery.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/idiom/VerifySqlQuery.scala @@ -5,11 +5,11 @@ import io.getquill.context.sql._ import io.getquill.quotation.FreeVariables import io.getquill.quat.Quat -case class Error(free: List[Ident], ast: Ast) -case class InvalidSqlQuery(errors: List[Error]) { - override def toString = { +final case class Error(free: List[Ident], ast: Ast) +final case class InvalidSqlQuery(errors: List[Error]) { + override def toString: String = { val allVars = errors.flatMap(_.free).distinct - val firstVar = errors.headOption.flatMap(_.free.headOption).getOrElse("someVar") + errors.headOption.flatMap(_.free.headOption).getOrElse("someVar") s""" |When synthesizing Joins, Quill found some variables that could not be traced back to their |origin: ${allVars.map(_.name)}. Typically this happens when there are some flatMapped @@ -54,7 +54,7 @@ object VerifySqlQuery { ) nav } - loop(q.from, Set()) + loop(q.from, Set.empty) } private def verify(query: FlattenSqlQuery): Option[InvalidSqlQuery] = { diff --git a/quill-engine/src/main/scala/io/getquill/sql/norm/ExpandJoin.scala b/quill-engine/src/main/scala/io/getquill/sql/norm/ExpandJoin.scala index c8d4932477..88d151f1e6 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/norm/ExpandJoin.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/norm/ExpandJoin.scala @@ -19,9 +19,9 @@ import io.getquill.norm.Normalize */ class ExpandJoin(normalize: Normalize) { - def apply(q: Ast) = expand(q, None) + def apply(q: Ast): Ast = expand(q, None) - def expand(q: Ast, id: Option[Ident]) = + def expand(q: Ast, id: Option[Ident]): Ast = Transform(q) { case q @ Join( _, diff --git a/quill-engine/src/main/scala/io/getquill/sql/norm/ExpandNestedQueries.scala b/quill-engine/src/main/scala/io/getquill/sql/norm/ExpandNestedQueries.scala index 1d8a607627..d26b26d0b5 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/norm/ExpandNestedQueries.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/norm/ExpandNestedQueries.scala @@ -98,8 +98,8 @@ object ExpandNestedQueries extends StatelessQueryTransformer { super.apply(q, level) } - case class FlattenNestedProperty(from: List[FromContext]) { - val inContext = InContext(from) + final case class FlattenNestedProperty(from: List[FromContext]) { + val inContext: InContext = InContext(from) def apply(p: Ast): Ast = p match { @@ -122,7 +122,7 @@ object ExpandNestedQueries extends StatelessQueryTransformer { case other => other } - def inside(ast: Ast) = + def inside(ast: Ast): Ast = Transform(ast) { case p: Property => apply(p) } diff --git a/quill-engine/src/main/scala/io/getquill/sql/norm/FlattenGroupByAggregation.scala b/quill-engine/src/main/scala/io/getquill/sql/norm/FlattenGroupByAggregation.scala index 9cd32c6b28..fae2a4c18e 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/norm/FlattenGroupByAggregation.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/norm/FlattenGroupByAggregation.scala @@ -18,9 +18,9 @@ import io.getquill.norm.BetaReduction import io.getquill.util.Messages.fail import io.getquill.ast.ConcatMap -case class FlattenGroupByAggregation(agg: Ident) extends StatelessTransformer { +final case class FlattenGroupByAggregation(agg: Ident) extends StatelessTransformer { - override def apply(ast: Ast) = + override def apply(ast: Ast): Ast = ast match { case q: Query if (isGroupByAggregation(q)) => q match { diff --git a/quill-engine/src/main/scala/io/getquill/sql/norm/HideTopLevelFilterAlias.scala b/quill-engine/src/main/scala/io/getquill/sql/norm/HideTopLevelFilterAlias.scala index 5c1c02387c..a47fd57ec7 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/norm/HideTopLevelFilterAlias.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/norm/HideTopLevelFilterAlias.scala @@ -19,12 +19,12 @@ import io.getquill.norm.BetaReduction // Note that this is the case with Oracle. With SqlServer we also use this functionality // but with output causes the alias becomes OUTPUT so it can be different in those cases. object HideTopLevelFilterAlias extends StatelessTransformer { - def hideAlias(alias: Ident, in: Ast) = { + def hideAlias(alias: Ident, in: Ast): (Ident, Ast) = { val newAlias = Ident.Opinionated(alias.name, alias.quat, Visibility.Hidden) (newAlias, BetaReduction(in, alias -> newAlias)) } - def hideAssignmentAlias(assignment: Assignment) = { + def hideAssignmentAlias(assignment: Assignment): Assignment = { val alias = assignment.alias val newAlias = Ident.Opinionated(alias.name, alias.quat, Visibility.Hidden) val newValue = BetaReduction(assignment.value, alias -> newAlias) diff --git a/quill-engine/src/main/scala/io/getquill/sql/norm/NormalizeActionAliases.scala b/quill-engine/src/main/scala/io/getquill/sql/norm/NormalizeActionAliases.scala index 042bf88426..bb3316b0b7 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/norm/NormalizeActionAliases.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/norm/NormalizeActionAliases.scala @@ -1,7 +1,6 @@ package io.getquill.sql.norm import io.getquill.ast._ -import io.getquill.norm.BetaReduction object NormalizeFilteredActionAliases { private[getquill] def chooseAlias(entityName: String, batchAlias: Option[String]) = { @@ -39,7 +38,7 @@ object HideInnerProperties extends StatelessTransformer { } } -case class NormalizeFilteredActionAliases(batchAlias: Option[String]) extends StatelessTransformer { +final case class NormalizeFilteredActionAliases(batchAlias: Option[String]) extends StatelessTransformer { override def apply(e: Action): Action = e match { diff --git a/quill-engine/src/main/scala/io/getquill/sql/norm/RemoveExtraAlias.scala b/quill-engine/src/main/scala/io/getquill/sql/norm/RemoveExtraAlias.scala index 95d4f4cfd0..11237a8ae0 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/norm/RemoveExtraAlias.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/norm/RemoveExtraAlias.scala @@ -10,7 +10,7 @@ import io.getquill.context.sql.{FlattenSqlQuery, SelectValue} * object) as well as entities whose aliases are the same as their selection * e.g. "select x.foo as foo" since this just adds syntactic noise. */ -case class RemoveExtraAlias(strategy: NamingStrategy) extends StatelessQueryTransformer { +final case class RemoveExtraAlias(strategy: NamingStrategy) extends StatelessQueryTransformer { // Remove aliases that are the same as as the select values. Since a strategy may change the name, // use a heuristic where if the column naming strategy make the property name be different from the // alias, keep the column property name. diff --git a/quill-engine/src/main/scala/io/getquill/sql/norm/RemoveUnusedSelects.scala b/quill-engine/src/main/scala/io/getquill/sql/norm/RemoveUnusedSelects.scala index 7343895975..91500ea8b2 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/norm/RemoveUnusedSelects.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/norm/RemoveUnusedSelects.scala @@ -2,7 +2,6 @@ package io.getquill.sql.norm import io.getquill.ast.{Ast, CollectAst, Ident, Property, StatefulTransformer} import io.getquill.context.sql.{ - DistinctKind, FlatJoinContext, FlattenSqlQuery, FromContext, @@ -112,16 +111,16 @@ object RemoveUnusedSelects { } private def references(alias: String, asts: List[Ast]) = - LinkedHashSet.empty ++ (References(State(Ident(alias, Quat.Value), Nil))(asts)(_.apply)._2.state.references) + LinkedHashSet.empty ++ (References(State(Ident(alias, Quat.Value), List.empty))(asts)(_.apply)._2.state.references) } -case class State(ident: Ident, references: List[Property]) +final case class State(ident: Ident, references: List[Property]) -case class References(val state: State) extends StatefulTransformer[State] { +final case class References(val state: State) extends StatefulTransformer[State] { import state._ - override def apply(a: Ast) = + override def apply(a: Ast): (Ast, StatefulTransformer[State]) = a match { case `reference`(p) => (p, References(State(ident, references :+ p))) case other => super.apply(a) diff --git a/quill-engine/src/main/scala/io/getquill/sql/norm/SelectPropertyProtractor.scala b/quill-engine/src/main/scala/io/getquill/sql/norm/SelectPropertyProtractor.scala index 7439d9d4dd..bdb1c8d285 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/norm/SelectPropertyProtractor.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/norm/SelectPropertyProtractor.scala @@ -33,23 +33,23 @@ import io.getquill.sql.norm.InContext.{InContextType, InInfixContext, InQueryCon * that we may not know the FromContext that a property comes from since it may * not exist. */ -case class InContext(from: List[FromContext]) { +final case class InContext(from: List[FromContext]) { // Are we sure it is a subselect - def isSubselect(ast: Ast) = + def isSubselect(ast: Ast): Boolean = contextReferenceType(ast) match { case Some(InQueryContext) => true case _ => false } // Are we sure it is a table reference - def isEntityReference(ast: Ast) = + def isEntityReference(ast: Ast): Boolean = contextReferenceType(ast) match { case Some(InTableContext) => true case Some(InInfixContext) => true case _ => false } - def contextReferenceType(ast: Ast) = { + def contextReferenceType(ast: Ast): Option[InContextType] = { val references = collectTableAliases(from) ast match { case Ident(v, _) => references.get(v) @@ -65,7 +65,7 @@ case class InContext(from: List[FromContext]) { case c: InfixContext => Map(c.alias -> InInfixContext) case JoinContext(_, a, b, _) => collectTableAliases(List(a)) ++ collectTableAliases(List(b)) case FlatJoinContext(_, from, _) => collectTableAliases(List(from)) - }.foldLeft(Map[String, InContextType]())(_ ++ _) + }.foldLeft(Map.empty[String, InContextType])(_ ++ _) } object InContext { sealed trait InContextType @@ -74,8 +74,8 @@ object InContext { case object InInfixContext extends InContextType } -case class SelectPropertyProtractor(from: List[FromContext]) { - val inContext = InContext(from) +final case class SelectPropertyProtractor(from: List[FromContext]) { + val inContext: InContext = InContext(from) /* * Properties that do not belong to an entity i.e. where the 'from' is not @@ -142,7 +142,7 @@ case class SelectPropertyProtractor(from: List[FromContext]) { * quat: CC(foo,bar:Quat(a,b)) with core id:Ident(x) => * List( Prop(id,foo) [foo], Prop(Prop(id,bar),a) [bar.a], Prop(Prop(id,bar),b) [bar.b] ) */ -case class ProtractQuat(refersToEntity: Boolean) { +final case class ProtractQuat(refersToEntity: Boolean) { def apply(quat: Quat.Product, core: Ast): List[(Property, List[String])] = { val prot = applyInner(quat, core) prot diff --git a/quill-engine/src/main/scala/io/getquill/sql/norm/SqlNormalize.scala b/quill-engine/src/main/scala/io/getquill/sql/norm/SqlNormalize.scala index 9d1622f686..12b2143461 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/norm/SqlNormalize.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/norm/SqlNormalize.scala @@ -6,7 +6,6 @@ import io.getquill.norm.ConcatBehavior.AnsiConcat import io.getquill.norm.EqualityBehavior.AnsiEquality import io.getquill.norm.capture.{AvoidAliasConflict, DemarcateExternalAliases} import io.getquill.util.Messages.{TraceType, title} -import io.getquill.util.TraceConfig object SqlNormalize { def apply( @@ -72,5 +71,5 @@ class SqlNormalize( } .andThen(demarcate("Normalize")) - def apply(ast: Ast) = normalize(ast) + def apply(ast: Ast): Ast = normalize(ast) } diff --git a/quill-engine/src/main/scala/io/getquill/sql/norm/StatelessQueryTransformer.scala b/quill-engine/src/main/scala/io/getquill/sql/norm/StatelessQueryTransformer.scala index 588235c17e..d4612a3792 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/norm/StatelessQueryTransformer.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/norm/StatelessQueryTransformer.scala @@ -16,7 +16,7 @@ import io.getquill.quat.Quat sealed trait QueryLevel { def isTop: Boolean - def withoutTopQuat = + def withoutTopQuat: QueryLevel = this match { case QueryLevel.Top(_) => QueryLevel.TopUnwrapped case QueryLevel.TopUnwrapped => QueryLevel.TopUnwrapped @@ -26,7 +26,7 @@ sealed trait QueryLevel { object QueryLevel { /** Top-level externally-facing query */ - case class Top(topLevelQuat: Quat) extends QueryLevel { val isTop = true } + final case class Top(topLevelQuat: Quat) extends QueryLevel { val isTop = true } /** * Top-level query that is not externally facing e.g. it's an unwrapped case diff --git a/quill-engine/src/main/scala/io/getquill/sql/norm/VendorizeBooleans.scala b/quill-engine/src/main/scala/io/getquill/sql/norm/VendorizeBooleans.scala index 22b51a51d3..334b05fcea 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/norm/VendorizeBooleans.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/norm/VendorizeBooleans.scala @@ -33,7 +33,7 @@ object VendorizeBooleans extends StatelessTransformer { object OperatorOnExpressions { import BooleanOperator._ - def unapply(op: BinaryOperator) = + def unapply(op: BinaryOperator): Option[BinaryOperator] = op match { case `||` | `&&` => Some(op) case _ => None @@ -43,7 +43,7 @@ object VendorizeBooleans extends StatelessTransformer { object OperatorOnValues { import NumericOperator._ - def unapply(op: BinaryOperator) = + def unapply(op: BinaryOperator): Option[BinaryOperator] = op match { case `<` | `>` | `<=` | `>=` | EqualityOperator.`_==` | EqualityOperator.`_!=` => Some(op) case _ => None @@ -53,7 +53,7 @@ object VendorizeBooleans extends StatelessTransformer { object StringTransformerOperation { import StringOperator._ - def unapply(op: UnaryOperation) = + def unapply(op: UnaryOperation): Option[UnaryOperation] = op.operator match { case `toUpperCase` | `toLowerCase` | `toLong` | `toInt` => Some(op) case _ => None diff --git a/quill-engine/src/main/scala/io/getquill/sql/norm/nested/Elements.scala b/quill-engine/src/main/scala/io/getquill/sql/norm/nested/Elements.scala index d5c0203ff8..e5b26658ec 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/norm/nested/Elements.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/norm/nested/Elements.scala @@ -18,7 +18,7 @@ object Elements { * * This class keeps track of the values needed in order to perform do this. */ - case class OrderedSelect(order: List[Int], selectValue: SelectValue) extends PseudoAst { + final case class OrderedSelect(order: List[Int], selectValue: SelectValue) extends PseudoAst { override def toString: String = s"[${order.mkString(",")}]${selectValue}" } object OrderedSelect { diff --git a/quill-engine/src/main/scala/io/getquill/sql/norm/nested/FindUnexpressedInfixes.scala b/quill-engine/src/main/scala/io/getquill/sql/norm/nested/FindUnexpressedInfixes.scala index f4ebb9002f..6361893ea8 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/norm/nested/FindUnexpressedInfixes.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/norm/nested/FindUnexpressedInfixes.scala @@ -31,7 +31,7 @@ class FindUnexpressedInfixes(select: List[OrderedSelect], traceConfig: TraceConf val interp = new Interpolator(NestedQueryExpansion, traceConfig, 3) import interp._ - def apply(refs: List[OrderedSelect]) = { + def apply(refs: List[OrderedSelect]): List[OrderedSelect] = { def pathExists(path: List[Int]) = refs.map(_.order).contains(path) @@ -44,7 +44,7 @@ class FindUnexpressedInfixes(select: List[OrderedSelect], traceConfig: TraceConf trace"Searching for infix: $ast in the sub-path $parentOrder".andLog() if (pathExists(parentOrder)) trace"No infixes found" andContinue - List() + List.empty else ast match { case Tuple(values) => @@ -63,7 +63,7 @@ class FindUnexpressedInfixes(select: List[OrderedSelect], traceConfig: TraceConf trace"Found unexpressed infix inside $other in $parentOrder".andLog() List((other, parentOrder)) case _ => - List() + List.empty } } diff --git a/quill-engine/src/main/scala/io/getquill/util/Cache.scala b/quill-engine/src/main/scala/io/getquill/util/Cache.scala index 2bda06ae13..2e5c0e7a37 100644 --- a/quill-engine/src/main/scala/io/getquill/util/Cache.scala +++ b/quill-engine/src/main/scala/io/getquill/util/Cache.scala @@ -9,7 +9,7 @@ class Cache[K, V <: Closeable] { private case class Entry(value: Option[V], expiration: Long) - private var cache = Map[K, Entry]() + private var cache = Map.empty[K, Entry] def getOrElseUpdate(key: K, value: => Option[V], ttl: Duration): Option[V] = synchronized { diff --git a/quill-engine/src/main/scala/io/getquill/util/ContextLogger.scala b/quill-engine/src/main/scala/io/getquill/util/ContextLogger.scala index 93c41e98d3..91be55f6d6 100644 --- a/quill-engine/src/main/scala/io/getquill/util/ContextLogger.scala +++ b/quill-engine/src/main/scala/io/getquill/util/ContextLogger.scala @@ -6,14 +6,14 @@ import org.slf4j.LoggerFactory import scala.annotation.tailrec class ContextLogger(name: String) { - val underlying = Logger(LoggerFactory.getLogger(name)) + val underlying: Logger = Logger(LoggerFactory.getLogger(name)) private def bindsEnabled = io.getquill.util.Messages.logBinds || underlying.underlying.isTraceEnabled private val nullToken = "null" private def maxQueryLen = Messages.queryTooLongForLogs private implicit class TrimQueryOps(str: String) { - def trimTooLong = trimQuery(str) + def trimTooLong: String = trimQuery(str) } private def trimQuery(query: String) = diff --git a/quill-engine/src/main/scala/io/getquill/util/IndentUtil.scala b/quill-engine/src/main/scala/io/getquill/util/IndentUtil.scala index 908e504e25..6e3260ce17 100644 --- a/quill-engine/src/main/scala/io/getquill/util/IndentUtil.scala +++ b/quill-engine/src/main/scala/io/getquill/util/IndentUtil.scala @@ -8,7 +8,7 @@ object IndentUtil { } implicit class IndentOps(i: Int) { - def prefix = indentOf(i) + def prefix: String = indentOf(i) } private def indentOf(num: Int) = diff --git a/quill-engine/src/main/scala/io/getquill/util/Interpolator.scala b/quill-engine/src/main/scala/io/getquill/util/Interpolator.scala index b7111adb4e..1e5db9eb57 100644 --- a/quill-engine/src/main/scala/io/getquill/util/Interpolator.scala +++ b/quill-engine/src/main/scala/io/getquill/util/Interpolator.scala @@ -10,9 +10,9 @@ import io.getquill.util.IndentUtil._ import scala.collection.mutable import scala.util.matching.Regex -case class TraceConfig(enabledTraces: List[TraceType]) +final case class TraceConfig(enabledTraces: List[TraceType]) object TraceConfig { - val Empty = new TraceConfig(List()) + val Empty = new TraceConfig(List.empty) } class Interpolator( @@ -28,7 +28,7 @@ class Interpolator( def trace(elements: Any*) = new Traceable(sc, elements) } - def tracesEnabled(traceType: TraceType) = + def tracesEnabled(traceType: TraceType): Boolean = traceConfig.enabledTraces.contains(traceType) || globalTracesEnabled(traceType) class Traceable(sc: StringContext, elementsSeq: Seq[Any]) { @@ -115,7 +115,7 @@ class Interpolator( (sb.toList, indent) } - def generateString() = { + def generateString(): (String, Int) = { val (elementsRaw, indent) = readBuffers() val elements = elementsRaw.filter { @@ -154,12 +154,12 @@ class Interpolator( def andLog(): Unit = logIfEnabled().foreach(value => out.println(value._1)) - def andContinue[T](command: => T) = { + def andContinue[T](command: => T): T = { logIfEnabled().foreach(value => out.println(value._1)) command } - def andReturn[T](command: => T) = + def andReturn[T](command: => T): T = logIfEnabled() match { case Some((output, indent)) => // do the initial log @@ -173,7 +173,7 @@ class Interpolator( command } - def andReturnIf[T](command: => T)(showIf: T => Boolean) = + def andReturnIf[T](command: => T)(showIf: T => Boolean): T = logIfEnabled() match { case Some((output, indent)) => // Even though we usually want to evaluate the command after the initial log was done diff --git a/quill-engine/src/main/scala/io/getquill/util/LoadConfig.scala b/quill-engine/src/main/scala/io/getquill/util/LoadConfig.scala index 3624f1d8ba..7521becab8 100644 --- a/quill-engine/src/main/scala/io/getquill/util/LoadConfig.scala +++ b/quill-engine/src/main/scala/io/getquill/util/LoadConfig.scala @@ -1,10 +1,11 @@ package io.getquill.util import com.typesafe.config.ConfigFactory +import com.typesafe.config.Config object LoadConfig { - def apply(configPrefix: String) = { + def apply(configPrefix: String): Config = { val factory = ConfigFactory.load(getClass.getClassLoader) if (factory.hasPath(configPrefix)) factory.getConfig(configPrefix) diff --git a/quill-engine/src/main/scala/io/getquill/util/Messages.scala b/quill-engine/src/main/scala/io/getquill/util/Messages.scala index d8adebe10c..16995509c9 100644 --- a/quill-engine/src/main/scala/io/getquill/util/Messages.scala +++ b/quill-engine/src/main/scala/io/getquill/util/Messages.scala @@ -13,58 +13,58 @@ object Messages { private def cache[T](name: String, value: => T): T = cacheMap.getOrElseUpdate(name, value).asInstanceOf[T] - def quatKryoPoolSize = + def quatKryoPoolSize: Int = cache("quill.quat.kryoPool", variable("quill.quat.kryoPool", "quill_quat_kryoPool", "10").toInt) - def maxQuatFields = + def maxQuatFields: Int = cache("quill.quat.tooManyFields", variable("quill.quat.tooManyFields", "quill_quat_tooManyFields", "500").toInt) - def attachTopLevelQuats = cache( + def attachTopLevelQuats: Boolean = cache( "quill.quat.attachTopLevel", variable("quill.quat.attachTopLevel", "quill_quat_attachTopLevel", "true").toBoolean ) - def strictQuatChecking = + def strictQuatChecking: Boolean = cache("quill.quat.strict", variable("quill.quat.strict", "quill_quat_strict", "false").toBoolean) - def prettyPrint = + def prettyPrint: Boolean = cache("quill.macro.log.pretty", variable("quill.macro.log.pretty", "quill_macro_log", "false").toBoolean) - def alwaysAlias = + def alwaysAlias: Boolean = cache("quill.query.alwaysAlias", variable("quill.query.alwaysAlias", "quill_query_alwaysAlias", "false").toBoolean) - def pruneColumns = cache( + def pruneColumns: Boolean = cache( "quill.query.pruneColumns", variable("quill.query.pruneColumns", "quill_query_pruneColumns", "true").toBoolean ) - def smartBooleans = cache( + def smartBooleans: Boolean = cache( "quill.query.smartBooleans", variable("quill.query.smartBooleans", "quill_query_smartBooleans", "true").toBoolean ) - def debugEnabled = cache("quill.macro.log", variable("quill.macro.log", "quill_macro_log", "true").toBoolean) - def traceEnabled = + def debugEnabled: Boolean = cache("quill.macro.log", variable("quill.macro.log", "quill_macro_log", "true").toBoolean) + def traceEnabled: Boolean = cache("quill.trace.enabled", variable("quill.trace.enabled", "quill_trace_enabled", "false").toBoolean) - def traceColors = cache("quill.trace.color", variable("quill.trace.color", "quill_trace_color,", "false").toBoolean) - def traceOpinions = + def traceColors: Boolean = cache("quill.trace.color", variable("quill.trace.color", "quill_trace_color,", "false").toBoolean) + def traceOpinions: Boolean = cache("quill.trace.opinion", variable("quill.trace.opinion", "quill_trace_opinion", "false").toBoolean) - def traceAstSimple = + def traceAstSimple: Boolean = cache("quill.trace.ast.simple", variable("quill.trace.ast.simple", "quill_trace_ast_simple", "false").toBoolean) - def traceQuats = + def traceQuats: QuatTrace = cache("quill.trace.quat", QuatTrace(variable("quill.trace.quat", "quill_trace_quat", QuatTrace.None.value))) - def cacheDynamicQueries = cache( + def cacheDynamicQueries: Boolean = cache( "quill.query.cacheDynamic", variable("quill.query.cacheDynamic", "query_query_cacheDynamic", "true").toBoolean ) - def querySubexpand = + def querySubexpand: Boolean = cache("quill.query.subexpand", variable("quill.query.subexpand", "query_query_subexpand", "true").toBoolean) - def quillLogFile = cache("quill.log.file", LogToFile(variable("quill.log.file", "quill_log_file", "false"))) - def errorDetail = cache("quill.error.detail", variable("quill.error.detail", "quill_error_detail", "false").toBoolean) - def disableReturning = cache( + def quillLogFile: LogToFile = cache("quill.log.file", LogToFile(variable("quill.log.file", "quill_log_file", "false"))) + def errorDetail: Boolean = cache("quill.error.detail", variable("quill.error.detail", "quill_error_detail", "false").toBoolean) + def disableReturning: Boolean = cache( "quill.query.disableReturning", variable("quill.query.disableReturning", "quill_query_disableReturning", "false").toBoolean ) - def logBinds = cache("quill.binds.log", variable("quill.binds.log", "quill_binds_log", "false").toBoolean) - def queryTooLongForLogs = + def logBinds: Boolean = cache("quill.binds.log", variable("quill.binds.log", "quill_binds_log", "false").toBoolean) + def queryTooLongForLogs: Int = cache("quill.query.tooLong", variable("quill.query.tooLong", "quill_query_tooLong", "200").toInt) - def errorPrefix = cache("quill.error.prefix", variable("quill.error.prefix", "quill_error_prefix", "false").toBoolean) + def errorPrefix: Boolean = cache("quill.error.prefix", variable("quill.error.prefix", "quill_error_prefix", "false").toBoolean) sealed trait LogToFile object LogToFile { - case class Enabled(file: String) extends LogToFile + final case class Enabled(file: String) extends LogToFile case object Disabled extends LogToFile def apply(switch: String): LogToFile = switch.trim match { @@ -79,7 +79,7 @@ object Messages { case object Full extends QuatTrace { val value = "full" } case object All extends QuatTrace { val value = "all" } case object None extends QuatTrace { val value = "none" } - val values = List(Short, Full, All, None) + val values: List[QuatTrace] = List(Short, Full, All, None) def apply(str: String): QuatTrace = values .find(_.value == str) @@ -105,7 +105,7 @@ object Messages { ) } - def tracesEnabled(tt: TraceType) = + def tracesEnabled(tt: TraceType): Boolean = (traceEnabled && traces.contains(tt)) || tt == TraceType.Warning def enableTrace( @@ -210,13 +210,13 @@ object Messages { ) = new AstPrinter(traceOpinions, traceAstSimple, traceQuats) - def fail(msg: String) = + def fail(msg: String): Nothing = throw new IllegalStateException(msg) - def title[T](label: String, traceType: TraceType = TraceType.Standard) = + def title[T](label: String, traceType: TraceType = TraceType.Standard): T => T = trace[T](("=".repeat(10)) + s" $label " + ("=".repeat(10)), 0, traceType) - def trace[T](label: String, numIndent: Int = 0, traceType: TraceType = TraceType.Standard) = + def trace[T](label: String, numIndent: Int = 0, traceType: TraceType = TraceType.Standard): T => T = (v: T) => { val indent = (0 to numIndent).map(_ => "").mkString(" ") if (tracesEnabled(traceType)) @@ -227,6 +227,6 @@ object Messages { } implicit class StringExt(str: String) { - def repeat(n: Int) = (0 until n).map(_ => str).mkString + def repeat(n: Int): String = (0 until n).map(_ => str).mkString } } diff --git a/quill-engine/src/main/scala/io/getquill/util/Show.scala b/quill-engine/src/main/scala/io/getquill/util/Show.scala index 6e33718053..121a51530e 100644 --- a/quill-engine/src/main/scala/io/getquill/util/Show.scala +++ b/quill-engine/src/main/scala/io/getquill/util/Show.scala @@ -6,13 +6,13 @@ object Show { } object Show { - def apply[T](f: T => String) = new Show[T] { + def apply[T](f: T => String): Show[T] = new Show[T] { def show(v: T) = f(v) } } implicit class Shower[T](v: T)(implicit shower: Show[T]) { - def show = shower.show(v) + def show: String = shower.show(v) } implicit def listShow[T](implicit shower: Show[T]): Show[List[T]] = Show[List[T]] { case list => diff --git a/quill-engine/src/main/scala/io/getquill/util/Using.scala b/quill-engine/src/main/scala/io/getquill/util/Using.scala index 10930fd287..ad3ce23d3a 100644 --- a/quill-engine/src/main/scala/io/getquill/util/Using.scala +++ b/quill-engine/src/main/scala/io/getquill/util/Using.scala @@ -144,7 +144,7 @@ object Using { import Manager._ private var closed = false - private[this] var resources: List[Resource[_]] = Nil + private[this] var resources: List[Resource[_]] = List.empty /** * Registers the specified resource with this manager, so that the resource diff --git a/quill-jasync-mysql/src/main/scala/io/getquill/MysqlJAsyncContextConfig.scala b/quill-jasync-mysql/src/main/scala/io/getquill/MysqlJAsyncContextConfig.scala index d1eea13918..5d2d6646a6 100644 --- a/quill-jasync-mysql/src/main/scala/io/getquill/MysqlJAsyncContextConfig.scala +++ b/quill-jasync-mysql/src/main/scala/io/getquill/MysqlJAsyncContextConfig.scala @@ -6,5 +6,5 @@ import com.github.jasync.sql.db.mysql.util.URLParser import com.typesafe.config.Config import io.getquill.context.jasync.JAsyncContextConfig -case class MysqlJAsyncContextConfig(config: Config) +final case class MysqlJAsyncContextConfig(config: Config) extends JAsyncContextConfig[MySQLConnection](config, new MySQLConnectionFactory(_), URLParser.INSTANCE) diff --git a/quill-jasync-postgres/src/main/scala/io/getquill/PostgresJAsyncContext.scala b/quill-jasync-postgres/src/main/scala/io/getquill/PostgresJAsyncContext.scala index 91e18e398e..e456c941b9 100644 --- a/quill-jasync-postgres/src/main/scala/io/getquill/PostgresJAsyncContext.scala +++ b/quill-jasync-postgres/src/main/scala/io/getquill/PostgresJAsyncContext.scala @@ -7,7 +7,6 @@ import com.typesafe.config.Config import io.getquill.ReturnAction.{ReturnColumns, ReturnNothing, ReturnRecord} import io.getquill.context.jasync.{ArrayDecoders, ArrayEncoders, JAsyncContext, UUIDObjectEncoding} import io.getquill.util.LoadConfig -import io.getquill.util.Messages.fail import scala.jdk.CollectionConverters._ class PostgresJAsyncContext[+N <: NamingStrategy](naming: N, pool: ConnectionPool[PostgreSQLConnection]) diff --git a/quill-jasync-postgres/src/main/scala/io/getquill/PostgresJAsyncContextConfig.scala b/quill-jasync-postgres/src/main/scala/io/getquill/PostgresJAsyncContextConfig.scala index fa6f77a6d2..b0a193119c 100644 --- a/quill-jasync-postgres/src/main/scala/io/getquill/PostgresJAsyncContextConfig.scala +++ b/quill-jasync-postgres/src/main/scala/io/getquill/PostgresJAsyncContextConfig.scala @@ -6,5 +6,5 @@ import com.github.jasync.sql.db.postgresql.util.URLParser import com.typesafe.config.Config import io.getquill.context.jasync.JAsyncContextConfig -case class PostgresJAsyncContextConfig(config: Config) +final case class PostgresJAsyncContextConfig(config: Config) extends JAsyncContextConfig[PostgreSQLConnection](config, new PostgreSQLConnectionFactory(_), URLParser.INSTANCE) diff --git a/quill-jasync-postgres/src/main/scala/io/getquill/context/jasync/ArrayDecoders.scala b/quill-jasync-postgres/src/main/scala/io/getquill/context/jasync/ArrayDecoders.scala index 1bc7d2cef1..3312d11fb4 100644 --- a/quill-jasync-postgres/src/main/scala/io/getquill/context/jasync/ArrayDecoders.scala +++ b/quill-jasync-postgres/src/main/scala/io/getquill/context/jasync/ArrayDecoders.scala @@ -8,7 +8,6 @@ import io.getquill.context.sql.encoding.ArrayEncoding import io.getquill.util.Messages.fail import scala.reflect.ClassTag -import scala.collection.compat._ import scala.jdk.CollectionConverters._ trait ArrayDecoders extends ArrayEncoding { diff --git a/quill-jasync-zio-postgres/src/main/scala/io/getquill/context/qzio/PostgresJAsyncContextConfig.scala b/quill-jasync-zio-postgres/src/main/scala/io/getquill/context/qzio/PostgresJAsyncContextConfig.scala index 6e88f2b6b9..1ed98ec0d4 100644 --- a/quill-jasync-zio-postgres/src/main/scala/io/getquill/context/qzio/PostgresJAsyncContextConfig.scala +++ b/quill-jasync-zio-postgres/src/main/scala/io/getquill/context/qzio/PostgresJAsyncContextConfig.scala @@ -5,5 +5,5 @@ import com.github.jasync.sql.db.postgresql.pool.PostgreSQLConnectionFactory import com.github.jasync.sql.db.postgresql.util.URLParser import com.typesafe.config.Config -case class PostgresJAsyncContextConfig(config: Config) +final case class PostgresJAsyncContextConfig(config: Config) extends JAsyncContextConfig[PostgreSQLConnection](config, new PostgreSQLConnectionFactory(_), URLParser.INSTANCE) diff --git a/quill-jasync-zio-postgres/src/main/scala/io/getquill/context/qzio/jasync/ArrayDecoders.scala b/quill-jasync-zio-postgres/src/main/scala/io/getquill/context/qzio/jasync/ArrayDecoders.scala index f8c043a0f8..3268f6e3c3 100644 --- a/quill-jasync-zio-postgres/src/main/scala/io/getquill/context/qzio/jasync/ArrayDecoders.scala +++ b/quill-jasync-zio-postgres/src/main/scala/io/getquill/context/qzio/jasync/ArrayDecoders.scala @@ -7,7 +7,6 @@ import io.getquill.util.Messages.fail import java.time.{LocalDate, LocalDateTime, ZoneId} import java.util import java.util.Date -import scala.collection.compat._ import scala.jdk.CollectionConverters._ import scala.reflect.ClassTag diff --git a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/Decoders.scala b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/Decoders.scala index bc5654c0ad..925d71b10b 100644 --- a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/Decoders.scala +++ b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/Decoders.scala @@ -1,7 +1,6 @@ package io.getquill.context.qzio import com.github.jasync.sql.db.RowData -import io.getquill.context.Context import io.getquill.util.Messages.fail import java.math.{BigDecimal => JavaBigDecimal} @@ -20,7 +19,7 @@ trait Decoders { type DecoderSqlType = SqlTypes.SqlTypes case class AsyncDecoder[T](sqlType: DecoderSqlType)(implicit decoder: BaseDecoder[T]) extends BaseDecoder[T] { - override def apply(index: Index, row: ResultRow, session: Session) = + override def apply(index: Index, row: ResultRow, session: Session): T = decoder(index, row, session) } @@ -48,7 +47,7 @@ trait Decoders { trait NumericDecoder[T] extends BaseDecoder[T] { - def apply(index: Index, row: ResultRow, session: Session) = + def apply(index: Index, row: ResultRow, session: Session): T = (row.get(index): Any) match { case v: Byte => decode(v) case v: Short => decode(v) diff --git a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/Encoders.scala b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/Encoders.scala index 52daa2c718..003a56d243 100644 --- a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/Encoders.scala +++ b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/Encoders.scala @@ -1,7 +1,6 @@ package io.getquill.context.qzio import com.github.jasync.sql.db.RowData -import io.getquill.context.Context import java.time._ import java.util.Date @@ -19,7 +18,7 @@ trait Encoders { type DecoderSqlType = SqlTypes.SqlTypes case class AsyncEncoder[T](sqlType: DecoderSqlType)(implicit encoder: BaseEncoder[T]) extends BaseEncoder[T] { - override def apply(index: Index, value: T, row: PrepareRow, session: Session) = + override def apply(index: Index, value: T, row: PrepareRow, session: Session): PrepareRow = encoder.apply(index, value, row, session) } diff --git a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/UUIDObjectEncoding.scala b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/UUIDObjectEncoding.scala index dc1b89c95f..fc204f03ef 100644 --- a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/UUIDObjectEncoding.scala +++ b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/UUIDObjectEncoding.scala @@ -8,7 +8,7 @@ trait UUIDObjectEncoding { implicit val uuidEncoder: Encoder[UUID] = encoder[UUID](SqlTypes.UUID) implicit val uuidDecoder: Decoder[UUID] = - AsyncDecoder(SqlTypes.UUID)((index: Index, row: ResultRow, session: Session) => + AsyncDecoder(SqlTypes.UUID)((index: Index, row: ResultRow, _: Session) => row.get(index) match { case value: UUID => value } diff --git a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/UUIDStringEncoding.scala b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/UUIDStringEncoding.scala index c92bb102c0..97c11fd521 100644 --- a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/UUIDStringEncoding.scala +++ b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/UUIDStringEncoding.scala @@ -8,7 +8,7 @@ trait UUIDStringEncoding { implicit val uuidEncoder: Encoder[UUID] = encoder[UUID]((v: UUID) => v.toString, SqlTypes.UUID) implicit val uuidDecoder: Decoder[UUID] = - AsyncDecoder(SqlTypes.UUID)((index: Index, row: ResultRow, session: Session) => + AsyncDecoder(SqlTypes.UUID)((index: Index, row: ResultRow, _: Session) => row.get(index) match { case value: String => UUID.fromString(value) } diff --git a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZIOMonad.scala b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZIOMonad.scala index 4f8b2f80cf..a9656d1d20 100644 --- a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZIOMonad.scala +++ b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZIOMonad.scala @@ -32,7 +32,7 @@ trait ZIOMonad extends IOMonad { def flatten[Y, M[X] <: IterableOnce[X]]( seq: Sequence[Y, M, Effect] - ) = { + ): ZIO[ZioJAsyncConnection,Throwable,M[Y]] = { val builder = seq.cbfResultToValue.newBuilder ZIO .foldLeft(seq.in.iterator.toIterable)(builder) { (r, ioa) => diff --git a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZioJAsyncContext.scala b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZioJAsyncContext.scala index 129f974f79..48ca4eed96 100644 --- a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZioJAsyncContext.scala +++ b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZioJAsyncContext.scala @@ -24,7 +24,7 @@ abstract class ZioJAsyncContext[D <: SqlIdiom, +N <: NamingStrategy, C <: Concre with Encoders with ZIOMonad { - protected val dateTimeZone = ZoneId.systemDefault() + protected val dateTimeZone: ZoneId = ZoneId.systemDefault() private val logger = ContextLogger(classOf[ZioJAsyncContext[_, _, _]]) @@ -80,7 +80,7 @@ abstract class ZioJAsyncContext[D <: SqlIdiom, +N <: NamingStrategy, C <: Concre info: ExecutionInfo, dc: DatasourceContext ): RIO[ZioJAsyncConnection, List[T]] = { - val (params, values) = prepare(Nil, ()) + val (params, values) = prepare(List.empty, ()) logger.logQuery(sql, params) ZioJAsyncConnection .sendPreparedStatement(sql, values) @@ -98,7 +98,7 @@ abstract class ZioJAsyncContext[D <: SqlIdiom, +N <: NamingStrategy, C <: Concre sql: String, prepare: Prepare = identityPrepare )(info: ExecutionInfo, dc: DatasourceContext): Result[Long] = { - val (params, values) = prepare(Nil, ()) + val (params, values) = prepare(List.empty, ()) logger.logQuery(sql, params) ZioJAsyncConnection.sendPreparedStatement(sql, values).map(_.getRowsAffected) } @@ -118,7 +118,7 @@ abstract class ZioJAsyncContext[D <: SqlIdiom, +N <: NamingStrategy, C <: Concre returningAction: ReturnAction )(info: ExecutionInfo, dc: DatasourceContext): RIO[ZioJAsyncConnection, List[T]] = { val expanded = expandAction(sql, returningAction) - val (params, values) = prepare(Nil, ()) + val (params, values) = prepare(List.empty, ()) logger.logQuery(sql, params) ZioJAsyncConnection .sendPreparedStatement(expanded, values) @@ -153,6 +153,6 @@ abstract class ZioJAsyncContext[D <: SqlIdiom, +N <: NamingStrategy, C <: Concre .map(_.flatten.toList) override private[getquill] def prepareParams(statement: String, prepare: Prepare): Seq[String] = - prepare(Nil, ())._2.map(prepareParam) + prepare(List.empty, ())._2.map(prepareParam) } diff --git a/quill-jasync/src/main/scala/io/getquill/context/jasync/Decoders.scala b/quill-jasync/src/main/scala/io/getquill/context/jasync/Decoders.scala index bbfd1d3e6f..f928d9860f 100644 --- a/quill-jasync/src/main/scala/io/getquill/context/jasync/Decoders.scala +++ b/quill-jasync/src/main/scala/io/getquill/context/jasync/Decoders.scala @@ -16,7 +16,7 @@ trait Decoders { type DecoderSqlType = SqlTypes.SqlTypes case class AsyncDecoder[T](sqlType: DecoderSqlType)(implicit decoder: BaseDecoder[T]) extends BaseDecoder[T] { - override def apply(index: Index, row: ResultRow, session: Session) = + override def apply(index: Index, row: ResultRow, session: Session): T = decoder(index, row, session) } @@ -44,7 +44,7 @@ trait Decoders { trait NumericDecoder[T] extends BaseDecoder[T] { - def apply(index: Index, row: ResultRow, session: Session) = + def apply(index: Index, row: ResultRow, session: Session): T = (row.get(index): Any) match { case v: Byte => decode(v) case v: Short => decode(v) diff --git a/quill-jasync/src/main/scala/io/getquill/context/jasync/Encoders.scala b/quill-jasync/src/main/scala/io/getquill/context/jasync/Encoders.scala index dff73b8494..a9ae3c7ede 100644 --- a/quill-jasync/src/main/scala/io/getquill/context/jasync/Encoders.scala +++ b/quill-jasync/src/main/scala/io/getquill/context/jasync/Encoders.scala @@ -11,7 +11,7 @@ trait Encoders { type EncoderSqlType = SqlTypes.SqlTypes case class AsyncEncoder[T](sqlType: DecoderSqlType)(implicit encoder: BaseEncoder[T]) extends BaseEncoder[T] { - override def apply(index: Index, value: T, row: PrepareRow, session: Session) = + override def apply(index: Index, value: T, row: PrepareRow, session: Session): PrepareRow = encoder.apply(index, value, row, session) } diff --git a/quill-jasync/src/main/scala/io/getquill/context/jasync/JAsyncContext.scala b/quill-jasync/src/main/scala/io/getquill/context/jasync/JAsyncContext.scala index b756c96d8a..855b1d5c14 100644 --- a/quill-jasync/src/main/scala/io/getquill/context/jasync/JAsyncContext.scala +++ b/quill-jasync/src/main/scala/io/getquill/context/jasync/JAsyncContext.scala @@ -46,7 +46,7 @@ abstract class JAsyncContext[D <: SqlIdiom, +N <: NamingStrategy, C <: ConcreteC override type NullChecker = JasyncNullChecker type Runner = Unit - protected val dateTimeZone = ZoneId.systemDefault() + protected val dateTimeZone: ZoneId = ZoneId.systemDefault() class JasyncNullChecker extends BaseNullChecker { override def apply(index: Int, row: RowData): Boolean = @@ -61,12 +61,12 @@ abstract class JAsyncContext[D <: SqlIdiom, +N <: NamingStrategy, C <: ConcreteC override def invoke(t: T): R = f(t) } - override def close = { + override def close: Unit = { Await.result(pool.disconnect(), Duration.Inf) () } - protected def withConnection[T](f: Connection => Future[T])(implicit ec: ExecutionContext) = + protected def withConnection[T](f: Connection => Future[T])(implicit ec: ExecutionContext): Future[T] = ec match { case TransactionalExecutionContext(ec, conn) => f(conn) case other => f(pool) @@ -78,12 +78,12 @@ abstract class JAsyncContext[D <: SqlIdiom, +N <: NamingStrategy, C <: ConcreteC protected def expandAction(sql: String, returningAction: ReturnAction) = sql - def probe(sql: String) = + def probe(sql: String): Try[QueryResult] = Try { Await.result(pool.sendQuery(sql), Duration.Inf) } - def transaction[T](f: TransactionalExecutionContext => Future[T])(implicit ec: ExecutionContext) = + def transaction[T](f: TransactionalExecutionContext => Future[T])(implicit ec: ExecutionContext): CompletableFuture[T] = ec match { case tec: TransactionalExecutionContext => toCompletableFuture(f(tec)) case _ => @@ -102,7 +102,7 @@ abstract class JAsyncContext[D <: SqlIdiom, +N <: NamingStrategy, C <: ConcreteC info: ExecutionInfo, dc: Runner )(implicit ec: ExecutionContext): Future[List[T]] = { - val (params, values) = prepare(Nil, ()) + val (params, values) = prepare(List.empty, ()) logger.logQuery(sql, params) withConnection(_.sendPreparedStatement(sql, values.asJava)) .map(_.getRows.asScala.iterator.map(row => extractor(row, ())).toList) @@ -118,7 +118,7 @@ abstract class JAsyncContext[D <: SqlIdiom, +N <: NamingStrategy, C <: ConcreteC def executeAction(sql: String, prepare: Prepare = identityPrepare)(info: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext ): Future[Long] = { - val (params, values) = prepare(Nil, ()) + val (params, values) = prepare(List.empty, ()) logger.logQuery(sql, params) withConnection(_.sendPreparedStatement(sql, values.asJava)).map(_.getRowsAffected) } @@ -138,7 +138,7 @@ abstract class JAsyncContext[D <: SqlIdiom, +N <: NamingStrategy, C <: ConcreteC returningAction: ReturnAction )(info: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext): Future[List[T]] = { val expanded = expandAction(sql, returningAction) - val (params, values) = prepare(Nil, ()) + val (params, values) = prepare(List.empty, ()) logger.logQuery(sql, params) withConnection(_.sendPreparedStatement(expanded, values.asJava)) .map(extractActionResult(returningAction, extractor)) @@ -176,6 +176,6 @@ abstract class JAsyncContext[D <: SqlIdiom, +N <: NamingStrategy, C <: ConcreteC }.map(_.flatten.toList) override private[getquill] def prepareParams(statement: String, prepare: Prepare): Seq[String] = - prepare(Nil, ())._2.map(prepareParam) + prepare(List.empty, ())._2.map(prepareParam) } diff --git a/quill-jasync/src/main/scala/io/getquill/context/jasync/TransactionalExecutionContext.scala b/quill-jasync/src/main/scala/io/getquill/context/jasync/TransactionalExecutionContext.scala index 13e5b44acc..cac74ca1f3 100644 --- a/quill-jasync/src/main/scala/io/getquill/context/jasync/TransactionalExecutionContext.scala +++ b/quill-jasync/src/main/scala/io/getquill/context/jasync/TransactionalExecutionContext.scala @@ -4,7 +4,7 @@ import com.github.jasync.sql.db.Connection import scala.concurrent.ExecutionContext -case class TransactionalExecutionContext(ec: ExecutionContext, conn: Connection) extends ExecutionContext { +final case class TransactionalExecutionContext(ec: ExecutionContext, conn: Connection) extends ExecutionContext { def execute(runnable: Runnable): Unit = ec.execute(runnable) diff --git a/quill-jasync/src/main/scala/io/getquill/context/jasync/UUIDObjectEncoding.scala b/quill-jasync/src/main/scala/io/getquill/context/jasync/UUIDObjectEncoding.scala index 8d066f4509..0124f6c3ab 100644 --- a/quill-jasync/src/main/scala/io/getquill/context/jasync/UUIDObjectEncoding.scala +++ b/quill-jasync/src/main/scala/io/getquill/context/jasync/UUIDObjectEncoding.scala @@ -8,7 +8,7 @@ trait UUIDObjectEncoding { implicit val uuidEncoder: Encoder[UUID] = encoder[UUID](SqlTypes.UUID) implicit val uuidDecoder: Decoder[UUID] = - AsyncDecoder(SqlTypes.UUID)((index: Index, row: ResultRow, session: Session) => + AsyncDecoder(SqlTypes.UUID)((index: Index, row: ResultRow, _: Session) => row.get(index) match { case value: UUID => value } diff --git a/quill-jasync/src/main/scala/io/getquill/context/jasync/UUIDStringEncoding.scala b/quill-jasync/src/main/scala/io/getquill/context/jasync/UUIDStringEncoding.scala index 5a98aa3f2c..327a8c1992 100644 --- a/quill-jasync/src/main/scala/io/getquill/context/jasync/UUIDStringEncoding.scala +++ b/quill-jasync/src/main/scala/io/getquill/context/jasync/UUIDStringEncoding.scala @@ -8,7 +8,7 @@ trait UUIDStringEncoding { implicit val uuidEncoder: Encoder[UUID] = encoder[UUID]((v: UUID) => v.toString, SqlTypes.UUID) implicit val uuidDecoder: Decoder[UUID] = - AsyncDecoder(SqlTypes.UUID)((index: Index, row: ResultRow, session: Session) => + AsyncDecoder(SqlTypes.UUID)((index: Index, row: ResultRow, _: Session) => row.get(index) match { case value: String => UUID.fromString(value) } diff --git a/quill-jdbc-monix/src/main/scala/io/getquill/context/monix/MonixJdbcContext.scala b/quill-jdbc-monix/src/main/scala/io/getquill/context/monix/MonixJdbcContext.scala index d3de20acee..92401175ad 100644 --- a/quill-jdbc-monix/src/main/scala/io/getquill/context/monix/MonixJdbcContext.scala +++ b/quill-jdbc-monix/src/main/scala/io/getquill/context/monix/MonixJdbcContext.scala @@ -250,7 +250,7 @@ abstract class MonixJdbcContext[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] /** * Override to enable specific vendor options needed for streaming */ - protected def prepareStatementForStreaming(sql: String, conn: Connection, fetchSize: Option[Int]) = { + protected def prepareStatementForStreaming(sql: String, conn: Connection, fetchSize: Option[Int]): PreparedStatement = { val stmt = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) fetchSize.foreach { size => stmt.setFetchSize(size) @@ -286,8 +286,8 @@ abstract class MonixJdbcContext[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] object MonixJdbcContext { object EffectWrapper { - def default = new EffectWrapper {} - def using(scheduler: Scheduler) = new EffectWrapper { + def default: EffectWrapper = new EffectWrapper {} + def using(scheduler: Scheduler): EffectWrapper = new EffectWrapper { override def schedule[T](t: Task[T]): Task[T] = t.executeOn(scheduler, true) override def boundary[T](t: Task[T]): Task[T] = t.executeOn(scheduler, true) override def scheduleObservable[T](o: Observable[T]): Observable[T] = o.executeOn(scheduler, true) diff --git a/quill-jdbc-zio/src/main/scala-2.13/io/getquill/context/json/PostgresJsonExtensions.scala b/quill-jdbc-zio/src/main/scala-2.13/io/getquill/context/json/PostgresJsonExtensions.scala index 642fba6602..af4924f266 100644 --- a/quill-jdbc-zio/src/main/scala-2.13/io/getquill/context/json/PostgresJsonExtensions.scala +++ b/quill-jdbc-zio/src/main/scala-2.13/io/getquill/context/json/PostgresJsonExtensions.scala @@ -37,7 +37,7 @@ trait PostgresJsonExtensions { this: Encoders with Decoders => ) def astDecoder[Wrapper](valueFromString: Json => Wrapper): Decoder[Wrapper] = - decoder { (index, row, session) => + decoder { (index, row, _) => val obj = row.getObject(index, classOf[org.postgresql.util.PGobject]) val jsonString = obj.getValue Json.decoder.decodeJson(jsonString) match { @@ -72,7 +72,7 @@ trait PostgresJsonExtensions { this: Encoders with Decoders => jsonType: String, jsonDecoder: JsonDecoder[JsValue] ): Decoder[Wrapper] = - decoder { (index, row, session) => + decoder { (index, row, _) => val obj = row.getObject(index, classOf[org.postgresql.util.PGobject]) val jsonString = obj.getValue jsonDecoder.decodeJson(jsonString) match { diff --git a/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioJdbcUnderlyingContext.scala b/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioJdbcUnderlyingContext.scala index 737b26f91c..6a58be1a55 100644 --- a/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioJdbcUnderlyingContext.scala +++ b/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioJdbcUnderlyingContext.scala @@ -4,7 +4,6 @@ import io.getquill.context.ZioJdbc._ import io.getquill.context.jdbc.JdbcContextVerbExecute import io.getquill.context.sql.idiom.SqlIdiom import io.getquill.context.{ContextVerbStream, ExecutionInfo} -import io.getquill.context.json.PostgresJsonExtensions import io.getquill.util.ContextLogger import io.getquill.{NamingStrategy, ReturnAction} import zio.Exit.{Failure, Success} @@ -174,7 +173,7 @@ abstract class ZioJdbcUnderlyingContext[+Dialect <: SqlIdiom, +Naming <: NamingS /** * Override to enable specific vendor options needed for streaming */ - protected def prepareStatementForStreaming(sql: String, conn: Connection, fetchSize: Option[Int]) = { + protected def prepareStatementForStreaming(sql: String, conn: Connection, fetchSize: Option[Int]): PreparedStatement = { val stmt = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) fetchSize.foreach { size => stmt.setFetchSize(size) diff --git a/quill-jdbc/src/main/scala/io/getquill/JdbcContextConfig.scala b/quill-jdbc/src/main/scala/io/getquill/JdbcContextConfig.scala index 60c96468a1..e3358a11c7 100644 --- a/quill-jdbc/src/main/scala/io/getquill/JdbcContextConfig.scala +++ b/quill-jdbc/src/main/scala/io/getquill/JdbcContextConfig.scala @@ -7,9 +7,9 @@ import com.zaxxer.hikari.HikariDataSource import java.util.Properties import scala.util.control.NonFatal -case class JdbcContextConfig(config: Config) { +final case class JdbcContextConfig(config: Config) { - def configProperties = { + def configProperties: Properties = { import scala.jdk.CollectionConverters._ val p = new Properties for (entry <- config.entrySet.asScala) @@ -17,7 +17,7 @@ case class JdbcContextConfig(config: Config) { p } - def dataSource = + def dataSource: HikariDataSource = try new HikariDataSource(new HikariConfig(configProperties)) catch { diff --git a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/ArrayDecoders.scala b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/ArrayDecoders.scala index 8eecf41832..b72c3d89a8 100644 --- a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/ArrayDecoders.scala +++ b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/ArrayDecoders.scala @@ -9,7 +9,6 @@ import java.math.{BigDecimal => JBigDecimal} import io.getquill.context.sql.encoding.ArrayEncoding import io.getquill.util.Messages.fail -import scala.collection.compat._ import scala.reflect.ClassTag trait ArrayDecoders extends ArrayEncoding { @@ -57,7 +56,7 @@ trait ArrayDecoders extends ArrayEncoding { * JDBC array decoder */ def arrayDecoder[I, O, Col <: Seq[O]](mapper: I => O)(implicit bf: CBF[O, Col], tag: ClassTag[I]): Decoder[Col] = - decoder[Col] { (idx: Index, row: ResultRow, session: Session) => + decoder[Col] { (idx: Index, row: ResultRow, _: Session) => val arr = row.getArray(idx) if (arr == null) bf.newBuilder.result() else diff --git a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/ArrayEncoders.scala b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/ArrayEncoders.scala index 647bd8766e..7cd95ea5fe 100644 --- a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/ArrayEncoders.scala +++ b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/ArrayEncoders.scala @@ -6,7 +6,6 @@ import java.time.LocalDate import java.util.Date import io.getquill.context.sql.encoding.ArrayEncoding -import scala.collection.compat._ trait ArrayEncoders extends ArrayEncoding { self: JdbcContextTypes[_, _] => diff --git a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/BooleanIntEncoding.scala b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/BooleanIntEncoding.scala index 0d140f9ac2..52a1bde553 100644 --- a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/BooleanIntEncoding.scala +++ b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/BooleanIntEncoding.scala @@ -7,5 +7,5 @@ trait BooleanIntEncoding { implicit val booleanEncoder: Encoder[Boolean] = encoder(Types.TINYINT, (index, value, row) => row.setInt(index, if (value) 1 else 0)) - implicit val booleanDecoder: Decoder[Boolean] = decoder((index, row, session) => row.getInt(index) == 1) + implicit val booleanDecoder: Decoder[Boolean] = decoder((index, row, _) => row.getInt(index) == 1) } diff --git a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/Decoders.scala b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/Decoders.scala index c0fd2aaa38..82270e63be 100644 --- a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/Decoders.scala +++ b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/Decoders.scala @@ -1,8 +1,7 @@ package io.getquill.context.jdbc -import java.sql.Types import java.time.{Instant, LocalDate, LocalDateTime, LocalTime, OffsetDateTime, OffsetTime, ZoneOffset, ZonedDateTime} -import java.{time, util} +import java.util import java.util.{Calendar, TimeZone} import scala.math.BigDecimal.javaBigDecimal2bigDecimal @@ -12,7 +11,7 @@ trait Decoders { type Decoder[T] = JdbcDecoder[T] case class JdbcDecoder[T](decoder: BaseDecoder[T]) extends BaseDecoder[T] { - def apply(index: Index, row: ResultRow, session: Session) = + def apply(index: Index, row: ResultRow, session: Session): T = decoder(index + 1, row, session) } @@ -20,7 +19,7 @@ trait Decoders { JdbcDecoder(d) def decoder[T](f: ResultRow => Index => T): Decoder[T] = - decoder((index, row, session) => f(row)(index)) + decoder((index, row, _) => f(row)(index)) implicit def mappedDecoder[I, O](implicit mapped: MappedEncoding[I, O], d: Decoder[I]): Decoder[O] = JdbcDecoder(mappedBaseDecoder(mapped, d.decoder)) @@ -46,7 +45,7 @@ trait Decoders { implicit val stringDecoder: Decoder[String] = decoder(_.getString) implicit val bigDecimalDecoder: Decoder[BigDecimal] = - decoder((index, row, session) => row.getBigDecimal(index)) + decoder((index, row, _) => row.getBigDecimal(index)) implicit val byteDecoder: Decoder[Byte] = decoder(_.getByte) implicit val shortDecoder: Decoder[Short] = decoder(_.getShort) implicit val intDecoder: Decoder[Int] = decoder(_.getInt) @@ -55,48 +54,48 @@ trait Decoders { implicit val doubleDecoder: Decoder[Double] = decoder(_.getDouble) implicit val byteArrayDecoder: Decoder[Array[Byte]] = decoder(_.getBytes) implicit val dateDecoder: Decoder[util.Date] = - decoder((index, row, session) => new util.Date(row.getTimestamp(index, Calendar.getInstance(dateTimeZone)).getTime)) + decoder((index, row, _) => new util.Date(row.getTimestamp(index, Calendar.getInstance(dateTimeZone)).getTime)) } trait BasicTimeDecoders { self: Decoders => def dateTimeZone: TimeZone implicit val localDateDecoder: Decoder[LocalDate] = - decoder((index, row, session) => row.getDate(index).toLocalDate) + decoder((index, row, _) => row.getDate(index).toLocalDate) implicit val localTimeDecoder: Decoder[LocalTime] = - decoder((index, row, session) => row.getTime(index).toLocalTime) + decoder((index, row, _) => row.getTime(index).toLocalTime) implicit val localDateTimeDecoder: Decoder[LocalDateTime] = - decoder((index, row, session) => row.getTimestamp(index).toLocalDateTime) + decoder((index, row, _) => row.getTimestamp(index).toLocalDateTime) implicit val zonedDateTimeDecoder: Decoder[ZonedDateTime] = - decoder((index, row, session) => ZonedDateTime.ofInstant(row.getTimestamp(index).toInstant, dateTimeZone.toZoneId)) + decoder((index, row, _) => ZonedDateTime.ofInstant(row.getTimestamp(index).toInstant, dateTimeZone.toZoneId)) implicit val instantDecoder: Decoder[Instant] = - decoder((index, row, session) => row.getTimestamp(index).toInstant) + decoder((index, row, _) => row.getTimestamp(index).toInstant) implicit val offsetTimeDecoder: Decoder[OffsetTime] = - decoder { (index, row, session) => + decoder { (index, row, _) => val utcLocalTime = row.getTime(index).toLocalTime utcLocalTime.atOffset(ZoneOffset.UTC) } implicit val offsetDateTimeDecoder: Decoder[OffsetDateTime] = - decoder((index, row, session) => OffsetDateTime.ofInstant(row.getTimestamp(index).toInstant, dateTimeZone.toZoneId)) + decoder((index, row, _) => OffsetDateTime.ofInstant(row.getTimestamp(index).toInstant, dateTimeZone.toZoneId)) } trait ObjectGenericTimeDecoders { self: Decoders => implicit val localDateDecoder: Decoder[LocalDate] = - decoder((index, row, session) => row.getObject(index, classOf[LocalDate])) + decoder((index, row, _) => row.getObject(index, classOf[LocalDate])) implicit val localTimeDecoder: Decoder[LocalTime] = - decoder((index, row, session) => row.getObject(index, classOf[LocalTime])) + decoder((index, row, _) => row.getObject(index, classOf[LocalTime])) implicit val localDateTimeDecoder: Decoder[LocalDateTime] = - decoder((index, row, session) => row.getObject(index, classOf[LocalDateTime])) + decoder((index, row, _) => row.getObject(index, classOf[LocalDateTime])) implicit val zonedDateTimeDecoder: Decoder[ZonedDateTime] = - decoder((index, row, session) => row.getObject(index, classOf[OffsetDateTime]).toZonedDateTime) + decoder((index, row, _) => row.getObject(index, classOf[OffsetDateTime]).toZonedDateTime) implicit val instantDecoder: Decoder[Instant] = - decoder((index, row, session) => row.getObject(index, classOf[OffsetDateTime]).toInstant) + decoder((index, row, _) => row.getObject(index, classOf[OffsetDateTime]).toInstant) implicit val offsetTimeDecoder: Decoder[OffsetTime] = - decoder((index, row, session) => row.getObject(index, classOf[OffsetTime])) + decoder((index, row, _) => row.getObject(index, classOf[OffsetTime])) implicit val offsetDateTimeDecoder: Decoder[OffsetDateTime] = - decoder((index, row, session) => row.getObject(index, classOf[OffsetDateTime])) + decoder((index, row, _) => row.getObject(index, classOf[OffsetDateTime])) } diff --git a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/Encoders.scala b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/Encoders.scala index bebf77651d..d199d63831 100644 --- a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/Encoders.scala +++ b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/Encoders.scala @@ -1,7 +1,6 @@ package io.getquill.context.jdbc -import java.sql.{Date, Timestamp, Types} -import java.time.temporal.TemporalField +import java.sql.{Timestamp, Types} import java.time.{Instant, LocalDate, LocalDateTime, LocalTime, OffsetDateTime, OffsetTime, ZoneOffset, ZonedDateTime} import java.util.Calendar import java.{sql, util} @@ -12,14 +11,14 @@ trait Encoders { type Encoder[T] = JdbcEncoder[T] case class JdbcEncoder[T](sqlType: Int, encoder: BaseEncoder[T]) extends BaseEncoder[T] { - override def apply(index: Index, value: T, row: PrepareRow, session: Session) = + override def apply(index: Index, value: T, row: PrepareRow, session: Session): PrepareRow = encoder(index + 1, value, row, session) } def encoder[T](sqlType: Int, f: (Index, T, PrepareRow) => Unit): Encoder[T] = JdbcEncoder( sqlType, - (index: Index, value: T, row: PrepareRow, session: Session) => { + (index: Index, value: T, row: PrepareRow, _: Session) => { f(index, value, row) row } diff --git a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContext.scala b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContext.scala index 6a4e0a6f75..0bdc873d29 100644 --- a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContext.scala +++ b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContext.scala @@ -88,21 +88,21 @@ abstract class JdbcContext[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] protected val currentConnection = new DynamicVariable[Option[Connection]](None) - protected def withConnection[T](f: Connection => Result[T]) = + protected def withConnection[T](f: Connection => Result[T]): Result[T] = currentConnection.value.map(f).getOrElse { val conn = dataSource.getConnection try f(conn) finally conn.close() } - def close() = dataSource.close() + def close(): Unit = dataSource.close() - def probe(sql: String) = + def probe(sql: String): Try[Result[Boolean]] = Try { withConnection(_.createStatement.execute(sql)) } - def transaction[T](f: => T) = + def transaction[T](f: => T): T = currentConnection.value match { case Some(_) => f // already in transaction case None => diff --git a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextTypes.scala b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextTypes.scala index 964ed19a6b..444c412836 100644 --- a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextTypes.scala +++ b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextTypes.scala @@ -1,13 +1,11 @@ package io.getquill.context.jdbc -import io.getquill.{NamingStrategy, ReturnAction} -import io.getquill.ReturnAction.{ReturnColumns, ReturnNothing, ReturnRecord} -import io.getquill.context.{Context, ExecutionInfo} +import io.getquill.NamingStrategy +import io.getquill.context.Context import io.getquill.context.sql.SqlContext import io.getquill.context.sql.idiom.SqlIdiom -import io.getquill.util.ContextLogger -import java.sql.{Connection, JDBCType, PreparedStatement, ResultSet, Statement} +import java.sql.{Connection, JDBCType, PreparedStatement, ResultSet} import java.util.TimeZone trait JdbcContextTypes[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] diff --git a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbExecute.scala b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbExecute.scala index a717942328..e1b9a04aed 100644 --- a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbExecute.scala +++ b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbExecute.scala @@ -7,6 +7,7 @@ import io.getquill.util.ContextLogger import io.getquill.{NamingStrategy, ReturnAction} import java.sql.{Connection, ResultSet, Statement} +import java.sql.PreparedStatement trait JdbcContextVerbExecute[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] extends JdbcContextTypes[Dialect, Naming] { @@ -77,7 +78,7 @@ trait JdbcContextVerbExecute[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] extractResult(ps.getGeneratedKeys, conn, extractor) } - protected def prepareWithReturning(sql: String, conn: Connection, returningBehavior: ReturnAction) = + protected def prepareWithReturning(sql: String, conn: Connection, returningBehavior: ReturnAction): PreparedStatement = returningBehavior match { case ReturnRecord => conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS) case ReturnColumns(columns) => conn.prepareStatement(sql, columns.toArray) diff --git a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/ResultSetExtractor.scala b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/ResultSetExtractor.scala index c4d5850944..3a7cd444f8 100644 --- a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/ResultSetExtractor.scala +++ b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/ResultSetExtractor.scala @@ -9,7 +9,7 @@ object ResultSetExtractor { conn: Connection, extractor: (ResultSet, Connection) => T ): List[T] = - extractResult(rs, conn, extractor, List()) + extractResult(rs, conn, extractor, List.empty) @tailrec private[getquill] final def extractResult[T]( diff --git a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/UUIDObjectEncoding.scala b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/UUIDObjectEncoding.scala index ca73c63bbe..ccc7f1bd90 100644 --- a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/UUIDObjectEncoding.scala +++ b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/UUIDObjectEncoding.scala @@ -8,5 +8,5 @@ trait UUIDObjectEncoding { implicit val uuidEncoder: Encoder[UUID] = encoder(Types.OTHER, (index, value, row) => row.setObject(index, value, Types.OTHER)) implicit val uuidDecoder: Decoder[UUID] = - decoder((index, row, conn) => UUID.fromString(row.getObject(index).toString)) + decoder((index, row, _) => UUID.fromString(row.getObject(index).toString)) } diff --git a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/UUIDStringEncoding.scala b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/UUIDStringEncoding.scala index f19983e541..04748a0aac 100644 --- a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/UUIDStringEncoding.scala +++ b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/UUIDStringEncoding.scala @@ -7,5 +7,5 @@ trait UUIDStringEncoding { this: JdbcContextTypes[_, _] => implicit val uuidEncoder: Encoder[UUID] = encoder(Types.VARCHAR, (index, value, row) => row.setString(index, value.toString)) - implicit val uuidDecoder: Decoder[UUID] = decoder((index, row, conn) => UUID.fromString(row.getString(index))) + implicit val uuidDecoder: Decoder[UUID] = decoder((index, row, _) => UUID.fromString(row.getString(index))) } diff --git a/quill-monix/src/main/scala/io/getquill/context/monix/MonixContext.scala b/quill-monix/src/main/scala/io/getquill/context/monix/MonixContext.scala index 8efad101ff..f53bfc9081 100644 --- a/quill-monix/src/main/scala/io/getquill/context/monix/MonixContext.scala +++ b/quill-monix/src/main/scala/io/getquill/context/monix/MonixContext.scala @@ -2,7 +2,6 @@ package io.getquill.context.monix import io.getquill.NamingStrategy import io.getquill.context.{Context, ExecutionInfo, ContextVerbStream} -import io.getquill.mirrorContextWithQueryProbing.Runner import monix.eval.Task import monix.reactive.Observable diff --git a/quill-orientdb/src/main/scala/io/getquill/OrientDBContextConfig.scala b/quill-orientdb/src/main/scala/io/getquill/OrientDBContextConfig.scala index 023b130c6e..54ba38733a 100644 --- a/quill-orientdb/src/main/scala/io/getquill/OrientDBContextConfig.scala +++ b/quill-orientdb/src/main/scala/io/getquill/OrientDBContextConfig.scala @@ -2,7 +2,7 @@ package io.getquill import com.typesafe.config.Config -case class OrientDBContextConfig(config: Config) { +final case class OrientDBContextConfig(config: Config) { def dbUrl: String = config.getString("dbUrl") def username: String = config.getString("username") def password: String = config.getString("password") diff --git a/quill-orientdb/src/main/scala/io/getquill/context/orientdb/OrientDBIdiom.scala b/quill-orientdb/src/main/scala/io/getquill/context/orientdb/OrientDBIdiom.scala index 80fc0eb9fa..6ae109b861 100644 --- a/quill-orientdb/src/main/scala/io/getquill/context/orientdb/OrientDBIdiom.scala +++ b/quill-orientdb/src/main/scala/io/getquill/context/orientdb/OrientDBIdiom.scala @@ -109,7 +109,7 @@ trait OrientDBIdiom extends Idiom { val (l, e) = flatten(b) ((cond, a) +: l, e) case other => - (List(), other) + (List.empty, other) } val (l, e) = flatten(ast) @@ -210,7 +210,7 @@ trait OrientDBIdiom extends Idiom { protected def tokenOrderBy( criteria: List[OrderByCriteria] - )(implicit strategy: NamingStrategy, idiomContext: IdiomContext) = + )(implicit strategy: NamingStrategy, idiomContext: IdiomContext): Statement = stmt"ORDER BY ${criteria.token}" implicit def sourceTokenizer(implicit strategy: NamingStrategy, idiomContext: IdiomContext): Tokenizer[FromContext] = @@ -375,7 +375,7 @@ trait OrientDBIdiom extends Idiom { renameable.fixedOr(name.token)(strategy.table(name).token) } - protected def scopedTokenizer[A <: Ast](ast: A)(implicit token: Tokenizer[A]) = + protected def scopedTokenizer[A <: Ast](ast: A)(implicit token: Tokenizer[A]): Token = ast match { case _: Query => stmt"(${ast.token})" case _: BinaryOperation => stmt"(${ast.token})" diff --git a/quill-orientdb/src/main/scala/io/getquill/context/orientdb/OrientDBSessionContext.scala b/quill-orientdb/src/main/scala/io/getquill/context/orientdb/OrientDBSessionContext.scala index d53ae78b0a..11597505d6 100644 --- a/quill-orientdb/src/main/scala/io/getquill/context/orientdb/OrientDBSessionContext.scala +++ b/quill-orientdb/src/main/scala/io/getquill/context/orientdb/OrientDBSessionContext.scala @@ -9,6 +9,7 @@ import io.getquill.util.Messages.fail import scala.collection.mutable.ArrayBuffer import scala.util.Try import io.getquill.context.Context +import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx abstract class OrientDBSessionContext[+N <: NamingStrategy]( val naming: N, @@ -36,7 +37,7 @@ abstract class OrientDBSessionContext[+N <: NamingStrategy]( implicit val nullChecker: NullChecker = new OrientDBNullChecker() protected val session = new OPartitionedDatabasePool(dbUrl, username, password) - protected val oDatabase = session.acquire() + protected val oDatabase: ODatabaseDocumentTx = session.acquire() val idiom = OrientDBIdiom @@ -47,7 +48,7 @@ abstract class OrientDBSessionContext[+N <: NamingStrategy]( session.close() } - override def probe(orientDBQl: String) = + override def probe(orientDBQl: String): Try[Unit] = Try { prepare() () diff --git a/quill-orientdb/src/main/scala/io/getquill/context/orientdb/dsl/OrientDBDsl.scala b/quill-orientdb/src/main/scala/io/getquill/context/orientdb/dsl/OrientDBDsl.scala index 76c7031c52..3508e220af 100644 --- a/quill-orientdb/src/main/scala/io/getquill/context/orientdb/dsl/OrientDBDsl.scala +++ b/quill-orientdb/src/main/scala/io/getquill/context/orientdb/dsl/OrientDBDsl.scala @@ -1,11 +1,12 @@ package io.getquill.context.orientdb.dsl import io.getquill.context.orientdb.OrientDBContext +import io.getquill.Quoted trait OrientDBDsl { this: OrientDBContext[_] => implicit class Like(s1: String) { - def like(s2: String) = quote(sql"$s1 like $s2".as[Boolean]) + def like(s2: String): Quoted[Boolean] = quote(sql"$s1 like $s2".as[Boolean]) } } diff --git a/quill-orientdb/src/main/scala/io/getquill/context/orientdb/encoding/CollectionDecoders.scala b/quill-orientdb/src/main/scala/io/getquill/context/orientdb/encoding/CollectionDecoders.scala index fbf9e8b732..dffa29af8f 100644 --- a/quill-orientdb/src/main/scala/io/getquill/context/orientdb/encoding/CollectionDecoders.scala +++ b/quill-orientdb/src/main/scala/io/getquill/context/orientdb/encoding/CollectionDecoders.scala @@ -8,9 +8,9 @@ trait CollectionDecoders { this: OrientDBSessionContext[_] => implicit def listDecoder[T]: Decoder[List[T]] = - decoder((index, row, session) => row.field[java.util.List[T]](row.fieldNames()(index)).asScala.toList) + decoder((index, row, _) => row.field[java.util.List[T]](row.fieldNames()(index)).asScala.toList) implicit def setDecoder[T]: Decoder[Set[T]] = - decoder((index, row, session) => row.field[OTrackedSet[T]](row.fieldNames()(index)).asScala.toSet) + decoder((index, row, _) => row.field[OTrackedSet[T]](row.fieldNames()(index)).asScala.toSet) implicit def mapDecoder[K, V]: Decoder[Map[K, V]] = - decoder((index, row, session) => row.field[java.util.Map[K, V]](row.fieldNames()(index)).asScala.toMap[K, V]) + decoder((index, row, _) => row.field[java.util.Map[K, V]](row.fieldNames()(index)).asScala.toMap[K, V]) } diff --git a/quill-orientdb/src/main/scala/io/getquill/context/orientdb/encoding/Decoders.scala b/quill-orientdb/src/main/scala/io/getquill/context/orientdb/encoding/Decoders.scala index 6eee5a3b37..dd167beb3f 100644 --- a/quill-orientdb/src/main/scala/io/getquill/context/orientdb/encoding/Decoders.scala +++ b/quill-orientdb/src/main/scala/io/getquill/context/orientdb/encoding/Decoders.scala @@ -11,7 +11,7 @@ trait Decoders extends CollectionDecoders { type Decoder[T] = OrientDBDecoder[T] case class OrientDBDecoder[T](decoder: BaseDecoder[T]) extends BaseDecoder[T] { - override def apply(index: Index, row: ResultRow, session: Session) = + override def apply(index: Index, row: ResultRow, session: Session): T = decoder(index, row, session) } @@ -23,7 +23,7 @@ trait Decoders extends CollectionDecoders { ) def decoder[T](f: ResultRow => Index => T): Decoder[T] = - decoder((index, row, session) => f(row)(index)) + decoder((index, row, _) => f(row)(index)) implicit def optionDecoder[T](implicit d: Decoder[T]): Decoder[Option[T]] = OrientDBDecoder { (index, row, session) => @@ -39,26 +39,26 @@ trait Decoders extends CollectionDecoders { OrientDBDecoder(mappedBaseDecoder(mapped, decoder.decoder)) implicit val stringDecoder: Decoder[String] = - decoder((index, row, session) => row.field[String](row.fieldNames()(index))) + decoder((index, row, _) => row.field[String](row.fieldNames()(index))) implicit val doubleDecoder: Decoder[Double] = - decoder((index, row, session) => row.field[Double](row.fieldNames()(index))) + decoder((index, row, _) => row.field[Double](row.fieldNames()(index))) implicit val bigDecimalDecoder: Decoder[BigDecimal] = - decoder((index, row, session) => row.field[java.math.BigDecimal](row.fieldNames()(index))) + decoder((index, row, _) => row.field[java.math.BigDecimal](row.fieldNames()(index))) implicit val booleanDecoder: Decoder[Boolean] = - decoder((index, row, session) => row.field[Boolean](row.fieldNames()(index))) - implicit val intDecoder: Decoder[Int] = decoder((index, row, session) => row.field[Int](row.fieldNames()(index))) + decoder((index, row, _) => row.field[Boolean](row.fieldNames()(index))) + implicit val intDecoder: Decoder[Int] = decoder((index, row, _) => row.field[Int](row.fieldNames()(index))) implicit val shortDecoder: Decoder[Short] = - decoder((index, row, session) => row.field[Short](row.fieldNames()(index))) - implicit val byteDecoder: Decoder[Byte] = decoder((index, row, session) => row.field[Byte](row.fieldNames()(index))) - implicit val longDecoder: Decoder[Long] = decoder { (index, row, session) => + decoder((index, row, _) => row.field[Short](row.fieldNames()(index))) + implicit val byteDecoder: Decoder[Byte] = decoder((index, row, _) => row.field[Byte](row.fieldNames()(index))) + implicit val longDecoder: Decoder[Long] = decoder { (index, row, _) => if (row.fieldValues()(index).isInstanceOf[Int]) { row.field[Int](row.fieldNames()(index)).toLong } else row.field[Long](row.fieldNames()(index)) } implicit val floatDecoder: Decoder[Float] = - decoder((index, row, session) => row.field[Float](row.fieldNames()(index))) + decoder((index, row, _) => row.field[Float](row.fieldNames()(index))) implicit val byteArrayDecoder: Decoder[Array[Byte]] = - decoder((index, row, session) => row.field[Array[Byte]](row.fieldNames()(index))) - implicit val dateDecoder: Decoder[Date] = decoder((index, row, session) => row.field[Date](row.fieldNames()(index))) + decoder((index, row, _) => row.field[Array[Byte]](row.fieldNames()(index))) + implicit val dateDecoder: Decoder[Date] = decoder((index, row, _) => row.field[Date](row.fieldNames()(index))) } diff --git a/quill-orientdb/src/main/scala/io/getquill/context/orientdb/encoding/Encoders.scala b/quill-orientdb/src/main/scala/io/getquill/context/orientdb/encoding/Encoders.scala index ee399fb2c2..4c198fd5b9 100644 --- a/quill-orientdb/src/main/scala/io/getquill/context/orientdb/encoding/Encoders.scala +++ b/quill-orientdb/src/main/scala/io/getquill/context/orientdb/encoding/Encoders.scala @@ -10,20 +10,20 @@ trait Encoders extends CollectionEncoders { type Encoder[T] = OrientDBEncoder[T] case class OrientDBEncoder[T](encoder: BaseEncoder[T]) extends BaseEncoder[T] { - override def apply(index: Index, value: T, row: PrepareRow, session: Session) = + override def apply(index: Index, value: T, row: PrepareRow, session: Session): PrepareRow = encoder(index, value, row, session) } def encoder[T](e: BaseEncoder[T]): Encoder[T] = OrientDBEncoder(e) def encoder[T](f: PrepareRow => (Index, T) => PrepareRow): Encoder[T] = - encoder((index, value, row, session) => f(row)(index, value)) + encoder((index, value, row, _) => f(row)(index, value)) def encoder[T](f: (Index, T, PrepareRow) => PrepareRow): Encoder[T] = - encoder((index, value, row, session) => f(index, value, row)) + encoder((index, value, row, _) => f(index, value, row)) private[this] val nullEncoder: Encoder[Null] = - encoder { (index, value, row, session) => row.insert(index, null); row } + encoder { (index, _, row, _) => row.insert(index, null); row } implicit def optionEncoder[T](implicit d: Encoder[T]): Encoder[Option[T]] = encoder { (index, value, row, session) => diff --git a/quill-spark/src/main/scala/io/getquill/QuillSparkContext.scala b/quill-spark/src/main/scala/io/getquill/QuillSparkContext.scala index 396d7df08d..26c51f1480 100644 --- a/quill-spark/src/main/scala/io/getquill/QuillSparkContext.scala +++ b/quill-spark/src/main/scala/io/getquill/QuillSparkContext.scala @@ -40,15 +40,14 @@ trait QuillSparkContext extends Context[SparkDialect, Literal] with Encoders wit private[getquill] val queryCounter = new AtomicInteger(0) - def close() = {} + def close(): Unit = {} def probe(statement: String): Try[_] = Success(()) val idiom = SparkDialect val naming = Literal - private implicit def datasetEncoder[T]: (Index, Dataset[T], List[Binding], ResultRow) => List[Binding] = - (idx: Int, ds: Dataset[T], row: List[Binding], session: Session) => row :+ DatasetBinding(ds) + __ def liftQuery[T](ds: Dataset[T]) = quote { @@ -146,7 +145,7 @@ trait QuillSparkContext extends Context[SparkDialect, Literal] with Encoders wit string: String, prepare: Prepare = identityPrepare, extractor: Extractor[T] = identityExtractor - )(info: ExecutionInfo, dc: Runner)(implicit enc: SparkEncoder[T], spark: SQLContext) = { + )(info: ExecutionInfo, dc: Runner)(implicit enc: SparkEncoder[T], spark: SQLContext): Dataset[T] = { val ds = spark.sql(prepareString(string, prepare)) percolateNullArrays(ds.toDF(CaseAccessors[T](ds.schema): _*).as[T]) } @@ -155,7 +154,7 @@ trait QuillSparkContext extends Context[SparkDialect, Literal] with Encoders wit string: String, prepare: Prepare = identityPrepare, extractor: Extractor[T] = identityExtractor - )(info: ExecutionInfo, dc: Runner)(implicit enc: SparkEncoder[T], spark: SQLContext) = { + )(info: ExecutionInfo, dc: Runner)(implicit enc: SparkEncoder[T], spark: SQLContext): Dataset[T] = { val ds = spark.sql(prepareString(string, prepare)) percolateNullArrays(ds.toDF(CaseAccessors[T](ds.schema): _*).as[T]) } @@ -163,7 +162,7 @@ trait QuillSparkContext extends Context[SparkDialect, Literal] with Encoders wit private[getquill] def prepareString(string: String, prepare: Prepare)(implicit spark: SQLContext) = { var dsId = 0 val withSubstitutions = - prepare(Nil, ())._2.foldLeft(string) { + prepare(List.empty, ())._2.foldLeft(string) { case (string, DatasetBinding(ds)) => dsId += 1 val name = s"ds${queryCounter.incrementAndGet()}" diff --git a/quill-spark/src/main/scala/io/getquill/context/spark/Binding.scala b/quill-spark/src/main/scala/io/getquill/context/spark/Binding.scala index 116e2e36ff..a63986f030 100644 --- a/quill-spark/src/main/scala/io/getquill/context/spark/Binding.scala +++ b/quill-spark/src/main/scala/io/getquill/context/spark/Binding.scala @@ -4,6 +4,6 @@ import org.apache.spark.sql.Dataset sealed trait Binding -case class DatasetBinding[T](ds: Dataset[T]) extends Binding +final case class DatasetBinding[T](ds: Dataset[T]) extends Binding -case class ValueBinding(str: String) extends Binding +final case class ValueBinding(str: String) extends Binding diff --git a/quill-spark/src/main/scala/io/getquill/context/spark/Encoders.scala b/quill-spark/src/main/scala/io/getquill/context/spark/Encoders.scala index c1f43d5a1d..32db22d4f4 100644 --- a/quill-spark/src/main/scala/io/getquill/context/spark/Encoders.scala +++ b/quill-spark/src/main/scala/io/getquill/context/spark/Encoders.scala @@ -9,7 +9,7 @@ trait Encoders { type PrepareRow = List[Binding] def encoder[T](f: T => String): Encoder[T] = - (index: Index, value: T, row: PrepareRow, session: Session) => row :+ ValueBinding(f(value)) + (_: Index, value: T, row: PrepareRow, _: Session) => row :+ ValueBinding(f(value)) private def toStringEncoder[T]: Encoder[T] = encoder((v: T) => s"$v") diff --git a/quill-spark/src/main/scala/io/getquill/context/spark/SparkDialect.scala b/quill-spark/src/main/scala/io/getquill/context/spark/SparkDialect.scala index 6b75db2a50..8894336974 100644 --- a/quill-spark/src/main/scala/io/getquill/context/spark/SparkDialect.scala +++ b/quill-spark/src/main/scala/io/getquill/context/spark/SparkDialect.scala @@ -31,12 +31,13 @@ import io.getquill.idiom.Token import io.getquill.util.Messages.trace import io.getquill.context.{CannotReturn, ExecutionType} import io.getquill.quat.Quat +import io.getquill.idiom.Statement class SparkDialect extends SparkIdiom trait SparkIdiom extends SqlIdiom with CannotReturn { self => - def parentTokenizer(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy, idiomContext: IdiomContext) = + def parentTokenizer(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy, idiomContext: IdiomContext): Tokenizer[SqlQuery] = super.sqlQueryTokenizer def liftingPlaceholder(index: Int): String = "?" @@ -50,7 +51,7 @@ trait SparkIdiom extends SqlIdiom with CannotReturn { self => override def translate(ast: Ast, topLevelQuat: Quat, executionType: ExecutionType, idiomContext: IdiomContext)( implicit naming: NamingStrategy - ) = { + ): (Ast, Statement, ExecutionType) = { val normalizedAst = EscapeQuestionMarks(SqlNormalize(ast, idiomContext.config)) implicit val implicitIdiomContext: IdiomContext = idiomContext diff --git a/quill-spark/src/main/scala/io/getquill/context/spark/norm/QuestionMarkEscaper.scala b/quill-spark/src/main/scala/io/getquill/context/spark/norm/QuestionMarkEscaper.scala index b3d6cfd75b..d39162fd84 100644 --- a/quill-spark/src/main/scala/io/getquill/context/spark/norm/QuestionMarkEscaper.scala +++ b/quill-spark/src/main/scala/io/getquill/context/spark/norm/QuestionMarkEscaper.scala @@ -3,9 +3,9 @@ package io.getquill.context.spark.norm import java.util.regex.Matcher object QuestionMarkEscaper { - def escape(str: String) = str.replace("?", "\\?") - def unescape(str: String) = str.replace("\\?", "?") + def escape(str: String): String = str.replace("?", "\\?") + def unescape(str: String): String = str.replace("\\?", "?") - def pluginValueSafe(str: String, value: String) = + def pluginValueSafe(str: String, value: String): String = str.replaceFirst("(? implicit class Like(s1: String) { - def like(s2: String) = quote(sql"$s1 like $s2".pure.asCondition) + def like(s2: String): Quoted[Boolean] = quote(sql"$s1 like $s2".pure.asCondition) } implicit class ForUpdate[T](q: Query[T]) { - def forUpdate() = quote(sql"$q FOR UPDATE".as[Query[T]]) + def forUpdate(): Quoted[Query[T]] = quote(sql"$q FOR UPDATE".as[Query[T]]) } } diff --git a/quill-util/src/main/scala/io/getquill/util/ThrowableOps.scala b/quill-util/src/main/scala/io/getquill/util/ThrowableOps.scala index 493a0662b1..87e82ce88f 100644 --- a/quill-util/src/main/scala/io/getquill/util/ThrowableOps.scala +++ b/quill-util/src/main/scala/io/getquill/util/ThrowableOps.scala @@ -4,7 +4,7 @@ import java.io.ByteArrayOutputStream object ThrowableOps { implicit class ThrowableOpsMethods(t: Throwable) { - def stackTraceToString = { + def stackTraceToString: String = { val stream = new ByteArrayOutputStream() val writer = new java.io.BufferedWriter(new java.io.OutputStreamWriter(stream)) t.printStackTrace(new java.io.PrintWriter(writer)) From b6608b89bfdaac6afa61ad9990cf957789625398 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 18:26:06 +0400 Subject: [PATCH 02/21] Clean --- build.sbt | 16 ++-- .../io/getquill/CassandraZioContext.scala | 2 +- .../io/getquill/CassandraZioSession.scala | 8 +- .../context/cassandra/encoding/UdtOps.scala | 2 +- .../jdbc/ComposeableTraitsJdbcCodegen.scala | 17 ++-- .../getquill/codegen/jdbc/DatabaseTypes.scala | 21 +++-- .../codegen/jdbc/gen/JdbcGenerator.scala | 4 +- .../codegen/gen/CodeGeneratorComponents.scala | 2 +- .../io/getquill/codegen/gen/Generator.scala | 9 +- .../io/getquill/codegen/model/Naming.scala | 4 +- .../getquill/codegen/util/MapExtensions.scala | 4 +- .../io/getquill/codegen/util/StringUtil.scala | 17 ++-- .../io/getquill/AsyncMirrorContext.scala | 6 +- .../main/scala/io/getquill/FutureTests.scala | 2 - .../scala/io/getquill/MirrorContext.scala | 7 +- .../scala/io/getquill/context/Context.scala | 1 - .../scala/io/getquill/monad/IOMonad.scala | 2 +- .../scala/io/getquill/quat/QuatMaking.scala | 3 +- .../scala/io/getquill/quotation/Parsing.scala | 7 +- .../getquill/quotation/QuatUnliftable.scala | 7 +- .../io/getquill/quotation/ReifyLiftings.scala | 2 +- .../main/scala/io/getquill/AstPrinter.scala | 4 +- .../main/scala/io/getquill/IdiomContext.scala | 8 +- .../scala/io/getquill/NamingStrategy.scala | 8 +- .../scala/io/getquill/PostgresDialect.scala | 7 +- .../main/scala/io/getquill/ReturnAction.scala | 4 +- .../src/main/scala/io/getquill/ast/Ast.scala | 90 +++++++++++-------- .../io/getquill/ast/StatefulTransformer.scala | 4 +- .../io/getquill/context/RowContext.scala | 4 +- .../norm/FlattenOptionOperation.scala | 2 - .../scala/io/getquill/norm/Normalize.scala | 2 - .../main/scala/io/getquill/quat/Quat.scala | 17 +++- .../quotation/NonQuotedException.scala | 4 +- .../main/scala/io/getquill/sql/SqlQuery.scala | 14 +-- .../getquill/sql/idiom/VerifySqlQuery.scala | 2 +- .../scala/io/getquill/util/Messages.scala | 14 +-- .../io/getquill/context/qzio/ZIOMonad.scala | 2 +- .../context/jasync/JAsyncContext.scala | 4 +- .../context/monix/MonixJdbcContext.scala | 6 +- .../qzio/ZioJdbcUnderlyingContext.scala | 6 +- .../context/jdbc/JdbcContextVerbExecute.scala | 6 +- .../orientdb/OrientDBSessionContext.scala | 2 +- .../getquill/context/spark/SparkDialect.scala | 6 +- 43 files changed, 212 insertions(+), 147 deletions(-) diff --git a/build.sbt b/build.sbt index 93507196e0..0e4c3f0ad5 100644 --- a/build.sbt +++ b/build.sbt @@ -21,18 +21,18 @@ inThisBuild( scmInfo := Some( ScmInfo(url("https://github.com/zio/zio-quill"), "git:git@github.com:zio/zio-quill.git") ), - scalaVersion := scala_v_13, + scalaVersion := scala_v_13, crossScalaVersions := Seq(scala_v_12, scala_v_13, scala_v_30), - scalafmtCheck := true, - scalafmtSbtCheck := true, - scalafmtOnCompile := !insideCI.value, - semanticdbEnabled := scalaVersion.value.startsWith("2.13"), + scalafmtCheck := true, + scalafmtSbtCheck := true, + scalafmtOnCompile := !insideCI.value, + semanticdbEnabled := scalaVersion.value.startsWith("2.13"), semanticdbOptions += "-P:semanticdb:synthetics:on", - semanticdbVersion := scalafixSemanticdb.revision, // use Scalafix compatible version + semanticdbVersion := scalafixSemanticdb.revision, // use Scalafix compatible version scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value), scalafixDependencies ++= List( - "com.github.vovapolu" %% "scaluzzi" % "0.1.23", - "io.github.ghostbuster91.scalafix-unified" %% "unified" % "0.0.9" + "com.github.vovapolu" %% "scaluzzi" % "0.1.23", + "io.github.ghostbuster91.scalafix-unified" %% "unified" % "0.0.9" ) ) ) diff --git a/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala b/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala index bc73e6240f..d466ddd5c4 100644 --- a/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala +++ b/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala @@ -94,7 +94,7 @@ class CassandraZioContext[+N <: NamingStrategy](val naming: N) cql: String, prepare: Prepare = identityPrepare, extractor: Extractor[T] = identityExtractor - )(info: ExecutionInfo, dc: Runner): ZStream[CassandraZioSession,Throwable,T] = { + )(info: ExecutionInfo, dc: Runner): ZStream[CassandraZioSession, Throwable, T] = { val stream = for { csession <- ZStream.service[CassandraZioSession] diff --git a/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioSession.scala b/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioSession.scala index 4e92668160..29a08e4a07 100644 --- a/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioSession.scala +++ b/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioSession.scala @@ -29,7 +29,11 @@ object CassandraZioSession { def fromContextConfig(config: CassandraContextConfig): ZLayer[Any, Throwable, CassandraZioSession] = ZLayer.succeed(config) >>> live - def fromConfig(config: Config): ZLayer[Any,Throwable,CassandraZioSession] = fromContextConfig(CassandraContextConfig(config)) + def fromConfig(config: Config): ZLayer[Any, Throwable, CassandraZioSession] = fromContextConfig( + CassandraContextConfig(config) + ) // Call the by-name constructor for the construction to fail inside of the effect if it fails - def fromPrefix(configPrefix: String): ZLayer[Any,Throwable,CassandraZioSession] = fromContextConfig(CassandraContextConfig(LoadConfig(configPrefix))) + def fromPrefix(configPrefix: String): ZLayer[Any, Throwable, CassandraZioSession] = fromContextConfig( + CassandraContextConfig(LoadConfig(configPrefix)) + ) } diff --git a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/UdtOps.scala b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/UdtOps.scala index 133423873c..c18e027a7c 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/UdtOps.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/UdtOps.scala @@ -12,7 +12,7 @@ class UdtValueOps(val udt: UdtValue) extends AnyVal { def getScalaSet[A](name: String, cls: Class[A]): mutable.Set[A] = udt.getSet(name, cls).asScala - def getScalaMap[K, V](name: String, kcls: Class[K], vcls: Class[V]): mutable.Map[K,V] = + def getScalaMap[K, V](name: String, kcls: Class[K], vcls: Class[V]): mutable.Map[K, V] = udt.getMap(name, kcls, vcls).asScala def setScalaList[A](name: String, v: Seq[A], cls: Class[A]): UdtValue = diff --git a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/ComposeableTraitsJdbcCodegen.scala b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/ComposeableTraitsJdbcCodegen.scala index 46087ef926..ef05f77d67 100644 --- a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/ComposeableTraitsJdbcCodegen.scala +++ b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/ComposeableTraitsJdbcCodegen.scala @@ -143,10 +143,11 @@ class ComposeableTraitsJdbcCodegen( ) = this(Seq(connectionMaker), packagePrefix, false) override def makeGenerators: Seq[ContextifiedUnitGenerator] = new MultiGeneratorFactory(generatorMaker).apply - override def generatorMaker: SingleGeneratorFactory[ContextifiedUnitGenerator] = new SingleGeneratorFactory[ContextifiedUnitGenerator] { - override def apply(emitterSettings: EmitterSettings[JdbcTableMeta, JdbcColumnMeta]): ContextifiedUnitGenerator = - new ContextifiedUnitGenerator(emitterSettings) - } + override def generatorMaker: SingleGeneratorFactory[ContextifiedUnitGenerator] = + new SingleGeneratorFactory[ContextifiedUnitGenerator] { + override def apply(emitterSettings: EmitterSettings[JdbcTableMeta, JdbcColumnMeta]): ContextifiedUnitGenerator = + new ContextifiedUnitGenerator(emitterSettings) + } override def packagingStrategy: PackagingStrategy = PackagingStrategy.ByPackageHeader @@ -180,8 +181,10 @@ class ComposeableTraitsJdbcCodegen( |""".stripMargin.trimFront) .getOrElse("") - override def CombinedTableSchemas: (TableStereotype[TableMeta,ColumnMeta], QuerySchemaNaming) => CombinedTableSchemasGen = new CombinedTableSchemasGen(_, _) { - override def objectName: Option[String] = super.objectName.map(_ + "Dao") - } + override def CombinedTableSchemas + : (TableStereotype[TableMeta, ColumnMeta], QuerySchemaNaming) => CombinedTableSchemasGen = + new CombinedTableSchemasGen(_, _) { + override def objectName: Option[String] = super.objectName.map(_ + "Dao") + } } } diff --git a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/DatabaseTypes.scala b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/DatabaseTypes.scala index 548797a5e0..bed8db9975 100644 --- a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/DatabaseTypes.scala +++ b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/DatabaseTypes.scala @@ -27,23 +27,28 @@ object DatabaseTypes { def databaseName: String; def context: Class[_ <: JdbcContext[_, _]]; def dialect: Class[_ <: SqlIdiom] } case object H2 extends DatabaseType { - def databaseName = "H2"; def context: Class[_ <: JdbcContext[_, _]] = classOf[H2JdbcContext[_]]; def dialect: Class[H2Dialect] = classOf[H2Dialect] + def databaseName = "H2"; def context: Class[_ <: JdbcContext[_, _]] = classOf[H2JdbcContext[_]]; + def dialect: Class[H2Dialect] = classOf[H2Dialect] } case object MySql extends DatabaseType { - def databaseName = "MySQL"; def context: Class[_ <: JdbcContext[_, _]] = classOf[MysqlJdbcContext[_]]; def dialect: Class[MySQLDialect] = classOf[MySQLDialect] + def databaseName = "MySQL"; def context: Class[_ <: JdbcContext[_, _]] = classOf[MysqlJdbcContext[_]]; + def dialect: Class[MySQLDialect] = classOf[MySQLDialect] } case object SqlServer extends DatabaseType { - def databaseName = "Microsoft SQL Server"; def context: Class[_ <: JdbcContext[_, _]] = classOf[SqlServerJdbcContext[_]]; - def dialect: Class[SQLServerDialect] = classOf[SQLServerDialect] + def databaseName = "Microsoft SQL Server"; + def context: Class[_ <: JdbcContext[_, _]] = classOf[SqlServerJdbcContext[_]]; + def dialect: Class[SQLServerDialect] = classOf[SQLServerDialect] } case object Postgres extends DatabaseType { - def databaseName = "PostgreSQL"; def context: Class[_ <: JdbcContext[_, _]] = classOf[PostgresJdbcContext[_]]; - def dialect: Class[PostgresDialect] = classOf[PostgresDialect] + def databaseName = "PostgreSQL"; def context: Class[_ <: JdbcContext[_, _]] = classOf[PostgresJdbcContext[_]]; + def dialect: Class[PostgresDialect] = classOf[PostgresDialect] } case object Sqlite extends DatabaseType { - def databaseName = "SQLite"; def context: Class[_ <: JdbcContext[_, _]] = classOf[SqliteJdbcContext[_]]; def dialect: Class[SqliteDialect] = classOf[SqliteDialect] + def databaseName = "SQLite"; def context: Class[_ <: JdbcContext[_, _]] = classOf[SqliteJdbcContext[_]]; + def dialect: Class[SqliteDialect] = classOf[SqliteDialect] } case object Oracle extends DatabaseType { - def databaseName = "Oracle"; def context: Class[_ <: JdbcContext[_, _]] = classOf[SqliteJdbcContext[_]]; def dialect: Class[OracleDialect] = classOf[OracleDialect] + def databaseName = "Oracle"; def context: Class[_ <: JdbcContext[_, _]] = classOf[SqliteJdbcContext[_]]; + def dialect: Class[OracleDialect] = classOf[OracleDialect] } } diff --git a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/JdbcGenerator.scala b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/JdbcGenerator.scala index 4be69b89d7..5c163a2d1c 100644 --- a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/JdbcGenerator.scala +++ b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/gen/JdbcGenerator.scala @@ -22,8 +22,8 @@ class JdbcGeneratorBase(val connectionMakers: Seq[JdbcConnectionMaker], val pack trait JdbcGenerator extends Generator { this: JdbcCodeGeneratorComponents with JdbcStereotyper => val connectionMakers: Seq[JdbcConnectionMaker] - val databaseType: DatabaseType = DiscoverDatabaseType.apply(connectionMakers.head) - val columnGetter: ColumnMeta => String = (cm: ColumnMeta) => cm.columnName + val databaseType: DatabaseType = DiscoverDatabaseType.apply(connectionMakers.head) + val columnGetter: ColumnMeta => String = (cm: ColumnMeta) => cm.columnName override def filter(tc: RawSchema[JdbcTableMeta, JdbcColumnMeta]): Boolean = databaseType match { diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/gen/CodeGeneratorComponents.scala b/quill-codegen/src/main/scala/io/getquill/codegen/gen/CodeGeneratorComponents.scala index 1f362a5e5e..393d379f6d 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/gen/CodeGeneratorComponents.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/gen/CodeGeneratorComponents.scala @@ -22,7 +22,7 @@ trait CodeGeneratorComponents extends HasBasicMeta with QuerySchemaNaming { type ColumnGetter = ColumnMeta => String def defaultExcludedSchemas: Set[String] = Set.empty[String] - def querySchemaImports = "" + def querySchemaImports = "" def nameParser: NameParser def unrecognizedTypeStrategy: UnrecognizedTypeStrategy def typer: Typer diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/gen/Generator.scala b/quill-codegen/src/main/scala/io/getquill/codegen/gen/Generator.scala index 385ecd0669..049830acf2 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/gen/Generator.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/gen/Generator.scala @@ -151,14 +151,14 @@ trait Generator { override def packagePrefix: String = Generator.this.packagePrefix override def code: String = surroundByPackage(body) - def body: String = caseClassesCode + "\n\n" + tableSchemasCode + def body: String = caseClassesCode + "\n\n" + tableSchemasCode def caseClassesCode: String = caseClassTables.map(CaseClass(_).code).mkString("\n\n") def tableSchemasCode: String = querySchemaTables.map(CombinedTableSchemas(_, querySchemaNaming).code).mkString("\n") protected def ifMembers(str: String): String = if (renderMembers) str else "" - def CaseClass: TableStereotype[TableMeta,ColumnMeta] => CaseClassGen = new CaseClassGen(_) + def CaseClass: TableStereotype[TableMeta, ColumnMeta] => CaseClassGen = new CaseClassGen(_) class CaseClassGen(val tableColumns: TableStereotype[TableMeta, ColumnMeta]) extends super.AbstractCaseClassGen with CaseClassNaming[TableMeta, ColumnMeta] { @@ -177,7 +177,8 @@ trait Generator { } } - def CombinedTableSchemas: (TableStereotype[TableMeta,ColumnMeta], QuerySchemaNaming) => CombinedTableSchemasGen = new CombinedTableSchemasGen(_, _) + def CombinedTableSchemas: (TableStereotype[TableMeta, ColumnMeta], QuerySchemaNaming) => CombinedTableSchemasGen = + new CombinedTableSchemasGen(_, _) class CombinedTableSchemasGen( tableColumns: TableStereotype[TableMeta, ColumnMeta], querySchemaNaming: QuerySchemaNaming @@ -201,7 +202,7 @@ trait Generator { Seq(imports, schemas).pruneEmpty.mkString("\n\n") } - def QuerySchema: (TableStereotype[TableMeta,ColumnMeta], TableMeta) => QuerySchemaGen = new QuerySchemaGen(_, _) + def QuerySchema: (TableStereotype[TableMeta, ColumnMeta], TableMeta) => QuerySchemaGen = new QuerySchemaGen(_, _) class QuerySchemaGen(val tableColumns: TableStereotype[TableMeta, ColumnMeta], schema: TableMeta) extends AbstractQuerySchemaGen with CaseClassNaming[TableMeta, ColumnMeta] { diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/model/Naming.scala b/quill-codegen/src/main/scala/io/getquill/codegen/model/Naming.scala index 73f36a942c..98b0f68dac 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/model/Naming.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/model/Naming.scala @@ -12,7 +12,7 @@ sealed trait CodeWrapper final case class PackageHeader(packageName: String) extends CodeWrapper final case class PackageObject(packageName: String) extends CodeWrapper final case class SimpleObject(packageName: String) extends CodeWrapper -case object NoWrapper extends CodeWrapper +case object NoWrapper extends CodeWrapper sealed trait FileNamingStrategy @@ -50,5 +50,5 @@ trait CaseClassNaming[TableMeta, ColumnMeta] { trait FieldNaming[ColumnMeta] { def column: ColumnFusion[ColumnMeta] def rawFieldName: String = column.name - def fieldName: String = escape(rawFieldName) + def fieldName: String = escape(rawFieldName) } diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/util/MapExtensions.scala b/quill-codegen/src/main/scala/io/getquill/codegen/util/MapExtensions.scala index 1e7c831593..57168a34d1 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/util/MapExtensions.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/util/MapExtensions.scala @@ -5,8 +5,8 @@ import scala.collection.immutable.{ListMap, ListSet} object MapExtensions { implicit class MapOps[K, V](m: Map[K, V]) { - def zipOnKeys(o: Map[K, V]): Map[K,(Option[V], Option[V])] = zipMapsOnKeys(m, o) - def zipOnKeysOrdered(o: Map[K, V]): ListMap[K,(Option[V], Option[V])] = zipMapsOnKeysOrdered(m, o) + def zipOnKeys(o: Map[K, V]): Map[K, (Option[V], Option[V])] = zipMapsOnKeys(m, o) + def zipOnKeysOrdered(o: Map[K, V]): ListMap[K, (Option[V], Option[V])] = zipMapsOnKeysOrdered(m, o) } def zipMapsOnKeys[K, V](one: Map[K, V], two: Map[K, V]): Map[K, (Option[V], Option[V])] = diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/util/StringUtil.scala b/quill-codegen/src/main/scala/io/getquill/codegen/util/StringUtil.scala index b0d458f315..4b86088a39 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/util/StringUtil.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/util/StringUtil.scala @@ -10,9 +10,9 @@ object StringUtil { } } - implicit class StringExtensions(str: String) { + implicit final class StringExtensions(private val str: String) extends AnyVal { def snakeToUpperCamel: String = str.split("_").map(_.toLowerCase).map(_.capitalize).mkString - def snakeToLowerCamel = str.split("_").map(_.toLowerCase).map(_.capitalize).mkString.uncapitalize + def snakeToLowerCamel = str.split("_").map(_.toLowerCase).map(_.capitalize).mkString.uncapitalize def lowerCamelToSnake: String = str.split("(?=[A-Z])").mkString("_").toLowerCase def uncapitalize = new String( @@ -21,15 +21,14 @@ object StringUtil { case Nil => Nil }).toArray ) - def unquote: String = str.replaceFirst("^\"", "").replaceFirst("\"$", "") - def trimFront: String = str.dropWhile(_ == '\n') - def notEmpty: Option[String] = if (str.trim == "") None else Some(str) - def inSetNocase(seq: String*): Boolean = - seq.map(_.toLowerCase).toSeq.contains(str.toLowerCase) + def unquote: String = str.replaceFirst("^\"", "").replaceFirst("\"$", "") + def trimFront: String = str.dropWhile(_ == '\n') + def notEmpty: Option[String] = if (str.trim == "") None else Some(str) + def inSetNocase(seq: String*): Boolean = seq.map(_.toLowerCase).contains(str.toLowerCase) } - implicit class OptionStringExtensions(str: Option[String]) { + implicit final class OptionStringExtensions(private val str: Option[String]) extends AnyVal { def existsInSetNocase(seq: String*): Boolean = - str.map(_.toLowerCase).exists(value => seq.map(_.toLowerCase).toSeq.contains(value)) + str.map(_.toLowerCase).exists(value => seq.map(_.toLowerCase).contains(value)) } } diff --git a/quill-core/src/main/scala/io/getquill/AsyncMirrorContext.scala b/quill-core/src/main/scala/io/getquill/AsyncMirrorContext.scala index 155b93b145..413108734a 100644 --- a/quill-core/src/main/scala/io/getquill/AsyncMirrorContext.scala +++ b/quill-core/src/main/scala/io/getquill/AsyncMirrorContext.scala @@ -117,7 +117,7 @@ class AsyncMirrorContext[+Idiom <: BaseIdiom, +Naming <: NamingStrategy]( prepare: Prepare = identityPrepare, extractor: Extractor[O], returningBehavior: ReturnAction - )(executionInfo: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext): Future[ActionReturningMirror[O,O]] = + )(executionInfo: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext): Future[ActionReturningMirror[O, O]] = Future(ActionReturningMirror[O, O](string, prepare(Row(), session)._2, extractor, returningBehavior, executionInfo)) def executeActionReturningMany[O]( @@ -125,7 +125,9 @@ class AsyncMirrorContext[+Idiom <: BaseIdiom, +Naming <: NamingStrategy]( prepare: Prepare = identityPrepare, extractor: Extractor[O], returningBehavior: ReturnAction - )(executionInfo: ExecutionInfo, dc: Runner)(implicit ec: ExecutionContext): Future[ActionReturningMirror[O,List[O]]] = + )(executionInfo: ExecutionInfo, dc: Runner)(implicit + ec: ExecutionContext + ): Future[ActionReturningMirror[O, List[O]]] = Future( ActionReturningMirror[O, List[O]](string, prepare(Row(), session)._2, extractor, returningBehavior, executionInfo) ) diff --git a/quill-core/src/main/scala/io/getquill/FutureTests.scala b/quill-core/src/main/scala/io/getquill/FutureTests.scala index 6e03e639ad..40fb5b0e1a 100644 --- a/quill-core/src/main/scala/io/getquill/FutureTests.scala +++ b/quill-core/src/main/scala/io/getquill/FutureTests.scala @@ -1,7 +1,5 @@ package io.getquill - - //package io.getquill // //import io.getquill.util.PrintMac diff --git a/quill-core/src/main/scala/io/getquill/MirrorContext.scala b/quill-core/src/main/scala/io/getquill/MirrorContext.scala index fd3e8e970e..ef4fdf0079 100644 --- a/quill-core/src/main/scala/io/getquill/MirrorContext.scala +++ b/quill-core/src/main/scala/io/getquill/MirrorContext.scala @@ -123,7 +123,7 @@ class MirrorContext[+Idiom <: BaseIdiom, +Naming <: NamingStrategy]( prepare: Prepare = identityPrepare, extractor: Extractor[O], returningBehavior: ReturnAction - )(info: ExecutionInfo, dc: Runner): ActionReturningMirror[O,List[O]] = + )(info: ExecutionInfo, dc: Runner): ActionReturningMirror[O, List[O]] = ActionReturningMirror[O, List[O]](string, prepare(Row(), session)._2, extractor, returningBehavior, info) def executeBatchAction(groups: List[BatchGroup])(info: ExecutionInfo, dc: Runner): BatchActionMirrorGeneric[Row] = @@ -146,7 +146,10 @@ class MirrorContext[+Idiom <: BaseIdiom, +Naming <: NamingStrategy]( info ) - def prepareAction(string: String, prepare: Prepare = identityPrepare)(info: ExecutionInfo, dc: Runner): Session => PrepareRow = + def prepareAction(string: String, prepare: Prepare = identityPrepare)( + info: ExecutionInfo, + dc: Runner + ): Session => PrepareRow = (session: Session) => prepare(Row(), session)._2 def prepareBatchAction(groups: List[BatchGroup])(info: ExecutionInfo, dc: Runner): Session => List[PrepareRow] = diff --git a/quill-core/src/main/scala/io/getquill/context/Context.scala b/quill-core/src/main/scala/io/getquill/context/Context.scala index 3b8e32c437..668b65228d 100644 --- a/quill-core/src/main/scala/io/getquill/context/Context.scala +++ b/quill-core/src/main/scala/io/getquill/context/Context.scala @@ -1,6 +1,5 @@ package io.getquill.context - import scala.language.higherKinds import scala.language.experimental.macros import io.getquill.dsl.CoreDsl diff --git a/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala b/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala index 988ccc8ae8..fddcc0759c 100644 --- a/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala +++ b/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala @@ -78,7 +78,7 @@ trait IOMonad { IO.fromTry(f(r)) } - def lowerFromTry[U](implicit ev: T => Try[U]): IO[U,E] = + def lowerFromTry[U](implicit ev: T => Try[U]): IO[U, E] = transform(_.flatMap(ev)) def liftToTry: IO[Try[T], E] = diff --git a/quill-core/src/main/scala/io/getquill/quat/QuatMaking.scala b/quill-core/src/main/scala/io/getquill/quat/QuatMaking.scala index 442e4726f9..4baeb4d610 100644 --- a/quill-core/src/main/scala/io/getquill/quat/QuatMaking.scala +++ b/quill-core/src/main/scala/io/getquill/quat/QuatMaking.scala @@ -94,7 +94,8 @@ object RuntimeEntityQuat { object CaseClass { // Common methods to exclude from object fields - val exclude: Set[String] = classOf[Product].getMethods.map(_.getName).toSet ++ classOf[Object].getMethods.map(_.getName).toSet + val exclude: Set[String] = + classOf[Product].getMethods.map(_.getName).toSet ++ classOf[Object].getMethods.map(_.getName).toSet def unapply(cls: Class[_]): Option[List[Method]] = if (cls.getInterfaces.contains(classOf[Product])) { diff --git a/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala b/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala index c0b4a66334..89e0e2d1ae 100644 --- a/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala +++ b/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala @@ -201,7 +201,7 @@ trait Parsing extends ValueComputation with QuatMaking with MacroUtilBase { case q"$pack.querySchema[$t](${name: String}, ..$properties)" => q"$t".tpe inferQuat(q"$t".tpe) - val quat = inferQuat(q"$t".tpe).probit + val quat = inferQuat(q"$t".tpe).probit c.warn(VerifyNoBranches.in(quat)) Entity.Opinionated(name, properties.map(propertyAliasParser(_)), quat, Fixed) @@ -377,7 +377,8 @@ trait Parsing extends ValueComputation with QuatMaking with MacroUtilBase { Quat.improveInfixQuat(value) } - val impureInfixParser: Parser[Ast] = combinedInfixParser(false, Quat.Value) // TODO Verify Quat in what cases does this come up? + val impureInfixParser: Parser[Ast] = + combinedInfixParser(false, Quat.Value) // TODO Verify Quat in what cases does this come up? object InfixMatch { def unapply(tree: Tree): Option[(List[String], List[Tree])] = @@ -835,8 +836,6 @@ trait Parsing extends ValueComputation with QuatMaking with MacroUtilBase { symbol.isClass && symbol.asClass.isCaseClass } - - object ClassTypeRefMatch { def unapply(tpe: Type): Option[(ClassSymbol, List[Type])] = tpe match { case TypeRef(_, cls, args) if (cls.isClass) => Some((cls.asClass, args)) diff --git a/quill-core/src/main/scala/io/getquill/quotation/QuatUnliftable.scala b/quill-core/src/main/scala/io/getquill/quotation/QuatUnliftable.scala index f3b272fdf9..25d2998526 100644 --- a/quill-core/src/main/scala/io/getquill/quotation/QuatUnliftable.scala +++ b/quill-core/src/main/scala/io/getquill/quotation/QuatUnliftable.scala @@ -9,9 +9,10 @@ trait QuatUnliftable { val mctx: Context import mctx.universe.{Constant => _, Function => _, Ident => _, If => _, _} - def unliftQuat(v: Tree): Quat = quatUnliftable.unapply(v).getOrElse(mctx.fail(s"Can't unlift $v")) - def unliftQuats(v: Seq[Tree]): Seq[Quat] = v.map(unliftQuat(_)) - def unliftString(v: Tree)(implicit u: Unliftable[String]): String = u.unapply(v).getOrElse(mctx.fail(s"Can't unlift $v")) + def unliftQuat(v: Tree): Quat = quatUnliftable.unapply(v).getOrElse(mctx.fail(s"Can't unlift $v")) + def unliftQuats(v: Seq[Tree]): Seq[Quat] = v.map(unliftQuat(_)) + def unliftString(v: Tree)(implicit u: Unliftable[String]): String = + u.unapply(v).getOrElse(mctx.fail(s"Can't unlift $v")) def unliftStrings(v: Seq[Tree])(implicit u: Unliftable[String]): Seq[String] = v.map(unliftString(_)) implicit val quatProductUnliftable: Unliftable[Quat.Product] = Unliftable[Quat.Product] { diff --git a/quill-core/src/main/scala/io/getquill/quotation/ReifyLiftings.scala b/quill-core/src/main/scala/io/getquill/quotation/ReifyLiftings.scala index ac510aba14..e2e82a56e3 100644 --- a/quill-core/src/main/scala/io/getquill/quotation/ReifyLiftings.scala +++ b/quill-core/src/main/scala/io/getquill/quotation/ReifyLiftings.scala @@ -80,7 +80,7 @@ trait ReifyLiftings extends QuatMaking with TranspileConfigSummoning { } } - override def apply(ast: Ast): (Ast, StatefulTransformer[Map[TermName,Reified]]) = + override def apply(ast: Ast): (Ast, StatefulTransformer[Map[TermName, Reified]]) = ast match { case ast: Lift => diff --git a/quill-engine/src/main/scala/io/getquill/AstPrinter.scala b/quill-engine/src/main/scala/io/getquill/AstPrinter.scala index be65f4c268..f4f6452362 100644 --- a/quill-engine/src/main/scala/io/getquill/AstPrinter.scala +++ b/quill-engine/src/main/scala/io/getquill/AstPrinter.scala @@ -105,8 +105,8 @@ class AstPrinter(traceOpinions: Boolean, traceAstSimple: Boolean, traceQuats: Qu case i: Infix => val content = List(i.parts.toList, i.params.toList) ++ (if (i.pure) List("pure") else List.empty) ++ (if (i.transparent) - List("transparent") - else List.empty) + List("transparent") + else List.empty) Tree.Apply("Infix", treemake(content: _*).withQuat(i.bestQuat).make) case e: Entity if (!traceOpinions) => diff --git a/quill-engine/src/main/scala/io/getquill/IdiomContext.scala b/quill-engine/src/main/scala/io/getquill/IdiomContext.scala index 3d934439e3..a9a00f6cad 100644 --- a/quill-engine/src/main/scala/io/getquill/IdiomContext.scala +++ b/quill-engine/src/main/scala/io/getquill/IdiomContext.scala @@ -20,8 +20,12 @@ object IdiomContext { case object Update extends Regular case object Delete extends Regular - final case class BatchInsert(foreachAlias: String) extends Batch { val batchAlias: Some[String] = Some(foreachAlias) } - final case class BatchUpdate(foreachAlias: String) extends Batch { val batchAlias: Some[String] = Some(foreachAlias) } + final case class BatchInsert(foreachAlias: String) extends Batch { + val batchAlias: Some[String] = Some(foreachAlias) + } + final case class BatchUpdate(foreachAlias: String) extends Batch { + val batchAlias: Some[String] = Some(foreachAlias) + } sealed trait Regular extends QueryType { val isBatch = false; val batchAlias = None } sealed trait Batch extends QueryType { val isBatch = true } diff --git a/quill-engine/src/main/scala/io/getquill/NamingStrategy.scala b/quill-engine/src/main/scala/io/getquill/NamingStrategy.scala index 27d951f7ab..19395a2de6 100644 --- a/quill-engine/src/main/scala/io/getquill/NamingStrategy.scala +++ b/quill-engine/src/main/scala/io/getquill/NamingStrategy.scala @@ -150,9 +150,9 @@ trait PostgresEscape extends Escape { object PostgresEscape extends PostgresEscape trait MysqlEscape extends NamingStrategy { - override def table(s: String): String = quote(s) - override def column(s: String): String = quote(s) - override def default(s: String) = s - private def quote(s: String) = s"`$s`" + override def table(s: String): String = quote(s) + override def column(s: String): String = quote(s) + override def default(s: String) = s + private def quote(s: String) = s"`$s`" } object MysqlEscape extends MysqlEscape diff --git a/quill-engine/src/main/scala/io/getquill/PostgresDialect.scala b/quill-engine/src/main/scala/io/getquill/PostgresDialect.scala index 8ba25431dd..fb68b06089 100644 --- a/quill-engine/src/main/scala/io/getquill/PostgresDialect.scala +++ b/quill-engine/src/main/scala/io/getquill/PostgresDialect.scala @@ -249,8 +249,6 @@ final case class ReplaceLiftings( loop(newCol, 1) } - - override def apply(e: Ast): (Ast, StatefulTransformer[ListMap[String, ScalarTag]]) = e match { case lift @ ScalarTag(_, External.Source.UnparsedProperty(propNameRaw)) => @@ -264,7 +262,10 @@ final case class ReplaceLiftings( } } object ReplaceLiftings { - def of(ast: Ast)(foreachIdent: String, existingColumnNames: List[String]): (Ast, immutable.Iterable[String], immutable.Iterable[ScalarTag]) = { + def of(ast: Ast)( + foreachIdent: String, + existingColumnNames: List[String] + ): (Ast, immutable.Iterable[String], immutable.Iterable[ScalarTag]) = { val (newAst, transform) = new ReplaceLiftings(foreachIdent, existingColumnNames, ListMap()).apply(ast) (newAst, transform.state.map(_._1), transform.state.map(_._2)) } diff --git a/quill-engine/src/main/scala/io/getquill/ReturnAction.scala b/quill-engine/src/main/scala/io/getquill/ReturnAction.scala index f17a3c6ab0..71ed85017c 100644 --- a/quill-engine/src/main/scala/io/getquill/ReturnAction.scala +++ b/quill-engine/src/main/scala/io/getquill/ReturnAction.scala @@ -2,7 +2,7 @@ package io.getquill sealed trait ReturnAction object ReturnAction { - case object ReturnNothing extends ReturnAction + case object ReturnNothing extends ReturnAction final case class ReturnColumns(columns: List[String]) extends ReturnAction - case object ReturnRecord extends ReturnAction + case object ReturnRecord extends ReturnAction } diff --git a/quill-engine/src/main/scala/io/getquill/ast/Ast.scala b/quill-engine/src/main/scala/io/getquill/ast/Ast.scala index 1a0b423f7b..7ff1966231 100644 --- a/quill-engine/src/main/scala/io/getquill/ast/Ast.scala +++ b/quill-engine/src/main/scala/io/getquill/ast/Ast.scala @@ -193,8 +193,8 @@ case object AscNullsLast extends PropertyOrdering case object DescNullsLast extends PropertyOrdering final case class GroupBy(query: Ast, alias: Ident, body: Ast) extends Query { - def quat: Quat.Product = Quat.Tuple(body.quat, query.quat) - def bestQuat: Quat = Quat.Tuple(body.bestQuat, query.bestQuat) + def quat: Quat.Product = Quat.Tuple(body.quat, query.quat) + def bestQuat: Quat = Quat.Tuple(body.bestQuat, query.bestQuat) } final case class GroupByMap(query: Ast, byAlias: Ident, byBody: Ast, mapAlias: Ident, mapBody: Ast) extends Query { @@ -249,8 +249,8 @@ final case class Join( aliasB: Ident, on: Ast ) extends Query { - def quat: Quat.Product = Quat.Tuple(a.quat, b.quat) - def bestQuat: Quat = Quat.Tuple(a.bestQuat, b.bestQuat) + def quat: Quat.Product = Quat.Tuple(a.quat, b.quat) + def bestQuat: Quat = Quat.Tuple(a.bestQuat, b.bestQuat) } final case class FlatJoin(typ: JoinType, a: Ast, aliasA: Ident, on: Ast) extends Query { @@ -301,12 +301,19 @@ final class Infix(val parts: List[String], val params: List[Ast], val pure: Bool Infix(parts, params, pure, transparent, quat) } object Infix { - final private case class Id(val parts: List[String], val params: List[Ast], val pure: Boolean, val transparent: Boolean) + final private case class Id( + val parts: List[String], + val params: List[Ast], + val pure: Boolean, + val transparent: Boolean + ) def apply(parts: List[String], params: List[Ast], pure: Boolean, transparent: Boolean, quat: => Quat) = new Infix(parts, params, pure, transparent)(quat) - def unapply(i: Infix): Some[(List[String], List[Ast], Boolean, Boolean, Quat)] = Some((i.parts, i.params, i.pure, i.transparent, i.quat)) + def unapply(i: Infix): Some[(List[String], List[Ast], Boolean, Boolean, Quat)] = Some( + (i.parts, i.params, i.pure, i.transparent, i.quat) + ) } final case class Function(params: List[Ident], body: Ast) extends Ast { @@ -354,7 +361,7 @@ final class Ident private (val name: String)(theQuat: => Quat)(val visibility: V object Ident { final private case class Id(name: String) def apply(name: String, quat: => Quat = Quat.Value) = new Ident(name)(quat)(Visibility.Visible) - def unapply(p: Ident): Some[(String, Quat)] = Some((p.name, p.quat)) + def unapply(p: Ident): Some[(String, Quat)] = Some((p.name, p.quat)) object Opinionated { def apply(name: String, quatNew: => Quat, visibilityNew: Visibility) = @@ -387,8 +394,8 @@ final class ExternalIdent private (val name: String)(theQuat: => Quat)(val renam object ExternalIdent { final private case class Id(name: String) - def apply(name: String, quat: => Quat) = new ExternalIdent(name)(quat)(Renameable.neutral) - def unapply(e: ExternalIdent): Some[(String, Quat)] = Some((e.name, e.quat)) + def apply(name: String, quat: => Quat) = new ExternalIdent(name)(quat)(Renameable.neutral) + def unapply(e: ExternalIdent): Some[(String, Quat)] = Some((e.name, e.quat)) object Opinionated { def apply(name: String, quat: => Quat, rename: Renameable) = @@ -450,9 +457,9 @@ object Renameable extends OpinionValues[Renameable] { */ final class Property(val ast: Ast, val name: String)(val renameable: Renameable, val visibility: Visibility) extends Ast { - def quat: Quat = ast.quat.lookup(name, Messages.strictQuatChecking) - def bestQuat: Quat = ast.quat.lookup(name, false) - def prevName: Option[String] = ast.quat.beforeRenamed(name) + def quat: Quat = ast.quat.lookup(name, Messages.strictQuatChecking) + def bestQuat: Quat = ast.quat.lookup(name, false) + def prevName: Option[String] = ast.quat.beforeRenamed(name) private def id = Property.Id(ast, name) @@ -481,8 +488,8 @@ object Property { // 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[(Ast, String)] = Some((p.ast, p.name)) + def apply(ast: Ast, name: String) = new Property(ast, name)(Renameable.neutral, Visibility.Visible) + def unapply(p: Property): Some[(Ast, String)] = Some((p.ast, p.name)) object Opinionated { def apply( @@ -497,7 +504,7 @@ object Property { } } -sealed trait OptionOperation extends Ast +sealed trait OptionOperation extends Ast final case class OptionFlatten(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } final case class OptionGetOrElse(ast: Ast, body: Ast) extends OptionOperation { def quat = body.quat; def bestQuat = body.bestQuat @@ -550,12 +557,12 @@ final class OptionNone(theQuat: => Quat) extends OptionOperation with Terminal { case e: OptionNone => true case _ => false } - override def hashCode(): Int = OptionNoneId.hashCode() + override def hashCode(): Int = OptionNoneId.hashCode() def copy(quat: => Quat = this.quat): OptionNone = OptionNone(quat) } object OptionNone { - def apply(quat: => Quat): OptionNone = new OptionNone(quat) - def unapply(on: OptionNone): Some[Quat] = Some(on.quat) + def apply(quat: => Quat): OptionNone = new OptionNone(quat) + def unapply(on: OptionNone): Some[Quat] = Some(on.quat) } final case class OptionSome(ast: Ast) extends OptionOperation { def quat = ast.quat; def bestQuat = ast.bestQuat } @@ -634,8 +641,8 @@ final class Constant(val v: Any)(theQuat: => Quat) extends Value { object Constant { final private case class Id(v: Any) - def apply(v: Any, quat: => Quat): Constant = new Constant(v)(quat) - def unapply(const: Constant): Some[(Any, Quat)] = Some((const.v, const.quat)) + def apply(v: Any, quat: => Quat): Constant = new Constant(v)(quat) + def unapply(const: Constant): Some[(Any, Quat)] = Some((const.v, const.quat)) def auto(v: Any): Constant = { lazy val theQuat = if (v.isInstanceOf[Boolean]) Quat.BooleanValue else Quat.Value @@ -684,10 +691,10 @@ object CaseClass { //************************************************************ final case class Block(statements: List[Ast]) extends Ast { - private lazy val computedQuat = statements.last.quat - def quat = computedQuat + private lazy val computedQuat = statements.last.quat + def quat = computedQuat statements.last.bestQuat - def bestQuat = computedQuat + def bestQuat = computedQuat } // Note. Assuming Block is not Empty final case class Val(name: Ident, body: Ast) extends Ast { @@ -752,11 +759,11 @@ object OnConflict { } sealed trait Target - case object NoTarget extends Target + case object NoTarget extends Target final case class Properties(props: List[Property]) extends Target sealed trait Action - case object Ignore extends Action + case object Ignore extends Action final case class Update(assignments: List[AssignmentDual]) extends Action } //************************************************************ @@ -770,7 +777,7 @@ final class Dynamic(val tree: Any)(theQuat: => Quat) extends Ast { object Dynamic { def apply(tree: Any, quat: => Quat): Dynamic = new Dynamic(tree)(quat) - def unapply(d: Dynamic): Some[(Any, Quat)] = Some((d.tree, d.quat)) + def unapply(d: Dynamic): Some[(Any, Quat)] = Some((d.tree, d.quat)) def apply(v: Any): Dynamic = { lazy val theQuat = if (v.isInstanceOf[Boolean]) Quat.BooleanValue else Quat.Value @@ -785,7 +792,7 @@ object External { sealed trait Source object Source { final case class UnparsedProperty(name: String) extends Source - case object Parser extends Source + case object Parser extends Source } } @@ -809,8 +816,8 @@ sealed trait ScalarLift extends Lift with Terminal { final class ScalarValueLift(val name: String, val source: External.Source, val value: Any, val encoder: Any)( theQuat: => Quat ) extends ScalarLift { - def quat: Quat = theQuat - def bestQuat = quat + def quat: Quat = theQuat + def bestQuat = quat override def withQuat(quat: => Quat): ScalarValueLift = this.copy(quat = quat) private val id = ScalarValueLift.Id(name, source, value, encoder) @@ -833,12 +840,14 @@ object ScalarValueLift { final private case class Id(name: String, source: External.Source, value: Any, encoder: Any) def apply(name: String, source: External.Source, value: Any, encoder: Any, quat: => Quat): ScalarValueLift = new ScalarValueLift(name, source, value, encoder)(quat) - def unapply(svl: ScalarValueLift): Some[(String, External.Source, Any, Any, Quat)] = Some((svl.name, svl.source, svl.value, svl.encoder, svl.quat)) + def unapply(svl: ScalarValueLift): Some[(String, External.Source, Any, Any, Quat)] = Some( + (svl.name, svl.source, svl.value, svl.encoder, svl.quat) + ) } final class ScalarQueryLift(val name: String, val value: Any, val encoder: Any)(theQuat: => Quat) extends ScalarLift { - def quat: Quat = theQuat - def bestQuat = quat + def quat: Quat = theQuat + def bestQuat = quat override def withQuat(quat: => Quat): ScalarQueryLift = this.copy(quat = quat) private val id = ScalarQueryLift.Id(name, value, encoder) @@ -849,7 +858,12 @@ final class ScalarQueryLift(val name: String, val value: Any, val encoder: Any)( case _ => false } - def copy(name: String = this.name, value: Any = this.value, encoder: Any = this.encoder, quat: => Quat = this.quat): ScalarQueryLift = + def copy( + name: String = this.name, + value: Any = this.value, + encoder: Any = this.encoder, + quat: => Quat = this.quat + ): ScalarQueryLift = ScalarQueryLift(name, value, encoder, quat) } object ScalarQueryLift { @@ -863,8 +877,8 @@ sealed trait CaseClassLift extends Lift final class CaseClassValueLift(val name: String, val simpleName: String, val value: Any)(theQuat: => Quat) extends CaseClassLift { - def quat: Quat = theQuat - def bestQuat = quat + def quat: Quat = theQuat + def bestQuat = quat override def withQuat(quat: => Quat): CaseClassValueLift = this.copy(quat = quat) private val id = CaseClassValueLift.Id(name, simpleName, value) @@ -890,8 +904,8 @@ object CaseClassValueLift { } final class CaseClassQueryLift(val name: String, val value: Any)(theQuat: => Quat) extends CaseClassLift { - def quat: Quat = theQuat - def bestQuat = quat + def quat: Quat = theQuat + def bestQuat = quat override def withQuat(quat: => Quat): CaseClassQueryLift = this.copy(quat = quat) private val id = CaseClassQueryLift.Id(name, value) @@ -909,7 +923,7 @@ final class CaseClassQueryLift(val name: String, val value: Any)(theQuat: => Qua object CaseClassQueryLift { final private case class Id(name: String, value: Any) def apply(name: String, value: Any, quat: => Quat): CaseClassQueryLift = new CaseClassQueryLift(name, value)(quat) - def unapply(l: CaseClassQueryLift): Some[(String, Any, Quat)] = Some((l.name, l.value, l.quat)) + def unapply(l: CaseClassQueryLift): Some[(String, Any, Quat)] = Some((l.name, l.value, l.quat)) } /** diff --git a/quill-engine/src/main/scala/io/getquill/ast/StatefulTransformer.scala b/quill-engine/src/main/scala/io/getquill/ast/StatefulTransformer.scala index a4548fadb5..f78c816ee9 100644 --- a/quill-engine/src/main/scala/io/getquill/ast/StatefulTransformer.scala +++ b/quill-engine/src/main/scala/io/getquill/ast/StatefulTransformer.scala @@ -317,7 +317,9 @@ trait StatefulTransformer[T] { (OnConflict.Update(at), att) } - def apply[U, R](list: List[U])(f: StatefulTransformer[T] => U => (R, StatefulTransformer[T])): (List[R], StatefulTransformer[T]) = + def apply[U, R](list: List[U])( + f: StatefulTransformer[T] => U => (R, StatefulTransformer[T]) + ): (List[R], StatefulTransformer[T]) = list.foldLeft((List.empty[R], this)) { case ((values, t), v) => val (vt, vtt) = f(t)(v) (values :+ vt, vtt) diff --git a/quill-engine/src/main/scala/io/getquill/context/RowContext.scala b/quill-engine/src/main/scala/io/getquill/context/RowContext.scala index 163822d07d..d0f8a0678b 100644 --- a/quill-engine/src/main/scala/io/getquill/context/RowContext.scala +++ b/quill-engine/src/main/scala/io/getquill/context/RowContext.scala @@ -6,8 +6,8 @@ trait RowContext { type PrepareRow type ResultRow - protected val identityPrepare: Prepare = (p: PrepareRow, _: Session) => (List.empty, p) - protected val identityExtractor: (ResultRow, Session) => ResultRow = (rr: ResultRow, _: Session) => rr + protected val identityPrepare: Prepare = (p: PrepareRow, _: Session) => (List.empty, p) + protected val identityExtractor: (ResultRow, Session) => ResultRow = (rr: ResultRow, _: Session) => rr case class BatchGroup(string: String, prepare: List[Prepare]) case class BatchGroupReturning(string: String, returningBehavior: ReturnAction, prepare: List[Prepare]) diff --git a/quill-engine/src/main/scala/io/getquill/norm/FlattenOptionOperation.scala b/quill-engine/src/main/scala/io/getquill/norm/FlattenOptionOperation.scala index 5863d41b91..e3132544eb 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/FlattenOptionOperation.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/FlattenOptionOperation.scala @@ -12,8 +12,6 @@ class FlattenOptionOperation(concatBehavior: ConcatBehavior, traceConfig: TraceC val interp = new Interpolator(TraceType.FlattenOptionOperation, traceConfig, 2) import interp._ - - def validateContainsOrElse(containsNon: Boolean, succeedWith: () => Ast, orElse: () => Ast): Ast = if (containsNon) succeedWith() else orElse() diff --git a/quill-engine/src/main/scala/io/getquill/norm/Normalize.scala b/quill-engine/src/main/scala/io/getquill/norm/Normalize.scala index 301062baef..30737f380f 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/Normalize.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/Normalize.scala @@ -36,8 +36,6 @@ class Normalize(config: TranspileConfig) extends StatelessTransformer { trace"Avoid Capture and Normalize $q into:" andReturn norm(DealiasPhase(AvoidAliasConflictPhase(q, false))) - - private def demarcate(heading: String) = ((ast: Query) => title(s"(Normalize) $heading", TraceType.Normalizations)(ast)) diff --git a/quill-engine/src/main/scala/io/getquill/quat/Quat.scala b/quill-engine/src/main/scala/io/getquill/quat/Quat.scala index a944830567..f5884bc4b0 100644 --- a/quill-engine/src/main/scala/io/getquill/quat/Quat.scala +++ b/quill-engine/src/main/scala/io/getquill/quat/Quat.scala @@ -11,7 +11,9 @@ object LinkedHashMapOps { def zipWith[R](m2: mutable.LinkedHashMap[K, V])(f: PartialFunction[(K, V, Option[V]), R]): List[R] = LinkedHashMapOps.zipWith(m1, m2, f) - def outerZipWith[R](m2: mutable.LinkedHashMap[K, V])(f: PartialFunction[(K, Option[V], Option[V]), R]): mutable.LinkedHashSet[R] = + def outerZipWith[R](m2: mutable.LinkedHashMap[K, V])( + f: PartialFunction[(K, Option[V], Option[V]), R] + ): mutable.LinkedHashSet[R] = LinkedHashMapOps.outerZipWith(m1, m2, f) } @@ -400,7 +402,7 @@ object Quat { (mutable.LinkedHashMap[String, String]() ++ renames): mutable.LinkedHashMap[String, String] ) - def unapply(p: Quat.Product): Some[(mutable.LinkedHashMap[String,Quat], mutable.LinkedHashMap[String,String])] = + def unapply(p: Quat.Product): Some[(mutable.LinkedHashMap[String, Quat], mutable.LinkedHashMap[String, String])] = Some((p.fields, p.renames)) } @@ -421,7 +423,16 @@ object Quat { Product.WithRenames.iterated(name, tpe, fields.zip(values).iterator, renamesFrom.zip(renamesTo).iterator) } - def unapply(p: Quat.Product): Some[(String, Type, mutable.Iterable[String], mutable.Iterable[Quat], mutable.Iterable[String], mutable.Iterable[String])] = { + def unapply(p: Quat.Product): Some[ + ( + String, + Type, + mutable.Iterable[String], + mutable.Iterable[Quat], + mutable.Iterable[String], + mutable.Iterable[String] + ) + ] = { val (fields, values) = p.fields.unzip val (renamesFrom, renamesTo) = p.renames.unzip Some((p.name, p.tpe, fields, values, renamesFrom, renamesTo)) diff --git a/quill-engine/src/main/scala/io/getquill/quotation/NonQuotedException.scala b/quill-engine/src/main/scala/io/getquill/quotation/NonQuotedException.scala index a60df52689..29b11c970d 100644 --- a/quill-engine/src/main/scala/io/getquill/quotation/NonQuotedException.scala +++ b/quill-engine/src/main/scala/io/getquill/quotation/NonQuotedException.scala @@ -3,6 +3,6 @@ package io.getquill.quotation class NonQuotedException extends Exception(NonQuotedException.message) object NonQuotedException { - final val message = "The query definition must happen within a `quote` block." - def apply(): Nothing = throw new NonQuotedException + final val message = "The query definition must happen within a `quote` block." + def apply(): Nothing = throw new NonQuotedException } diff --git a/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala b/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala index 86d492fdcf..d1015d1393 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala @@ -39,9 +39,9 @@ case object UnionAllOperation extends SetOperation sealed trait DistinctKind { def isDistinct: Boolean } case object DistinctKind { - case object Distinct extends DistinctKind { val isDistinct: Boolean = true } + case object Distinct extends DistinctKind { val isDistinct: Boolean = true } final case class DistinctOn(props: List[Ast]) extends DistinctKind { val isDistinct: Boolean = true } - case object None extends DistinctKind { val isDistinct: Boolean = false } + case object None extends DistinctKind { val isDistinct: Boolean = false } } final case class SetOperationSqlQuery( @@ -191,11 +191,11 @@ class SqlQueryApply(traceConfig: TraceConfig) { case _: GroupByMap => trace"base| Nesting GroupByMap $q" andReturn nest(source(q, alias)) case Map(GroupBy(input, id, _), _, _) => input match { - case _: Map => - nest(source(input, id.name)) - case _ => - base(input, id.name, nestNextMap) - } + case _: Map => + nest(source(input, id.name)) + case _ => + base(input, id.name, nestNextMap) + } trace"base| Nesting Map(GroupBy) $q" andReturn { nest(source(q, alias)) diff --git a/quill-engine/src/main/scala/io/getquill/sql/idiom/VerifySqlQuery.scala b/quill-engine/src/main/scala/io/getquill/sql/idiom/VerifySqlQuery.scala index 60eb8cb5e0..2973d09779 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/idiom/VerifySqlQuery.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/idiom/VerifySqlQuery.scala @@ -8,7 +8,7 @@ import io.getquill.quat.Quat final case class Error(free: List[Ident], ast: Ast) final case class InvalidSqlQuery(errors: List[Error]) { override def toString: String = { - val allVars = errors.flatMap(_.free).distinct + val allVars = errors.flatMap(_.free).distinct errors.headOption.flatMap(_.free.headOption).getOrElse("someVar") s""" |When synthesizing Joins, Quill found some variables that could not be traced back to their diff --git a/quill-engine/src/main/scala/io/getquill/util/Messages.scala b/quill-engine/src/main/scala/io/getquill/util/Messages.scala index 16995509c9..032ccbfa9e 100644 --- a/quill-engine/src/main/scala/io/getquill/util/Messages.scala +++ b/quill-engine/src/main/scala/io/getquill/util/Messages.scala @@ -38,7 +38,8 @@ object Messages { def debugEnabled: Boolean = cache("quill.macro.log", variable("quill.macro.log", "quill_macro_log", "true").toBoolean) def traceEnabled: Boolean = cache("quill.trace.enabled", variable("quill.trace.enabled", "quill_trace_enabled", "false").toBoolean) - def traceColors: Boolean = cache("quill.trace.color", variable("quill.trace.color", "quill_trace_color,", "false").toBoolean) + def traceColors: Boolean = + cache("quill.trace.color", variable("quill.trace.color", "quill_trace_color,", "false").toBoolean) def traceOpinions: Boolean = cache("quill.trace.opinion", variable("quill.trace.opinion", "quill_trace_opinion", "false").toBoolean) def traceAstSimple: Boolean = @@ -51,8 +52,10 @@ object Messages { ) def querySubexpand: Boolean = cache("quill.query.subexpand", variable("quill.query.subexpand", "query_query_subexpand", "true").toBoolean) - def quillLogFile: LogToFile = cache("quill.log.file", LogToFile(variable("quill.log.file", "quill_log_file", "false"))) - def errorDetail: Boolean = cache("quill.error.detail", variable("quill.error.detail", "quill_error_detail", "false").toBoolean) + def quillLogFile: LogToFile = + cache("quill.log.file", LogToFile(variable("quill.log.file", "quill_log_file", "false"))) + def errorDetail: Boolean = + cache("quill.error.detail", variable("quill.error.detail", "quill_error_detail", "false").toBoolean) def disableReturning: Boolean = cache( "quill.query.disableReturning", variable("quill.query.disableReturning", "quill_query_disableReturning", "false").toBoolean @@ -60,12 +63,13 @@ object Messages { def logBinds: Boolean = cache("quill.binds.log", variable("quill.binds.log", "quill_binds_log", "false").toBoolean) def queryTooLongForLogs: Int = cache("quill.query.tooLong", variable("quill.query.tooLong", "quill_query_tooLong", "200").toInt) - def errorPrefix: Boolean = cache("quill.error.prefix", variable("quill.error.prefix", "quill_error_prefix", "false").toBoolean) + def errorPrefix: Boolean = + cache("quill.error.prefix", variable("quill.error.prefix", "quill_error_prefix", "false").toBoolean) sealed trait LogToFile object LogToFile { final case class Enabled(file: String) extends LogToFile - case object Disabled extends LogToFile + case object Disabled extends LogToFile def apply(switch: String): LogToFile = switch.trim match { case "false" => Disabled diff --git a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZIOMonad.scala b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZIOMonad.scala index a9656d1d20..3fe7bb186a 100644 --- a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZIOMonad.scala +++ b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZIOMonad.scala @@ -32,7 +32,7 @@ trait ZIOMonad extends IOMonad { def flatten[Y, M[X] <: IterableOnce[X]]( seq: Sequence[Y, M, Effect] - ): ZIO[ZioJAsyncConnection,Throwable,M[Y]] = { + ): ZIO[ZioJAsyncConnection, Throwable, M[Y]] = { val builder = seq.cbfResultToValue.newBuilder ZIO .foldLeft(seq.in.iterator.toIterable)(builder) { (r, ioa) => diff --git a/quill-jasync/src/main/scala/io/getquill/context/jasync/JAsyncContext.scala b/quill-jasync/src/main/scala/io/getquill/context/jasync/JAsyncContext.scala index 855b1d5c14..6a9c2d1ddd 100644 --- a/quill-jasync/src/main/scala/io/getquill/context/jasync/JAsyncContext.scala +++ b/quill-jasync/src/main/scala/io/getquill/context/jasync/JAsyncContext.scala @@ -83,7 +83,9 @@ abstract class JAsyncContext[D <: SqlIdiom, +N <: NamingStrategy, C <: ConcreteC Await.result(pool.sendQuery(sql), Duration.Inf) } - def transaction[T](f: TransactionalExecutionContext => Future[T])(implicit ec: ExecutionContext): CompletableFuture[T] = + def transaction[T]( + f: TransactionalExecutionContext => Future[T] + )(implicit ec: ExecutionContext): CompletableFuture[T] = ec match { case tec: TransactionalExecutionContext => toCompletableFuture(f(tec)) case _ => diff --git a/quill-jdbc-monix/src/main/scala/io/getquill/context/monix/MonixJdbcContext.scala b/quill-jdbc-monix/src/main/scala/io/getquill/context/monix/MonixJdbcContext.scala index 92401175ad..e7c511d91c 100644 --- a/quill-jdbc-monix/src/main/scala/io/getquill/context/monix/MonixJdbcContext.scala +++ b/quill-jdbc-monix/src/main/scala/io/getquill/context/monix/MonixJdbcContext.scala @@ -250,7 +250,11 @@ abstract class MonixJdbcContext[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] /** * Override to enable specific vendor options needed for streaming */ - protected def prepareStatementForStreaming(sql: String, conn: Connection, fetchSize: Option[Int]): PreparedStatement = { + protected def prepareStatementForStreaming( + sql: String, + conn: Connection, + fetchSize: Option[Int] + ): PreparedStatement = { val stmt = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) fetchSize.foreach { size => stmt.setFetchSize(size) diff --git a/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioJdbcUnderlyingContext.scala b/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioJdbcUnderlyingContext.scala index 6a58be1a55..db7c4968b3 100644 --- a/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioJdbcUnderlyingContext.scala +++ b/quill-jdbc-zio/src/main/scala/io/getquill/context/qzio/ZioJdbcUnderlyingContext.scala @@ -173,7 +173,11 @@ abstract class ZioJdbcUnderlyingContext[+Dialect <: SqlIdiom, +Naming <: NamingS /** * Override to enable specific vendor options needed for streaming */ - protected def prepareStatementForStreaming(sql: String, conn: Connection, fetchSize: Option[Int]): PreparedStatement = { + protected def prepareStatementForStreaming( + sql: String, + conn: Connection, + fetchSize: Option[Int] + ): PreparedStatement = { val stmt = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) fetchSize.foreach { size => stmt.setFetchSize(size) diff --git a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbExecute.scala b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbExecute.scala index e1b9a04aed..1f14c0eaa3 100644 --- a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbExecute.scala +++ b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContextVerbExecute.scala @@ -78,7 +78,11 @@ trait JdbcContextVerbExecute[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] extractResult(ps.getGeneratedKeys, conn, extractor) } - protected def prepareWithReturning(sql: String, conn: Connection, returningBehavior: ReturnAction): PreparedStatement = + protected def prepareWithReturning( + sql: String, + conn: Connection, + returningBehavior: ReturnAction + ): PreparedStatement = returningBehavior match { case ReturnRecord => conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS) case ReturnColumns(columns) => conn.prepareStatement(sql, columns.toArray) diff --git a/quill-orientdb/src/main/scala/io/getquill/context/orientdb/OrientDBSessionContext.scala b/quill-orientdb/src/main/scala/io/getquill/context/orientdb/OrientDBSessionContext.scala index 11597505d6..a819b0e5d5 100644 --- a/quill-orientdb/src/main/scala/io/getquill/context/orientdb/OrientDBSessionContext.scala +++ b/quill-orientdb/src/main/scala/io/getquill/context/orientdb/OrientDBSessionContext.scala @@ -36,7 +36,7 @@ abstract class OrientDBSessionContext[+N <: NamingStrategy]( } implicit val nullChecker: NullChecker = new OrientDBNullChecker() - protected val session = new OPartitionedDatabasePool(dbUrl, username, password) + protected val session = new OPartitionedDatabasePool(dbUrl, username, password) protected val oDatabase: ODatabaseDocumentTx = session.acquire() val idiom = OrientDBIdiom diff --git a/quill-spark/src/main/scala/io/getquill/context/spark/SparkDialect.scala b/quill-spark/src/main/scala/io/getquill/context/spark/SparkDialect.scala index 8894336974..efaed91c53 100644 --- a/quill-spark/src/main/scala/io/getquill/context/spark/SparkDialect.scala +++ b/quill-spark/src/main/scala/io/getquill/context/spark/SparkDialect.scala @@ -37,7 +37,11 @@ class SparkDialect extends SparkIdiom trait SparkIdiom extends SqlIdiom with CannotReturn { self => - def parentTokenizer(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy, idiomContext: IdiomContext): Tokenizer[SqlQuery] = + def parentTokenizer(implicit + astTokenizer: Tokenizer[Ast], + strategy: NamingStrategy, + idiomContext: IdiomContext + ): Tokenizer[SqlQuery] = super.sqlQueryTokenizer def liftingPlaceholder(index: Int): String = "?" From c43920b0003c7ccc7d0c3b20841e1798040d3b7c Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 19:05:17 +0400 Subject: [PATCH 03/21] Clean --- .../src/main/scala/io/getquill/CassandraZioContext.scala | 2 -- 1 file changed, 2 deletions(-) diff --git a/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala b/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala index d466ddd5c4..7d3dd1e9e1 100644 --- a/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala +++ b/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala @@ -45,8 +45,6 @@ class CassandraZioContext[+N <: NamingStrategy](val naming: N) with Context[CqlIdiom, N] with Probing { - ContextLogger(classOf[CassandraZioContext[_]]) - override type Error = Throwable override type Environment = CassandraZioSession From 20874bde6ce8f14e051b65c9ac63b53572fbbb6e Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 19:05:44 +0400 Subject: [PATCH 04/21] Clean --- .../src/main/scala/io/getquill/cassandrazio/Quill.scala | 2 -- 1 file changed, 2 deletions(-) diff --git a/quill-cassandra-zio/src/main/scala/io/getquill/cassandrazio/Quill.scala b/quill-cassandra-zio/src/main/scala/io/getquill/cassandrazio/Quill.scala index 6f8306f0c1..6a32c7a1dd 100644 --- a/quill-cassandra-zio/src/main/scala/io/getquill/cassandrazio/Quill.scala +++ b/quill-cassandra-zio/src/main/scala/io/getquill/cassandrazio/Quill.scala @@ -25,8 +25,6 @@ object Quill { with Context[CqlIdiom, N] with Probing { - ContextLogger(classOf[Quill.Cassandra[_]]) - override type Error = Throwable override type Environment = Any From 1e73808ad658d88aa79f14829c04de6dbfc9121b Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 19:06:05 +0400 Subject: [PATCH 05/21] Clean --- .../io/getquill/codegen/jdbc/model/DefaultJdbcTyper.scala | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/model/DefaultJdbcTyper.scala b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/model/DefaultJdbcTyper.scala index 97fe850933..99dae4c4f1 100644 --- a/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/model/DefaultJdbcTyper.scala +++ b/quill-codegen-jdbc/src/main/scala/io/getquill/codegen/jdbc/model/DefaultJdbcTyper.scala @@ -1,10 +1,8 @@ package io.getquill.codegen.jdbc.model -import java.sql.Types._ - import io.getquill.codegen.model._ -import io.getquill.util.ContextLogger +import java.sql.Types._ import scala.reflect.{ClassTag, classTag} class DefaultJdbcTyper( @@ -12,7 +10,6 @@ class DefaultJdbcTyper( numericPreference: NumericPreference ) extends (JdbcTypeInfo => Option[ClassTag[_]]) { - ContextLogger(classOf[DefaultJdbcTyper]) private[getquill] val MaxIntDigits = 9 private[getquill] val MaxLongDigits = 18 From 353bcc8036a6abb902eb4fa6de47fd6bd23eeb21 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 19:07:15 +0400 Subject: [PATCH 06/21] Clean --- .../scala/io/getquill/util/EnableReflectiveCalls.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/quill-core/src/main/scala/io/getquill/util/EnableReflectiveCalls.scala b/quill-core/src/main/scala/io/getquill/util/EnableReflectiveCalls.scala index 998e99b7ac..eae7ec0262 100644 --- a/quill-core/src/main/scala/io/getquill/util/EnableReflectiveCalls.scala +++ b/quill-core/src/main/scala/io/getquill/util/EnableReflectiveCalls.scala @@ -7,8 +7,9 @@ object EnableReflectiveCalls { def apply(c: Context): List[c.universe.SymTree with Trees.``] = { import c.universe._ - q"import _root_.scala.language.reflectiveCalls" :: - q"Nil.asInstanceOf[{ def size }].size" :: - List.empty + List( + q"import _root_.scala.language.reflectiveCalls", + q"Nil.asInstanceOf[{ def size }].size" + ) } } From dfde86f6b0e4d340bf41191a23fc832aa6d42c1f Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 19:08:28 +0400 Subject: [PATCH 07/21] Clean --- .../src/main/scala/io/getquill/norm/DisablePhase.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quill-engine/src/main/scala/io/getquill/norm/DisablePhase.scala b/quill-engine/src/main/scala/io/getquill/norm/DisablePhase.scala index faf4e4d9c3..f3453a7720 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/DisablePhase.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/DisablePhase.scala @@ -14,7 +14,7 @@ object OptionalPhase { sealed trait ApplyMap extends OptionalPhase case object ApplyMap extends ApplyMap - val all: List[ApplyMap.type] = List(ApplyMap) + val all: List[OptionalPhase] = List(ApplyMap) } trait DisablePhase { @@ -37,7 +37,7 @@ object ConfigList { sealed trait HList[+H] final case class ::[+H, +T <: HList[_]](head: H, tail: T) extends HList[H] sealed trait HNil extends HList[Nothing] { - def ::[H](h: H) = ConfigList.::[H, HNil](h, this) + def ::[H](h: H): HList[H] = ConfigList.::[H, HNil](h, this) } case object HNil extends HNil } From 4ccc0edb34208646b6a1b52f776e26f93db61f84 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 19:10:36 +0400 Subject: [PATCH 08/21] Clean --- quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala b/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala index d1015d1393..d04e5ee811 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala @@ -180,7 +180,7 @@ class SqlQueryApply(traceConfig: TraceConfig) { nestNextMap: Boolean ): FlattenSqlQuery = { - def select(alias: String, quat: Quat) = SelectValue(Ident(alias, quat), None) :: List.empty + def select(alias: String, quat: Quat): List[SelectValue] = List(SelectValue(Ident(alias, quat), None)) def base(q: Ast, alias: String, nestNextMap: Boolean): FlattenSqlQuery = trace"Computing Base (nestingMaps=${nestNextMap}) for Query: $q" andReturn { From 7d7634a28a71a0cdac32cd5f34e3d2f3bedd680b Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 19:11:05 +0400 Subject: [PATCH 09/21] Clean --- quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala | 2 -- 1 file changed, 2 deletions(-) diff --git a/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala b/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala index d04e5ee811..9e65dc3b94 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/SqlQuery.scala @@ -528,6 +528,4 @@ class SqlQueryApply(traceConfig: TraceConfig) { case FlatJoinContext(_, from, _) => collectAliases(List(from)) } - List.emptyList.empty - } From 3923a0a203c581a7113060ef5d8a53e627185200 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 19:11:47 +0400 Subject: [PATCH 10/21] Clean --- .../src/main/scala/io/getquill/sql/idiom/SqlIdiom.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/quill-engine/src/main/scala/io/getquill/sql/idiom/SqlIdiom.scala b/quill-engine/src/main/scala/io/getquill/sql/idiom/SqlIdiom.scala index 14bc43da78..c92610ab22 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/idiom/SqlIdiom.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/idiom/SqlIdiom.scala @@ -202,13 +202,12 @@ trait SqlIdiom extends Idiom { case _ => select.token } - def distinctTokenizer = (: Statement + def distinctTokenizer: Statement = distinct match { case DistinctKind.Distinct => stmt"DISTINCT " case DistinctKind.DistinctOn(props) => stmt"DISTINCT ON (${props.token}) " case DistinctKind.None => stmt"" } - ) def withDistinct: Statement = stmt"$distinctTokenizer${selectTokenizer}" @@ -389,7 +388,9 @@ trait SqlIdiom extends Idiom { case UnionAllOperation => stmt"UNION ALL" } - protected def limitOffsetToken(query: Statement)(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy): Tokenizer[(Option[Ast], Option[Ast])] = + protected def limitOffsetToken( + query: Statement + )(implicit astTokenizer: Tokenizer[Ast], strategy: NamingStrategy): Tokenizer[(Option[Ast], Option[Ast])] = Tokenizer[(Option[Ast], Option[Ast])] { case (None, None) => query case (Some(limit), None) => stmt"$query LIMIT ${limit.token}" From aea40514737de2ba145e121b4f0dd4811a9f06d6 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 19:12:11 +0400 Subject: [PATCH 11/21] Clean --- quill-spark/src/main/scala/io/getquill/QuillSparkContext.scala | 2 -- 1 file changed, 2 deletions(-) diff --git a/quill-spark/src/main/scala/io/getquill/QuillSparkContext.scala b/quill-spark/src/main/scala/io/getquill/QuillSparkContext.scala index 26c51f1480..d312e0b316 100644 --- a/quill-spark/src/main/scala/io/getquill/QuillSparkContext.scala +++ b/quill-spark/src/main/scala/io/getquill/QuillSparkContext.scala @@ -47,8 +47,6 @@ trait QuillSparkContext extends Context[SparkDialect, Literal] with Encoders wit val idiom = SparkDialect val naming = Literal - __ - def liftQuery[T](ds: Dataset[T]) = quote { sql"${lift(ds)}".pure.as[Query[T]] From 9d2ef43c8945d1c8eb2717d8c55c2b17ebadb334 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 19:12:56 +0400 Subject: [PATCH 12/21] Clean --- .../main/scala/io/getquill/context/sql/dsl/SqlDsl.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/quill-sql/src/main/scala/io/getquill/context/sql/dsl/SqlDsl.scala b/quill-sql/src/main/scala/io/getquill/context/sql/dsl/SqlDsl.scala index 2a7d71fe3d..24c8d8d238 100644 --- a/quill-sql/src/main/scala/io/getquill/context/sql/dsl/SqlDsl.scala +++ b/quill-sql/src/main/scala/io/getquill/context/sql/dsl/SqlDsl.scala @@ -2,16 +2,17 @@ package io.getquill.context.sql.dsl import io.getquill.Query import io.getquill.context.sql.SqlContext -import io.getquill.Quoted +@SuppressWarnings(Array("scalafix:ExplicitResultTypes")) +// noinspection TypeAnnotation trait SqlDsl { this: SqlContext[_, _] => implicit class Like(s1: String) { - def like(s2: String): Quoted[Boolean] = quote(sql"$s1 like $s2".pure.asCondition) + def like(s2: String) = quote(sql"$s1 like $s2".pure.asCondition) } implicit class ForUpdate[T](q: Query[T]) { - def forUpdate(): Quoted[Query[T]] = quote(sql"$q FOR UPDATE".as[Query[T]]) + def forUpdate() = quote(sql"$q FOR UPDATE".as[Query[T]]) } } From 0e7ee749d5bab5c869314ae34f7868863e215699 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 19:20:15 +0400 Subject: [PATCH 13/21] Fix compilation --- .../scala/io/getquill/idiom/StatementInterpolator.scala | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/quill-engine/src/main/scala/io/getquill/idiom/StatementInterpolator.scala b/quill-engine/src/main/scala/io/getquill/idiom/StatementInterpolator.scala index bb6ee69167..f80eeda021 100644 --- a/quill-engine/src/main/scala/io/getquill/idiom/StatementInterpolator.scala +++ b/quill-engine/src/main/scala/io/getquill/idiom/StatementInterpolator.scala @@ -51,11 +51,7 @@ object StatementInterpolator { implicit def liftTokenizer: Tokenizer[Lift] = Tokenizer[Lift] { - case tag: ScalarTag => ScalarTagToken(tag) - case tag: QuotationTag => QuotationTagToken(tag) - case lift: ScalarLift => ScalarLiftToken(lift) - // TODO Longer Explanation - case lift: Tag => fail("Cannot tokenizer a non-scalar tagging.") + case lift: ScalarLift => ScalarLiftToken(lift) case lift: Lift => fail( s"Can't tokenize a non-scalar lifting. ${lift.name}\n" + From d56f00fc159e4a077471396ba739b6350791d8f0 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 19:30:37 +0400 Subject: [PATCH 14/21] Remove all `import scala.language.higherKinds` --- quill-core/src/main/scala/io/getquill/MirrorContext.scala | 1 - quill-core/src/main/scala/io/getquill/context/Context.scala | 1 - .../src/main/scala/io/getquill/context/ContextVerbPrepare.scala | 1 - .../src/main/scala/io/getquill/context/ContextVerbStream.scala | 1 - .../main/scala/io/getquill/context/ContextVerbTranslate.scala | 1 - quill-core/src/main/scala/io/getquill/dsl/EncodingDsl.scala | 2 +- quill-core/src/main/scala/io/getquill/monad/IOMonad.scala | 2 +- .../src/main/scala/io/getquill/monad/ScalaFutureIOMonad.scala | 1 - quill-core/src/main/scala/io/getquill/monad/SyncIOMonad.scala | 1 - .../src/main/scala/io/getquill/util/OrderedGroupByExt.scala | 1 - quill-core/src/test/scala/io/getquill/base/Spec.scala | 1 - .../src/main/scala/io/getquill/context/ProtoContext.scala | 2 -- .../src/main/scala/io/getquill/context/qzio/ZIOMonad.scala | 2 +- .../scala/io/getquill/context/sql/encoding/ArrayEncoding.scala | 1 - 14 files changed, 3 insertions(+), 15 deletions(-) diff --git a/quill-core/src/main/scala/io/getquill/MirrorContext.scala b/quill-core/src/main/scala/io/getquill/MirrorContext.scala index ef4fdf0079..63134a381b 100644 --- a/quill-core/src/main/scala/io/getquill/MirrorContext.scala +++ b/quill-core/src/main/scala/io/getquill/MirrorContext.scala @@ -4,7 +4,6 @@ import io.getquill.context.mirror.{MirrorDecoders, MirrorEncoders, MirrorSession import io.getquill.context.{Context, ContextVerbPrepareLambda, ContextVerbTranslate, ExecutionInfo, ProtoContext} import io.getquill.idiom.{Idiom => BaseIdiom} import io.getquill.monad.SyncIOMonad -import scala.language.higherKinds import scala.util.{Failure, Success, Try} diff --git a/quill-core/src/main/scala/io/getquill/context/Context.scala b/quill-core/src/main/scala/io/getquill/context/Context.scala index 668b65228d..caaa5d76fc 100644 --- a/quill-core/src/main/scala/io/getquill/context/Context.scala +++ b/quill-core/src/main/scala/io/getquill/context/Context.scala @@ -1,6 +1,5 @@ package io.getquill.context -import scala.language.higherKinds import scala.language.experimental.macros import io.getquill.dsl.CoreDsl import io.getquill.util.Messages.fail diff --git a/quill-core/src/main/scala/io/getquill/context/ContextVerbPrepare.scala b/quill-core/src/main/scala/io/getquill/context/ContextVerbPrepare.scala index 73d489456f..5f241782d3 100644 --- a/quill-core/src/main/scala/io/getquill/context/ContextVerbPrepare.scala +++ b/quill-core/src/main/scala/io/getquill/context/ContextVerbPrepare.scala @@ -3,7 +3,6 @@ package io.getquill.context import io.getquill.{Action, BatchAction, Query, Quoted} import io.getquill.dsl.CoreDsl import scala.language.experimental.macros -import scala.language.higherKinds trait ContextVerbPrepare extends CoreDsl { type Result[T] diff --git a/quill-core/src/main/scala/io/getquill/context/ContextVerbStream.scala b/quill-core/src/main/scala/io/getquill/context/ContextVerbStream.scala index 6319ae2854..8feb136774 100644 --- a/quill-core/src/main/scala/io/getquill/context/ContextVerbStream.scala +++ b/quill-core/src/main/scala/io/getquill/context/ContextVerbStream.scala @@ -2,7 +2,6 @@ package io.getquill.context import io.getquill.{NamingStrategy, Query, Quoted} -import scala.language.higherKinds import scala.language.experimental.macros trait ContextVerbStream[+Idiom <: io.getquill.idiom.Idiom, +Naming <: NamingStrategy] { diff --git a/quill-core/src/main/scala/io/getquill/context/ContextVerbTranslate.scala b/quill-core/src/main/scala/io/getquill/context/ContextVerbTranslate.scala index 36fe36c8ff..7083e905c0 100644 --- a/quill-core/src/main/scala/io/getquill/context/ContextVerbTranslate.scala +++ b/quill-core/src/main/scala/io/getquill/context/ContextVerbTranslate.scala @@ -5,7 +5,6 @@ import io.getquill.idiom.Idiom import scala.annotation.tailrec import scala.language.experimental.macros -import scala.language.higherKinds trait ContextVerbTranslate extends ContextTranslateMacro { this: Context[_ <: Idiom, _ <: NamingStrategy] => diff --git a/quill-core/src/main/scala/io/getquill/dsl/EncodingDsl.scala b/quill-core/src/main/scala/io/getquill/dsl/EncodingDsl.scala index 3b3d9e458e..1e73540530 100644 --- a/quill-core/src/main/scala/io/getquill/dsl/EncodingDsl.scala +++ b/quill-core/src/main/scala/io/getquill/dsl/EncodingDsl.scala @@ -4,7 +4,7 @@ import io.getquill.quotation.NonQuotedException import scala.annotation.compileTimeOnly import scala.language.experimental.macros -import scala.language.higherKinds + import io.getquill.Query trait LowPriorityImplicits { diff --git a/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala b/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala index fddcc0759c..6f0af6de56 100644 --- a/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala +++ b/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala @@ -1,7 +1,7 @@ package io.getquill.monad import scala.collection.compat._ -import scala.language.higherKinds + import scala.util.Failure import scala.util.Success import scala.util.Try diff --git a/quill-core/src/main/scala/io/getquill/monad/ScalaFutureIOMonad.scala b/quill-core/src/main/scala/io/getquill/monad/ScalaFutureIOMonad.scala index 7925d0bb74..fc149df698 100644 --- a/quill-core/src/main/scala/io/getquill/monad/ScalaFutureIOMonad.scala +++ b/quill-core/src/main/scala/io/getquill/monad/ScalaFutureIOMonad.scala @@ -3,7 +3,6 @@ package io.getquill.monad import io.getquill.context.Context import language.experimental.macros -import language.higherKinds import scala.collection.compat._ import scala.util.Failure import scala.util.Success diff --git a/quill-core/src/main/scala/io/getquill/monad/SyncIOMonad.scala b/quill-core/src/main/scala/io/getquill/monad/SyncIOMonad.scala index 0c14b69a9d..f5071ffd97 100644 --- a/quill-core/src/main/scala/io/getquill/monad/SyncIOMonad.scala +++ b/quill-core/src/main/scala/io/getquill/monad/SyncIOMonad.scala @@ -1,6 +1,5 @@ package io.getquill.monad -import scala.language.higherKinds import scala.collection.compat._ import language.experimental.macros import io.getquill.context.Context diff --git a/quill-core/src/main/scala/io/getquill/util/OrderedGroupByExt.scala b/quill-core/src/main/scala/io/getquill/util/OrderedGroupByExt.scala index 245b3c0628..2324c2a97b 100644 --- a/quill-core/src/main/scala/io/getquill/util/OrderedGroupByExt.scala +++ b/quill-core/src/main/scala/io/getquill/util/OrderedGroupByExt.scala @@ -2,7 +2,6 @@ package io.getquill.util import collection.immutable.ListSet import collection.mutable.{LinkedHashMap => MMap, Builder} -import scala.language.higherKinds object OrderedGroupByExt { implicit class GroupByOrderedImplicitImpl[A](private val t: Traversable[A]) extends AnyVal { diff --git a/quill-core/src/test/scala/io/getquill/base/Spec.scala b/quill-core/src/test/scala/io/getquill/base/Spec.scala index 30cedb90cc..6d4d47636d 100644 --- a/quill-core/src/test/scala/io/getquill/base/Spec.scala +++ b/quill-core/src/test/scala/io/getquill/base/Spec.scala @@ -7,7 +7,6 @@ import io.getquill.quat.Quat import org.scalatest.BeforeAndAfterAll import org.scalatest.freespec.AnyFreeSpec import org.scalatest.matchers.must.Matchers -import scala.language.higherKinds import scala.concurrent.duration.Duration import scala.concurrent.{Await, Future} diff --git a/quill-engine/src/main/scala/io/getquill/context/ProtoContext.scala b/quill-engine/src/main/scala/io/getquill/context/ProtoContext.scala index d405dcc133..d1198a37f3 100644 --- a/quill-engine/src/main/scala/io/getquill/context/ProtoContext.scala +++ b/quill-engine/src/main/scala/io/getquill/context/ProtoContext.scala @@ -4,8 +4,6 @@ import io.getquill.{NamingStrategy, ReturnAction} import io.getquill.ast.Ast import io.getquill.quat.Quat -import scala.language.higherKinds - /** * A common context used between Quill and ProtoQuill. This is more like a * pre-context because the actual `run` methods cannot be contained here since diff --git a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZIOMonad.scala b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZIOMonad.scala index 3fe7bb186a..653aa733db 100644 --- a/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZIOMonad.scala +++ b/quill-jasync-zio/src/main/scala/io/getquill/context/qzio/ZIOMonad.scala @@ -7,7 +7,7 @@ import zio.{RIO, ZIO} import scala.collection.compat._ import scala.language.experimental.macros -import scala.language.higherKinds + import scala.util.{Failure, Success} trait ZIOMonad extends IOMonad { diff --git a/quill-sql/src/main/scala/io/getquill/context/sql/encoding/ArrayEncoding.scala b/quill-sql/src/main/scala/io/getquill/context/sql/encoding/ArrayEncoding.scala index 32bb7abbdd..ba088c1cba 100644 --- a/quill-sql/src/main/scala/io/getquill/context/sql/encoding/ArrayEncoding.scala +++ b/quill-sql/src/main/scala/io/getquill/context/sql/encoding/ArrayEncoding.scala @@ -6,7 +6,6 @@ import java.util.Date import io.getquill.context.sql.SqlContext import scala.collection.compat._ -import scala.language.higherKinds trait ArrayEncoding { self: SqlContext[_, _] => From 5034b787accd3db43e453c92a989c4d31e36031d Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 19:35:55 +0400 Subject: [PATCH 15/21] Fix `EnableReflectiveCalls` compilation --- .../main/scala/io/getquill/util/EnableReflectiveCalls.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/quill-core/src/main/scala/io/getquill/util/EnableReflectiveCalls.scala b/quill-core/src/main/scala/io/getquill/util/EnableReflectiveCalls.scala index eae7ec0262..c209dba30f 100644 --- a/quill-core/src/main/scala/io/getquill/util/EnableReflectiveCalls.scala +++ b/quill-core/src/main/scala/io/getquill/util/EnableReflectiveCalls.scala @@ -1,11 +1,10 @@ package io.getquill.util -import scala.reflect.macros.blackbox.Context -import scala.reflect.api.Trees +import scala.reflect.macros.blackbox object EnableReflectiveCalls { - def apply(c: Context): List[c.universe.SymTree with Trees.``] = { + def apply(c: blackbox.Context): List[c.universe.Tree] = { import c.universe._ List( q"import _root_.scala.language.reflectiveCalls", From 0550c047a249f32d5185196df9356644bf1f1d09 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Thu, 28 Sep 2023 19:40:01 +0400 Subject: [PATCH 16/21] Add missing implicit --- .../src/main/scala/io/getquill/QuillSparkContext.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/quill-spark/src/main/scala/io/getquill/QuillSparkContext.scala b/quill-spark/src/main/scala/io/getquill/QuillSparkContext.scala index d312e0b316..a04685649d 100644 --- a/quill-spark/src/main/scala/io/getquill/QuillSparkContext.scala +++ b/quill-spark/src/main/scala/io/getquill/QuillSparkContext.scala @@ -40,17 +40,21 @@ trait QuillSparkContext extends Context[SparkDialect, Literal] with Encoders wit private[getquill] val queryCounter = new AtomicInteger(0) - def close(): Unit = {} + def close(): Unit = () def probe(statement: String): Try[_] = Success(()) val idiom = SparkDialect val naming = Literal - def liftQuery[T](ds: Dataset[T]) = + def liftQuery[T](ds: Dataset[T]) = { + implicit val datasetEncoder: (Index, Dataset[T], List[Binding], ResultRow) => List[Binding] = + (_: Int, ds: Dataset[T], row: List[Binding], _: Session) => row :+ DatasetBinding(ds) + quote { sql"${lift(ds)}".pure.as[Query[T]] } + } // Helper class for the percolateNullArrays method case class StructElement(column: Column, structField: StructField) { From 5ba9c3b55fc742c2bbf59b179b97b02ee3fbc4b1 Mon Sep 17 00:00:00 2001 From: Jules Ivanic Date: Thu, 28 Sep 2023 19:44:47 +0400 Subject: [PATCH 17/21] More Scalafix (#2887) --- .../src/main/scala/io/getquill/CassandraZioContext.scala | 1 - .../src/main/scala/io/getquill/cassandrazio/Quill.scala | 1 - .../src/main/scala/io/getquill/codegen/util/StringUtil.scala | 2 +- quill-engine/src/main/scala/io/getquill/norm/Normalize.scala | 3 +-- 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala b/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala index 7d3dd1e9e1..fcccaf057c 100644 --- a/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala +++ b/quill-cassandra-zio/src/main/scala/io/getquill/CassandraZioContext.scala @@ -7,7 +7,6 @@ import io.getquill.context.{Context, ExecutionInfo} import io.getquill.context.cassandra.{CassandraRowContext, CqlIdiom} import io.getquill.context.qzio.ZioContext import io.getquill.util.Messages.fail -import io.getquill.util.ContextLogger import zio.stream.ZStream import zio.{Chunk, ChunkBuilder, ZEnvironment, ZIO} diff --git a/quill-cassandra-zio/src/main/scala/io/getquill/cassandrazio/Quill.scala b/quill-cassandra-zio/src/main/scala/io/getquill/cassandrazio/Quill.scala index 6a32c7a1dd..a9f523cf96 100644 --- a/quill-cassandra-zio/src/main/scala/io/getquill/cassandrazio/Quill.scala +++ b/quill-cassandra-zio/src/main/scala/io/getquill/cassandrazio/Quill.scala @@ -4,7 +4,6 @@ import com.datastax.oss.driver.api.core.cql.{BoundStatement, Row} import io.getquill.context.cassandra.{CassandraRowContext, CqlIdiom} import io.getquill.context.qzio.ZioContext import io.getquill.context.{Context, ExecutionInfo} -import io.getquill.util.ContextLogger import io.getquill.{CassandraZioContext, NamingStrategy} import zio.stream.ZStream import zio.{Tag, ZEnvironment, ZIO, ZLayer} diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/util/StringUtil.scala b/quill-codegen/src/main/scala/io/getquill/codegen/util/StringUtil.scala index 4b86088a39..aa17ca91b6 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/util/StringUtil.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/util/StringUtil.scala @@ -12,7 +12,7 @@ object StringUtil { implicit final class StringExtensions(private val str: String) extends AnyVal { def snakeToUpperCamel: String = str.split("_").map(_.toLowerCase).map(_.capitalize).mkString - def snakeToLowerCamel = str.split("_").map(_.toLowerCase).map(_.capitalize).mkString.uncapitalize + def snakeToLowerCamel: String = str.split("_").map(_.toLowerCase).map(_.capitalize).mkString.uncapitalize def lowerCamelToSnake: String = str.split("(?=[A-Z])").mkString("_").toLowerCase def uncapitalize = new String( diff --git a/quill-engine/src/main/scala/io/getquill/norm/Normalize.scala b/quill-engine/src/main/scala/io/getquill/norm/Normalize.scala index 30737f380f..f5863b99af 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/Normalize.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/Normalize.scala @@ -6,8 +6,7 @@ import io.getquill.ast.StatelessTransformer import io.getquill.norm.capture.{AvoidAliasConflictApply, DealiasApply} import io.getquill.ast.Action import io.getquill.util.Interpolator -import io.getquill.util.Messages.{TraceType, title, trace} -import io.getquill.util.Messages.TraceType.Normalizations +import io.getquill.util.Messages.{TraceType, title} import scala.annotation.tailrec From 5eda1068acfbfe2b8b91cd4167099c7551f2f998 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Sat, 30 Sep 2023 16:36:45 +0400 Subject: [PATCH 18/21] clean --- .../src/main/scala/io/getquill/codegen/gen/Generator.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/quill-codegen/src/main/scala/io/getquill/codegen/gen/Generator.scala b/quill-codegen/src/main/scala/io/getquill/codegen/gen/Generator.scala index 049830acf2..011cae53f9 100644 --- a/quill-codegen/src/main/scala/io/getquill/codegen/gen/Generator.scala +++ b/quill-codegen/src/main/scala/io/getquill/codegen/gen/Generator.scala @@ -101,7 +101,6 @@ trait Generator { } val fileWithExtension = fileName.resolveSibling(fileName.getFileName.toString + ".scala") - Paths.get(location) (gen, Paths.get(location, fileWithExtension.toString)) } From 84e6efd05ce8b9fb52a201905cece2838d1c91d8 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Sat, 30 Sep 2023 16:37:47 +0400 Subject: [PATCH 19/21] clean --- quill-core/src/main/scala/io/getquill/quotation/Parsing.scala | 2 -- 1 file changed, 2 deletions(-) diff --git a/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala b/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala index 89e0e2d1ae..7f45069ece 100644 --- a/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala +++ b/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala @@ -199,8 +199,6 @@ trait Parsing extends ValueComputation with QuatMaking with MacroUtilBase { Entity("unused", Nil, quat) case q"$pack.querySchema[$t](${name: String}, ..$properties)" => - q"$t".tpe - inferQuat(q"$t".tpe) val quat = inferQuat(q"$t".tpe).probit c.warn(VerifyNoBranches.in(quat)) Entity.Opinionated(name, properties.map(propertyAliasParser(_)), quat, Fixed) From 95574dcfef9b573c7b3641d30a228173dfff336a Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Sat, 30 Sep 2023 16:38:47 +0400 Subject: [PATCH 20/21] clean --- quill-core/src/main/scala/io/getquill/quotation/Parsing.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala b/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala index 7f45069ece..2062027618 100644 --- a/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala +++ b/quill-core/src/main/scala/io/getquill/quotation/Parsing.scala @@ -1226,7 +1226,7 @@ trait Parsing extends ValueComputation with QuatMaking with MacroUtilBase { case false => maybeQuoted case true => q"unquote($maybeQuoted)" } - TypeName(c.freshName("T")) + try c.typecheck(unquoted(tree), c.TYPEmode) catch { From 177d41fb507241db9a3724e83260566fa5039f12 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Sat, 30 Sep 2023 16:42:40 +0400 Subject: [PATCH 21/21] Prefer `bestComputedQuat` --- quill-engine/src/main/scala/io/getquill/ast/Ast.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quill-engine/src/main/scala/io/getquill/ast/Ast.scala b/quill-engine/src/main/scala/io/getquill/ast/Ast.scala index 7ff1966231..33befbe743 100644 --- a/quill-engine/src/main/scala/io/getquill/ast/Ast.scala +++ b/quill-engine/src/main/scala/io/getquill/ast/Ast.scala @@ -693,8 +693,8 @@ object CaseClass { final case class Block(statements: List[Ast]) extends Ast { private lazy val computedQuat = statements.last.quat def quat = computedQuat - statements.last.bestQuat - def bestQuat = computedQuat + private lazy val bestComputedQuat = statements.last.bestQuat + def bestQuat = bestComputedQuat } // Note. Assuming Block is not Empty final case class Val(name: Ident, body: Ast) extends Ast {