From 3f76473d910cee3231dd77f1ba26934caf51a075 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Thu, 5 Oct 2023 09:48:04 +0900 Subject: [PATCH] avoid `enum` name --- .../scalaxb/compiler/xsd/ContextProcessor.scala | 10 +++++----- .../scala/scalaxb/compiler/xsd/GenSource.scala | 16 ++++++++-------- .../main/scala/scalaxb/compiler/xsd/Lookup.scala | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cli/src/main/scala/scalaxb/compiler/xsd/ContextProcessor.scala b/cli/src/main/scala/scalaxb/compiler/xsd/ContextProcessor.scala index 786e8d14..1b23dacb 100644 --- a/cli/src/main/scala/scalaxb/compiler/xsd/ContextProcessor.scala +++ b/cli/src/main/scala/scalaxb/compiler/xsd/ContextProcessor.scala @@ -285,12 +285,12 @@ trait ContextProcessor extends ScalaNames with PackageName { def makeEnumValues(decl: SimpleTypeDecl, scope: scala.xml.NamespaceBinding, context: XsdContext) : Unit = { val enumValues = context.enumValueNames(packageName(decl.namespace, context)) val name = context.typeNames(decl) - filterEnumeration(decl) map { enum => - enumValues(name -> enum) = makeProtectedTypeName(decl.namespace, - enum.value match { + filterEnumeration(decl) map { enumDecl => + enumValues(name -> enumDecl) = makeProtectedTypeName(decl.namespace, + enumDecl.value match { case qname: QName => Option(scope.getPrefix(qname.getNamespaceURI)).getOrElse("") + qname.getLocalPart.capitalize - case x if enum.value.toString.length > enumNameMaxLength => "longName" - case _ => enum.value.toString + case x if enumDecl.value.toString.length > enumNameMaxLength => "longName" + case _ => enumDecl.value.toString }, "Value", context) } } diff --git a/cli/src/main/scala/scalaxb/compiler/xsd/GenSource.scala b/cli/src/main/scala/scalaxb/compiler/xsd/GenSource.scala index 8583e8bb..91ea32c3 100644 --- a/cli/src/main/scala/scalaxb/compiler/xsd/GenSource.scala +++ b/cli/src/main/scala/scalaxb/compiler/xsd/GenSource.scala @@ -616,22 +616,22 @@ class GenSource(val schema: SchemaDecl, val baseSym : Option[XsTypeSymbol] = decl.content match {case SimpTypRestrictionDecl(base, _) => Some(base) case _ => None} val baseType: Option[String ] = baseSym.map(buildTypeName(_)) - def makeEnum(enum: EnumerationDecl[_]) = - "case object " + buildTypeName(localName, enum, true) + " extends " + localName + - " { override def toString = " + quote(enum.value.toString) + " }" + def makeEnum(enumDecl: EnumerationDecl[_]) = + "case object " + buildTypeName(localName, enumDecl, true) + " extends " + localName + + " { override def toString = " + quote(enumDecl.value.toString) + " }" - def makeCaseEntry(enum: EnumerationDecl[_]) = baseSym match { - case Some(XsQName) => s"${indent(3)}case ${quote(enum.value.toString)} => ${buildTypeName(localName, enum, false)}\n" + def makeCaseEntry(enumDecl: EnumerationDecl[_]) = baseSym match { + case Some(XsQName) => s"${indent(3)}case ${quote(enumDecl.value.toString)} => ${buildTypeName(localName, enumDecl, false)}\n" case _ => baseType.map {tpe => - s"${indent(3)}case x: $tpe if x == scalaxb.fromXML[$tpe](scala.xml.Text(${quote(enum.value.toString)})) => ${buildTypeName(localName, enum, false)}\n" + s"${indent(3)}case x: $tpe if x == scalaxb.fromXML[$tpe](scala.xml.Text(${quote(enumDecl.value.toString)})) => ${buildTypeName(localName, enumDecl, false)}\n" }.getOrElse { - s"${indent(3)}case ${quote(enum.value.toString)} => ${buildTypeName(localName, enum, false)}\n" + s"${indent(3)}case ${quote(enumDecl.value.toString)} => ${buildTypeName(localName, enumDecl, false)}\n" } } val enumString = enums.map(makeEnum).mkString(newline) - val enumListString = enums.map(enum => buildTypeName(localName, enum, true)).mkString(", ") + val enumListString = enums.map(enumDecl => buildTypeName(localName, enumDecl, true)).mkString(", ") val enumValuesString = s"lazy val values: Seq[$localName] = Seq($enumListString)" def valueCode: String = baseSym match { diff --git a/cli/src/main/scala/scalaxb/compiler/xsd/Lookup.scala b/cli/src/main/scala/scalaxb/compiler/xsd/Lookup.scala index f6f06a54..6699e622 100644 --- a/cli/src/main/scala/scalaxb/compiler/xsd/Lookup.scala +++ b/cli/src/main/scala/scalaxb/compiler/xsd/Lookup.scala @@ -179,14 +179,14 @@ trait Lookup extends ContextProcessor { def buildTypeName(group: AttributeGroupDecl, shortLocal: Boolean): String = buildTypeName(packageName(group, context), group, shortLocal) - def buildTypeName(enumTypeName: String, enum: EnumerationDecl[_], shortLocal: Boolean): String = { + def buildTypeName(enumTypeName: String, enumDecl: EnumerationDecl[_], shortLocal: Boolean): String = { val pkg = packageName(schema, context) val typeNames = context.enumValueNames(pkg) - if (!typeNames.contains(enumTypeName, enum)) - sys.error(s"${pkg}: Type name not found: " + enum.toString) + if (!typeNames.contains(enumTypeName, enumDecl)) + sys.error(s"${pkg}: Type name not found: " + enumDecl.toString) - if (shortLocal && pkg == packageName(schema, context)) typeNames(enumTypeName, enum) - else buildFullyQualifiedNameFromPackage(pkg, typeNames(enumTypeName, enum)) + if (shortLocal && pkg == packageName(schema, context)) typeNames(enumTypeName, enumDecl) + else buildFullyQualifiedNameFromPackage(pkg, typeNames(enumTypeName, enumDecl)) } def buildFullyQualifiedNameFromNS(namespace: Option[String], localName: String): String = {