Skip to content

Commit

Permalink
add explicit return types (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsrh committed Jul 29, 2020
1 parent b34fb39 commit 251dd63
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ast/src/main/scala/org/json4s/Diff.scala
Expand Up @@ -104,6 +104,6 @@ object Diff {
/** Return a diff.
* @see org.json4s.Diff#diff
*/
def diff(other: JValue) = Diff.diff(this, other)
def diff(other: JValue): Diff = Diff.diff(this, other)
}
}
10 changes: 5 additions & 5 deletions ast/src/main/scala/org/json4s/JsonAST.scala
Expand Up @@ -25,7 +25,7 @@ object JsonAST {
* concat(JInt(1), JInt(2)) == JArray(List(JInt(1), JInt(2)))
* </pre>
*/
def concat(xs: JValue*) = xs.foldLeft(JNothing: JValue)(_ ++ _)
def concat(xs: JValue*): JValue = xs.foldLeft(JNothing: JValue)(_ ++ _)

object JValue extends Merge.Mergeable

Expand Down Expand Up @@ -151,22 +151,22 @@ object JsonAST {

case class JObject(obj: List[JField]) extends JValue {
type Values = Map[String, Any]
def values = obj.iterator.map { case (n, v) => (n, v.values) }.toMap
def values: Map[String,Any] = obj.iterator.map { case (n, v) => (n, v.values) }.toMap

override def equals(that: Any): Boolean = that match {
case o: JObject => obj.toSet == o.obj.toSet
case _ => false
}

override def hashCode = obj.toSet[JField].hashCode
override def hashCode: Int = obj.toSet[JField].hashCode
}
case object JObject {
def apply(fs: JField*): JObject = JObject(fs.toList)
}

case class JArray(arr: List[JValue]) extends JValue {
type Values = List[Any]
def values = arr.map(_.values)
def values: Values = arr.map(_.values)
override def apply(i: Int): JValue = arr(i)
}

Expand All @@ -189,7 +189,7 @@ object JsonAST {

type JField = (String, JValue)
object JField {
def apply(name: String, value: JValue) = (name, value)
def apply(name: String, value: JValue): (String, JValue) = (name, value)

final class OptionStringJValue(val get: JField) extends AnyVal {
def isEmpty: Boolean = false
Expand Down
22 changes: 11 additions & 11 deletions ast/src/main/scala/org/json4s/JsonDSL.scala
Expand Up @@ -41,9 +41,9 @@ trait DoubleMode { self: Implicits =>
}
object DoubleMode extends Implicits with DoubleMode
trait Implicits {
implicit def short2jvalue(x: Short): JValue = JInt(x)
implicit def byte2jvalue(x: Byte): JValue = JInt(x)
implicit def char2jvalue(x: Char): JValue = JInt(x)
implicit def short2jvalue(x: Short): JValue = JInt(x: Int)
implicit def byte2jvalue(x: Byte): JValue = JInt(x: Int)
implicit def char2jvalue(x: Char): JValue = JInt(x: Int)
implicit def int2jvalue(x: Int): JValue = JInt(x)
implicit def long2jvalue(x: Long): JValue = JInt(x)
implicit def bigint2jvalue(x: BigInt): JValue = JInt(x)
Expand All @@ -67,22 +67,22 @@ object JsonDSL extends JsonDSL with DoubleMode {
}
trait JsonDSL extends Implicits {

implicit def seq2jvalue[A](s: Iterable[A])(implicit ev: A => JValue) =
JArray(s.toList.map { a => val v: JValue = a; v })
implicit def seq2jvalue[A](s: Iterable[A])(implicit ev: A => JValue): JArray =
JArray(s.toList.map(ev))

implicit def map2jvalue[A](m: Map[String, A])(implicit ev: A => JValue) =
implicit def map2jvalue[A](m: Map[String, A])(implicit ev: A => JValue): JObject =
JObject(m.toList.map { case (k, v) => JField(k, v) })

implicit def option2jvalue[A](opt: Option[A])(implicit ev: A => JValue): JValue = opt match {
case Some(x) => x
case None => JNothing
}

implicit def symbol2jvalue(x: Symbol) = JString(x.name)
implicit def pair2jvalue[A](t: (String, A))(implicit ev: A => JValue) = JObject(List(JField(t._1, t._2)))
implicit def list2jvalue(l: List[JField]) = JObject(l)
implicit def jobject2assoc(o: JObject) = new JsonListAssoc(o.obj)
implicit def pair2Assoc[A](t: (String, A))(implicit ev: A => JValue) = new JsonAssoc(t)
implicit def symbol2jvalue(x: Symbol): JString = JString(x.name)
implicit def pair2jvalue[A](t: (String, A))(implicit ev: A => JValue): JObject = JObject(List(JField(t._1, t._2)))
implicit def list2jvalue(l: List[JField]): JObject = JObject(l)
implicit def jobject2assoc(o: JObject): JsonListAssoc = new JsonListAssoc(o.obj)
implicit def pair2Assoc[A](t: (String, A))(implicit ev: A => JValue): JsonAssoc[A] = new JsonAssoc(t)

class JsonAssoc[A](left: (String, A))(implicit ev: A => JValue) {
def ~[B](right: (String, B))(implicit ev1: B => JValue) = {
Expand Down
2 changes: 1 addition & 1 deletion ast/src/main/scala/org/json4s/Merge.scala
Expand Up @@ -32,7 +32,7 @@ private[json4s] trait MergeDep[A <: JValue, B <: JValue, R <: JValue] {
}

private[json4s] trait LowPriorityMergeDep {
implicit def jjj[A <: JValue, B <: JValue] = new MergeDep[A, B, JValue] {
implicit def jjj[A <: JValue, B <: JValue]: MergeDep[A,B,JValue] = new MergeDep[A, B, JValue] {
def apply(val1: A, val2: B): JValue = merge(val1, val2)

private def merge(val1: JValue, val2: JValue): JValue = (val1, val2) match {
Expand Down

0 comments on commit 251dd63

Please sign in to comment.