From e87ea86f9a17e0777d083261a64f2e7c1f947354 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Sat, 7 Oct 2023 15:41:27 +0900 Subject: [PATCH] use string interpolation instead of format method --- .../main/scala/scalaxb/compiler/Module.scala | 4 +- .../scalaxb/compiler/wsdl11/GenSource.scala | 73 ++++++++----------- .../scala/scalaxb/compiler/xsd/Args.scala | 8 +- .../compiler/xsd/ContextProcessor.scala | 22 +++--- .../scala/scalaxb/compiler/xsd/Decl.scala | 2 +- .../scalaxb/compiler/xsd/XMLOutput.scala | 2 +- .../src/test/scala/CompilerMatcher.scala | 2 +- 7 files changed, 48 insertions(+), 65 deletions(-) diff --git a/cli/src/main/scala/scalaxb/compiler/Module.scala b/cli/src/main/scala/scalaxb/compiler/Module.scala index af3063802..cae561b6e 100644 --- a/cli/src/main/scala/scalaxb/compiler/Module.scala +++ b/cli/src/main/scala/scalaxb/compiler/Module.scala @@ -541,7 +541,5 @@ class ReferenceNotFound(kind: String, namespace: Option[String], name: String) e (namespace map { "{" + _ + "}" } getOrElse {"(unqualified) "}) + name + " was not found.") class CaseClassTooLong(fqn: String, xmlname: String) extends RuntimeException( - """Error: A case class with > 22 parameters cannot be created for %s. Consider using --wrap-contents "%s" option.""".format( - fqn, xmlname - ) + s"""Error: A case class with > 22 parameters cannot be created for ${fqn}. Consider using --wrap-contents "${xmlname}" option.""" ) diff --git a/cli/src/main/scala/scalaxb/compiler/wsdl11/GenSource.scala b/cli/src/main/scala/scalaxb/compiler/wsdl11/GenSource.scala index 8dc678e43..628f353f7 100644 --- a/cli/src/main/scala/scalaxb/compiler/wsdl11/GenSource.scala +++ b/cli/src/main/scala/scalaxb/compiler/wsdl11/GenSource.scala @@ -231,10 +231,7 @@ trait {interfaceTypeName}{taglessTypeConstraint} {{ self => } outputOpt flatMap { (output: XParamType) => isMultiPart(output, binding.output) map { _ => - "case class %s(%s)".format( - makeOperationOutputWrapperName(op), - makeOperationOutputArgs map {_.toScalaCode} mkString(", ") - ) + s"case class ${makeOperationOutputWrapperName(op)}(${makeOperationOutputArgs map {_.toScalaCode} mkString(", ")})" } } } @@ -281,46 +278,40 @@ trait {interfaceTypeName}{taglessTypeConstraint} {{ self => val retval = (op.xoperationtypeoption, config.httpClientStyle) match { case (DataRecord(_, _, XOnewayoperationSequence(input)), HttpClientStyle.Future) => - "def %s(%s)(implicit ec: ExecutionContext): Future[Unit]".format(name, arg(input)) + s"def ${name}(${arg(input)})(implicit ec: ExecutionContext): Future[Unit]" case (DataRecord(_, _, XOnewayoperationSequence(input)), HttpClientStyle.Sync) => - "def %s(%s): Unit".format(name, arg(input)) + s"def ${name}(${arg(input)}): Unit" case (DataRecord(_, _, XOnewayoperationSequence(input)), HttpClientStyle.Tagless) => - "def %s(%s): %s[Unit]".format(name, arg(input), taglessParamName) + s"def ${name}(${arg(input)}): ${taglessParamName}[Unit]" case (DataRecord(_, _, XRequestresponseoperationSequence(input, output, faults)), HttpClientStyle.Future) => - "def %s(%s)(implicit ec: ExecutionContext): Future[%s]".format(name, arg(input), - outputTypeName(binding, op, output, soapBindingStyle)) + s"def ${name}(${arg(input)})(implicit ec: ExecutionContext): Future[${outputTypeName(binding, op, output, soapBindingStyle)}]" case (DataRecord(_, _, XRequestresponseoperationSequence(input, output, faults)), HttpClientStyle.Sync) => - "def %s(%s): Either[%s, %s]".format(name, arg(input), - faultsToTypeName(faults, soap12), outputTypeName(binding, op, output, soapBindingStyle)) + s"def ${name}(${arg(input)}): Either[${faultsToTypeName(faults, soap12)}, ${outputTypeName(binding, op, output, soapBindingStyle)}]" case (DataRecord(_, _, XRequestresponseoperationSequence(input, output, faults)), HttpClientStyle.Tagless) => - "def %s(%s): %s[%s]".format(name, arg(input), taglessParamName, - outputTypeName(binding, op, output, soapBindingStyle)) + s"def ${name}(${arg(input)}): ${taglessParamName}[${outputTypeName(binding, op, output, soapBindingStyle)}]" case (DataRecord(_, _, XSolicitresponseoperationSequence(output, input, faults)), HttpClientStyle.Future) => - "def %s(%s)(implicit ec: ExecutionContext): Future[%s]".format(name, arg(input), - outputTypeName(binding, op, output, soapBindingStyle)) + s"def ${name}(${arg(input)})(implicit ec: ExecutionContext): Future[${outputTypeName(binding, op, output, soapBindingStyle)}]" case (DataRecord(_, _, XSolicitresponseoperationSequence(output, input, faults)), HttpClientStyle.Sync) => - "def %s(%s): Either[%s, %s]".format(name, arg(input), - faultsToTypeName(faults, soap12), outputTypeName(binding, op, output, soapBindingStyle)) + s"def ${name}(${arg(input)}): Either[${faultsToTypeName(faults, soap12)}, ${outputTypeName(binding, op, output, soapBindingStyle)}]" case (DataRecord(_, _, XSolicitresponseoperationSequence(output, input, faults)), HttpClientStyle.Tagless) => - "def %s(%s): %s[%s]".format(name, arg(input), taglessParamName, - outputTypeName(binding, op, output, soapBindingStyle)) + s"def ${name}(${arg(input)}): ${taglessParamName}[${outputTypeName(binding, op, output, soapBindingStyle)}]" case (DataRecord(_, _, XNotificationoperationSequence(output)), HttpClientStyle.Future) => - "def %s(implicit ec: ExecutionContext): Future[%s]".format(name, outputTypeName(binding, op, output, soapBindingStyle)) + s"def ${name}(implicit ec: ExecutionContext): Future[${outputTypeName(binding, op, output, soapBindingStyle)}]" case (DataRecord(_, _, XNotificationoperationSequence(output)), HttpClientStyle.Sync) => - "def %s: %s".format(name, outputTypeName(binding, op, output, soapBindingStyle)) + s"def ${name}: ${outputTypeName(binding, op, output, soapBindingStyle)}" case (DataRecord(_, _, XNotificationoperationSequence(output)), HttpClientStyle.Tagless) => - "def %s: %s[%s]".format(name, taglessParamName, outputTypeName(binding, op, output, soapBindingStyle)) + s"def ${name}: ${taglessParamName}[${outputTypeName(binding, op, output, soapBindingStyle)}]" case _ => sys.error("unsupported.") } @@ -372,7 +363,7 @@ trait {interfaceTypeName}{taglessTypeConstraint} {{ self => def boundOperation(binding: XBinding_operationType, intf: XPortTypeType) = (intf.operation filter {_.name == binding.name}).headOption getOrElse { - sys.error("operation %s was not found in %s".format(binding.name, intf.name)) + sys.error(s"operation ${binding.name} was not found in ${intf.name}") } def parseSoapBindingStyle(anyHeadOption: Option[DataRecord[Any]], defaultSoapBindingStyle: SoapBindingStyle): SoapBindingStyle = @@ -544,13 +535,13 @@ trait {interfaceTypeName}{taglessTypeConstraint} {{ self => val opImpl = (op.xoperationtypeoption, config.httpClientStyle) match { case (DataRecord(_, _, XOnewayoperationSequence(input)), HttpClientStyle.Tagless) => - "self.%s(%s)".format(name, arg(input)) + s"self.${name}(${arg(input)})" case (DataRecord(_, _, XRequestresponseoperationSequence(input, _, _)), HttpClientStyle.Tagless) => - "self.%s(%s)".format(name, arg(input)) + s"self.${name}(${arg(input)})" case (DataRecord(_, _, XSolicitresponseoperationSequence(_, input, _)), HttpClientStyle.Tagless) => - "self.%s(%s)".format(name, arg(input)) + s"self.${name}(${arg(input)})" case (DataRecord(_, _, XNotificationoperationSequence(_)), HttpClientStyle.Tagless) => - "self.%s".format(name) + s"self.${name}" case _ => sys.error("unsupported.") } @@ -626,13 +617,13 @@ trait {interfaceTypeName}{taglessTypeConstraint} {{ self => case _ => sys.error("Elem not found!") }""" else "" - "scalaxb.toXML(%s, %s, %s, defaultScope)%s".format(v, nsString, label, post) + s"scalaxb.toXML(${v}, ${nsString}, ${label}, defaultScope)${post}" } } match { case Nil => "Nil" case x :: Nil => x - case xs if config.useLists => "List.concat(%s)".format(xs.mkString("," + NL + " ")) - case xs => "Seq.concat(%s)".format(xs.mkString("," + NL + " ")) + case xs if config.useLists => s"List.concat(${xs.mkString("," + NL + " ")})" + case xs => s"Seq.concat(${xs.mkString("," + NL + " ")})" } // http://www.w3.org/TR/wsdl#_soap:body @@ -647,7 +638,7 @@ trait {interfaceTypeName}{taglessTypeConstraint} {{ self => case symbol: BuiltInSimpleTypeSymbol => (buildIRIStyleArgs(input) map {_.toParamName}).head case ReferenceTypeSymbol(decl: SimpleTypeDecl) => (buildIRIStyleArgs(input) map {_.toParamName}).head case _ => - "%s(%s)".format(toParamCache(bodyParts.head).baseTypeName, buildIRIStyleArgs(input) map {_.toVarg} mkString(", ")) + s"${toParamCache(bodyParts.head).baseTypeName}(${buildIRIStyleArgs(input) map {_.toVarg} mkString(", ")})" } lazy val opLabel = "\"%s\"".format(op.name) @@ -673,7 +664,7 @@ trait {interfaceTypeName}{taglessTypeConstraint} {{ self => val nsString = namespace map {"Some(\"%s\")".format(_)} getOrElse {"None"} - "scalaxb.toXML(%s, %s, %s, defaultScope)".format(v, nsString, label) + + s"scalaxb.toXML(${v}, ${nsString}, ${label}, defaultScope)" + (soapBindingStyle match { case DocumentStyle if !p.element.isDefined => """ match { @@ -689,8 +680,8 @@ trait {interfaceTypeName}{taglessTypeConstraint} {{ self => case (DocumentStyle, x :: xs) => x case (DocumentStyle, _) => "Nil" case _ => - """scala.xml.Elem(%s, %s, scala.xml.Null, defaultScope, true, - %s: _*)""".format(prefix, opLabel, argsString) + s"""scala.xml.Elem(${prefix}, ${opLabel}, scala.xml.Null, defaultScope, true, + ${argsString}: _*)""" } } @@ -743,8 +734,7 @@ trait {interfaceTypeName}{taglessTypeConstraint} {{ self => }) if (!multipart) fromXmls.head - else "%s(%s)".format(xsdgenerator.buildFullyQualifiedNameFromPackage(pkg, makeOperationOutputWrapperName(op)), - fromXmls.mkString("," + NL + " ")) + else s"${xsdgenerator.buildFullyQualifiedNameFromPackage(pkg, makeOperationOutputWrapperName(op))}(${fromXmls.mkString("," + NL + " ")})" } } @@ -775,7 +765,7 @@ trait {interfaceTypeName}{taglessTypeConstraint} {{ self => } def baseTypeName: String = xsdgenerator.buildTypeName(typeSymbol) def toParamName: String = escapeKeyWord(paramName) - def toScalaCode: String = "%s: %s".format(toParamName, typeName) + def toScalaCode: String = s"${toParamName}: ${typeName}" def toVarg: String = if (seqParam) toParamName + ": _*" else toParamName @@ -821,7 +811,7 @@ trait {interfaceTypeName}{taglessTypeConstraint} {{ self => } getOrElse {sys.error("unexpected input: " + input)} def buildPartsArg(input: XParamType): String = (paramMessage(input).part map { part => - "%s: %s".format(part.name getOrElse {"in"}, toParamCache(part).typeName) + s"${part.name getOrElse {"in"}}: ${toParamCache(part).typeName}" }).mkString(", ") def toParamCache(part: XPartType): ParamCache = @@ -877,13 +867,10 @@ trait {interfaceTypeName}{taglessTypeConstraint} {{ self => } def faultsToTypeName(faults: Seq[XFaultType], soap12: Boolean): String = - "%s[%s]".format( - if (soap12) "scalaxb.Fault" else "scalaxb.Soap11Fault", - faultsToFaultParamTypeName(faults) match { + s"${if (soap12) "scalaxb.Fault" else "scalaxb.Soap11Fault"}[${faultsToFaultParamTypeName(faults) match { case (x, true) => s"""Option[$x]""" case (x, _) => x - } - ) + }}]" // param type and nillable def faultParamTypeName(fault: XFaultType): (String, Boolean) = { diff --git a/cli/src/main/scala/scalaxb/compiler/xsd/Args.scala b/cli/src/main/scala/scalaxb/compiler/xsd/Args.scala index eb3067576..b220a7be6 100644 --- a/cli/src/main/scala/scalaxb/compiler/xsd/Args.scala +++ b/cli/src/main/scala/scalaxb/compiler/xsd/Args.scala @@ -29,12 +29,10 @@ trait Args extends Params { def buildFromXML(typeName: String): String = "scalaxb.fromXML[" + typeName + "]" def buildFromXML(typeName: String, selector: String, stackItem: Option[String], formatter: Option[String]): String = - buildFromXML(typeName) + "(%s, %s)%s".format(selector, - stackItem map { + buildFromXML(typeName) + s"(${selector}, ${stackItem map { case "stack" => "stack" case x => "scalaxb.ElemName(" + x + ") :: stack" - } getOrElse {"Nil"}, - formatter map {"(" + _ + ")"} getOrElse {""}) + } getOrElse {"Nil"}})${formatter map {"(" + _ + ")"} getOrElse {""}}" def buildToXML(typeName: String, args: String): String = "scalaxb.toXML[" + typeName + "](" + args + ")" @@ -228,7 +226,7 @@ trait Args extends Params { if (elem.global) elem.namespace match { case None => elem.name case Some(ns) => - if (prependNamespace) "{%s}".format(ns) + elem.name + if (prependNamespace) s"{${ns}}" + elem.name else elem.name } else elem.name diff --git a/cli/src/main/scala/scalaxb/compiler/xsd/ContextProcessor.scala b/cli/src/main/scala/scalaxb/compiler/xsd/ContextProcessor.scala index 1b23dacbe..dc28b1ffc 100644 --- a/cli/src/main/scala/scalaxb/compiler/xsd/ContextProcessor.scala +++ b/cli/src/main/scala/scalaxb/compiler/xsd/ContextProcessor.scala @@ -77,7 +77,7 @@ trait ContextProcessor extends ScalaNames with PackageName { val anonymousTypes = mutable.ListBuffer.empty[(SchemaDecl, ComplexTypeDecl)] for (schema <- schemas) { - logger.debug("processContext - %s".format(schema.targetNamespace)) + logger.debug(s"processContext - ${schema.targetNamespace}") context.typeNames(schema) = makeProtectedTypeName(schema, context) resolveType(schema, context) } @@ -92,7 +92,7 @@ trait ContextProcessor extends ScalaNames with PackageName { if (context.typeNames.contains(decl)) registerDuplicatedType(schema, decl, decl.name) else { context.typeNames(decl) = makeProtectedTypeName(schema.targetNamespace, initialName, postfix, context) - logger.debug("processContent: enum %s is named %s".format(decl.name, context.typeNames(decl))) + logger.debug(s"processContent: enum ${decl.name} is named ${context.typeNames(decl)}") makeEnumValues(decl, schema.scope, context) } // if-else } @@ -107,7 +107,7 @@ trait ContextProcessor extends ScalaNames with PackageName { } ref.decl match { case decl: ComplexTypeDecl => anonymousTypes += ((schema, decl)) - logger.debug("processContent: %s's %s".format(elem.name, decl.name)) + logger.debug(s"processContent: ${elem.name}'s ${decl.name}") if (context.typeNames.contains(decl)) registerDuplicatedType(schema, decl, elem.name) context.typeNames.getOrElseUpdate(decl, { @@ -115,7 +115,7 @@ trait ContextProcessor extends ScalaNames with PackageName { if (decl.family != List(elem.name, elem.name) && config.prependFamilyName) Some(decl.family.head) else None val name = makeProtectedTypeName(schema.targetNamespace, prefix, elem, context) - logger.debug("processContent: %s's %s is named %s".format(elem.name, decl.name, name)) + logger.debug(s"processContent: ${elem.name}'s ${decl.name} is named ${name}") name }) @@ -132,16 +132,16 @@ trait ContextProcessor extends ScalaNames with PackageName { typ <- schema.topTypes } typ match { case (_, decl: ComplexTypeDecl) => - logger.debug("processContext: top-level type %s".format(decl.name)) + logger.debug(s"processContext: top-level type ${decl.name}") namedTypes += ((schema, decl)) if (context.typeNames.contains(decl)) registerDuplicatedType(schema, decl, decl.name) else { val name = makeProtectedTypeName(schema.targetNamespace, decl, context) - logger.debug("processContext: top-level type %s is named %s".format(decl.name, name)) + logger.debug(s"processContext: top-level type ${decl.name} is named ${name}") context.typeNames.getOrElseUpdate(decl, name) } case (_, decl@SimpleTypeDecl(_, _, _, _, _)) if containsEnumeration(decl) => - logger.debug("processContext: top-level type %s".format(decl.name)) + logger.debug(s"processContext: top-level type ${decl.name}") nameEnumSimpleType(schema, decl, decl.name) case _ => } @@ -172,14 +172,14 @@ trait ContextProcessor extends ScalaNames with PackageName { if !base.abstractValue && !context.schemas.exists(schema => context.duplicatedTypes.contains((schema, base))) ) { context.typeNames(base) = makeTraitName(base) - logger.debug("processContext: naming trait %s".format(context.typeNames(base))) + logger.debug(s"processContext: naming trait ${context.typeNames(base)}") } for (schema <- schemas; group <- schema.topGroups.valuesIterator.toList) { val pair = (schema, group) context.groups += pair - logger.debug("processContext: added group %s".format(group.name)) + logger.debug(s"processContext: added group ${group.name}") } for (schema <- schemas; @@ -187,7 +187,7 @@ trait ContextProcessor extends ScalaNames with PackageName { elem.substitutionGroup foreach { sub => if (!context.substituteGroups.contains(sub)) { context.substituteGroups += sub - logger.debug("processContext: added sub group %s".format(sub)) + logger.debug(s"processContext: added sub group ${sub}") } } } @@ -197,7 +197,7 @@ trait ContextProcessor extends ScalaNames with PackageName { typ <- schema.typeList if !(schema.topTypes.valuesIterator contains typ) } typ match { case decl: SimpleTypeDecl if containsEnumeration(decl) => - logger.debug("processContext: inner simple type %s".format(decl.name)) + logger.debug(s"processContext: inner simple type ${decl.name}") nameEnumSimpleType(schema, decl, decl.family.last) case _ => } diff --git a/cli/src/main/scala/scalaxb/compiler/xsd/Decl.scala b/cli/src/main/scala/scalaxb/compiler/xsd/Decl.scala index 37413558c..7d4c16642 100644 --- a/cli/src/main/scala/scalaxb/compiler/xsd/Decl.scala +++ b/cli/src/main/scala/scalaxb/compiler/xsd/Decl.scala @@ -420,7 +420,7 @@ object ElemDecl { } getOrElse { for (child <- node.child) child.label match { case "complexType" => - val decl = ComplexTypeDecl.fromXML(child, "@%s".format((family :+ name).mkString("/")), family :+ name, config) + val decl = ComplexTypeDecl.fromXML(child, s"@${(family :+ name).mkString("/")}", family :+ name, config) config.typeList += decl val symbol = ReferenceTypeSymbol(config.targetNamespace, decl.name) symbol.decl = decl diff --git a/cli/src/main/scala/scalaxb/compiler/xsd/XMLOutput.scala b/cli/src/main/scala/scalaxb/compiler/xsd/XMLOutput.scala index bff2f515c..ed972df87 100644 --- a/cli/src/main/scala/scalaxb/compiler/xsd/XMLOutput.scala +++ b/cli/src/main/scala/scalaxb/compiler/xsd/XMLOutput.scala @@ -114,7 +114,7 @@ trait XMLOutput extends Args { def buildToString(selector: String, typeSymbol: XsTypeSymbol): String = typeSymbol match { case symbol: BuiltInSimpleTypeSymbol => buildTypeName(symbol) match { - case "javax.xml.namespace.QName" => "scalaxb.Helper.toString(%s, __scope)".format(selector) + case "javax.xml.namespace.QName" => s"scalaxb.Helper.toString(${selector}, __scope)" case "BigDecimal" => selector + ".bigDecimal.toPlainString" case _ => selector + ".toString" } diff --git a/integration/src/test/scala/CompilerMatcher.scala b/integration/src/test/scala/CompilerMatcher.scala index 10dc80126..e8998c931 100644 --- a/integration/src/test/scala/CompilerMatcher.scala +++ b/integration/src/test/scala/CompilerMatcher.scala @@ -88,7 +88,7 @@ trait CompilerMatcher extends CompilerMatcherBase { sys.error(s"""Error compiling: ${ files.mkString(",") }""") } code foreach { c => main.interpret(c) match { - case IR.Error => sys.error("Error interpreting %s" format (c)) + case IR.Error => sys.error(s"Error interpreting ${c}") case _ => }} val holder0 = allCatch opt {