Skip to content

Commit

Permalink
Resolving structural issues with scalameta
Browse files Browse the repository at this point in the history
  • Loading branch information
blast-hardcheese committed Feb 3, 2020
1 parent 79abd3b commit d09ad01
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.twilio.guardrail.circe

import scala.meta._

sealed trait CirceVersion {
def encoderObject: String
def print: String
def encoderObject: Type
def print: Term.Name
}
object CirceVersion {
case object V011 extends CirceVersion {
def encoderObject = "ObjectEncoder"
def print = "pretty"
def encoderObject = t"ObjectEncoder"
def print = q"pretty"
}
case object V012 extends CirceVersion {
def encoderObject = "Encoder.AsObject"
def print = "print"
def encoderObject = t"Encoder.AsObject"
def print = q"print"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ object AkkaHttpGenerator {
implicit printer: Printer = Printer.noSpaces
): ToEntityMarshaller[${jsonType}] =
Marshaller.withFixedContentType(MediaTypes.`application/json`) { json =>
HttpEntity(MediaTypes.`application/json`, printer.${circeVersion.print}(json))
HttpEntity(MediaTypes.`application/json`, ${Term.Select(q"printer", circeVersion.print)}(json))
}

// Translate [A: Encoder] => HttpEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,8 @@ object CirceProtocolGenerator {
.to[List]
Option(
q"""
new ${circeVersion.encoderObject}[${Type.Name(clsName)}] {
final def encodeObject(a: ${Type
.Name(clsName)}): JsonObject = JsonObject.fromIterable(Vector(..${pairs}))
new ${Init(Type.Apply(circeVersion.encoderObject, List(Type.Name(clsName))), Name.Anonymous(), List.empty)} {
final def encodeObject(a: ${Type.Name(clsName)}): JsonObject = JsonObject.fromIterable(Vector(..${pairs}))
}
"""
)
Expand Down

0 comments on commit d09ad01

Please sign in to comment.