Skip to content

Commit

Permalink
varargs generation parameterized
Browse files Browse the repository at this point in the history
  • Loading branch information
lbruand committed Nov 17, 2014
1 parent cec34d6 commit 729d96c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
16 changes: 9 additions & 7 deletions cli/src/main/scala/scalaxb/compiler/xsd/Args.scala
Expand Up @@ -65,12 +65,14 @@ trait Args extends Params {
buildFromXML(typeName, "x", stackItem, formatter) + ") }"
else selector + ".headOption map { x => scalaxb.DataRecord(x, " +
buildFromXML(typeName, "x", stackItem, formatter) + ") }"
} else (cardinality, nillable) match {
case (Multiple, true) => selector + ".toSeq map { _.nilOption map { " + fromU + " }}"
case (Multiple, false) => selector + ".toSeq map { " + fromU + " }"
case (Optional, true) => selector + ".headOption map { _.nilOption map { " + fromU + " }}"
case (Optional, false) => selector + ".headOption map { " + fromU + " }"
case (Single, _) =>
} else (cardinality, nillable, config.generateLens) match {
case (Multiple, true, true) => selector + " map { _.nilOption map { " + fromU + " }}"
case (Multiple, false, true) => selector + " map { " + fromU + " }"
case (Multiple, true, false) => selector + ".toSeq map { _.nilOption map { " + fromU + " }}"
case (Multiple, false, false) => selector + ".toSeq map { " + fromU + " }"
case (Optional, true, _) => selector + ".headOption map { _.nilOption map { " + fromU + " }}"
case (Optional, false, _) => selector + ".headOption map { " + fromU + " }"
case (Single, _, _) =>
buildSingleArg(typeName, selector, stackItem, nillable, defaultValue, fixedValue, formatter)
}

Expand Down Expand Up @@ -142,7 +144,7 @@ trait Args extends Params {
case ReferenceTypeSymbol(decl: ComplexTypeDecl) =>
if (compositorWrapper.contains(decl))
(toCardinality(elem.minOccurs, elem.maxOccurs), elem.nillable getOrElse {false}) match {
case (Multiple, _) => selector + ".toSeq"
case (Multiple, _) if !config.generateLens => selector + ".toSeq"
case (Optional, true) => selector + " getOrElse { None }"
case _ => selector
}
Expand Down
8 changes: 5 additions & 3 deletions cli/src/main/scala/scalaxb/compiler/xsd/GenSource.scala
Expand Up @@ -269,8 +269,10 @@ abstract class GenSource(val schema: SchemaDecl,
(!paramList.head.attribute) && (!effectiveMixed) && (!longAll)

def paramsString = if (hasSequenceParam) makeParamName(paramList.head.name, false) + ": " +
paramList.head.singleTypeName + "*"
else paramList.map(_.toScalaCode).mkString("," + newline + indent(1))
{ if (config.generateLens) "Seq["+paramList.head.singleTypeName + "]"

This comment has been minimized.

Copy link
@eed3si9n

eed3si9n Nov 17, 2014

Instead of including a condition there, config.useVarArg or something should be added be part of val hasSequenceParam at line 268.

else paramList.head.singleTypeName + "*" }

else paramList.map(_.toScalaCode).mkString("," + newline + indent(1))

val defLenses = config.generateLens match {
case true => paramList.map( param => genLens.buildDefLens(localName, param)).mkString(newline + indent(1))
Expand All @@ -288,7 +290,7 @@ abstract class GenSource(val schema: SchemaDecl,
case _ => false
}

def argsString = if (hasSequenceParam) particleArgs.head + ": _*"
def argsString = if (hasSequenceParam) particleArgs.head + (if (config.generateLens) "" else ": _*")
else {
val particleString = if (effectiveMixed) "Seq.concat(" + particleArgs.mkString("," + newline + indent(4)) + ")"
else if (longAll) "scala.collection.immutable.ListMap(List(" + newline +
Expand Down
2 changes: 2 additions & 0 deletions integration/src/test/resources/PurchaseOrderUsage.scala
Expand Up @@ -180,6 +180,7 @@ object PurchaseOrderUsage {
val obj = fromXML[Element1](subject)
obj match {
case Element1(DataRecord(Some("http://www.example.com/IPO"), Some("Choice2"), 1)) =>
case Element1(List(DataRecord(Some("http://www.example.com/IPO"), Some("Choice2"), 1))) =>
case _ => sys.error("match failed: " + obj.toString)
}

Expand Down Expand Up @@ -283,6 +284,7 @@ object PurchaseOrderUsage {
val obj2 = fromXML[Element1](document)
obj2 match {
case Element1(DataRecord(Some("http://www.w3.org/1998/Math/MathML"), Some("math"), _)) =>
case Element1(List(DataRecord(Some("http://www.w3.org/1998/Math/MathML"), Some("math"), _))) =>
case _ => sys.error("match failed: " + document.toString)
}
}
Expand Down
8 changes: 2 additions & 6 deletions integration/src/test/scala/LensPurchaseOrderTest.scala
Expand Up @@ -3,10 +3,6 @@ import org.specs2.matcher.ValueCheck.valueIsTypedValueCheck

import scalaxb.compiler.Config

case class SuperMy(a : String, opr : String*)

def hello(superMy : SuperMy) : SuperMy = superMy.copy(a= "hello")

object LensPurchaseOrderTest extends TestBase {
val inFile = new File("integration/src/test/resources/ipo.xsd")
val usageFile = new File(tmp, "PurchaseOrderUsage.scala")
Expand All @@ -18,7 +14,7 @@ object LensPurchaseOrderTest extends TestBase {
outdir = tmp,
generateLens = true
))
/*

"ipo.scala file must compile so Address can be used" in {
(List("import ipo._",
"Address(\"\", \"\", \"\").toString"),
Expand All @@ -29,5 +25,5 @@ object LensPurchaseOrderTest extends TestBase {
(List("import ipo._",
"PurchaseOrderUsage.allTests"),
usageFile :: generated) must evaluateTo(true, outdir = "./tmp", usecurrentcp = true)
}*/
}
}

0 comments on commit 729d96c

Please sign in to comment.