Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use string interpolation instead of format method #633

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions cli/src/main/scala/scalaxb/compiler/Module.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
)
73 changes: 30 additions & 43 deletions cli/src/main/scala/scalaxb/compiler/wsdl11/GenSource.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(", ")})"
}
}
}
Expand Down Expand Up @@ -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.")
}
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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.")
}
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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}: _*)"""
}
}

Expand Down Expand Up @@ -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 + " ")})"
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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) = {
Expand Down
8 changes: 3 additions & 5 deletions cli/src/main/scala/scalaxb/compiler/xsd/Args.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ")"
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions cli/src/main/scala/scalaxb/compiler/xsd/ContextProcessor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
}
Expand All @@ -107,15 +107,15 @@ 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, {
val prefix: Option[String] =
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
})

Expand All @@ -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 _ =>
}
Expand Down Expand Up @@ -172,22 +172,22 @@ 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;
elem <- schema.topElems.valuesIterator.toList) {
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}")
}
}
}
Expand All @@ -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 _ =>
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/scala/scalaxb/compiler/xsd/Decl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/scala/scalaxb/compiler/xsd/XMLOutput.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion integration/src/test/scala/CompilerMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down