Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi! I cleaned up your code for you! #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/scala/literaljson/extraction.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package literaljson
package literaljson

import scala.reflect.Manifest
import JsonAST._
Expand All @@ -14,7 +14,7 @@ object Extraction {
*
* Example mapping.
*
* package xx
* package xx
* case class Person(name: String, address: Address, children: List[Child])
* case class Address(street: String, city: String)
* case class Child(name: String, age: BigInt)
Expand Down Expand Up @@ -46,13 +46,13 @@ object Extraction {

def build(root: JValue, mapping: Mapping, argStack: List[Any]): List[Any] = mapping match {
case Value(path) => fieldValue(root, path).values :: argStack
case Constructor(path, classname, args) =>
case Constructor(path, classname, args) =>
val newRoot = path match {
case Some(p) => root \ p
case None => root
}
newInstance(classname, args.flatMap(build(newRoot, _, argStack))) :: Nil
case ListConstructor(path, classname, args) =>
case ListConstructor(path, classname, args) =>
val arr = fieldValue(root, path).asInstanceOf[JArray]
arr.arr.map(elem => newInstance(classname, args.flatMap(build(elem, _, argStack)))) :: argStack
}
Expand All @@ -76,7 +76,7 @@ object Extraction {
else if (x.getType == classOf[List[_]]) makeMapping(Some(x.getName), Util.parametrizedType(x), true)
else makeMapping(Some(x.getName), x.getType, false)
}.toList.reverse // FIXME Java6 returns these in reverse order, verify that and check other vms

makeMapping(None, clazz, false)
}
}
6 changes: 3 additions & 3 deletions src/main/scala/literaljson/json.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ object JsonAST {
case JString(s) => text("\"" + quote(s) + "\"")
case JArray(arr) => text("[") :: series(trimArr(arr).map(render(_))) :: text("]")
case JField(n, v) => text("\"" + n + "\":") :: render(v)
case JObject(obj) =>
case JObject(obj) =>
val nested = break :: fields(trimObj(obj).map(f => text("\"" + f.name + "\":") :: render(f.value)))
text("{") :: nest(2, nested) :: break :: text("}")
}
Expand All @@ -141,7 +141,7 @@ object JsonAST {
case d :: ds => (d :: p) :: punctuate(p, ds)
}

private def quote(s: String) = (s.map {
private def quote(s: String) = (s.map {
case '\r' => "\\r"
case '\n' => "\\n"
case '\t' => "\\t"
Expand Down Expand Up @@ -197,7 +197,7 @@ trait Printer {

def compact(d: Document) = {
def layout(doc: Document): String = doc match {
case DocText(s) => s
case DocText(s) => s
case DocCons(d1, d2) => layout(d1) + layout(d2)
case DocBreak => ""
case DocNest(_, d) => layout(d)
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/literaljson/parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ object JsonParser {
case class MArray() extends MValue with MBlock[MValue] {
def toJValue = JArray(elems.map(_.toJValue).reverse)
}
def parse(s: String): Either[ParseError, JValue] =

def parse(s: String): Either[ParseError, JValue] =
try {
Right(parse0(s))
} catch {
Expand All @@ -76,7 +76,7 @@ object JsonParser {

def closeBlock(v: MValue) {
vals.peekOption match {
case Some(f: MField) =>
case Some(f: MField) =>
f.value = v
val field = vals.pop[MField]
vals.peek[MObject] += field
Expand Down Expand Up @@ -107,7 +107,7 @@ object JsonParser {
case DoubleVal(x) => newValue(MDouble(x))
case BoolVal(x) => newValue(MBool(x))
case NullVal => newValue(MNull)
case CloseObj => closeBlock(vals.pop[MValue])
case CloseObj => closeBlock(vals.pop[MValue])
case OpenArr => vals.push(MArray())
case CloseArr => closeBlock(vals.pop[MArray])
case End =>
Expand Down
10 changes: 5 additions & 5 deletions src/test/scala/literaljson/examples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ExampleSuite extends FunSuite {
"""

val person = """
{
{
"person": {
"name": "Joe",
"age": 35,
Expand All @@ -92,19 +92,19 @@ class ExampleSuite extends FunSuite {
}
"""

val personDSL =
val personDSL =
("person" ->
("name" -> "Joe") ~
("age" -> 35) ~
("spouse" ->
("person" ->
("spouse" ->
("person" ->
("name" -> "Marilyn") ~
("age" -> 33)
)
)
)

val objArray =
val objArray =
"""
{ "name": "joe",
"address": {
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/literaljson/generators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import JsonAST._
trait JValueGen {
def genJValue: Gen[JValue] = frequency((5, genSimple), (1, lzy(genArray)), (1, lzy(genObject)))
def genSimple: Gen[JValue] = oneOf(
value(JNull),
value(JNull),
arbitrary[Int].map(JInt(_)),
arbitrary[Double].map(JDouble(_)),
arbitrary[Boolean].map(JBool(_)),
Expand Down