From e11c63be07e04f7171cfed0f2d21e9e4596a6862 Mon Sep 17 00:00:00 2001 From: Takeru Sato Date: Sat, 21 Dec 2019 19:34:26 +0900 Subject: [PATCH] Omit the compiler warnings of main dirs --- build.sbt | 25 ++++++------------- core/src/main/scala/agni/Serializer.scala | 12 ++++----- .../agni/internal/ScalaVersionSpecifics.scala | 19 +++++++++++--- .../agni/internal/ScalaVersionSpecifics.scala | 4 +++ core/src/test/scala/agni/TypedSuite.scala | 10 ++++---- 5 files changed, 38 insertions(+), 32 deletions(-) diff --git a/build.sbt b/build.sbt index 76e93dd..44f3149 100644 --- a/build.sbt +++ b/build.sbt @@ -5,8 +5,7 @@ val preferences = ScalariformKeys.preferences := ScalariformKeys.preferences.value .setPreference(DanglingCloseParenthesis, Force) -lazy val root = project.in(file(".")) - .settings(name := "agni") +lazy val agni = project.in(file(".")) .settings(allSettings) .settings(noPublishSettings) .aggregate(core, `twitter-util`, monix, `cats-effect`, examples) @@ -105,9 +104,7 @@ lazy val publishSettings = Seq( ) lazy val noPublishSettings = Seq( - publish := ((): Unit), - publishLocal := ((): Unit), - publishArtifact := false + skip in publish := true ) lazy val crossVersionSharedSources: Seq[Setting[_]] = @@ -133,16 +130,14 @@ lazy val core = project.in(file("core")) ) .settings( description := "agni core", - moduleName := "agni-core", - name := "core" + moduleName := "agni-core" ) lazy val `twitter-util` = project.in(file("twitter-util")) .settings(allSettings) .settings( description := "agni twitter-util", - moduleName := "agni-twitter-util", - name := "twitter-util", + moduleName := "agni-twitter-util" ) .settings( libraryDependencies ++= Seq( @@ -155,8 +150,7 @@ lazy val monix = project.in(file("monix")) .settings(allSettings) .settings( description := "agni monix", - moduleName := "agni-monix", - name := "monix", + moduleName := "agni-monix" ) .settings( libraryDependencies ++= Seq( @@ -170,8 +164,7 @@ lazy val `cats-effect` = project.in(file("cats-effect")) .settings(allSettings) .settings( description := "agni cats-effect", - moduleName := "agni-cats-effect", - name := "cats-effect", + moduleName := "agni-cats-effect" ) .settings( libraryDependencies ++= Seq( @@ -185,8 +178,7 @@ lazy val benchmarks = project.in(file("benchmarks")) .settings(noPublishSettings) .settings( description := "agni benchmarks", - moduleName := "agni-benchmarks", - name := "benchmarks", + moduleName := "agni-benchmarks" ) .settings( scalacOptions ++= Seq( @@ -203,8 +195,7 @@ lazy val examples = project.in(file("examples")) .settings(noPublishSettings) .settings( description := "agni examples", - moduleName := "agni-examples", - name := "examples", + moduleName := "agni-examples" ) .settings( libraryDependencies ++= Seq( diff --git a/core/src/main/scala/agni/Serializer.scala b/core/src/main/scala/agni/Serializer.scala index 62fa9c6..488e7ff 100644 --- a/core/src/main/scala/agni/Serializer.scala +++ b/core/src/main/scala/agni/Serializer.scala @@ -5,6 +5,7 @@ import java.nio.ByteBuffer import java.time.{ Instant, LocalDate, ZonedDateTime } import java.util.UUID +import agni.internal.ScalaVersionSpecifics._ import cats.instances.either._ import cats.syntax.apply._ import cats.syntax.either._ @@ -13,7 +14,6 @@ import com.datastax.oss.driver.api.core.`type`.codec.TypeCodecs import com.datastax.oss.driver.api.core.data.CqlDuration import scala.annotation.tailrec -import scala.collection.generic.IsTraversableOnce import scala.collection.mutable trait Serializer[A] { @@ -23,7 +23,7 @@ trait Serializer[A] { def contramap[B](f: B => A): Serializer[B] = new Serializer[B] { override def apply(value: B, version: ProtocolVersion): Either[Throwable, ByteBuffer] = - self.apply(f(value), version) + self(f(value), version) } } @@ -35,7 +35,7 @@ object Serializer { override def apply(value: Option[A], version: ProtocolVersion): Either[Throwable, ByteBuffer] = value match { case None => Right(null) - case Some(v) => A.apply(v, version) + case Some(v) => A(v, version) } } @@ -167,18 +167,18 @@ object Serializer { implicit def serializeTraversableOnce[A0, C[_]]( implicit A: Serializer[A0], - is: IsTraversableOnce[C[A0]] { type A = A0 } + is: IsIterableOnce.Aux[C[A0], A0] ): Serializer[C[A0]] = new Serializer[C[A0]] { override def apply(value: C[A0], version: ProtocolVersion): Either[Throwable, ByteBuffer] = { if (value == null) Left(new NullPointerException) else { val items = mutable.ArrayBuilder.make[ByteBuffer] - val it = is.conversion(value).toIterator + val it = is(value).iterator @tailrec def go(toAllocate: Int): Either[Throwable, (Array[ByteBuffer], Int)] = { if (!it.hasNext) (items.result(), toAllocate).asRight else { - A.apply(it.next(), version) match { + A(it.next(), version) match { case Right(v) => items += v go(toAllocate + 4 + v.remaining()) diff --git a/core/src/main/scala_2.12-/agni/internal/ScalaVersionSpecifics.scala b/core/src/main/scala_2.12-/agni/internal/ScalaVersionSpecifics.scala index f41cae9..5060b30 100644 --- a/core/src/main/scala_2.12-/agni/internal/ScalaVersionSpecifics.scala +++ b/core/src/main/scala_2.12-/agni/internal/ScalaVersionSpecifics.scala @@ -1,12 +1,23 @@ package agni.internal -import scala.collection.generic.CanBuildFrom -import scala.collection.mutable +import scala.collection.generic._ +import scala.collection.{ mutable, GenTraversableOnce } private[agni] object ScalaVersionSpecifics { private[agni] type Factory[-E, +T] = CanBuildFrom[Nothing, E, T] - implicit private[agni] class FactoryOps[F, E, T](val bf: Factory[E, T]) extends AnyVal { - def newBuilder: mutable.Builder[E, T] = bf.apply() + private[agni] implicit class FactoryOps[F, E, T](val underlying: Factory[E, T]) extends AnyVal { + def newBuilder: mutable.Builder[E, T] = underlying.apply() + } + + object IsIterableOnce { + type Aux[Repr, A0] = IsTraversableOnce[Repr] { type A = A0 } + } + + private[agni] implicit class IsIterableOnceOps[Repr, A](val underlying: IsIterableOnce.Aux[Repr, A]) extends AnyVal { + def apply(coll: Repr): GenTraversableOnce[A] = underlying.conversion(coll) + } + private[agni] implicit class GenTraversableOnceOps[A](val underlying: GenTraversableOnce[A]) extends AnyVal { + def iterator: Iterator[A] = underlying.toIterator } } diff --git a/core/src/main/scala_2.13+/agni/internal/ScalaVersionSpecifics.scala b/core/src/main/scala_2.13+/agni/internal/ScalaVersionSpecifics.scala index c0cb943..8b74629 100644 --- a/core/src/main/scala_2.13+/agni/internal/ScalaVersionSpecifics.scala +++ b/core/src/main/scala_2.13+/agni/internal/ScalaVersionSpecifics.scala @@ -2,4 +2,8 @@ package agni.internal private[agni] object ScalaVersionSpecifics { private[agni] type Factory[-E, +T] = scala.collection.Factory[E, T] + + object IsIterableOnce { + type Aux[A0, B] = scala.collection.generic.IsIterableOnce[A0] { type A = B } + } } diff --git a/core/src/test/scala/agni/TypedSuite.scala b/core/src/test/scala/agni/TypedSuite.scala index 3cbfb25..5edc3ee 100644 --- a/core/src/test/scala/agni/TypedSuite.scala +++ b/core/src/test/scala/agni/TypedSuite.scala @@ -31,10 +31,10 @@ trait TypedSuite extends FunSuite with Checkers { type T17 = (Option[Int], String, Int, Long, Float, Double, BigDecimal, Byte, Short, BigInt, UUID, ByteBuffer, InetAddress, LocalDate, Instant, CqlDuration, List[Int]) type T18 = (Option[Int], String, Int, Long, Float, Double, BigDecimal, Byte, Short, BigInt, UUID, ByteBuffer, InetAddress, LocalDate, Instant, CqlDuration, List[Int], Vector[String]) type T19 = (Option[Int], String, Int, Long, Float, Double, BigDecimal, Byte, Short, BigInt, UUID, ByteBuffer, InetAddress, LocalDate, Instant, CqlDuration, List[Int], Vector[String], Set[Double]) - type T20 = (Option[Int], String, Int, Long, Float, Double, BigDecimal, Byte, Short, BigInt, UUID, ByteBuffer, InetAddress, LocalDate, Instant, CqlDuration, List[Int], Vector[String], Set[Double], Stream[Float]) - type T21 = (Option[Int], String, Int, Long, Float, Double, BigDecimal, Byte, Short, BigInt, UUID, ByteBuffer, InetAddress, LocalDate, Instant, CqlDuration, List[Int], Vector[String], Set[Double], Stream[Float], Map[Int, String]) - type T22 = (Option[Int], String, Int, Long, Float, Double, BigDecimal, Byte, Short, BigInt, UUID, ByteBuffer, InetAddress, LocalDate, Instant, CqlDuration, List[Int], Vector[String], Set[Double], Stream[Float], Map[Int, String], TupleValue) - type T22_2 = (Option[Int], String, Int, Long, Float, Double, BigDecimal, Byte, Short, BigInt, UUID, ByteBuffer, InetAddress, LocalDate, Instant, CqlDuration, List[Int], Vector[String], Set[Double], Stream[Float], Map[Int, String], UdtValue) + type T20 = (Option[Int], String, Int, Long, Float, Double, BigDecimal, Byte, Short, BigInt, UUID, ByteBuffer, InetAddress, LocalDate, Instant, CqlDuration, List[Int], Vector[String], Set[Double], Iterable[Float]) + type T21 = (Option[Int], String, Int, Long, Float, Double, BigDecimal, Byte, Short, BigInt, UUID, ByteBuffer, InetAddress, LocalDate, Instant, CqlDuration, List[Int], Vector[String], Set[Double], Iterable[Float], Map[Int, String]) + type T22 = (Option[Int], String, Int, Long, Float, Double, BigDecimal, Byte, Short, BigInt, UUID, ByteBuffer, InetAddress, LocalDate, Instant, CqlDuration, List[Int], Vector[String], Set[Double], Iterable[Float], Map[Int, String], TupleValue) + type T22_2 = (Option[Int], String, Int, Long, Float, Double, BigDecimal, Byte, Short, BigInt, UUID, ByteBuffer, InetAddress, LocalDate, Instant, CqlDuration, List[Int], Vector[String], Set[Double], Iterable[Float], Map[Int, String], UdtValue) type IDV = Record.`'foo -> Int, 'bar -> Double, 'quux -> Vector[Int]`.T @@ -62,7 +62,7 @@ object TypedSuite { listInt: List[Int], vectorString: Vector[String], setDouble: Set[Double], - streamFloat: Stream[Float], + streamFloat: Iterable[Float], mapIntString: Map[Int, String], tupleValue: TupleValue, udtValue: UdtValue