Permalink
Browse files

Scala 2.8 cleanups

Replace deprecated functions, remove _root_ from imports, use Tuple3.zip, etc.
  • Loading branch information...
1 parent 754baaa commit ae00042d5f420ae6b208d732758e62c3f6979294 Joni Freeman committed Dec 29, 2010
Showing with 73 additions and 82 deletions.
  1. +2 −0 framework/lift-base/lift-json/project/build/src/LiftJson.scala
  2. +1 −1 framework/lift-base/lift-json/src/main/scala/net/liftweb/json/Diff.scala
  3. +9 −10 framework/lift-base/lift-json/src/main/scala/net/liftweb/json/Extraction.scala
  4. +3 −3 framework/lift-base/lift-json/src/main/scala/net/liftweb/json/Formats.scala
  5. +1 −1 framework/lift-base/lift-json/src/main/scala/net/liftweb/json/JsonAST.scala
  6. +3 −2 framework/lift-base/lift-json/src/main/scala/net/liftweb/json/Merge.scala
  7. +1 −12 framework/lift-base/lift-json/src/main/scala/net/liftweb/json/Meta.scala
  8. +2 −2 framework/lift-base/lift-json/src/main/scala/net/liftweb/json/Xml.scala
  9. +2 −2 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/DiffExamples.scala
  10. +2 −2 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/Examples.scala
  11. +2 −2 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/ExtractionBugs.scala
  12. +2 −2 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/ExtractionExamples.scala
  13. +3 −3 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/FormatsExamples.scala
  14. +5 −5 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/JsonASTTest.scala
  15. +2 −2 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/LottoExample.scala
  16. +2 −2 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/MergeExamples.scala
  17. +2 −2 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/ParserBugs.scala
  18. +5 −5 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/ParserTest.scala
  19. +5 −5 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/PrintingTest.scala
  20. +2 −2 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/PullParserExample.scala
  21. +3 −3 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/QueryExamples.scala
  22. +3 −3 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/SerializationBugs.scala
  23. +2 −2 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/SerializationExamples.scala
  24. +2 −2 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/XmlBugs.scala
  25. +2 −2 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/XmlExamples.scala
  26. +5 −5 framework/lift-base/lift-json/src/test/scala/net/liftweb/json/XmlTest.scala
@@ -6,6 +6,8 @@ class LiftJson(info: ProjectInfo) extends DefaultProject(info) {
val specs = "org.scala-tools.testing" %% "specs" % "1.6.5"
val scalacheck = "org.scala-tools.testing" %% "scalacheck" % "1.7"
+ override def compileOptions = super.compileOptions ++ compileOptions("-unchecked")
+
override def ivyXML =
<publications>
<artifact name="lift-json" type="jar" ext="jar"/>
@@ -65,7 +65,7 @@ object Diff {
case x :: xs => yleft find (_.name == x.name) match {
case Some(y) =>
val Diff(c1, a1, d1) = diff(x, y)
- val Diff(c2, a2, d2) = diffRec(xs, yleft-y)
+ val Diff(c2, a2, d2) = diffRec(xs, yleft filterNot (_ == y))
Diff(c1 ++ c2, a1 ++ a2, d1 ++ d2) map {
case f: JField => JObject(f :: Nil)
case x => x
@@ -96,15 +96,14 @@ object Extraction {
def flatten0(path: String, json: JValue): Map[String, String] = {
json match {
- case JNothing | JNull => Map()
- case JString(s: String) => Map(path -> ("\"" + quote(s) + "\""))
- case JDouble(num: Double) => Map(path -> num.toString)
- case JInt(num: BigInt) => Map(path -> num.toString)
- case JBool(value: Boolean) => Map(path -> value.toString)
- case JField(name: String,
- value: JValue) => flatten0(path + escapePath(name), value)
- case JObject(obj: List[JField]) => obj.foldLeft(Map[String, String]()) { (map, field) => map ++ flatten0(path + ".", field) }
- case JArray(arr: List[JValue]) => arr.length match {
+ case JNothing | JNull => Map()
+ case JString(s) => Map(path -> ("\"" + quote(s) + "\""))
+ case JDouble(num) => Map(path -> num.toString)
+ case JInt(num) => Map(path -> num.toString)
+ case JBool(value) => Map(path -> value.toString)
+ case JField(name, value) => flatten0(path + escapePath(name), value)
+ case JObject(obj) => obj.foldLeft(Map[String, String]()) { (map, field) => map ++ flatten0(path + ".", field) }
+ case JArray(arr) => arr.length match {
case 0 => Map(path -> "[]")
case _ => arr.foldLeft((Map[String, String](), 0)) {
(tuple, value) => (tuple._1 ++ flatten0(path + "[" + tuple._2 + "]", value), tuple._2 + 1)
@@ -153,7 +152,7 @@ object Extraction {
case ArrayElem(p, i) => set + p
case x @ _ => set + x
}
- }.toList.sort(_ < _) // Sort is necessary to get array order right
+ }.toList.sortWith(_ < _) // Sort is necessary to get array order right
uniquePaths.foldLeft[JValue](JNothing) { (jvalue, key) =>
jvalue.merge(key match {
@@ -119,9 +119,9 @@ trait TypeHints {
/**
* Chooses most specific class.
*/
- def hintFor(clazz: Class[_]): String = components.filter(_.containsHint_?(clazz)).
- map(th => (th.hintFor(clazz), th.classFor(th.hintFor(clazz)).getOrElse(error("hintFor/classFor not invertible for " + th)))).
- sort((x, y) => delta(x._2, clazz) - delta(y._2, clazz) < 0).head._1
+ def hintFor(clazz: Class[_]): String = components.filter(_.containsHint_?(clazz))
+ .map(th => (th.hintFor(clazz), th.classFor(th.hintFor(clazz)).getOrElse(error("hintFor/classFor not invertible for " + th))))
+ .sort((x, y) => delta(x._2, clazz) - delta(y._2, clazz) < 0).head._1
def classFor(hint: String): Option[Class[_]] = hints find (hintFor(_) == hint)
@@ -444,7 +444,7 @@ object JsonDSL extends JsonDSL with Printer
trait JsonDSL extends Implicits {
import JsonAST._
- implicit def seq2jvalue[A <% JValue](s: Seq[A]) = JArray(s.toList.map { a => val v: JValue = a; v })
+ implicit def seq2jvalue[A <% JValue](s: Traversable[A]) = JArray(s.toList.map { a => val v: JValue = a; v })
implicit def option2jvalue[A <% JValue](opt: Option[A]): JValue = opt match {
case Some(x) => x
case None => JNothing
@@ -43,7 +43,8 @@ object Merge {
def mergeRec(xleft: List[JField], yleft: List[JField]): List[JField] = xleft match {
case Nil => yleft
case JField(xn, xv) :: xs => yleft find (_.name == xn) match {
- case Some(y @ JField(yn, yv)) => JField(xn, merge(xv, yv)) :: mergeRec(xs, yleft-y)
+ case Some(y @ JField(yn, yv)) =>
+ JField(xn, merge(xv, yv)) :: mergeRec(xs, yleft filterNot (_ == y))
case None => JField(xn, xv) :: mergeRec(xs, yleft)
}
}
@@ -55,7 +56,7 @@ object Merge {
def mergeRec(xleft: List[JValue], yleft: List[JValue]): List[JValue] = xleft match {
case Nil => yleft
case x :: xs => yleft find (_ == x) match {
- case Some(y) => merge(x, y) :: mergeRec(xs, yleft-y)
+ case Some(y) => merge(x, y) :: mergeRec(xs, yleft filterNot (_ == y))
case None => x :: mergeRec(xs, yleft)
}
}
@@ -177,7 +177,7 @@ private[json] object Meta {
val names = paranamer.lookupParameterNames(c).map(clean)
val types = c.getParameterTypes
val ptypes = c.getGenericParameterTypes
- zip3(names.toList, types.toList, ptypes.toList)
+ (names.toList, types.toList, ptypes.toList).zip
} catch {
case e: ParameterNamesNotFoundException => Nil
}
@@ -188,17 +188,6 @@ private[json] object Meta {
def primaryConstructorArgs(c: Class[_]) = constructorArgs(c.getDeclaredConstructors()(0))
- // FIXME Replace this with Tuple3.zipped when moving to 2.8
- private def zip3[A, B, C](l1: List[A], l2: List[B], l3: List[C]): List[(A, B, C)] = {
- def zip(x1: List[A], x2: List[B], x3: List[C], acc: List[(A, B, C)]): List[(A, B, C)] =
- x1 match {
- case Nil => acc.reverse
- case x :: xs => zip(xs, x2.tail, x3.tail, (x, x2.head, x3.head) :: acc)
- }
-
- zip(l1, l2, l3, Nil)
- }
-
def typeParameters(t: Type, k: Kind): List[Class[_]] = {
def term(i: Int) = t match {
case ptype: ParameterizedType => ptype.getActualTypeArguments()(i) match {
@@ -92,7 +92,7 @@ object Xml {
!descendant(node).find(_.isInstanceOf[Elem]).isDefined
}
- def array_?(nodeNames: Seq[String]) = nodeNames.size != 1 && nodeNames.toList.removeDuplicates.size == 1
+ def array_?(nodeNames: Seq[String]) = nodeNames.size != 1 && nodeNames.toList.distinct.size == 1
def directChildren(n: Node): NodeSeq = n.child.filter(c => c.isInstanceOf[Elem])
def nameOf(n: Node) = (if (n.prefix ne null) n.prefix + ":" else "") + n.label
def buildAttrs(n: Node) = n.attributes.map((a: MetaData) => (a.key, XValue(a.value.text))).toList
@@ -144,7 +144,7 @@ object Xml {
buildNodes(xml) match {
case List(x @ XLeaf(_, _ :: _)) => toJValue(x)
- case List(x) => JObject(JField(nameOf(xml.first), toJValue(x)) :: Nil)
+ case List(x) => JObject(JField(nameOf(xml.head), toJValue(x)) :: Nil)
case x => JArray(x.map(toJValue))
}
}
@@ -17,8 +17,8 @@
package net.liftweb {
package json {
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
class DiffExamplesTest extends Runner(DiffExamples) with JUnit
object DiffExamples extends Specification {
@@ -17,8 +17,8 @@
package net.liftweb {
package json {
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
class ExampleTest extends Runner(Examples) with JUnit
object Examples extends Specification {
@@ -17,8 +17,8 @@
package net.liftweb {
package json {
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
class ExtractionBugsTest extends Runner(ExtractionBugs) with JUnit
object ExtractionBugs extends Specification {
@@ -18,8 +18,8 @@ package net.liftweb {
package json {
import java.util.Date
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
import JsonAST._
class ExtractionExampleTest extends Runner(ExtractionExamples) with JUnit
@@ -18,8 +18,8 @@ package net.liftweb {
package json {
import java.util.Date
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
class FormatsExamplesTest extends Runner(FormatsExamples) with JUnit
@@ -47,4 +47,4 @@ object FormatsExamples extends Specification with TypeHintExamples {
}
}
-}
+}
@@ -17,11 +17,11 @@
package net.liftweb {
package json {
-import _root_.org.scalacheck._
-import _root_.org.scalacheck.Prop.{forAll, forAllNoShrink}
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
-import _root_.org.specs.ScalaCheck
+import org.scalacheck._
+import org.scalacheck.Prop.{forAll, forAllNoShrink}
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
+import org.specs.ScalaCheck
class JsonASTTest extends Runner(JsonASTSpec) with JUnit
object JsonASTSpec extends Specification with JValueGen with ScalaCheck {
@@ -17,8 +17,8 @@
package net.liftweb {
package json {
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
class LottoExampleTest extends Runner(LottoExample) with JUnit
object LottoExample extends Specification {
@@ -17,8 +17,8 @@
package net.liftweb {
package json {
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
class MergeExamplesTest extends Runner(MergeExamples) with JUnit
object MergeExamples extends Specification {
@@ -17,8 +17,8 @@
package net.liftweb {
package json {
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
class ParserBugsTest extends Runner(ParserBugs) with JUnit
object ParserBugs extends Specification {
@@ -17,11 +17,11 @@
package net.liftweb {
package json {
-import _root_.org.scalacheck._
-import _root_.org.scalacheck.Prop._
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
-import _root_.org.specs.ScalaCheck
+import org.scalacheck._
+import org.scalacheck.Prop._
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
+import org.specs.ScalaCheck
class ParserTest extends Runner(ParserSpec) with JUnit
object ParserSpec extends Specification with JValueGen with ScalaCheck {
@@ -17,11 +17,11 @@
package net.liftweb {
package json {
-import _root_.org.scalacheck._
-import _root_.org.scalacheck.Prop.forAll
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
-import _root_.org.specs.ScalaCheck
+import org.scalacheck._
+import org.scalacheck.Prop.forAll
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
+import org.specs.ScalaCheck
class PrintingTest extends Runner(PrintingSpec) with JUnit
object PrintingSpec extends Specification with JValueGen with ScalaCheck {
@@ -1,7 +1,7 @@
package net.liftweb.json
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
class PullParserExampleTest extends Runner(PullParserExample) with JUnit
object PullParserExample extends Specification {
@@ -17,8 +17,8 @@
package net.liftweb {
package json {
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
class QueryExamplesTest extends Runner(QueryExamples) with JUnit
object QueryExamples extends Specification {
@@ -57,7 +57,7 @@ object QueryExamples extends Specification {
JField("uptime", JInt(uptime)) <- server
} yield Server(ip, uptime.longValue)
- servers sort (_.uptime > _.uptime) mustEqual List(Server("192.168.1.127", 901214), Server("192.168.2.125", 453423), Server("192.168.2.126", 214312), Server("192.168.1.126", 189822), Server("192.168.1.125", 150123))
+ servers sortWith (_.uptime > _.uptime) mustEqual List(Server("192.168.1.127", 901214), Server("192.168.2.125", 453423), Server("192.168.2.126", 214312), Server("192.168.1.126", 189822), Server("192.168.1.125", 150123))
}
"Clusters administered by liza" in {
@@ -17,8 +17,8 @@
package net.liftweb {
package json {
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
class SerializationBugsTest extends Runner(SerializationBugs) with JUnit
object SerializationBugs extends Specification {
@@ -64,7 +64,7 @@ object SerializationBugs extends Specification {
}
"StackOverflowError with large Lists" in {
- val xs = LongList(List.make(5000, 0).map(Num))
+ val xs = LongList(List.fill(5000)(0).map(Num))
val ser = swrite(xs)
read[LongList](ser).xs.length mustEqual 5000
}
@@ -18,8 +18,8 @@ package net.liftweb {
package json {
import java.util.Date
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
class SerializationExamplesTest extends Runner(SerializationExamples, ShortTypeHintExamples, FullTypeHintExamples, CustomClassExamples) with JUnit
object SerializationExamples extends Specification {
@@ -17,8 +17,8 @@
package net.liftweb {
package json {
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
class XmlBugsTest extends Runner(XmlBugs) with JUnit
object XmlBugs extends Specification {
@@ -17,8 +17,8 @@
package net.liftweb {
package json {
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
class XmlExamplesTest extends Runner(XmlExamples) with JUnit
object XmlExamples extends Specification {
@@ -17,11 +17,11 @@
package net.liftweb {
package json {
-import _root_.org.scalacheck._
-import _root_.org.scalacheck.Prop.forAll
-import _root_.org.specs.Specification
-import _root_.org.specs.runner.{Runner, JUnit}
-import _root_.org.specs.ScalaCheck
+import org.scalacheck._
+import org.scalacheck.Prop.forAll
+import org.specs.Specification
+import org.specs.runner.{Runner, JUnit}
+import org.specs.ScalaCheck
class XmlTest extends Runner(XmlSpec) with JUnit
object XmlSpec extends Specification with NodeGen with JValueGen with ScalaCheck {

0 comments on commit ae00042

Please sign in to comment.