Skip to content

Commit

Permalink
Merge pull request #175 from wvlet/scala-2.13.0-M4
Browse files Browse the repository at this point in the history
Scala 2.13.0-M4
  • Loading branch information
xerial authored Jul 19, 2018
2 parents 99dc3f6 + f34c123 commit 9cb2861
Show file tree
Hide file tree
Showing 52 changed files with 285 additions and 271 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ matrix:
script:
- ./sbt ++$SCALA_VERSION "; coverage; ${PROJECT}/test; coverageReport"
- "./sbt coverageAggregate && bash <(curl -s https://codecov.io/bash)"
- env: SCALA_VERSION=2.13.0-M3 PROJECT=projectJVM
- env: SCALA_VERSION=2.13.0-M4 PROJECT=projectJVM
services: postgresql
before_script: psql -c 'create database travis_ci_test;' -U postgres
jdk: oraclejdk8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import wvlet.surface.{Surface, Zero}
import scala.collection.JavaConverters._
import scala.collection.mutable

/**
*
*/
object CollectionCodec {

object BaseSeqCodec {
Expand Down Expand Up @@ -59,7 +56,7 @@ object CollectionCodec {
}
}

case class SeqCodec[A](surface: Surface, elementCodec: MessageCodec[A]) extends MessageCodec[Seq[A]] {
class SeqCodec[A](surface: Surface, elementCodec: MessageCodec[A]) extends MessageCodec[Seq[A]] {
override def pack(p: MessagePacker, v: Seq[A]): Unit = {
BaseSeqCodec.pack(p, v, elementCodec)
}
Expand All @@ -69,7 +66,7 @@ object CollectionCodec {
}
}

case class IndexedSeqCodec[A](surface: Surface, elementCodec: MessageCodec[A]) extends MessageCodec[IndexedSeq[A]] {
class IndexedSeqCodec[A](surface: Surface, elementCodec: MessageCodec[A]) extends MessageCodec[IndexedSeq[A]] {
override def pack(p: MessagePacker, v: IndexedSeq[A]): Unit = {
BaseSeqCodec.pack(p, v, elementCodec)
}
Expand All @@ -88,7 +85,7 @@ object CollectionCodec {
[error] at scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:172)
</code>
*/
case class ListCodec[A](surface: Surface, elementCodec: MessageCodec[A]) extends MessageCodec[Seq[A]] {
class ListCodec[A](surface: Surface, elementCodec: MessageCodec[A]) extends MessageCodec[Seq[A]] {
override def pack(p: MessagePacker, v: Seq[A]): Unit = {
BaseSeqCodec.pack(p, v, elementCodec)
}
Expand Down Expand Up @@ -123,7 +120,7 @@ object CollectionCodec {
case class MapCodec[A, B](keyCodec: MessageCodec[A], valueCodec: MessageCodec[B]) extends MessageCodec[Map[A, B]] {
override def pack(p: MessagePacker, m: Map[A, B]): Unit = {
p.packMapHeader(m.size)
for ((k, v) <- m.seq) {
for ((k, v) <- m) {
keyCodec.pack(p, k)
valueCodec.pack(p, v)
}
Expand All @@ -148,7 +145,7 @@ object CollectionCodec {
extends MessageCodec[java.util.Map[A, B]] {
override def pack(p: MessagePacker, m: java.util.Map[A, B]): Unit = {
p.packMapHeader(m.size)
for ((k, v) <- m.asScala.seq) {
for ((k, v) <- m.asScala) {
keyCodec.pack(p, k)
valueCodec.pack(p, v)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object JDBCCodec {
}
}

override def unpack(u: MessageUnpacker, v: MessageHolder) {
override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = {
val size = u.unpackArrayHeader()
for (i <- 0 until size) {
u.unpackValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import wvlet.log.LogSupport
import scala.reflect.runtime.{universe => ru}
import scala.util.{Failure, Success, Try}

trait MessageCodec[A] extends LogSupport {
def pack(p: MessagePacker, v: A)
def unpack(u: MessageUnpacker, v: MessageHolder)
trait MessageCodec[A] {
def pack(p: MessagePacker, v: A): Unit
def unpack(u: MessageUnpacker, v: MessageHolder): Unit

// TODO add specialized methods for primitive values
// def unpackInt(u:MessageUnpacker) : Int
Expand Down Expand Up @@ -51,11 +51,11 @@ trait MessageValueCodec[A] extends MessageCodec[A] {
def pack(v: A): Value
def unpack(v: Value): A

override def pack(p: MessagePacker, v: A) {
override def pack(p: MessagePacker, v: A): Unit = {
p.packValue(pack(v))
}

override def unpack(u: MessageUnpacker, v: MessageHolder) {
override def unpack(u: MessageUnpacker, v: MessageHolder): Unit = {
val vl = u.unpackValue()
Try(unpack(vl)) match {
case Success(x) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package wvlet.airframe.codec

import wvlet.airframe.codec.CollectionCodec._
import CollectionCodec._
import wvlet.airframe.codec.ScalaStandardCodec.{OptionCodec, TupleCodec}
import wvlet.airframe.codec.StandardCodec.EnumCodec
import wvlet.log.LogSupport
Expand All @@ -26,7 +26,7 @@ import scala.reflect.runtime.{universe => ru}
/**
*
*/
class MessageCodecFactory(knownCodecs: Map[Surface, MessageCodec[_]]) extends LogSupport {
class MessageCodecFactory(knownCodecs: Map[Surface, MessageCodec[_]]) {

def withCodecs(additionalCodecs: Map[Surface, MessageCodec[_]]): MessageCodecFactory = {
new MessageCodecFactory(knownCodecs ++ additionalCodecs)
Expand All @@ -45,7 +45,8 @@ class MessageCodecFactory(knownCodecs: Map[Surface, MessageCodec[_]]) extends Lo
throw new IllegalArgumentException(s"Codec for recursive types is not supported: ${surface}")
} else {
val seenSet = seen + surface
trace(s"Finding MessageCodec of ${surface.dealias}")
//trace(s"Finding MessageCodec of ${surface.dealias}")

val codec =
surface.dealias match {
case s if s.isOption =>
Expand All @@ -58,22 +59,22 @@ class MessageCodecFactory(knownCodecs: Map[Surface, MessageCodec[_]]) extends Lo
EnumCodec(cl)
case g: GenericSurface if ReflectTypeUtil.isSeq(g.rawType) =>
// Seq[A]
val elementSurface = ofSurface(g.typeArgs(0), seenSet)
val elementSurface = this.ofSurface(g.typeArgs(0), seenSet)
if (ReflectTypeUtil.isIndexedSeq(g.rawType)) {
IndexedSeqCodec(g.typeArgs(0), elementSurface)
new IndexedSeqCodec(g.typeArgs(0), elementSurface)
} else if (ReflectTypeUtil.isList(g.rawType)) {
ListCodec(g.typeArgs(0), elementSurface)
new ListCodec(g.typeArgs(0), elementSurface)
} else {
SeqCodec(g.typeArgs(0), elementSurface)
new SeqCodec(g.typeArgs(0), elementSurface)
}
case g: GenericSurface if ReflectTypeUtil.isJavaColleciton(g.rawType) =>
JavaListCodec(ofSurface(g.typeArgs(0), seenSet))
CollectionCodec.JavaListCodec(ofSurface(g.typeArgs(0), seenSet))
case g: GenericSurface if ReflectTypeUtil.isMap(g.rawType) =>
// Map[A,B]
MapCodec(ofSurface(g.typeArgs(0), seen), ofSurface(g.typeArgs(1), seenSet))
CollectionCodec.MapCodec(ofSurface(g.typeArgs(0), seen), ofSurface(g.typeArgs(1), seenSet))
case g: GenericSurface if ReflectTypeUtil.isJavaMap(g.rawType) =>
// Map[A,B]
JavaMapCodec(ofSurface(g.typeArgs(0), seen), ofSurface(g.typeArgs(1), seenSet))
CollectionCodec.JavaMapCodec(ofSurface(g.typeArgs(0), seen), ofSurface(g.typeArgs(1), seenSet))
case s if ReflectTypeUtil.isTuple(s.rawType) =>
// Tuple
TupleCodec(surface.typeArgs.map(x => ofSurface(x, seenSet)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,59 +33,59 @@ class MessageHolder {
def hasError: Boolean = err.isDefined
def getError: Option[Throwable] = err

def setNull {
def setNull: Unit = {
dataType = NIL
value = None
}

def setBoolean(v: Boolean) {
def setBoolean(v: Boolean): Unit = {
setValue(BOOLEAN, v)
b = v
}
def setByte(v: Byte) {
def setByte(v: Byte): Unit = {
setValue(INTEGER, v)
l = v
}
def setChar(v: Char) {
def setChar(v: Char): Unit = {
setValue(INTEGER, v)
l = v
}
def setShort(v: Short) {
def setShort(v: Short): Unit = {
setValue(INTEGER, v)
l = v
}
def setInt(v: Int) {
def setInt(v: Int): Unit = {
setValue(INTEGER, v)
l = v
}
def setLong(v: Long) {
def setLong(v: Long): Unit = {
setValue(INTEGER, v)
l = v
}

def setFloat(v: Float) {
def setFloat(v: Float): Unit = {
setValue(FLOAT, v)
d = v
}
def setDouble(v: Double) {
def setDouble(v: Double): Unit = {
setValue(FLOAT, v)
d = v
}

def setString(v: String) {
def setString(v: String): Unit = {
setValue(STRING, v)
s = v
}

def setObject(v: Any) {
def setObject(v: Any): Unit = {
if (v == null) {
setNull
} else {
setValue(ANY, v)
}
}

protected def setValue(dataType: DataType, v: Any) {
protected def setValue(dataType: DataType, v: Any): Unit = {
this.dataType = dataType
if (v != null) {
value = Some(v)
Expand Down Expand Up @@ -152,12 +152,12 @@ class MessageHolder {

def getLastValue: Any = value.getOrElse(null)

def setError[A](e: Throwable) {
def setError[A](e: Throwable): Unit = {
setNull
err = Option(e)
}

def setIncompatibleFormatException[A](codec: MessageCodec[A], message: String) {
def setIncompatibleFormatException[A](codec: MessageCodec[A], message: String): Unit = {
setError(new MessageCodecException(INVALID_DATA, codec, message))
}

Expand Down
Loading

0 comments on commit 9cb2861

Please sign in to comment.