diff --git a/cli/src/main/scala/scalaxb/compiler/xsd/GenSource.scala b/cli/src/main/scala/scalaxb/compiler/xsd/GenSource.scala index f1e096a0a..b9738c775 100644 --- a/cli/src/main/scala/scalaxb/compiler/xsd/GenSource.scala +++ b/cli/src/main/scala/scalaxb/compiler/xsd/GenSource.scala @@ -348,7 +348,7 @@ abstract class GenSource(val schema: SchemaDecl, {childString} } - val groups = filterGroup(decl) + val groups = filterGroup(decl) filter { g => primaryCompositor(g).particles.size > 0 } val companionSuperNames: List[String] = "scalaxb.ElemNameParser[" + fqn + "]" :: groups.map(g => buildFormatterName(g.namespace, groupTypeName(g))) @@ -495,7 +495,8 @@ abstract class GenSource(val schema: SchemaDecl, if (groups.isEmpty) List("scalaxb.AnyElemNameParser") else groups.map { g => buildFormatterName(g.namespace, groupTypeName(g)) } - val companionCode = { buildComment(group) } trait {formatterName} extends {superNames.mkString(" with ")} {{ + val companionCode = if (compositor.particles.size == 0) + else { buildComment(group) } trait {formatterName} extends {superNames.mkString(" with ")} {{ private val targetNamespace: Option[String] = { quote(schema.targetNamespace) } def parse{localName}(node: scala.xml.Node, stack: List[scalaxb.ElemName]): Parser[{param.baseTypeName}] = @@ -753,11 +754,11 @@ object {localName} {{ def flattenElements(namespace: Option[String], family: String, compositor: HasParticle, index: Int, wrapTopSequence: Boolean): List[ElemDecl] = { compositor match { - case ref:GroupRef => - List(buildCompositorRef(ref, index)) + case ref:GroupRef => flattenElements(namespace, family, buildGroup(ref), index, wrapTopSequence) case group:GroupDecl => - List(buildCompositorRef(group, index)) + if (primaryCompositor(group).particles.isEmpty) Nil + else List(buildCompositorRef(group, index)) case seq: SequenceDecl => if (wrapTopSequence && @@ -770,12 +771,13 @@ object {localName} {{ val occurence = mergeOccurrence(buildOccurrence(choice).copy(nillable = false), buildOccurrence(seq)) List(buildCompositorRef(choice, occurence, 0)) + case group: GroupDecl => flattenElements(namespace, family, group, index, wrapTopSequence) case _ => List(buildCompositorRef(seq, index)) } else List(buildCompositorRef(seq, index)) else splitLongSequence( namespace, family, compositor.particles).zipWithIndex flatMap { - case (ref: GroupRef, i: Int) => List(buildCompositorRef(ref, i)) + case (ref: GroupRef, i: Int) => flattenElements(namespace, family, buildGroup(ref), i, wrapTopSequence) case (compositor2: HasParticle, i: Int) => List(buildCompositorRef(compositor2, i)) case (elem: ElemDecl, i: Int) => List(elem) case (ref: ElemRef, i: Int) => List(buildElement(ref)) diff --git a/cli/src/main/scala/scalaxb/compiler/xsd/Parsers.scala b/cli/src/main/scala/scalaxb/compiler/xsd/Parsers.scala index 38656ae66..1553ecd47 100644 --- a/cli/src/main/scala/scalaxb/compiler/xsd/Parsers.scala +++ b/cli/src/main/scala/scalaxb/compiler/xsd/Parsers.scala @@ -91,7 +91,8 @@ trait Parsers extends Args with Params { else splitLong[SequenceDecl](seq.particles) { SequenceDecl(_, 1, 1, 0) } val parserList = if (mixed) (0 to seq.particles.size * 2 - 1).toList map { i => - if (i % 2 == 0) buildParser(seq.particles(i / 2), mixed, mixed) + if (seq.particles.size == 0) buildTextParser + else if (i % 2 == 0) buildParser(seq.particles(i / 2), mixed, mixed) else buildTextParser } else splits map { buildParser(_, mixed, mixed) } @@ -118,7 +119,8 @@ trait Parsers extends Args with Params { else argList.mkString("," + newline + indent(4)) "{ case " + - parserVariableList.mkString(" ~ ") + + (if (seq.particles.size == 0) "_" + else parserVariableList.mkString(" ~ ")) + (if (mixed) " => Seq.concat(" + argsString + ")" else if (wrapInDataRecord) " => scalaxb.DataRecord(" + fqn + "(" + argsString + "))" else " => " + fqn + "(" + argsString + ")") + @@ -151,7 +153,8 @@ trait Parsers extends Args with Params { // choice repeatable in case any one particle is repeatable. // this may violate the schema, but it is a compromise as long as plurals are // treated as Seq[DataRecord]. - def buildChoiceParser(choice: ChoiceDecl, occurrence: Occurrence, mixed: Boolean): String = { + def buildChoiceParser(choice: ChoiceDecl, occurrence: Occurrence, mixed: Boolean): String = { + assert(choice.particles.size > 0, "choice has no particles: " + choice) val containsStructure = if (mixed) true else choice.particles exists(_ match { case elem: ElemDecl => false diff --git a/integration/src/test/resources/general.xsd b/integration/src/test/resources/general.xsd index bdbb0effd..b0b13bc84 100644 --- a/integration/src/test/resources/general.xsd +++ b/integration/src/test/resources/general.xsd @@ -194,6 +194,15 @@ + + + + + + + + + @@ -373,4 +382,8 @@ + + + +