diff --git a/build.sc b/build.sc index 8ec77cc..8980dea 100644 --- a/build.sc +++ b/build.sc @@ -3,6 +3,7 @@ import $file.buildDeps import mill._ import buildSetup._ +import buildSetup.ScalaVersions._ import coursier.maven.MavenRepository import mill.contrib.scalapblib.ScalaPBModule import mill.contrib.buildinfo @@ -17,10 +18,6 @@ import mill.contrib.buildinfo.BuildInfo import scala.Ordering.Implicits._ -val scala212 = "2.12.18" -val scala213 = "2.13.12" -val scalaVersions = List(scala213, scala212) - object `compiler-core` extends Cross[CompilerCoreModule](scalaVersions) trait CompilerCoreModule extends CrossScalaModule @@ -304,7 +301,7 @@ trait ProtoModule def ivyDeps = super.ivyDeps() ++ Agg( buildDeps.smithy.build, buildDeps.scalapb.compilerPlugin, - buildDeps.scalapb.protocCache + buildDeps.scalapb.protocCache.withDottyCompat(scalaVersion()) ) def scalaPBVersion = buildDeps.scalapb.version diff --git a/buildSetup.sc b/buildSetup.sc index e48b12f..0cb6f9b 100644 --- a/buildSetup.sc +++ b/buildSetup.sc @@ -19,6 +19,14 @@ import mill.scalalib.api.ZincWorkerUtil import scala.Ordering.Implicits._ +object ScalaVersions { + val scala212 = "2.12.18" + val scala213 = "2.13.12" + val scala3 = "3.3.1" + + val scalaVersions = List(scala213, scala212, scala3) +} + trait BaseModule extends Module with HeaderModule { def millSourcePath: os.Path = { val originalRelativePath = super.millSourcePath.relativeTo(os.pwd) @@ -99,14 +107,17 @@ trait BasePublishModule extends BaseModule with CiReleaseModule { } trait BaseScala213Module extends BaseScalaModule with ScalafmtModule { - override def scalaVersion = T.input("2.13.12") + override def scalaVersion = T.input(ScalaVersions.scala213) } trait BaseScalaModule extends ScalaModule with BaseModule { - - override def scalacPluginIvyDeps = super.scalacPluginIvyDeps() ++ Agg( - ivy"org.typelevel:::kind-projector:0.13.2" - ) + override def scalacPluginIvyDeps = T { + val sv = scalaVersion() + val plugins = + if (sv.startsWith("2.")) Agg(ivy"org.typelevel:::kind-projector:0.13.2") + else Agg.empty + super.scalacPluginIvyDeps() ++ plugins + } def scalacOptions = T { super.scalacOptions() ++ scalacOptionsFor(scalaVersion()) @@ -163,9 +174,8 @@ case class ScalacOption( // format: off private val allScalacOptions = Seq( - ScalacOption("-Xsource:3", isSupported = version => v211 <= version || version < v300), // Treat compiler input as Scala source for the specified version, see scala/bug#8126. + ScalacOption("-Xsource:3", isSupported = version => v211 <= version && version < v300), // Treat compiler input as Scala source for the specified version, see scala/bug#8126. ScalacOption("-deprecation", isSupported = version => version < v213 || v300 <= version), // Emit warning and location for usages of deprecated APIs. Not really removed but deprecated in 2.13. - ScalacOption("-migration", isSupported = v300 <= _), // Emit warning and location for migration issues from Scala 2. ScalacOption("-explaintypes", isSupported = _ < v300), // Explain type errors in more detail. ScalacOption("-explain-types", isSupported = v300 <= _), // Explain type errors in more detail. ScalacOption("-explain", isSupported = v300 <= _), // Explain errors in more detail. @@ -177,7 +187,7 @@ private val allScalacOptions = Seq( ScalacOption("-language:existentials,experimental.macros,higherKinds,implicitConversions", isSupported = v300 <= _), // the four options above, dotty style ScalacOption("-unchecked"), // Enable additional warnings where generated code depends on assumptions. ScalacOption("-Xcheckinit", isSupported = _ < v300), // Wrap field accessors to throw an exception on uninitialized access. - ScalacOption("-Xfatal-warnings"), // Fail the compilation if there are any warnings. + ScalacOption("-Xfatal-warnings", isSupported = _ < v300), // Fail the compilation if there are any warnings. Disabled for scala3 because some warnings can't be `nowarn`ed ScalacOption("-Xlint", isSupported = _ < v211), // Used to mean enable all linting options but now the syntax for that is different (-Xlint:_ I think) ScalacOption("-Xlint:adapted-args", isSupported = version => v211 <= version && version < v300), // Warn if an argument list is modified to match the receiver. ScalacOption("-Xlint:by-name-right-associative", isSupported = version => v211 <= version && version < v213), // By-name parameter of right associative operator. diff --git a/modules/compiler-core/src/internals/IModelToSmithy.scala b/modules/compiler-core/src/internals/IModelToSmithy.scala index 703af1a..0bbf227 100644 --- a/modules/compiler-core/src/internals/IModelToSmithy.scala +++ b/modules/compiler-core/src/internals/IModelToSmithy.scala @@ -44,131 +44,164 @@ import scala.jdk.CollectionConverters._ private[compiler] final class IModelToSmithy(useEnumTraitSyntax: Boolean) extends (IModel => Model) { + def toStructure(s: Structure): JShape = { + val members = s.localFields.map { case Field(id, tpe, hints) => + val memName = id.memberName.value.toString + val nameWillNeedChange = sanitizeMemberName(memName) != memName + def isHeaderOrQuery = hints.exists { + case Header(_) => true + case QueryParam(_) => true + case _ => false + } + val jsonNameHint = + if (nameWillNeedChange && !isHeaderOrQuery) + List(Hint.JsonName(memName)) + else List.empty + + val memberBuilder = MemberShape + .builder() + .id(id.toSmithy) + .target(tpe.toSmithy) + + hintsToTraits(hints ++ jsonNameHint).foreach(memberBuilder.addTrait(_)) + memberBuilder.build() + } + val mixins = s.hints.collect { case Hint.HasMixin(defId) => + StructureShape.builder.id(defId.toSmithy).build() + }.asJava + val builder = StructureShape + .builder() + .id(s.id.toSmithy) + + hintsToTraits(s.hints).foreach(builder.addTrait(_)) + members.foreach(builder.addMember(_)) + mixins.forEach { m => + val _ = builder.addMixin(m) + } + builder.build() + } + + def toMap(m: MapDef): JShape = { + val builder = MapShape + .builder() + .id(m.id.toSmithy) + .key(m.key.toSmithy) + .value(m.value.toSmithy) + + hintsToTraits(m.hints).foreach(builder.addTrait(_)) + builder.build() + } + + def toList(l: ListDef): JShape = { + val builder = ListShape + .builder() + .id(l.id.toSmithy) + .member(l.member.toSmithy) + hintsToTraits(l.hints).foreach(builder.addTrait(_)) + builder.build() + } + + def toSet(s: SetDef): JShape = { + val builder = ListShape + .builder() + .id(s.id.toSmithy) + .member(s.member.toSmithy) + .addTrait(new UniqueItemsTrait()) + + hintsToTraits(s.hints).foreach(builder.addTrait(_)) + builder.build() + } + + def toUnion(u: Union): JShape = { + val builder = + UnionShape.builder().id(u.id.toSmithy) + u.alts.foreach { alt => + val memName = alt.id.memberName.value.toString + val nameWillNeedChange = sanitizeMemberName(memName) != memName + val jsonNameHint = + if (nameWillNeedChange) + List(Hint.JsonName(memName)) + else List.empty + val memberBuilder = MemberShape + .builder() + .id(alt.id.toSmithy) + .target(alt.tpe.toSmithy) + + hintsToTraits(alt.hints ++ jsonNameHint) + .foreach(memberBuilder.addTrait(_)) + builder.addMember(memberBuilder.build()) + } + u.kind match { + case UnionKind.Discriminated(d) => + builder.addTrait(new DiscriminatedUnionTrait(d)) + case UnionKind.Untagged => builder.addTrait(new UntaggedUnionTrait()) + case UnionKind.ContentTypeDiscriminated => + builder.addTrait(new ContentTypeDiscriminatedTrait()) + case UnionKind.Tagged => () + } + hintsToTraits(u.hints).foreach(builder.addTrait(_)) + builder.build() + } + + def toPrimitive(n: Newtype): JShape = { + val builder + : AbstractShapeBuilder[_ <: AbstractShapeBuilder[_, _], _ <: JShape] = + n.target.name.segments.last.value.toString match { + case "String" => StringShape.builder() + case "Integer" => IntegerShape.builder() + case "Long" => LongShape.builder() + case "BigInteger" => BigIntegerShape.builder() + case "BigDecimal" => BigDecimalShape.builder() + case "Short" => ShortShape.builder() + case "Float" => FloatShape.builder() + case "Double" => DoubleShape.builder() + case "Boolean" => BooleanShape.builder() + case "Byte" => ByteShape.builder() + case "Timestamp" => TimestampShape.builder() + case "Document" => DocumentShape.builder() + case "UUID" => StringShape.builder().addTrait(new UuidFormatTrait()) + case "Null" => + StructureShape.builder().addTrait(new NullFormatTrait()) + case other => + sys.error( + s"error processing ${n.id}, found $other" + ) + } + hintsToTraits(n.hints).foreach(builder.addTrait(_)) + builder.id(n.id.toSmithy) + builder.build() + } + + def toOperation(op: OperationDef): JShape = { + val builder = + OperationShape.builder().id(op.id.toSmithy) + op.output.foreach(o => builder.output(o.toSmithy)) + op.input.foreach(i => builder.input(i.toSmithy)) + hintsToTraits(op.hints).foreach(builder.addTrait(_)) + op.errors.foreach(e => builder.addError(e.toSmithy)) + builder.build() + } + + def toService(s: ServiceDef): JShape = { + val builder = ServiceShape + .builder() + .id(s.id.toSmithy) + hintsToTraits(s.hints).foreach(builder.addTrait(_)) + s.operations.foreach(o => builder.addOperation(o.toSmithy)) + builder.build() + } + def apply(iModel: IModel): Model = { - val shapes = iModel.definitions.map { - case Structure(id, fields, _, structHints) => - val members = fields.map { case Field(id, tpe, hints) => - val memName = id.memberName.value.toString - val nameWillNeedChange = sanitizeMemberName(memName) != memName - def isHeaderOrQuery = hints.exists { - case Header(_) => true - case QueryParam(_) => true - case _ => false - } - val jsonNameHint = - if (nameWillNeedChange && !isHeaderOrQuery) - List(Hint.JsonName(memName)) - else List.empty - - MemberShape - .builder() - .id(id.toSmithy) - .target(tpe.toSmithy) - .addHints(hints ++ jsonNameHint) - .build() - } - val mixins = structHints.collect { case Hint.HasMixin(defId) => - StructureShape.builder.id(defId.toSmithy).build() - }.asJava - val builder = StructureShape - .builder() - .id(id.toSmithy) - .addHints(structHints) - members.foreach(builder.addMember(_)) - mixins.forEach { m => - val _ = builder.addMixin(m) - } - builder.build() - case MapDef(id, key, value, hints) => - MapShape - .builder() - .id(id.toSmithy) - .key(key.toSmithy) - .value(value.toSmithy) - .addHints(hints) - .build() - case ListDef(id, member, hints) => - ListShape - .builder() - .id(id.toSmithy) - .member(member.toSmithy) - .addHints(hints) - .build() - case SetDef(id, member, hints) => - ListShape - .builder() - .id(id.toSmithy) - .member(member.toSmithy) - .addHints(hints) - .addTrait(new UniqueItemsTrait()) - .build() - case Union(id, altNames, unionKind, hints) => - val builder = - UnionShape.builder().id(id.toSmithy).addHints(hints) - altNames.foreach { alt => - val memName = alt.id.memberName.value.toString - val nameWillNeedChange = sanitizeMemberName(memName) != memName - val jsonNameHint = - if (nameWillNeedChange) - List(Hint.JsonName(memName)) - else List.empty - val member = MemberShape - .builder() - .id(alt.id.toSmithy) - .target(alt.tpe.toSmithy) - .addHints(alt.hints ++ jsonNameHint) - .build() - builder.addMember(member) - } - unionKind match { - case UnionKind.Discriminated(d) => - builder.addTrait(new DiscriminatedUnionTrait(d)) - case UnionKind.Untagged => builder.addTrait(new UntaggedUnionTrait()) - case UnionKind.ContentTypeDiscriminated => - builder.addTrait(new ContentTypeDiscriminatedTrait()) - case UnionKind.Tagged => () - } - builder.build() - case Newtype(id, target, hints) => - val builder = target.name.segments.last.value.toString match { - case "String" => StringShape.builder() - case "Integer" => IntegerShape.builder() - case "Long" => LongShape.builder() - case "BigInteger" => BigIntegerShape.builder() - case "BigDecimal" => BigDecimalShape.builder() - case "Short" => ShortShape.builder() - case "Float" => FloatShape.builder() - case "Double" => DoubleShape.builder() - case "Boolean" => BooleanShape.builder() - case "Byte" => ByteShape.builder() - case "Timestamp" => TimestampShape.builder() - case "Document" => DocumentShape.builder() - case "UUID" => StringShape.builder().addTrait(new UuidFormatTrait()) - case "Null" => - StructureShape.builder().addTrait(new NullFormatTrait()) - case other => sys.error(s"error processing $id, found $other") - } - builder.id(id.toSmithy) - hintsToTraits(hints).foreach(builder.addTrait(_)) - builder.build() - case OperationDef(id, input, output, errors, hints) => - val builder = - OperationShape.builder().id(id.toSmithy) - output.foreach(o => builder.output(o.toSmithy)) - input.foreach(i => builder.input(i.toSmithy)) - hintsToTraits(hints).foreach(builder.addTrait(_)) - errors.foreach(e => builder.addError(e.toSmithy)) - builder.build() - case ServiceDef(id, operations, hints) => - val builder = ServiceShape - .builder() - .id(id.toSmithy) - .addHints(hints) - operations.foreach(o => builder.addOperation(o.toSmithy)) - builder.build() - case e: Enumeration => buildEnum(e) - case other => - throw new IllegalArgumentException(s"Unexpected input: $other") + val shapes: Vector[JShape] = iModel.definitions.map { + case s: Structure => toStructure(s) + case m: MapDef => toMap(m) + case l: ListDef => toList(l) + case s: SetDef => toSet(s) + case u: Union => toUnion(u) + case n: Newtype => toPrimitive(n) + case op: OperationDef => toOperation(op) + case s: ServiceDef => toService(s) + case e: Enumeration => buildEnum(e) } val builder = Model.builder() if (iModel.suppressions.nonEmpty) { @@ -198,7 +231,9 @@ private[compiler] final class IModelToSmithy(useEnumTraitSyntax: Boolean) val name = sanitizeEnumMember(value, idx) enumBuilder.addMember(name, value) } - enumBuilder.addHints(hints).build() + + hintsToTraits(hints).foreach(enumBuilder.addTrait(_)) + enumBuilder.build() } } @@ -396,13 +431,4 @@ private[compiler] final class IModelToSmithy(useEnumTraitSyntax: Boolean) case _ => List.empty } - implicit class ShapeBuilderOps[A <: AbstractShapeBuilder[A, S], S <: JShape]( - builder: AbstractShapeBuilder[A, S] - ) { - final def addHints(hints: List[Hint]): A = { - hintsToTraits(hints).foreach(builder.addTrait) - builder.asInstanceOf[A] - } - } - } diff --git a/modules/compiler-core/src/internals/OpenApiPattern.scala b/modules/compiler-core/src/internals/OpenApiPattern.scala index 1494f46..2b11a5b 100644 --- a/modules/compiler-core/src/internals/OpenApiPattern.scala +++ b/modules/compiler-core/src/internals/OpenApiPattern.scala @@ -87,15 +87,15 @@ private[compiler] object OpenApiPattern { } // format: off - case class OpenApiPrimitive(context: Context, tpe: Primitive) extends OpenApiPattern[Nothing] - case class OpenApiRef(context: Context, ref: DefId) extends OpenApiPattern[Nothing] - case class OpenApiEnum(context: Context, values: Vector[String]) extends OpenApiPattern[Nothing] - case class OpenApiShortStop(context: Context, error: ToSmithyError) extends OpenApiPattern[Nothing] - case class OpenApiNull(context: Context) extends OpenApiPattern[Nothing] - case class OpenApiMap[A](context: Context, items: A) extends OpenApiPattern[A] - case class OpenApiArray[A](context: Context, items: A) extends OpenApiPattern[A] - case class OpenApiSet[A](context: Context, items: A) extends OpenApiPattern[A] - case class OpenApiAllOf[A](context: Context, allOfs: Vector[A]) extends OpenApiPattern[A] - case class OpenApiOneOf[A](context: Context, alternatives: Vector[HintedAlternative[A]], kind: UnionKind) extends OpenApiPattern[A] - case class OpenApiObject[A](context: Context, items: Vector[((String, Boolean), A)]) extends OpenApiPattern[A] +case class OpenApiPrimitive(context: Context, tpe: Primitive) extends OpenApiPattern[Nothing] +case class OpenApiRef(context: Context, ref: DefId) extends OpenApiPattern[Nothing] +case class OpenApiEnum(context: Context, values: Vector[String]) extends OpenApiPattern[Nothing] +case class OpenApiShortStop(context: Context, error: ToSmithyError) extends OpenApiPattern[Nothing] +case class OpenApiNull(context: Context) extends OpenApiPattern[Nothing] +case class OpenApiMap[A](context: Context, items: A) extends OpenApiPattern[A] +case class OpenApiArray[A](context: Context, items: A) extends OpenApiPattern[A] +case class OpenApiSet[A](context: Context, items: A) extends OpenApiPattern[A] +case class OpenApiAllOf[A](context: Context, allOfs: Vector[A]) extends OpenApiPattern[A] +case class OpenApiOneOf[A](context: Context, alternatives: Vector[HintedAlternative[A]], kind: UnionKind) extends OpenApiPattern[A] +case class OpenApiObject[A](context: Context, items: Vector[((String, Boolean), A)]) extends OpenApiPattern[A] // format: on diff --git a/modules/compiler-core/src/internals/postprocess/AllOfTransformer.scala b/modules/compiler-core/src/internals/postprocess/AllOfTransformer.scala index 09d841f..e396492 100644 --- a/modules/compiler-core/src/internals/postprocess/AllOfTransformer.scala +++ b/modules/compiler-core/src/internals/postprocess/AllOfTransformer.scala @@ -63,7 +63,6 @@ private[compiler] object AllOfTransformer extends IModelPostProcessor { case _: ServiceDef => false } loop(tail, hasRef) - case _ :: tail => loop(tail, isReferenced) } loop(allShapes.toList) diff --git a/modules/compiler-core/src/internals/recursion.scala b/modules/compiler-core/src/internals/recursion.scala index d4b3250..f6cd1c5 100644 --- a/modules/compiler-core/src/internals/recursion.scala +++ b/modules/compiler-core/src/internals/recursion.scala @@ -93,7 +93,7 @@ private[compiler] object recursion { type PatternWithLabel[T] = WithLabel[Pattern[T]] implicit val patternWithLabelTraverse : Traverse[PatternWithLabel] = Traverse[WithLabel].compose[Pattern] - refoldPar[F, PatternWithLabel, A, B](unfold, fold.tupled)(a) + refoldPar[F, PatternWithLabel, A, B](unfold, (fold.apply _).tupled)(a) } } diff --git a/modules/formatter/src/parsers/ControlParser.scala b/modules/formatter/src/parsers/ControlParser.scala index e83dc94..f2a5f48 100644 --- a/modules/formatter/src/parsers/ControlParser.scala +++ b/modules/formatter/src/parsers/ControlParser.scala @@ -33,6 +33,6 @@ object ControlParser { } val control_section: Parser0[ControlSection] = - control_statement.rep0.map(ControlSection) + control_statement.rep0.map(ControlSection(_)) } diff --git a/modules/formatter/src/parsers/MetadataParser.scala b/modules/formatter/src/parsers/MetadataParser.scala index e774e90..f778693 100644 --- a/modules/formatter/src/parsers/MetadataParser.scala +++ b/modules/formatter/src/parsers/MetadataParser.scala @@ -34,7 +34,7 @@ object MetadataParser { } val metadata_section: Parser0[MetadataSection] = - metadata_statement.rep0.map(MetadataSection) + metadata_statement.rep0.map(MetadataSection(_)) } /* diff --git a/modules/formatter/src/parsers/NodeParser.scala b/modules/formatter/src/parsers/NodeParser.scala index e399512..23fbd60 100644 --- a/modules/formatter/src/parsers/NodeParser.scala +++ b/modules/formatter/src/parsers/NodeParser.scala @@ -53,10 +53,10 @@ object NodeParser { } val escaped_char: Parser[EscapedChar] = - escape *> (Parser.charIn(escapeChars).map(CharCase) | unicode_escape) + escape *> (Parser.charIn(escapeChars).map(CharCase(_)) | unicode_escape) val quoted_char: Parser[QuotedChar] = - qChar.backtrack.map(SimpleCharCase) | - escaped_char.backtrack.map(EscapedCharCase) | + qChar.backtrack.map(SimpleCharCase(_)) | + escaped_char.backtrack.map(EscapedCharCase(_)) | nl.as(NewLineCase) val three_dquotes: Parser[Unit] = dquote *> dquote *> dquote @@ -66,17 +66,17 @@ object NodeParser { } val text_block: Parser[TextBlock] = ((three_dquotes ~ sp0 *> nl) *> text_block_content.rep0 <* three_dquotes) - .map(TextBlock) + .map(TextBlock(_)) val quoted_text: Parser[QuotedText] = - (dquote *> quoted_char.rep0 <* dquote).map(QuotedText) - val node_string_value: Parser[NodeStringValue] = shape_id.backtrack.map( - ShapeIdCase - ) | text_block.backtrack.map(TextBlockCase) | quoted_text.backtrack - .map(QuotedTextCase) + (dquote *> quoted_char.rep0 <* dquote).map(QuotedText(_)) + val node_string_value: Parser[NodeStringValue] = + shape_id.backtrack.map(ShapeIdCase(_)) | + text_block.backtrack.map(TextBlockCase(_)) | + quoted_text.backtrack.map(QuotedTextCase(_)) val node_keywords: Parser[NodeKeyword] = - Parser.stringIn(Set("true", "false", "null")).map(NodeKeyword) + Parser.stringIn(Set("true", "false", "null")).map(NodeKeyword(_)) - val frac: Parser[Frac] = Parser.char('.') *> digit.rep.string.map(Frac) + val frac: Parser[Frac] = Parser.char('.') *> digit.rep.string.map(Frac(_)) val exp: Parser[Exp] = (Parser.charIn('e', 'E') ~ opParser.? ~ digit.rep.string) .map { case ((a, b), c) => @@ -92,10 +92,9 @@ object NodeParser { nodeArray.backtrack | nodeObject.backtrack | number.backtrack | node_keywords.backtrack | node_string_value.backtrack ) - val node_object_key: Parser[NodeObjectKey] = quoted_text.backtrack - .map( - NodeObjectKey.QuotedTextNok - ) | identifier.map(NodeObjectKey.IdentifierNok) + val node_object_key: Parser[NodeObjectKey] = + quoted_text.backtrack.map(NodeObjectKey.QuotedTextNok(_)) | + identifier.map(NodeObjectKey.IdentifierNok(_)) lazy val node_object_kvp: Parser[NodeObjectKeyValuePair] = ((node_object_key ~ ws <* colon) ~ ws ~ node_value).map { @@ -109,7 +108,7 @@ object NodeParser { } val nodeArray: Parser[NodeArray] = { - val valueP = (node_value ~ ws).map(NodeArrayValue.tupled) + val valueP = (node_value ~ ws).map((NodeArrayValue.apply _).tupled) ((openSquare *> ws ~ valueP.backtrack.rep0) <* (ws ~ closeSquare)) .map { case (whitespace, maybeTuple) => NodeArray(whitespace, maybeTuple) diff --git a/modules/formatter/src/parsers/ShapeIdParser.scala b/modules/formatter/src/parsers/ShapeIdParser.scala index f7a846d..290be8d 100644 --- a/modules/formatter/src/parsers/ShapeIdParser.scala +++ b/modules/formatter/src/parsers/ShapeIdParser.scala @@ -33,16 +33,16 @@ import cats.parse.Rfc5234.{alpha, digit} object ShapeIdParser { val underscore: Parser[Underscore] = Parser.charIn('_').as(Underscore) val identifier_chars: Parser[IdentifierChar] = - (Parser.charIn('_') | digit | alpha).map(IdentifierChar) + (Parser.charIn('_') | digit | alpha).map(IdentifierChar(_)) val identifier_start: Parser[IdentifierStart] = - (underscore.rep0.with1 ~ alpha).map(IdentifierStart.tupled) + (underscore.rep0.with1 ~ alpha).map((IdentifierStart.apply _).tupled) val identifier: Parser[Identifier] = - (identifier_start ~ identifier_chars.rep0).map(Identifier.tupled) + (identifier_start ~ identifier_chars.rep0).map((Identifier.apply _).tupled) val shape_id_member: Parser[ShapeIdMember] = - (Parser.char('$') *> identifier).map(ShapeIdMember) + (Parser.char('$') *> identifier).map(ShapeIdMember(_)) val namespace: Parser[Namespace] = (identifier ~ (Parser.charIn('.') *> identifier).rep0) - .map(Namespace.tupled) + .map((Namespace.apply _).tupled) val absolute_root_shape_id: Parser[AbsoluteRootShapeId] = ((namespace <* Parser.char('#')) ~ identifier) .map { case (ns, id) => AbsoluteRootShapeId.apply(ns, id) } @@ -51,7 +51,7 @@ object ShapeIdParser { .eitherOr(identifier) .map(either => RootShapeId(either.swap)) val shape_id: Parser[ShapeId] = - (root_shape_id ~ shape_id_member.backtrack.?).map(ShapeId.tupled) + (root_shape_id ~ shape_id_member.backtrack.?).map((ShapeId.apply _).tupled) } /* diff --git a/modules/formatter/src/parsers/ShapeParser.scala b/modules/formatter/src/parsers/ShapeParser.scala index b6db292..c49f5ec 100644 --- a/modules/formatter/src/parsers/ShapeParser.scala +++ b/modules/formatter/src/parsers/ShapeParser.scala @@ -83,7 +83,7 @@ object ShapeParser { val enumTypeNames: Set[String] = Set("enum", "intEnum") val simple_type_name: Parser[SimpleTypeName] = - Parser.stringIn(simpleNames).map(SimpleTypeName) + Parser.stringIn(simpleNames).map(SimpleTypeName(_)) val enum_type_name: Parser[String] = Parser.stringIn(enumTypeNames) // see comments on ValueAssignment @@ -134,12 +134,10 @@ object ShapeParser { val explicit_list_member: Parser[ExplicitListMember] = Parser.string("member") *> sp0 *> Parser.charIn(':') *> sp0 *> shape_id - .map( - ExplicitListMember - ) + .map(ExplicitListMember(_)) val elided_list_member: Parser[ElidedListMember] = - shape_id_member.map(ElidedListMember) + shape_id_member.map(ElidedListMember(_)) val list_member: Parser[ListMember] = (trait_statements.with1.soft ~ (explicit_list_member.backtrack | elided_list_member)) @@ -173,17 +171,15 @@ object ShapeParser { object map_parsers { val elided_map_key: Parser[ElidedMapKey] = - shape_id_member.map(ElidedMapKey) + shape_id_member.map(ElidedMapKey(_)) val explicit_map_key: Parser[ExplicitMapKey] = - Parser.string("key") *> sp0 *> colon *> sp0 *> shape_id.map( - ExplicitMapKey - ) + Parser.string("key") *> sp0 *> colon *> sp0 *> + shape_id.map(ExplicitMapKey(_)) val elided_map_value: Parser[ElidedMapValue] = - shape_id_member.map(ElidedMapValue) + shape_id_member.map(ElidedMapValue(_)) val explicit_map_value: Parser[ExplicitMapValue] = - Parser.string("value") *> sp0 *> colon *> sp0 *> shape_id.map( - ExplicitMapValue - ) + Parser.string("value") *> sp0 *> colon *> sp0 *> + shape_id.map(ExplicitMapValue(_)) val map_value: Parser[MapValue] = (trait_statements.?.with1.soft ~ (explicit_map_value.backtrack | elided_map_value)) .map { case (traits, member) => @@ -210,9 +206,9 @@ object ShapeParser { object structure_parsers { val explicit_structure_member: Parser[ExplicitStructureMember] = ((identifier <* sp0 <* Parser.charIn(':') <* sp0) ~ shape_id) - .map(ExplicitStructureMember.tupled) + .map((ExplicitStructureMember.apply _).tupled) val elided_structure_member: Parser[ElidedStructureMember] = - (Parser.charIn('$') *> identifier).map(ElidedStructureMember) + (Parser.charIn('$') *> identifier).map(ElidedStructureMember(_)) val structure_member: Parser[StructureMember] = { ((explicit_structure_member.backtrack | elided_structure_member) ~ value_assigments.backtrack.?) .map { case (member, va) => @@ -231,7 +227,7 @@ object ShapeParser { } val structure_resource: Parser[StructureResource] = (sp0.with1 *> Parser.string("for") *> sp0 *> shape_id) - .map(StructureResource) + .map(StructureResource(_)) val structure_statement: Parser[StructureStatement] = (Parser.string( "structure" ) *> sp0 *> identifier ~ structure_resource.backtrack.? ~ mixinBT.? ~ ws ~ structure_members) @@ -243,7 +239,7 @@ object ShapeParser { object union_parsers { val union_member: Parser[UnionMember] = (structure_parsers.explicit_structure_member | structure_parsers.elided_structure_member) - .map(UnionMember) + .map(UnionMember(_)) val union_members: Parser[UnionMembers] = (openCurly *> ws ~ (trait_statements.with1 ~ union_member ~ ws).rep0 <* closeCurly) .map { case (ws0, members) => @@ -347,8 +343,8 @@ object ShapeParser { } } val shape_statement_or_apply: Parser[ShapeStatementsCase] = - shape_statement.map(ShapeStatementCase) | - apply_statement.map(ApplyStatementCase) + shape_statement.map(ShapeStatementCase(_)) | + apply_statement.map(ApplyStatementCase(_)) // The optional trailing BR is not in the spec but it exists in a lot of // files. @@ -366,7 +362,7 @@ object ShapeParser { (Parser.string("use") *> sp *> absolute_root_shape_id ~ br).map { case (arsi, br) => UseStatement(arsi, br) } - val use_section: Parser0[UseSection] = use_statement.rep0.map(UseSection) + val use_section: Parser0[UseSection] = use_statement.rep0.map(UseSection(_)) val shape_section: Parser0[ShapeSection] = (namespace_statement ~ use_section ~ shape_statements.?).?.map { op => ShapeSection(op.map { case ((ns, use), ss) => diff --git a/modules/formatter/src/parsers/SmithyTraitParser.scala b/modules/formatter/src/parsers/SmithyTraitParser.scala index f017fdb..089c1a1 100644 --- a/modules/formatter/src/parsers/SmithyTraitParser.scala +++ b/modules/formatter/src/parsers/SmithyTraitParser.scala @@ -39,13 +39,12 @@ object SmithyTraitParser { // TraitStructureKvp *(*WS TraitStructureKvp) val trait_structure: Parser[TraitStructure] = (trait_structure_kvp ~ (ws.with1 ~ trait_structure_kvp).backtrack.rep0) - .map(TraitStructure.tupled) + .map((TraitStructure.apply _).tupled) // trait_structure / node_value val strait_body_value: Parser0[SmithyTraitBodyValue] = - trait_structure.backtrack.map(SmithyTraitStructureCase) | node_value.map( - NodeValueCase - ) + trait_structure.backtrack.map(SmithyTraitStructureCase(_)) | + node_value.map(NodeValueCase(_)) // "(" ws trait_body_value ws ")" val strait_body: Parser0[TraitBody] = ((openParentheses *> ws ~ strait_body_value.? ~ ws) <* closeParentheses) @@ -54,7 +53,9 @@ object SmithyTraitParser { } // "@" shape_id [trait_body] val strait: Parser[SmithyTrait] = - Parser.char('@') *> (shape_id ~ strait_body.?).map { SmithyTrait.tupled } + Parser.char('@') *> (shape_id ~ strait_body.?).map { + (SmithyTrait.apply _).tupled + } // *(ws trait) ws val trait_statements: Parser0[TraitStatements] = ((ws.with1 ~ strait).backtrack.rep0 ~ ws).map { case (traits, ws) => @@ -73,7 +74,7 @@ object SmithyTraitParser { ApplyStatementBlock(a, b, c) } val apply_statement: Parser[ApplyStatement] = - apply_block.backtrack.eitherOr(apply_singular).map(ApplyStatement) + apply_block.backtrack.eitherOr(apply_singular).map(ApplyStatement(_)) } diff --git a/modules/formatter/src/parsers/WhitespaceParser.scala b/modules/formatter/src/parsers/WhitespaceParser.scala index d4e038c..0ac85b9 100644 --- a/modules/formatter/src/parsers/WhitespaceParser.scala +++ b/modules/formatter/src/parsers/WhitespaceParser.scala @@ -51,6 +51,6 @@ object WhitespaceParser { .rep0 .map(_.flatMap(_.swap.toOption.flatMap(_.swap.toOption))) .map(_.flatMap(_.toOption)) - .map(Whitespace) + .map(Whitespace(_)) } diff --git a/modules/json-schema/src/internals/Extractors.scala b/modules/json-schema/src/internals/Extractors.scala index baeb45e..c6c8506 100644 --- a/modules/json-schema/src/internals/Extractors.scala +++ b/modules/json-schema/src/internals/Extractors.scala @@ -84,7 +84,7 @@ private[json_schema] object Extractors { else Some(PDouble) val (typedMin, typedMax): (Double, Double) = prim match { - case Some(PInt) => (Int.MinValue, Int.MaxValue) + case Some(PInt) => (Int.MinValue.toDouble, Int.MaxValue.toDouble) case _ => (Double.MinValue, Double.MaxValue) } @@ -127,7 +127,7 @@ private[json_schema] object Extractors { // type: string case (s: StringSchema) => val pattern = - Option(s.getPattern()).map(_.pattern()).map(Hint.Pattern) + Option(s.getPattern()).map(_.pattern()).map(Hint.Pattern(_)) val max = Option(s.getMaxLength()).map(n => n.longValue()) val min = Option(s.getMinLength()).map(n => n.longValue()) val length = @@ -296,7 +296,7 @@ private[json_schema] object Extractors { case other => other } .map(GetExtensions.anyToNode) - .map(Hint.DefaultValue) + .map(Hint.DefaultValue(_)) List(description, default, current, target).flatten ++ extensions } diff --git a/modules/json-schema/src/internals/JsonSchemaToIModel.scala b/modules/json-schema/src/internals/JsonSchemaToIModel.scala index 0361703..7fbf6ad 100644 --- a/modules/json-schema/src/internals/JsonSchemaToIModel.scala +++ b/modules/json-schema/src/internals/JsonSchemaToIModel.scala @@ -30,6 +30,7 @@ import org.json.JSONObject import io.circe.Json import io.circe.ACursor import io.circe.JsonObject +import cats.catsParallelForId private[compiler] object JsonSchemaToIModel { @@ -293,7 +294,7 @@ private class JsonSchemaToIModel[F[_]: Parallel: TellShape: TellError]( private implicit class WithDescriptionSyntax(p: OpenApiPattern[Local]) { def withDescription(local: Local): OpenApiPattern[Local] = { val maybeDesc = - Option(local.schema.getDescription()).map(Hint.Description).toList + Option(local.schema.getDescription()).map(Hint.Description(_)).toList p.mapContext(_.addHints(maybeDesc, retainTopLevel = true)) } } diff --git a/modules/openapi/src/internals/OpenApiToIModel.scala b/modules/openapi/src/internals/OpenApiToIModel.scala index c795c5b..96f6e50 100644 --- a/modules/openapi/src/internals/OpenApiToIModel.scala +++ b/modules/openapi/src/internals/OpenApiToIModel.scala @@ -30,6 +30,7 @@ import cats.syntax.all._ import cats.Monad import org.typelevel.ci._ import GetExtensions.HasExtensions +import cats.catsParallelForId private[compiler] object OpenApiToIModel { @@ -40,8 +41,8 @@ private[compiler] object OpenApiToIModel { type ErrorLayer[A] = Writer[Chain[ToSmithyError], A] type WriterLayer[A] = WriterT[ErrorLayer, Chain[Either[Suppression, Definition]], A] - val (errors, (data, _)) = - compileF[WriterLayer](namespace, openAPI).run.run + + val (errors, (data, _)) = compileF[WriterLayer](namespace, openAPI).run.run val definitions = data.collect { case Right(d) => d } val suppressions = data.collect { case Left(s) => s } (errors, IModel(definitions.toVector, suppressions.toVector)) @@ -56,7 +57,9 @@ private[compiler] object OpenApiToIModel { val parser = new OpenApiToIModel[F](namespace, openApi) parser.recordAll case Left(errors) => - Tell.tell(Chain.one((ToSmithyError.OpenApiParseError(namespace, errors)))) + Tell.tell( + Chain.one((ToSmithyError.OpenApiParseError(namespace, errors))) + ) } } } @@ -368,7 +371,7 @@ private[openapi] class OpenApiToIModel[F[_]: Parallel: TellShape: TellError]( private implicit class WithDescriptionSyntax(p: OpenApiPattern[Local]) { def withDescription(local: Local): OpenApiPattern[Local] = { val maybeDesc = - Option(local.schema.getDescription()).map(Hint.Description).toList + Option(local.schema.getDescription()).map(Hint.Description(_)).toList p.mapContext(_.addHints(maybeDesc, retainTopLevel = true)) } } @@ -456,7 +459,7 @@ private[openapi] class OpenApiToIModel[F[_]: Parallel: TellShape: TellError]( if (minL.isDefined || maxL.isDefined) Some(Hint.Length(minL, maxL)) else None - val pattern = Option(local.schema.getPattern).map(Hint.Pattern) + val pattern = Option(local.schema.getPattern).map(Hint.Pattern(_)) val sensitive = Option(local.schema.getFormat()).flatMap(f => if (f == "password") Some(Hint.Sensitive) else None ) diff --git a/modules/openapi/src/internals/ParseOperations.scala b/modules/openapi/src/internals/ParseOperations.scala index 8514f00..07f97d9 100644 --- a/modules/openapi/src/internals/ParseOperations.scala +++ b/modules/openapi/src/internals/ParseOperations.scala @@ -173,7 +173,9 @@ private class ParseOperationsImpl( hasGlobalSecurity: Boolean )(opInfo: IOpInfo): ParseOperationsResult = { import opInfo._ - val localParams: Vector[Either[ToSmithyError, Param]] = getLocalInputParams(op) + val localParams: Vector[Either[ToSmithyError, Param]] = getLocalInputParams( + op + ) val body: Vector[Either[ToSmithyError, Param]] = getRequestBodyParam(op).toVector.map(Right(_)) val allInputParams: Vector[Either[ToSmithyError, Param]] = @@ -186,11 +188,12 @@ private class ParseOperationsImpl( val outputs = getOutputs(opInfo) val (errors, securityHint) = getSecurityHint(securitySchemes, opInfo, hasGlobalSecurity) - val descHint = Option(op.getDescription()).map(Hint.Description).toList + val descHint = Option(op.getDescription()).map(Hint.Description(_)).toList val exDocs = Option(opInfo.op.getExternalDocs()).map(e => Hint.ExternalDocs(Option(e.getDescription()), e.getUrl()) ) - val tags = Option(op.getTags()).map(_.asScala.toList).map(Hint.Tags).toList + val tags = + Option(op.getTags()).map(_.asScala.toList).map(Hint.Tags(_)).toList val hints = GetExtensions.from( @@ -307,7 +310,7 @@ private class ParseOperationsImpl( } val description = Option(resolvedParam.getDescription()) - .map[Hint](Hint.Description) + .map[Hint](Hint.Description(_)) .toList httpBinding .map { b => diff --git a/modules/proto/src/smithyproto/Text.scala b/modules/proto/src/smithyproto/Text.scala index 2616cf5..1c94fe6 100644 --- a/modules/proto/src/smithyproto/Text.scala +++ b/modules/proto/src/smithyproto/Text.scala @@ -22,10 +22,10 @@ import scala.annotation.tailrec */ sealed trait Text object Text { - final case class Line(string: String) extends Text - final case class Many(texts: List[Text]) extends Text - final case class Indent(text: Text) extends Text - final case object NewLine extends Text + case class Line(string: String) extends Text + case class Many(texts: List[Text]) extends Text + case class Indent(text: Text) extends Text + case object NewLine extends Text def line(string: String): Text.Line = Text.Line(string) diff --git a/modules/proto/src/smithyproto/proto3/Compiler.scala b/modules/proto/src/smithyproto/proto3/Compiler.scala index 6ead37f..a8fa683 100644 --- a/modules/proto/src/smithyproto/proto3/Compiler.scala +++ b/modules/proto/src/smithyproto/proto3/Compiler.scala @@ -134,7 +134,7 @@ class Compiler() { private def isProtoService(ss: ServiceShape): Boolean = ss.hasTrait(classOf[ProtoEnabledTrait]) - @annotation.nowarn("msg=class EnumTrait in package traits is deprecated") + @annotation.nowarn("msg=class EnumTrait in package (.*)traits is deprecated") private def getEnumTrait(s: Shape): Option[EnumTrait] = s.getTrait(classOf[EnumTrait]).toScala @@ -590,7 +590,9 @@ class Compiler() { def resourceShape(shape: ResourceShape): Option[Type] = None def serviceShape(shape: ServiceShape): Option[Type] = None - @annotation.nowarn("msg=class SetShape in package shapes is deprecated") + @annotation.nowarn( + "msg=class SetShape in package (.*)shapes is deprecated" + ) override def setShape(shape: SetShape): Option[Type] = Some( Type.MessageType( Namespacing.shapeIdToFqn(shape.getId), diff --git a/modules/readme-validator/src/ReadmeParser.scala b/modules/readme-validator/src/ReadmeParser.scala index 1c75bcd..bd84e57 100644 --- a/modules/readme-validator/src/ReadmeParser.scala +++ b/modules/readme-validator/src/ReadmeParser.scala @@ -69,15 +69,15 @@ object ReadmeParser { val openapiSection = sectionParser(openapiHeader, smithyHeader) .map(_.map(_.head)) - .map(Example.OpenApi.tupled) + .map((Example.OpenApi.apply _).tupled) val jsonSection = sectionParser(jsonHeader, smithyHeader) .map(_.map(_.head)) - .map(Example.JsonSchema.tupled) + .map((Example.JsonSchema.apply _).tupled) val protoSection = sectionParser(smithyHeader, protoHeader) .map(_.map(_.head)) - .map(Example.Proto.tupled) + .map((Example.Proto.apply _).tupled) val section = openapiSection.backtrack .orElse(jsonSection) .backtrack diff --git a/modules/transitive/src/closure/IdRefVisitor.scala b/modules/transitive/src/closure/IdRefVisitor.scala index 32a9b97..82ffe48 100644 --- a/modules/transitive/src/closure/IdRefVisitor.scala +++ b/modules/transitive/src/closure/IdRefVisitor.scala @@ -58,7 +58,7 @@ private[closure] final class IdRefVisitor( override def listShape(shape: ListShape): List[Shape] = visitSeqShape(shape.getMember()) - @annotation.nowarn("msg=class SetShape in package shapes is deprecated") + @annotation.nowarn("msg=class SetShape in package (.*)shapes is deprecated") override def setShape(shape: SetShape): List[Shape] = visitSeqShape(shape.getMember())