Permalink
Browse files

switched to scala 2.10, use builtin reflection instead of scmirror

  • Loading branch information...
1 parent cd23d43 commit d5dca580731436e184c8c898005bbd6ea290100f Herr Ritschwumm committed Jan 11, 2013
View
1 README
@@ -5,7 +5,6 @@ To build this code, get and install SBT from
Get and install these library/libraries before building:
https://github.com/ritschwumm/scutil
- https://github.com/ritschwumm/scmirror
Use these commands to build:
git clone git@github.com:ritschwumm/scjson.git
View
@@ -2,16 +2,28 @@ name := "scjson"
organization := "de.djini"
-version := "0.14.0"
+version := "0.15.0"
-scalaVersion := "2.9.2"
+scalaVersion := "2.10.0"
libraryDependencies ++= Seq(
- "de.djini" %% "scutil" % "0.14.0" % "compile",
- "de.djini" %% "scmirror" % "0.10.0" % "compile",
- "org.specs2" %% "specs2" % "1.12.3" % "test"
+ "de.djini" %% "scutil" % "0.15.0" % "compile",
+ "org.specs2" %% "specs2" % "1.13" % "test"
)
-scalacOptions ++= Seq("-deprecation", "-unchecked")
+libraryDependencies <+= (scalaVersion) { "org.scala-lang" % "scala-reflect" % _ }
+
+scalacOptions ++= Seq(
+ "-deprecation",
+ "-unchecked",
+ "-language:implicitConversions",
+ "-language:existentials",
+ // "-language:higherKinds",
+ // "-language:reflectiveCalls",
+ // "-language:dynamics",
+ "-language:postfixOps",
+ // "-language:experimental.macros"
+ "-feature"
+)
(sourceGenerators in Compile) <+= (sourceManaged in Compile) map Boilerplate.generate
@@ -24,7 +24,6 @@ object Boilerplate {
|package scjson.serialization
|
|import scutil.Implicits._
- |import scmirror._
|import scjson._
|import JSONSerializationUtil._
|
@@ -66,16 +65,16 @@ object Boilerplate {
"""
|package scjson.serialization
|
+ |import reflect.runtime.universe._
|import scutil.Implicits._
- |import scmirror._
|import scjson._
|import JSONSerializationUtil._
|
|trait CaseClassProtocolGenerated {
""".stripMargin +
(2 to 22 map genCaseClassMethod mkString "\n") +
"""
- | protected def fieldNamesFor[T:Manifest]:Seq[String]
+ | protected def fieldNamesFor[T:TypeTag]:Seq[String]
|}
""".stripMargin
}
@@ -86,7 +85,7 @@ object Boilerplate {
val typeNames = awc("S$")
val fieldNames = awc("k$")
("""
- | def caseClassJSONFormat"""+arity+"""["""+typeParams+""",T:Manifest](apply:("""+typeNames+""")=>T, unapply:T=>Option[("""+typeNames+""")]):JSONFormat[T] = {
+ | def caseClassJSONFormat"""+arity+"""["""+typeParams+""",T:TypeTag](apply:("""+typeNames+""")=>T, unapply:T=>Option[("""+typeNames+""")]):JSONFormat[T] = {
| val Seq("""+fieldNames+""") = fieldNamesFor[T]
| new JSONFormat[T] {
| def write(out:T):JSONValue = {
@@ -1,8 +1,8 @@
package scjson.serialization
-import scutil.Implicits._
+import reflect.runtime.universe._
-import scmirror._
+import scutil.Implicits._
import scjson._
@@ -11,7 +11,7 @@ import JSONSerializationUtil._
object CaseClassProtocol extends CaseClassProtocol
trait CaseClassProtocol extends CaseClassProtocolGenerated {
- def caseObjectJSONFormat[T:Manifest](singleton:T):JSONFormat[T] = {
+ def caseObjectJSONFormat[T:TypeTag](singleton:T):JSONFormat[T] = {
new JSONFormat[T] {
def write(out:T):JSONValue = {
JSONObject.empty
@@ -22,7 +22,7 @@ trait CaseClassProtocol extends CaseClassProtocolGenerated {
}
}
- def caseClassJSONFormat1[S1:JSONFormat,T:Manifest](apply:S1=>T, unapply:T=>Option[S1]):JSONFormat[T] = {
+ def caseClassJSONFormat1[S1:JSONFormat,T:TypeTag](apply:S1=>T, unapply:T=>Option[S1]):JSONFormat[T] = {
val Seq(k1) = fieldNamesFor[T]
new JSONFormat[T] {
def write(out:T):JSONValue = {
@@ -41,7 +41,7 @@ trait CaseClassProtocol extends CaseClassProtocolGenerated {
}
/*
- def caseClassJSONFormat2[S1:JSONFormat,S2:JSONFormat,T:Manifest](apply:(S1,S2)=>T, unapply:T=>Option[(S1,S2)]):JSONFormat[T] = {
+ def caseClassJSONFormat2[S1:JSONFormat,S2:JSONFormat,T:TypeTag](apply:(S1,S2)=>T, unapply:T=>Option[(S1,S2)]):JSONFormat[T] = {
val Seq(k1,k2) = fieldNamesFor[T]
new JSONFormat[T] {
def write(out:T):JSONValue = {
@@ -63,8 +63,16 @@ trait CaseClassProtocol extends CaseClassProtocolGenerated {
*/
// BETTER cache results
- protected def fieldNamesFor[T:Manifest]:Seq[String] =
- (Reflector constructor manifest[T].erasure) getOrError ("cannot get fields for type " + manifest[T].erasure)
+ protected def fieldNamesFor[T:TypeTag]:Seq[String] = {
+ val typ = typeOf[T]
+ val names:Option[Seq[String]] =
+ for {
+ primaryCtor <- typ.declarations filter { _.isMethod } map { _.asMethod } filter { _.isPrimaryConstructor } singleOption;
+ paramNames <- primaryCtor.paramss.singleOption
+ }
+ yield paramNames map { _.name.decoded }
+ names getOrError ("cannot get fields for type " + typ)
+ }
//------------------------------------------------------------------------------
//## sums of case classes
@@ -8,12 +8,12 @@ private object Summand {
implicit def fromClass[T:JSONFormat](clazz:Class[T]):Summand[T] =
Summand(clazz.getName, clazz, jsonFormat[T])
implicit def fromJSONFormat[T:Manifest](format:JSONFormat[T]):Summand[T] =
- Summand(manifest[T].erasure.getName, manifest[T].erasure, format)
+ Summand(manifest[T].runtimeClass.getName, manifest[T].runtimeClass, format)
implicit def fromClassWithIdentifier[T:JSONFormat](id:(String,Class[T])):Summand[T] =
Summand(id._1, id._2, jsonFormat[T])
implicit def fromJSONFormatWithIdentifier[T:Manifest](id:(String, JSONFormat[T])):Summand[T] =
- Summand(id._1, manifest[T].erasure, id._2)
+ Summand(id._1, manifest[T].runtimeClass, id._2)
}
private case class Summand[T](identifier:String, clazz:Class[_], format:JSONFormat[T]) {

0 comments on commit d5dca58

Please sign in to comment.