Skip to content

Commit

Permalink
Merge pull request #132 from wsargent/patch-1
Browse files Browse the repository at this point in the history
Prefix possibly colliding variables with __
  • Loading branch information
eed3si9n authored Jan 25, 2019
2 parents c9c8df5 + 1351423 commit 7f0e6c4
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 84 deletions.
18 changes: 9 additions & 9 deletions library/src/main/scala/sbt/contraband/CodecCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ class CodecCodeGen(codecParents: List[String],
|
|trait ${e.name.capitalize}Formats { $selfType
| implicit lazy val ${e.name}Format: JsonFormat[$fqn] = new JsonFormat[$fqn] {
| override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): $fqn = {
| jsOpt match {
| case Some(js) =>
| unbuilder.readString(js) match {
| override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): $fqn = {
| __jsOpt match {
| case Some(__js) =>
| unbuilder.readString(__js) match {
| ${readerValues mkString EOL}
| }
| case None =>
Expand Down Expand Up @@ -113,10 +113,10 @@ class CodecCodeGen(codecParents: List[String],
|
|trait ${r.name.capitalize}Formats { $selfType
| implicit lazy val ${r.name}Format: JsonFormat[$fqn] = new JsonFormat[$fqn] {
| override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): $fqn = {
| jsOpt match {
| case Some(js) =>
| unbuilder.beginObject(js)
| override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): $fqn = {
| __jsOpt match {
| case Some(__js) =>
| unbuilder.beginObject(__js)
| $getFields
| unbuilder.endObject()
| $reconstruct
Expand Down Expand Up @@ -149,7 +149,7 @@ class CodecCodeGen(codecParents: List[String],
|
|trait ${name.capitalize}Formats {
| implicit lazy val ${name}Format: JsonFormat[$fqn] = new JsonFormat[$fqn] {
| override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): $fqn = {
| override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): $fqn = {
| deserializationError("No known implementation of ${i.name}.")
| }
| override def write[J](obj: $fqn, builder: Builder[J]): Unit = {
Expand Down
16 changes: 8 additions & 8 deletions library/src/test/scala/GraphQLCodecCodeGenSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class GraphQLCodecCodeGenSpec extends FlatSpec with Matchers with Inside with Eq
|
|trait ChildTypeFormats { self: sjsonnew.BasicJsonProtocol =>
| implicit lazy val ChildTypeFormat: JsonFormat[com.example.ChildType] = new JsonFormat[com.example.ChildType] {
| override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): com.example.ChildType = {
| jsOpt match {
| case Some(js) =>
| unbuilder.beginObject(js)
| override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): com.example.ChildType = {
| __jsOpt match {
| case Some(__js) =>
| unbuilder.beginObject(__js)
| val name = unbuilder.readField[Option[String]]("name")
| val field = unbuilder.readField[Option[Int]]("field")
| unbuilder.endObject()
Expand Down Expand Up @@ -88,10 +88,10 @@ class GraphQLCodecCodeGenSpec extends FlatSpec with Matchers with Inside with Eq
|
|trait ChildTypeFormats { self: sjsonnew.BasicJsonProtocol =>
| implicit lazy val ChildTypeFormat: JsonFormat[com.example.ChildType] = new JsonFormat[com.example.ChildType] {
| override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): com.example.ChildType = {
| jsOpt match {
| case Some(js) =>
| unbuilder.beginObject(js)
| override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): com.example.ChildType = {
| __jsOpt match {
| case Some(__js) =>
| unbuilder.beginObject(__js)
| val name = unbuilder.readField[Option[String]]("name")
| val field = unbuilder.readField[Option[Int]]("field")
| unbuilder.endObject()
Expand Down
70 changes: 35 additions & 35 deletions library/src/test/scala/JsonCodecCodeGenSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class JsonCodecCodeGenSpec extends GCodeGenSpec("Codec") {
|
|trait SimpleEnumerationExampleFormats { self: sjsonnew.BasicJsonProtocol =>
| implicit lazy val simpleEnumerationExampleFormat: JsonFormat[_root_.simpleEnumerationExample] = new JsonFormat[_root_.simpleEnumerationExample] {
| override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.simpleEnumerationExample = {
| jsOpt match {
| case Some(js) =>
| unbuilder.readString(js) match {
| override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.simpleEnumerationExample = {
| __jsOpt match {
| case Some(__js) =>
| unbuilder.readString(__js) match {
| case "first" => _root_.simpleEnumerationExample.first
| case "second" => _root_.simpleEnumerationExample.second
| }
Expand Down Expand Up @@ -69,7 +69,7 @@ class JsonCodecCodeGenSpec extends GCodeGenSpec("Codec") {
|
|trait SimpleInterfaceExampleFormats {
| implicit lazy val simpleInterfaceExampleFormat: JsonFormat[_root_.simpleInterfaceExample] = new JsonFormat[_root_.simpleInterfaceExample] {
| override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.simpleInterfaceExample = {
| override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.simpleInterfaceExample = {
| deserializationError("No known implementation of simpleInterfaceExample.")
| }
| override def write[J](obj: _root_.simpleInterfaceExample, builder: Builder[J]): Unit = {
Expand Down Expand Up @@ -109,10 +109,10 @@ class JsonCodecCodeGenSpec extends GCodeGenSpec("Codec") {
|
|trait ChildRecordFormats { self: sjsonnew.BasicJsonProtocol =>
| implicit lazy val childRecordFormat: JsonFormat[_root_.childRecord] = new JsonFormat[_root_.childRecord] {
| override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.childRecord = {
| jsOpt match {
| case Some(js) =>
| unbuilder.beginObject(js)
| override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.childRecord = {
| __jsOpt match {
| case Some(__js) =>
| unbuilder.beginObject(__js)
| val field = unbuilder.readField[Int]("field")
| val x = unbuilder.readField[Int]("x")
| unbuilder.endObject()
Expand Down Expand Up @@ -169,7 +169,7 @@ class JsonCodecCodeGenSpec extends GCodeGenSpec("Codec") {
|
|trait GenerateArgDocExampleFormats {
| implicit lazy val generateArgDocExampleFormat: JsonFormat[_root_.generateArgDocExample] = new JsonFormat[_root_.generateArgDocExample] {
| override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.generateArgDocExample = {
| override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.generateArgDocExample = {
| deserializationError("No known implementation of generateArgDocExample.")
| }
| override def write[J](obj: _root_.generateArgDocExample, builder: Builder[J]): Unit = {
Expand All @@ -196,10 +196,10 @@ class JsonCodecCodeGenSpec extends GCodeGenSpec("Codec") {
|
|trait SimpleRecordExampleFormats { self: sjsonnew.BasicJsonProtocol =>
| implicit lazy val simpleRecordExampleFormat: JsonFormat[_root_.simpleRecordExample] = new JsonFormat[_root_.simpleRecordExample] {
| override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.simpleRecordExample = {
| jsOpt match {
| case Some(js) =>
| unbuilder.beginObject(js)
| override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.simpleRecordExample = {
| __jsOpt match {
| case Some(__js) =>
| unbuilder.beginObject(__js)
| val field = unbuilder.readField[java.net.URL]("field")
| unbuilder.endObject()
| _root_.simpleRecordExample(field)
Expand Down Expand Up @@ -233,10 +233,10 @@ class JsonCodecCodeGenSpec extends GCodeGenSpec("Codec") {
|
|trait GrowableAddOneFieldFormats { self: sjsonnew.BasicJsonProtocol =>
| implicit lazy val growableAddOneFieldFormat: JsonFormat[_root_.growableAddOneField] = new JsonFormat[_root_.growableAddOneField] {
| override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.growableAddOneField = {
| jsOpt match {
| case Some(js) =>
| unbuilder.beginObject(js)
| override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.growableAddOneField = {
| __jsOpt match {
| case Some(__js) =>
| unbuilder.beginObject(__js)
| val field = unbuilder.readField[Int]("field")
| unbuilder.endObject()
| _root_.growableAddOneField(field)
Expand Down Expand Up @@ -270,10 +270,10 @@ class JsonCodecCodeGenSpec extends GCodeGenSpec("Codec") {
|
|trait FooFormats { self: sjsonnew.BasicJsonProtocol =>
| implicit lazy val FooFormat: JsonFormat[_root_.Foo] = new JsonFormat[_root_.Foo] {
| override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.Foo = {
| jsOpt match {
| case Some(js) =>
| unbuilder.beginObject(js)
| override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.Foo = {
| __jsOpt match {
| case Some(__js) =>
| unbuilder.beginObject(__js)
| val x = unbuilder.readField[Option[Int]]("x")
| val y = unbuilder.readField[Vector[Int]]("y")
| unbuilder.endObject()
Expand Down Expand Up @@ -309,10 +309,10 @@ package generated
import _root_.sjsonnew.{ Unbuilder, Builder, JsonFormat, deserializationError }
trait PrimitiveTypesExample2Formats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val primitiveTypesExample2Format: JsonFormat[_root_.primitiveTypesExample2] = new JsonFormat[_root_.primitiveTypesExample2] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.primitiveTypesExample2 = {
jsOpt match {
case Some(js) =>
unbuilder.beginObject(js)
override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.primitiveTypesExample2 = {
__jsOpt match {
case Some(__js) =>
unbuilder.beginObject(__js)
val smallBoolean = unbuilder.readField[Boolean]("smallBoolean")
val bigBoolean = unbuilder.readField[Boolean]("bigBoolean")
unbuilder.endObject()
Expand Down Expand Up @@ -350,10 +350,10 @@ implicit lazy val primitiveTypesExample2Format: JsonFormat[_root_.primitiveTypes
|
|trait PrimitiveTypesExampleFormats { self: sjsonnew.BasicJsonProtocol =>
| implicit lazy val primitiveTypesExampleFormat: JsonFormat[_root_.primitiveTypesExample] = new JsonFormat[_root_.primitiveTypesExample] {
| override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.primitiveTypesExample = {
| jsOpt match {
| case Some(js) =>
| unbuilder.beginObject(js)
| override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.primitiveTypesExample = {
| __jsOpt match {
| case Some(__js) =>
| unbuilder.beginObject(__js)
| val simpleInteger = unbuilder.readField[Int]("simpleInteger")
| val lazyInteger = unbuilder.readField[Int]("lazyInteger")
| val arrayInteger = unbuilder.readField[Vector[Int]]("arrayInteger")
Expand Down Expand Up @@ -397,10 +397,10 @@ implicit lazy val primitiveTypesExample2Format: JsonFormat[_root_.primitiveTypes
|
|trait PrimitiveTypesNoLazyExampleFormats { self: sjsonnew.BasicJsonProtocol =>
| implicit lazy val primitiveTypesNoLazyExampleFormat: JsonFormat[_root_.primitiveTypesNoLazyExample] = new JsonFormat[_root_.primitiveTypesNoLazyExample] {
| override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.primitiveTypesNoLazyExample = {
| jsOpt match {
| case Some(js) =>
| unbuilder.beginObject(js)
| override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.primitiveTypesNoLazyExample = {
| __jsOpt match {
| case Some(__js) =>
| unbuilder.beginObject(__js)
| val simpleInteger = unbuilder.readField[Int]("simpleInteger")
| val arrayInteger = unbuilder.readField[Vector[Int]]("arrayInteger")
| unbuilder.endObject()
Expand Down Expand Up @@ -458,7 +458,7 @@ implicit lazy val primitiveTypesExample2Format: JsonFormat[_root_.primitiveTypes
|
|trait GreetingFormats {
| implicit lazy val GreetingFormat: JsonFormat[_root_.Greeting] = new JsonFormat[_root_.Greeting] {
| override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.Greeting = {
| override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.Greeting = {
| deserializationError("No known implementation of Greeting.")
| }
| override def write[J](obj: _root_.Greeting, builder: Builder[J]): Unit = {
Expand Down
40 changes: 20 additions & 20 deletions library/src/test/scala/JsonSchemaExample.scala
Original file line number Diff line number Diff line change
Expand Up @@ -976,10 +976,10 @@ import _root_.sjsonnew.{ Unbuilder, Builder, JsonFormat, deserializationError }
trait SimpleGreetingFormats { self: generated.GreetingHeaderFormats with sjsonnew.BasicJsonProtocol =>
implicit lazy val SimpleGreetingFormat: JsonFormat[com.example.SimpleGreeting] = new JsonFormat[com.example.SimpleGreeting] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): com.example.SimpleGreeting = {
jsOpt match {
case Some(js) =>
unbuilder.beginObject(js)
override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): com.example.SimpleGreeting = {
__jsOpt match {
case Some(__js) =>
unbuilder.beginObject(__js)
val message = unbuilder.readField[String]("message")
val header = unbuilder.readField[com.example.GreetingHeader]("header")
unbuilder.endObject()
Expand Down Expand Up @@ -1019,10 +1019,10 @@ import _root_.sjsonnew.{ Unbuilder, Builder, JsonFormat, deserializationError }
trait GreetingExtraImplFormats { self: generated.GreetingHeaderFormats with sjsonnew.BasicJsonProtocol =>
implicit lazy val GreetingExtraImplFormat: JsonFormat[com.example.GreetingExtraImpl] = new JsonFormat[com.example.GreetingExtraImpl] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): com.example.GreetingExtraImpl = {
jsOpt match {
case Some(js) =>
unbuilder.beginObject(js)
override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): com.example.GreetingExtraImpl = {
__jsOpt match {
case Some(__js) =>
unbuilder.beginObject(__js)
val message = unbuilder.readField[String]("message")
val header = unbuilder.readField[com.example.GreetingHeader]("header")
val extra = unbuilder.readField[Array[String]]("extra")
Expand Down Expand Up @@ -1054,10 +1054,10 @@ import _root_.sjsonnew.{ Unbuilder, Builder, JsonFormat, deserializationError }
trait GreetingWithAttachmentsFormats { self: generated.GreetingHeaderFormats with sjsonnew.BasicJsonProtocol =>
implicit lazy val GreetingWithAttachmentsFormat: JsonFormat[com.example.GreetingWithAttachments] = new JsonFormat[com.example.GreetingWithAttachments] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): com.example.GreetingWithAttachments = {
jsOpt match {
case Some(js) =>
unbuilder.beginObject(js)
override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): com.example.GreetingWithAttachments = {
__jsOpt match {
case Some(__js) =>
unbuilder.beginObject(__js)
val message = unbuilder.readField[String]("message")
val header = unbuilder.readField[com.example.GreetingHeader]("header")
val attachments = unbuilder.readField[Vector[java.io.File]]("attachments")
Expand Down Expand Up @@ -1087,10 +1087,10 @@ import _root_.sjsonnew.{ Unbuilder, Builder, JsonFormat, deserializationError }
trait GreetingHeaderFormats { self: java.util.DateFormats with generated.PriorityLevelFormats with sjsonnew.BasicJsonProtocol =>
implicit lazy val GreetingHeaderFormat: JsonFormat[com.example.GreetingHeader] = new JsonFormat[com.example.GreetingHeader] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): com.example.GreetingHeader = {
jsOpt match {
case Some(js) =>
unbuilder.beginObject(js)
override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): com.example.GreetingHeader = {
__jsOpt match {
case Some(__js) =>
unbuilder.beginObject(__js)
val created = unbuilder.readField[java.util.Date]("created")
val priority = unbuilder.readField[com.example.PriorityLevel]("priority")
val author = unbuilder.readField[String]("author")
Expand Down Expand Up @@ -1120,10 +1120,10 @@ import _root_.sjsonnew.{ Unbuilder, Builder, JsonFormat, deserializationError }
trait PriorityLevelFormats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val PriorityLevelFormat: JsonFormat[com.example.PriorityLevel] = new JsonFormat[com.example.PriorityLevel] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): com.example.PriorityLevel = {
jsOpt match {
case Some(js) =>
unbuilder.readString(js) match {
override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): com.example.PriorityLevel = {
__jsOpt match {
case Some(__js) =>
unbuilder.readString(__js) match {
case "Low" => com.example.PriorityLevel.Low
case "Medium" => com.example.PriorityLevel.Medium
case "High" => com.example.PriorityLevel.High
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import sjsonnew.{ Builder, deserializationError, JsonFormat, Unbuilder }

trait FileFormats {
implicit val fileFormat: JsonFormat[File] = new JsonFormat[File] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): File = {
jsOpt match {
case Some(js) => new File(unbuilder.readString(js))
override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): File = {
__jsOpt match {
case Some(__js) => new File(unbuilder.readString(__js))
case None => deserializationError("Expected JsString but found None")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import sjsonnew.{ Builder, deserializationError, JsonFormat, Unbuilder }

trait FileFormats {
implicit val fileFormat: JsonFormat[File] = new JsonFormat[File] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): File = {
jsOpt match {
case Some(js) => new File(unbuilder.readString(js))
override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): File = {
__jsOpt match {
case Some(__js) => new File(unbuilder.readString(__js))
case None => deserializationError("Expected JsString but found None")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import sjsonnew.{ Builder, deserializationError, JsonFormat, Unbuilder }

trait FileFormats {
implicit val fileFormat: JsonFormat[File] = new JsonFormat[File] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): File = {
jsOpt match {
case Some(js) => new File(unbuilder.readString(js))
override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): File = {
__jsOpt match {
case Some(__js) => new File(unbuilder.readString(__js))
case None => deserializationError("Expected JsString but found None")
}
}
Expand Down
Loading

0 comments on commit 7f0e6c4

Please sign in to comment.