From 1fbb658a83190e0f6a8bbb1bf97ab66231fb46f2 Mon Sep 17 00:00:00 2001
From: xuwei-k <6b656e6a69@gmail.com>
Date: Thu, 5 Oct 2023 14:52:22 +0900
Subject: [PATCH] avoid xml pattern match
---
.../compiler/xsd/ContentModelDecl.scala | 22 ++---
.../scala/scalaxb/compiler/xsd/Decl.scala | 82 +++++++++----------
2 files changed, 52 insertions(+), 52 deletions(-)
diff --git a/cli/src/main/scala/scalaxb/compiler/xsd/ContentModelDecl.scala b/cli/src/main/scala/scalaxb/compiler/xsd/ContentModelDecl.scala
index e33bda47a..a75bf1b66 100644
--- a/cli/src/main/scala/scalaxb/compiler/xsd/ContentModelDecl.scala
+++ b/cli/src/main/scala/scalaxb/compiler/xsd/ContentModelDecl.scala
@@ -99,14 +99,14 @@ object CompContRestrictionDecl {
val base = TypeSymbolParser.fromString(baseName, node.scope, config)
var compositor: Option[HasParticle] = None
- for (child <- node.child) child match {
- case { _* } =>
+ for (child <- node.child) child.label match {
+ case "group" =>
compositor = Some(CompositorDecl.fromXML(child, family, config))
- case { _* } =>
+ case "all" =>
compositor = Some(CompositorDecl.fromXML(child, family, config))
- case { _* } =>
+ case "choice" =>
compositor = Some(CompositorDecl.fromXML(child, family, config))
- case { _* } =>
+ case "sequence" =>
compositor = Some(CompositorDecl.fromXML(child, family, config))
case _ =>
@@ -127,14 +127,14 @@ object CompContExtensionDecl {
val base = TypeSymbolParser.fromString(baseName, node.scope, config)
var compositor: Option[HasParticle] = None
- for (child <- node.child) child match {
- case { _* } =>
+ for (child <- node.child) child.label match {
+ case "group" =>
compositor = Some(CompositorDecl.fromXML(child, family, config))
- case { _* } =>
+ case "all" =>
compositor = Some(CompositorDecl.fromXML(child, family, config))
- case { _* } =>
+ case "choice" =>
compositor = Some(CompositorDecl.fromXML(child, family, config))
- case { _* } =>
+ case "sequence" =>
compositor = Some(CompositorDecl.fromXML(child, family, config))
case _ =>
}
@@ -206,7 +206,7 @@ trait Facetable[A] {
object Facetable {
def fromParent(node: scala.xml.Node, base: XsTypeSymbol, config: ParserConfig): List[Facetable[_]] =
node.child.toList collect {
- case x@({ _* }) => EnumerationDecl.fromXML(x, base, config)
+ case x if x.label == "enumeration" => EnumerationDecl.fromXML(x, base, config)
}
}
diff --git a/cli/src/main/scala/scalaxb/compiler/xsd/Decl.scala b/cli/src/main/scala/scalaxb/compiler/xsd/Decl.scala
index 66675e4a8..37413558c 100644
--- a/cli/src/main/scala/scalaxb/compiler/xsd/Decl.scala
+++ b/cli/src/main/scala/scalaxb/compiler/xsd/Decl.scala
@@ -159,34 +159,34 @@ object SchemaDecl {
config.attributeQualifiedDefault = schema.attribute("attributeFormDefault").headOption map {
_.text == "qualified"} getOrElse {false}
- for (child <- schema.child) child match {
- case { _* } =>
+ for (child <- schema.child) child.label match {
+ case "element" =>
(child \ "@name").headOption foreach { x =>
val elem = ElemDecl.fromXML(child, List(x.text), true, config)
config.topElems += (elem.name -> elem) }
- case { _* } =>
+ case "attribute" =>
(child \ "@name").headOption foreach { x =>
val attr = AttributeDecl.fromXML(child, config, true)
config.topAttrs += (attr.name -> attr) }
- case { _* } =>
+ case "attributeGroup" =>
(child \ "@name").headOption foreach { x =>
val attrGroup = AttributeGroupDecl.fromXML(child, config)
config.topAttrGroups += (attrGroup.name -> attrGroup) }
- case { _* } =>
+ case "group" =>
(child \ "@name").headOption foreach { x =>
val group = GroupDecl.fromXML(child, config)
config.topGroups += (group.name -> group) }
- case { _* } =>
+ case "complexType" =>
(child \ "@name").headOption foreach { x =>
val decl = ComplexTypeDecl.fromXML(child, x.text, List(x.text), config)
config.typeList += decl
config.topTypes += (decl.name -> decl) }
- case { _* } =>
+ case "simpleType" =>
(child \ "@name").headOption foreach { x =>
val decl = SimpleTypeDecl.fromXML(child, x.text, List(x.text), config)
config.typeList += decl
@@ -316,8 +316,8 @@ object AttributeDecl {
if (typeName != "") {
typeSymbol = TypeSymbolParser.fromString(typeName, node.scope, config)
} else {
- for (child <- node.child) child match {
- case { _* } =>
+ for (child <- node.child) child.label match {
+ case "simpleType" =>
val decl = SimpleTypeDecl.fromXML(child, List(name), config)
config.typeList += decl
val symbol = ReferenceTypeSymbol(config.targetNamespace, decl.name)
@@ -418,15 +418,15 @@ object ElemDecl {
(node \ "@type").headOption map { typeName =>
typeSymbol = TypeSymbolParser.fromString(typeName.text, node.scope, config)
} getOrElse {
- for (child <- node.child) child match {
- case { _* } =>
+ for (child <- node.child) child.label match {
+ case "complexType" =>
val decl = ComplexTypeDecl.fromXML(child, "@%s".format((family :+ name).mkString("/")), family :+ name, config)
config.typeList += decl
val symbol = ReferenceTypeSymbol(config.targetNamespace, decl.name)
symbol.decl = decl
typeSymbol = symbol
- case { _* } =>
+ case "simpleType" =>
val decl = SimpleTypeDecl.fromXML(child, family :+ name, config)
config.typeList += decl
val symbol = ReferenceTypeSymbol(config.targetNamespace, decl.name)
@@ -491,10 +491,10 @@ object SimpleTypeDecl {
def fromXML(node: scala.xml.Node, name: String, family: List[String], config: ParserConfig): SimpleTypeDecl = {
var content: ContentTypeDecl = null
- for (child <- node.child) child match {
- case { _* } => content = SimpTypRestrictionDecl.fromXML(child, family, config)
- case { _* }
=> content = SimpTypListDecl.fromXML(child, family, config)
- case { _* } => content = SimpTypUnionDecl.fromXML(child, config)
+ for (child <- node.child) child.label match {
+ case "restriction" => content = SimpTypRestrictionDecl.fromXML(child, family, config)
+ case "list" => content = SimpTypListDecl.fromXML(child, family, config)
+ case "union" => content = SimpTypUnionDecl.fromXML(child, config)
case _ =>
}
@@ -533,22 +533,22 @@ object ComplexTypeDecl {
val attributes = AttributeLike.fromParentNode(node, config)
var content: HasComplexTypeContent = ComplexContentDecl.fromAttributes(attributes)
- for (child <- node.child) child match {
- case { _* } =>
+ for (child <- node.child) child.label match {
+ case "group" =>
content = ComplexContentDecl.fromCompositor(
CompositorDecl.fromXML(child, family, config), attributes)
- case { _* } =>
+ case "all" =>
content = ComplexContentDecl.fromCompositor(
CompositorDecl.fromXML(child, family, config), attributes)
- case { _* } =>
+ case "choice" =>
content = ComplexContentDecl.fromCompositor(
CompositorDecl.fromXML(child, family, config), attributes)
- case { _* } =>
+ case "sequence" =>
content = ComplexContentDecl.fromCompositor(
CompositorDecl.fromXML(child, family, config), attributes)
- case { _* } =>
+ case "simpleContent" =>
content = SimpleContentDecl.fromXML(child, family, config)
- case { _* } =>
+ case "complexContent" =>
content = ComplexContentDecl.fromXML(child, family, config)
case _ =>
}
@@ -578,10 +578,10 @@ object SimpleContentDecl {
def fromXML(node: scala.xml.Node, family: List[String], config: ParserConfig) = {
var content: ComplexTypeContent = null
- for (child <- node.child) child match {
- case { _* } =>
+ for (child <- node.child) child.label match {
+ case "restriction" =>
content = SimpContRestrictionDecl.fromXML(child, family, config)
- case { _* } =>
+ case "extension" =>
content = SimpContExtensionDecl.fromXML(child, family, config)
case _ =>
}
@@ -607,10 +607,10 @@ object ComplexContentDecl {
def fromXML(node: scala.xml.Node, family: List[String], config: ParserConfig) = {
var content: ComplexTypeContent = CompContRestrictionDecl.empty
- for (child <- node.child) child match {
- case { _* } =>
+ for (child <- node.child) child.label match {
+ case "restriction" =>
content = CompContRestrictionDecl.fromXML(child, family, config)
- case { _* } =>
+ case "extension" =>
content = CompContExtensionDecl.fromXML(child, family, config)
case _ =>
}
@@ -628,16 +628,16 @@ object CompositorDecl {
if (elem.label != "annotation") &&
(elem.label != "attribute") => elem
}) map(node =>
- node match {
- case { _* } =>
+ node.label match {
+ case "element" =>
if ((node \ "@name").headOption.isDefined) ElemDecl.fromXML(node, family, false, config)
else if ((node \ "@ref").headOption.isDefined) ElemRef.fromXML(node, config)
else sys.error("xsd: Unspported content type " + node.toString)
- case { _* } => ChoiceDecl.fromXML(node, family, config)
- case { _* } => SequenceDecl.fromXML(node, family, config)
- case { _* } => AllDecl.fromXML(node, family, config)
- case { _* } => AnyDecl.fromXML(node, config)
- case { _* } =>
+ case "choice" => ChoiceDecl.fromXML(node, family, config)
+ case "sequence" => SequenceDecl.fromXML(node, family, config)
+ case "all" => AllDecl.fromXML(node, family, config)
+ case "any" => AnyDecl.fromXML(node, config)
+ case "group" =>
if ((node \ "@name").headOption.isDefined) GroupDecl.fromXML(node, config)
else if ((node \ "@ref").headOption.isDefined) GroupRef.fromXML(node, config)
else sys.error("xsd: Unspported content type " + node.toString)
@@ -646,11 +646,11 @@ object CompositorDecl {
}
)
- def fromXML(node: scala.xml.Node, family: List[String], config: ParserConfig): HasParticle = node match {
- case { _* } => ChoiceDecl.fromXML(node, family, config)
- case { _* } => SequenceDecl.fromXML(node, family, config)
- case { _* } => AllDecl.fromXML(node, family, config)
- case { _* } =>
+ def fromXML(node: scala.xml.Node, family: List[String], config: ParserConfig): HasParticle = node.label match {
+ case "choice" => ChoiceDecl.fromXML(node, family, config)
+ case "sequence" => SequenceDecl.fromXML(node, family, config)
+ case "all" => AllDecl.fromXML(node, family, config)
+ case "group" =>
if ((node \ "@name").headOption.isDefined) GroupDecl.fromXML(node, config)
else if ((node \ "@ref").headOption.isDefined) GroupRef.fromXML(node, config)
else sys.error("xsd: Unspported content type " + node.toString)