Last active
February 22, 2018 12:41
-
-
Save edmondop/f41f34661ed3abee08d1d1f3e028b4ad to your computer and use it in GitHub Desktop.
Avro4s Macros results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object SchemaFor extends LowPrioritySchemaFor{ | |
implicit object ByteSchemaFor extends SchemaFor[Byte] { | |
private val schema = SchemaBuilder.builder().intType() | |
def apply(): org.apache.avro.Schema = schema | |
} | |
implicit object ShortSchemaFor extends SchemaFor[Short] { | |
private val schema = SchemaBuilder.builder().intType() | |
def apply(): org.apache.avro.Schema = schema | |
} | |
implicit object LongSchemaFor extends SchemaFor[Long] { | |
private val schema = SchemaBuilder.builder().longType() | |
def apply(): org.apache.avro.Schema = schema | |
} | |
implicit object IntSchemaFor extends SchemaFor[Int] { | |
private val schema = SchemaBuilder.builder().intType() | |
def apply(): org.apache.avro.Schema = schema | |
} | |
implicit object FloatSchemaFor extends SchemaFor[Float] { | |
private val schema = SchemaBuilder.builder().floatType() | |
def apply(): org.apache.avro.Schema = schema | |
} | |
implicit object DoubleSchemaFor extends SchemaFor[Double] { | |
private val schema = SchemaBuilder.builder().doubleType() | |
def apply(): org.apache.avro.Schema = schema | |
} | |
implicit object BooleanSchemaFor extends SchemaFor[Boolean] { | |
private val schema = SchemaBuilder.builder().booleanType() | |
def apply(): org.apache.avro.Schema = schema | |
} | |
implicit object StringSchemaFor extends SchemaFor[String] { | |
private val schema = SchemaBuilder.builder().stringType() | |
def apply(): org.apache.avro.Schema = schema | |
} | |
def fixedSchemaFor[T](name: String, annos: Seq[Anno], namespace: String, size: Int): SchemaFor[T] = { | |
new SchemaFor[T] { | |
private val schema = Schema.createFixed(name, doc(annos), namespace, size) | |
override def apply(): Schema = schema | |
} | |
} | |
def apply[T](implicit schemaFor:SchemaFor[T]): SchemaFor[T] = schemaFor | |
def applyImpl[T: c.WeakTypeTag](c: whitebox.Context): c.Expr[SchemaFor[T]] = { | |
import c.universe | |
import c.universe._ | |
val helper = TypeHelper(c) | |
val tType = weakTypeOf[T] | |
require(tType.typeSymbol.isClass, tType + " is not a class but is " + tType.typeSymbol.fullName) | |
def annotations(sym: Symbol): Seq[c.Tree] = sym.annotations.map { a => | |
val name = a.tree.tpe.typeSymbol.fullName | |
val args = a.tree.children.tail.map(_.toString.stripPrefix("\"").stripSuffix("\"")) | |
q"_root_.com.sksamuel.avro4s.Anno($name, $args)" | |
} | |
lazy val fixedAnnotation: Option[AvroFixed] = tType.typeSymbol.annotations.collectFirst { | |
case anno if anno.tree.tpe <:< c.weakTypeOf[AvroFixed] => | |
anno.tree.children.tail match { | |
case Literal(Constant(size: Int)) :: Nil => AvroFixed(size) | |
} | |
} | |
val valueClass = tType.typeSymbol.isClass && tType.typeSymbol.asClass.isDerivedValueClass && fixedAnnotation.isEmpty | |
val underlyingType = if (valueClass) { | |
tType.typeSymbol.asClass.primaryConstructor.asMethod.paramLists.flatten.head.typeSignature | |
} else { | |
tType | |
} | |
val sealedTraitOrClass = underlyingType.typeSymbol.isClass && underlyingType.typeSymbol.asClass.isSealed | |
// name of the actual class we are building | |
val name = underlyingType.typeSymbol.name.decodedName.toString | |
// the default namespace is just the package name | |
val defaultNamespace = Stream.iterate(underlyingType.typeSymbol.owner)(_.owner).dropWhile(!_.isPackage).head.fullName | |
// we read all annotations into quasi-quotable Anno dtos | |
val annos = annotations(underlyingType.typeSymbol) | |
val fieldSchemaPartTrees: Seq[Tree] = if (sealedTraitOrClass) { | |
c.abort(c.prefix.tree.pos, "Sealed traits/classes should be handled by coproduct generic!") | |
} else { | |
val fields = helper.fieldsOf(underlyingType) | |
fields.zipWithIndex.map { case ((f, sig), index) => | |
val name = f.name | |
// the simple name of the field | |
val fieldName = name.decodedName.toString.trim | |
// the full path of the field, eg a.b.c.Class.value | |
val fieldPath = f.fullName | |
val annos = annotations(f) | |
// this gets the method that generates the default value for this field | |
// (if the field has a default value otherwise its a nosymbol) | |
val ds = universe.asInstanceOf[Definitions with SymbolTable with StdNames] | |
val defaultGetter = ds.nme.defaultGetterName(ds.nme.CONSTRUCTOR, index + 1) | |
val defaultGetterName = TermName(defaultGetter.toString) | |
val member = underlyingType.companion.member(defaultGetterName) | |
if (f.isTerm && f.asTerm.isParamWithDefault && member.isMethod) { | |
q"""{ _root_.com.sksamuel.avro4s.SchemaFor.fieldBuilder[$sig]($fieldName, Seq(..$annos), $member, $defaultNamespace) }""" | |
} else if (f.typeSignature.<:<(typeOf[scala.Enumeration#Value])) { | |
val enumClass = f.typeSignature.toString.stripSuffix(".Value") | |
q"""{ _root_.com.sksamuel.avro4s.SchemaFor.enumBuilder($fieldName, $enumClass) }""" | |
} else { | |
q"""{ _root_.com.sksamuel.avro4s.SchemaFor.fieldBuilder[$sig]($fieldName, Seq(..$annos), null, $defaultNamespace) }""" | |
} | |
} | |
} | |
// we create an explicit ToSchema[T] in the scope of any | |
// fieldBuilder calls, containing the incomplete schema | |
// this is a higher priority implicit than | |
// LowPriorityToSchema.apply(SchemaFor[T]): ToSchema[T], so it | |
// avoids the use of the SchemaFor[T] we're in the middle of generating | |
// that's a good thing, since that depends on completeSchema, | |
// which is a Lazy value that ... depends on the fields we're | |
// generating in those fieldBuilder calls | |
val r = | |
if (valueClass) { | |
c.Expr[SchemaFor[T]]( | |
q""" | |
new _root_.com.sksamuel.avro4s.SchemaFor[$tType] { | |
private val schema: _root_.org.apache.avro.Schema = _root_.com.sksamuel.avro4s.SchemaFor.valueInvoker[$underlyingType] | |
def apply(): _root_.org.apache.avro.Schema = schema | |
} | |
""" | |
) | |
} else { | |
fixedAnnotation match { | |
case Some(AvroFixed(size)) => | |
val expr = c.Expr[SchemaFor[T]]( | |
q"""_root_.com.sksamuel.avro4s.SchemaFor.fixedSchemaFor[$tType]($name, Seq(..$annos), $defaultNamespace, $size)""" | |
) | |
expr | |
case None => | |
c.Expr[SchemaFor[T]]( | |
q""" | |
new _root_.com.sksamuel.avro4s.SchemaFor[$tType] { | |
val (incompleteSchema: _root_.org.apache.avro.Schema, completeSchema: _root_.shapeless.Lazy[_root_.org.apache.avro.Schema]) = { | |
_root_.com.sksamuel.avro4s.SchemaFor.recordBuilder[$tType]( | |
$name, | |
$defaultNamespace, | |
_root_.shapeless.Lazy { | |
val selfSchema = incompleteSchema | |
implicit val _: _root_.com.sksamuel.avro4s.ToSchema[$tType] = new _root_.com.sksamuel.avro4s.ToSchema[$tType] { | |
val schema: _root_.org.apache.avro.Schema = selfSchema | |
} | |
Seq(..$fieldSchemaPartTrees) | |
}, | |
Seq(..$annos) | |
) | |
} | |
def apply(): org.apache.avro.Schema = completeSchema.value | |
} | |
""" | |
) | |
} | |
} | |
println(r) | |
r | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Expr[com.sksamuel.avro4s.SchemaFor[Examples.this.Ingredient]]({ | |
final class $anon extends _root_.com.sksamuel.avro4s.SchemaFor[Examples.this.Ingredient] { | |
def <init>() = { | |
super.<init>(); | |
() | |
}; | |
<synthetic> <artifact> private[this] val x$1 = _root_.com.sksamuel.avro4s.SchemaFor.recordBuilder[Examples.this.Ingredient]("Ingredient", "com.sksamuel.avro4s.examples", _root_.shapeless.Lazy({ | |
val selfSchema = incompleteSchema; | |
implicit val _: _root_.com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient] = { | |
final class $anon extends _root_.com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient] { | |
def <init>() = { | |
super.<init>(); | |
() | |
}; | |
val schema: _root_.org.apache.avro.Schema = selfSchema | |
}; | |
new $anon() | |
}; | |
Seq(_root_.com.sksamuel.avro4s.SchemaFor.fieldBuilder[String]("name", Seq(), null, "com.sksamuel.avro4s.examples"), _root_.com.sksamuel.avro4s.SchemaFor.fieldBuilder[Double]("sugar", Seq(), null, "com.sksamuel.avro4s.examples"), _root_.com.sksamuel.avro4s.SchemaFor.fieldBuilder[Double]("fat", Seq(), null, "com.sksamuel.avro4s.examples")) | |
}), Seq()): @scala.unchecked match { | |
case scala.Tuple2((incompleteSchema @ (_: _root_.org.apache.avro.Schema)), (completeSchema @ (_: _root_.shapeless.Lazy[_root_.org.apache.avro.Schema]))) => scala.Tuple2(incompleteSchema, completeSchema) | |
}; | |
val incompleteSchema: _root_.org.apache.avro.Schema = x$1._1; | |
val completeSchema: _root_.shapeless.Lazy[_root_.org.apache.avro.Schema] = x$1._2; | |
def apply(): org.apache.avro.Schema = completeSchema.value | |
}; | |
new $anon() | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Expr[com.sksamuel.avro4s.SchemaFor[Examples.this.Pizza]]({ | |
final class $anon extends _root_.com.sksamuel.avro4s.SchemaFor[Examples.this.Pizza] { | |
def <init>() = { | |
super.<init>(); | |
() | |
}; | |
<synthetic> <artifact> private[this] val x$1 = _root_.com.sksamuel.avro4s.SchemaFor.recordBuilder[Examples.this.Pizza]("Pizza", "com.sksamuel.avro4s.examples", _root_.shapeless.Lazy({ | |
val selfSchema = incompleteSchema; | |
implicit val _: _root_.com.sksamuel.avro4s.ToSchema[Examples.this.Pizza] = { | |
final class $anon extends _root_.com.sksamuel.avro4s.ToSchema[Examples.this.Pizza] { | |
def <init>() = { | |
super.<init>(); | |
() | |
}; | |
val schema: _root_.org.apache.avro.Schema = selfSchema | |
}; | |
new $anon() | |
}; | |
Seq(_root_.com.sksamuel.avro4s.SchemaFor.fieldBuilder[String]("name", Seq(), null, "com.sksamuel.avro4s.examples"), _root_.com.sksamuel.avro4s.SchemaFor.fieldBuilder[Seq[Examples.this.Ingredient]]("ingredients", Seq(), null, "com.sksamuel.avro4s.examples"), _root_.com.sksamuel.avro4s.SchemaFor.fieldBuilder[Boolean]("vegetarian", Seq(), null, "com.sksamuel.avro4s.examples"), _root_.com.sksamuel.avro4s.SchemaFor.fieldBuilder[Boolean]("vegan", Seq(), null, "com.sksamuel.avro4s.examples"), _root_.com.sksamuel.avro4s.SchemaFor.fieldBuilder[Int]("calories", Seq(), null, "com.sksamuel.avro4s.examples")) | |
}), Seq()): @scala.unchecked match { | |
case scala.Tuple2((incompleteSchema @ (_: _root_.org.apache.avro.Schema)), (completeSchema @ (_: _root_.shapeless.Lazy[_root_.org.apache.avro.Schema]))) => scala.Tuple2(incompleteSchema, completeSchema) | |
}; | |
val incompleteSchema: _root_.org.apache.avro.Schema = x$1._1; | |
val completeSchema: _root_.shapeless.Lazy[_root_.org.apache.avro.Schema] = x$1._2; | |
def apply(): org.apache.avro.Schema = completeSchema.value | |
}; | |
new $anon() | |
}) | |
Expr[com.sksamuel.avro4s.SchemaFor[Examples.this.Ingredient]]({ | |
final class $anon extends _root_.com.sksamuel.avro4s.SchemaFor[Examples.this.Ingredient] { | |
def <init>() = { | |
super.<init>(); | |
() | |
}; | |
<synthetic> <artifact> private[this] val x$2 = _root_.com.sksamuel.avro4s.SchemaFor.recordBuilder[Examples.this.Ingredient]("Ingredient", "com.sksamuel.avro4s.examples", _root_.shapeless.Lazy({ | |
val selfSchema = incompleteSchema; | |
implicit val _: _root_.com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient] = { | |
final class $anon extends _root_.com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient] { | |
def <init>() = { | |
super.<init>(); | |
() | |
}; | |
val schema: _root_.org.apache.avro.Schema = selfSchema | |
}; | |
new $anon() | |
}; | |
Seq(_root_.com.sksamuel.avro4s.SchemaFor.fieldBuilder[String]("name", Seq(), null, "com.sksamuel.avro4s.examples"), _root_.com.sksamuel.avro4s.SchemaFor.fieldBuilder[Double]("sugar", Seq(), null, "com.sksamuel.avro4s.examples"), _root_.com.sksamuel.avro4s.SchemaFor.fieldBuilder[Double]("fat", Seq(), null, "com.sksamuel.avro4s.examples")) | |
}), Seq()): @scala.unchecked match { | |
case scala.Tuple2((incompleteSchema @ (_: _root_.org.apache.avro.Schema)), (completeSchema @ (_: _root_.shapeless.Lazy[_root_.org.apache.avro.Schema]))) => scala.Tuple2(incompleteSchema, completeSchema) | |
}; | |
val incompleteSchema: _root_.org.apache.avro.Schema = x$2._1; | |
val completeSchema: _root_.shapeless.Lazy[_root_.org.apache.avro.Schema] = x$2._2; | |
def apply(): org.apache.avro.Schema = completeSchema.value | |
}; | |
new $anon() | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ToRecord extends LowPriorityToRecord { | |
def apply[T](implicit toRecord:ToRecord[T]): ToRecord[T] = toRecord | |
def materializeImpl[T: c.WeakTypeTag](c: scala.reflect.macros.whitebox.Context): c.Expr[ToRecord[T]] = { | |
import c.universe._ | |
val helper = TypeHelper(c) | |
val tpe = weakTypeTag[T].tpe | |
val constructorArgumentsWithTypes = helper.fieldsOf(tpe) | |
val converters: Seq[Tree] = constructorArgumentsWithTypes.map { case (sym, sig) => | |
helper.fixed(sig.typeSymbol) match { | |
case Some(AvroFixed(_)) => q"""{_root_.shapeless.Lazy(com.sksamuel.avro4s.ToValue.fixed[$sig])}""" | |
case None => q"""_root_.com.sksamuel.avro4s.ToRecord.lazyConverter[$sig]""" | |
} | |
} | |
val puts: Seq[Tree] = constructorArgumentsWithTypes.zipWithIndex.map { | |
case ((sym, sig), idx) => | |
val name = sym.name.asInstanceOf[c.TermName] | |
val fieldName: String = name.decodedName.toString | |
val valueClass = sig.typeSymbol.isClass && sig.typeSymbol.asClass.isDerivedValueClass | |
val typeFixed = helper.fixed(sig.typeSymbol) | |
val fieldFixed = helper.fixed(sym) | |
// if the field has been annotated with fixed then we need to wrap it in a FixedToValue | |
if (typeFixed.nonEmpty) { | |
q""" | |
{ | |
val converter = converters($idx).asInstanceOf[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[$sig]]] | |
record.put($fieldName, converter.value(t.$name : $sig)) | |
} | |
""" | |
// else if the field has been annotated with fixed, then we need to convert | |
// the field value into a byte array | |
} else if (fieldFixed.nonEmpty) { | |
val size = fieldFixed.get.size | |
q""" | |
{ | |
val schema = _root_.org.apache.avro.SchemaBuilder.fixed($fieldName).size($size) | |
val f = new _root_.org.apache.avro.generic.GenericData.Fixed(schema, t.$name.getBytes("UTF-8").array) | |
record.put($fieldName, f) | |
} | |
""" | |
// if a field is a value class we need to handle it here, using a converter | |
// for the underlying value rather than the actual value class | |
} else if (valueClass) { | |
val valueCstr = sig.typeSymbol.asClass.primaryConstructor.asMethod.paramLists.flatten.head | |
val valueFieldType = valueCstr.typeSignature | |
val valueFieldName = valueCstr.name.asInstanceOf[c.TermName] | |
q""" | |
{ | |
val converter = _root_.com.sksamuel.avro4s.ToRecord.lazyConverter[$valueFieldType] | |
record.put($fieldName, converter.value(t.$name.$valueFieldName : $valueFieldType)) | |
} | |
""" | |
} else { | |
q""" | |
{ | |
val converter = converters($idx).asInstanceOf[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[$sig]]] | |
record.put($fieldName, converter.value(t.$name : $sig)) | |
} | |
""" | |
} | |
} | |
val tct = appliedType(symbolOf[SchemaFor[_]].toTypeConstructor, weakTypeOf[T] :: Nil) | |
val schemaForImplicit = c.inferImplicitValue(tct, silent = true, withMacrosDisabled = false) | |
if(schemaForImplicit == EmptyTree){ | |
c.abort(c.enclosingPosition,s"Cannot find implicit SchemaFor in context for type $tct") | |
} | |
val expr = c.Expr[ToRecord[T]]( | |
q"""new _root_.com.sksamuel.avro4s.ToRecord[$tpe] { | |
private val schemaFor : _root_.com.sksamuel.avro4s.SchemaFor[$tpe] = $schemaForImplicit | |
private val converters : Array[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[_]]] = Array(..$converters) | |
def apply(t : $tpe): _root_.org.apache.avro.generic.GenericRecord = { | |
val record = new _root_.org.apache.avro.generic.GenericData.Record(schemaFor()) | |
..$puts | |
record | |
} | |
}""" | |
) | |
println(expr) | |
expr | |
} | |
def lazyConverter[T](implicit toValue: Lazy[ToValue[T]]): Lazy[ToValue[T]] = toValue | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Expr[com.sksamuel.avro4s.ToRecord[Examples.this.Ingredient]]({ | |
final class $anon extends _root_.com.sksamuel.avro4s.ToRecord[Examples.this.Ingredient] { | |
def <init>() = { | |
super.<init>(); | |
() | |
}; | |
private val schemaFor: _root_.com.sksamuel.avro4s.SchemaFor[Examples.this.Ingredient] = { | |
final class $anon extends AnyRef with com.sksamuel.avro4s.SchemaFor[Examples.this.Ingredient] { | |
def <init>(): <$anon: com.sksamuel.avro4s.SchemaFor[Examples.this.Ingredient]> = { | |
$anon.super.<init>(); | |
() | |
}; | |
<synthetic> <artifact> private[this] val x$1: (org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema]) = (com.sksamuel.avro4s.SchemaFor.recordBuilder[Examples.this.Ingredient]("Ingredient", "com.sksamuel.avro4s.examples", shapeless.Lazy.apply[Seq[org.apache.avro.Schema.Field]]({ | |
val selfSchema: org.apache.avro.Schema = $anon.this.incompleteSchema; | |
implicit val _: com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient] = { | |
final class $anon extends AnyRef with com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient] { | |
def <init>(): <$anon: com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient]> = { | |
$anon.super.<init>(); | |
() | |
}; | |
private[this] val schema: org.apache.avro.Schema = selfSchema; | |
<stable> <accessor> def schema: org.apache.avro.Schema = $anon.this.schema | |
}; | |
new $anon() | |
}; | |
collection.this.Seq.apply[org.apache.avro.Schema.Field](com.sksamuel.avro4s.SchemaFor.fieldBuilder[String]("name", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")({ | |
val inst$macro$6: com.sksamuel.avro4s.ToSchema.StringToSchema.type = avro4s.this.ToSchema.StringToSchema.asInstanceOf[com.sksamuel.avro4s.ToSchema.StringToSchema.type]; | |
shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.StringToSchema.type](inst$macro$6) | |
}), com.sksamuel.avro4s.SchemaFor.fieldBuilder[Double]("sugar", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")({ | |
val inst$macro$8: com.sksamuel.avro4s.ToSchema.DoubleToSchema.type = avro4s.this.ToSchema.DoubleToSchema.asInstanceOf[com.sksamuel.avro4s.ToSchema.DoubleToSchema.type]; | |
shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.DoubleToSchema.type](inst$macro$8) | |
}), com.sksamuel.avro4s.SchemaFor.fieldBuilder[Double]("fat", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")({ | |
val inst$macro$10: com.sksamuel.avro4s.ToSchema.DoubleToSchema.type = avro4s.this.ToSchema.DoubleToSchema.asInstanceOf[com.sksamuel.avro4s.ToSchema.DoubleToSchema.type]; | |
shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.DoubleToSchema.type](inst$macro$10) | |
})) | |
}), collection.this.Seq.apply[Nothing]()): (org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema]) @unchecked) match { | |
case (_1: org.apache.avro.Schema, _2: shapeless.Lazy[org.apache.avro.Schema])(org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema])((incompleteSchema @ (_: org.apache.avro.Schema)), (completeSchema @ (_: shapeless.Lazy[org.apache.avro.Schema]))) => scala.Tuple2.apply[org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema]](incompleteSchema, completeSchema) | |
}; | |
private[this] val incompleteSchema: org.apache.avro.Schema = $anon.this.x$1._1; | |
<stable> <accessor> def incompleteSchema: org.apache.avro.Schema = $anon.this.incompleteSchema; | |
private[this] val completeSchema: shapeless.Lazy[org.apache.avro.Schema] = $anon.this.x$1._2; | |
<stable> <accessor> def completeSchema: shapeless.Lazy[org.apache.avro.Schema] = $anon.this.completeSchema; | |
def apply(): org.apache.avro.Schema = $anon.this.completeSchema.value | |
}; | |
new $anon() | |
}; | |
private val converters: Array[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[_$1] forSome { | |
<synthetic> type _$1 | |
}]] = Array(_root_.com.sksamuel.avro4s.ToRecord.lazyConverter[String], _root_.com.sksamuel.avro4s.ToRecord.lazyConverter[Double], _root_.com.sksamuel.avro4s.ToRecord.lazyConverter[Double]); | |
def apply(t: Examples.this.Ingredient): _root_.org.apache.avro.generic.GenericRecord = { | |
val record = new _root_.org.apache.avro.generic.GenericData.Record(schemaFor()); | |
{ | |
val converter = converters(0).asInstanceOf[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[String]]]; | |
record.put("name", converter.value((t.name: String))) | |
}; | |
{ | |
val converter = converters(1).asInstanceOf[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[Double]]]; | |
record.put("sugar", converter.value((t.sugar: Double))) | |
}; | |
{ | |
val converter = converters(2).asInstanceOf[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[Double]]]; | |
record.put("fat", converter.value((t.fat: Double))) | |
}; | |
record | |
} | |
}; | |
new $anon() | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Expr[com.sksamuel.avro4s.ToRecord[Examples.this.Pizza]]({ | |
final class $anon extends _root_.com.sksamuel.avro4s.ToRecord[Examples.this.Pizza] { | |
def <init>() = { | |
super.<init>(); | |
() | |
}; | |
private val schemaFor: _root_.com.sksamuel.avro4s.SchemaFor[Examples.this.Pizza] = { | |
final class $anon extends AnyRef with com.sksamuel.avro4s.SchemaFor[Examples.this.Pizza] { | |
def <init>(): <$anon: com.sksamuel.avro4s.SchemaFor[Examples.this.Pizza]> = { | |
$anon.super.<init>(); | |
() | |
}; | |
<synthetic> <artifact> private[this] val x$1: (org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema]) = (com.sksamuel.avro4s.SchemaFor.recordBuilder[Examples.this.Pizza]("Pizza", "com.sksamuel.avro4s.examples", shapeless.Lazy.apply[Seq[org.apache.avro.Schema.Field]]({ | |
val selfSchema: org.apache.avro.Schema = $anon.this.incompleteSchema; | |
implicit val _: com.sksamuel.avro4s.ToSchema[Examples.this.Pizza] = { | |
final class $anon extends AnyRef with com.sksamuel.avro4s.ToSchema[Examples.this.Pizza] { | |
def <init>(): <$anon: com.sksamuel.avro4s.ToSchema[Examples.this.Pizza]> = { | |
$anon.super.<init>(); | |
() | |
}; | |
private[this] val schema: org.apache.avro.Schema = selfSchema; | |
<stable> <accessor> def schema: org.apache.avro.Schema = $anon.this.schema | |
}; | |
new $anon() | |
}; | |
collection.this.Seq.apply[org.apache.avro.Schema.Field](com.sksamuel.avro4s.SchemaFor.fieldBuilder[String]("name", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")({ | |
val inst$macro$8: com.sksamuel.avro4s.ToSchema.StringToSchema.type = avro4s.this.ToSchema.StringToSchema.asInstanceOf[com.sksamuel.avro4s.ToSchema.StringToSchema.type]; | |
shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.StringToSchema.type](inst$macro$8) | |
}), com.sksamuel.avro4s.SchemaFor.fieldBuilder[Seq[Examples.this.Ingredient]]("ingredients", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")({ | |
val inst$macro$21: com.sksamuel.avro4s.ToSchema[Seq[Examples.this.Ingredient]] = { | |
final class anon$materialize$macro$20 extends AnyRef with Serializable { | |
def <init>(): anon$materialize$macro$20 = { | |
anon$materialize$macro$20.super.<init>(); | |
() | |
}; | |
lazy private[this] var inst$macro$18: com.sksamuel.avro4s.ToSchema.StringToSchema.type = _; | |
<stable> <accessor> lazy def inst$macro$18: com.sksamuel.avro4s.ToSchema.StringToSchema.type = { | |
anon$materialize$macro$20.this.inst$macro$18 = avro4s.this.ToSchema.StringToSchema.asInstanceOf[com.sksamuel.avro4s.ToSchema.StringToSchema.type]; | |
anon$materialize$macro$20.this.inst$macro$18 | |
}; | |
lazy private[this] var inst$macro$19: com.sksamuel.avro4s.ToSchema.DoubleToSchema.type = _; | |
<stable> <accessor> lazy def inst$macro$19: com.sksamuel.avro4s.ToSchema.DoubleToSchema.type = { | |
anon$materialize$macro$20.this.inst$macro$19 = avro4s.this.ToSchema.DoubleToSchema.asInstanceOf[com.sksamuel.avro4s.ToSchema.DoubleToSchema.type]; | |
anon$materialize$macro$20.this.inst$macro$19 | |
}; | |
lazy private[this] var inst$macro$9: com.sksamuel.avro4s.ToSchema[Seq[Examples.this.Ingredient]] = _; | |
<stable> <accessor> lazy def inst$macro$9: com.sksamuel.avro4s.ToSchema[Seq[Examples.this.Ingredient]] = { | |
anon$materialize$macro$20.this.inst$macro$9 = avro4s.this.ToSchema.SeqToSchema[Examples.this.Ingredient](avro4s.this.ToSchema.apply[Examples.this.Ingredient](reflect.this.ManifestFactory.classType[Examples.this.Ingredient](reflect.this.ManifestFactory.singleType[Examples.this.type](Examples.this), classOf[com.sksamuel.avro4s.examples.Examples$Ingredient]), { | |
final class $anon extends AnyRef with com.sksamuel.avro4s.SchemaFor[Examples.this.Ingredient] { | |
def <init>(): <$anon: com.sksamuel.avro4s.SchemaFor[Examples.this.Ingredient]> = { | |
$anon.super.<init>(); | |
() | |
}; | |
<synthetic> <artifact> private[this] val x$2: (org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema]) = (com.sksamuel.avro4s.SchemaFor.recordBuilder[Examples.this.Ingredient]("Ingredient", "com.sksamuel.avro4s.examples", shapeless.Lazy.apply[Seq[org.apache.avro.Schema.Field]]({ | |
val selfSchema: org.apache.avro.Schema = $anon.this.incompleteSchema; | |
implicit val _: com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient] = { | |
final class $anon extends AnyRef with com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient] { | |
def <init>(): <$anon: com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient]> = { | |
$anon.super.<init>(); | |
() | |
}; | |
private[this] val schema: org.apache.avro.Schema = selfSchema; | |
<stable> <accessor> def schema: org.apache.avro.Schema = $anon.this.schema | |
}; | |
new $anon() | |
}; | |
collection.this.Seq.apply[org.apache.avro.Schema.Field](com.sksamuel.avro4s.SchemaFor.fieldBuilder[String]("name", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")(shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.StringToSchema.type](anon$materialize$macro$20.this.inst$macro$18)), com.sksamuel.avro4s.SchemaFor.fieldBuilder[Double]("sugar", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")(shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.DoubleToSchema.type](anon$materialize$macro$20.this.inst$macro$19)), com.sksamuel.avro4s.SchemaFor.fieldBuilder[Double]("fat", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")(shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.DoubleToSchema.type](anon$materialize$macro$20.this.inst$macro$19))) | |
}), collection.this.Seq.apply[Nothing]()): (com.sksamuel.avro4s.SchemaFor.recordBuilder[Examples.this.Ingredient]("Ingredient", "com.sksamuel.avro4s.examples", shapeless.Lazy.apply[Seq[org.apache.avro.Schema.Field]]({ | |
val selfSchema: org.apache.avro.Schema = $anon.this.incompleteSchema; | |
implicit val _: com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient] = { | |
final class $anon extends AnyRef with com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient] { | |
def <init>(): <$anon: com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient]> = { | |
$anon.super.<init>(); | |
() | |
}; | |
private[this] val schema: org.apache.avro.Schema = selfSchema; | |
<stable> <accessor> def schema: org.apache.avro.Schema = $anon.this.schema | |
}; | |
new $anon() | |
}; | |
collection.this.Seq.apply[org.apache.avro.Schema.Field](com.sksamuel.avro4s.SchemaFor.fieldBuilder[String]("name", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")(shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.StringToSchema.type](anon$materialize$macro$20.this.inst$macro$18)), com.sksamuel.avro4s.SchemaFor.fieldBuilder[Double]("sugar", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")(shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.DoubleToSchema.type](anon$materialize$macro$20.this.inst$macro$19)), com.sksamuel.avro4s.SchemaFor.fieldBuilder[Double]("fat", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")(shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.DoubleToSchema.type](anon$materialize$macro$20.this.inst$macro$19))) | |
}), collection.this.Seq.apply[Nothing]()): (org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema]) @unchecked)) match { | |
case (_1: org.apache.avro.Schema, _2: shapeless.Lazy[org.apache.avro.Schema])(org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema])((incompleteSchema @ (_: org.apache.avro.Schema)), (completeSchema @ (_: shapeless.Lazy[org.apache.avro.Schema]))) => scala.Tuple2.apply[org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema]](incompleteSchema, completeSchema) | |
}; | |
private[this] val incompleteSchema: org.apache.avro.Schema = $anon.this.x$2._1; | |
<stable> <accessor> private def incompleteSchema: org.apache.avro.Schema = $anon.this.incompleteSchema; | |
private[this] val completeSchema: shapeless.Lazy[org.apache.avro.Schema] = $anon.this.x$2._2; | |
<stable> <accessor> private def completeSchema: shapeless.Lazy[org.apache.avro.Schema] = $anon.this.completeSchema; | |
def apply(): org.apache.avro.Schema = $anon.this.completeSchema.value | |
}; | |
new $anon() | |
})).asInstanceOf[com.sksamuel.avro4s.ToSchema[Seq[Examples.this.Ingredient]]]; | |
anon$materialize$macro$20.this.inst$macro$9 | |
} | |
}; | |
new anon$materialize$macro$20().inst$macro$9 | |
}; | |
shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema[Seq[Examples.this.Ingredient]]](inst$macro$21) | |
}), com.sksamuel.avro4s.SchemaFor.fieldBuilder[Boolean]("vegetarian", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")({ | |
val inst$macro$23: com.sksamuel.avro4s.ToSchema.BooleanToSchema.type = avro4s.this.ToSchema.BooleanToSchema.asInstanceOf[com.sksamuel.avro4s.ToSchema.BooleanToSchema.type]; | |
shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.BooleanToSchema.type](inst$macro$23) | |
}), com.sksamuel.avro4s.SchemaFor.fieldBuilder[Boolean]("vegan", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")({ | |
val inst$macro$25: com.sksamuel.avro4s.ToSchema.BooleanToSchema.type = avro4s.this.ToSchema.BooleanToSchema.asInstanceOf[com.sksamuel.avro4s.ToSchema.BooleanToSchema.type]; | |
shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.BooleanToSchema.type](inst$macro$25) | |
}), com.sksamuel.avro4s.SchemaFor.fieldBuilder[Int]("calories", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")({ | |
val inst$macro$27: com.sksamuel.avro4s.ToSchema.IntToSchema.type = avro4s.this.ToSchema.IntToSchema.asInstanceOf[com.sksamuel.avro4s.ToSchema.IntToSchema.type]; | |
shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.IntToSchema.type](inst$macro$27) | |
})) | |
}), collection.this.Seq.apply[Nothing]()): (org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema]) @unchecked) match { | |
case (_1: org.apache.avro.Schema, _2: shapeless.Lazy[org.apache.avro.Schema])(org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema])((incompleteSchema @ (_: org.apache.avro.Schema)), (completeSchema @ (_: shapeless.Lazy[org.apache.avro.Schema]))) => scala.Tuple2.apply[org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema]](incompleteSchema, completeSchema) | |
}; | |
private[this] val incompleteSchema: org.apache.avro.Schema = $anon.this.x$1._1; | |
<stable> <accessor> def incompleteSchema: org.apache.avro.Schema = $anon.this.incompleteSchema; | |
private[this] val completeSchema: shapeless.Lazy[org.apache.avro.Schema] = $anon.this.x$1._2; | |
<stable> <accessor> def completeSchema: shapeless.Lazy[org.apache.avro.Schema] = $anon.this.completeSchema; | |
def apply(): org.apache.avro.Schema = $anon.this.completeSchema.value | |
}; | |
new $anon() | |
}; | |
private val converters: Array[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[_$1] forSome { | |
<synthetic> type _$1 | |
}]] = Array(_root_.com.sksamuel.avro4s.ToRecord.lazyConverter[String], _root_.com.sksamuel.avro4s.ToRecord.lazyConverter[Seq[Examples.this.Ingredient]], _root_.com.sksamuel.avro4s.ToRecord.lazyConverter[Boolean], _root_.com.sksamuel.avro4s.ToRecord.lazyConverter[Boolean], _root_.com.sksamuel.avro4s.ToRecord.lazyConverter[Int]); | |
def apply(t: Examples.this.Pizza): _root_.org.apache.avro.generic.GenericRecord = { | |
val record = new _root_.org.apache.avro.generic.GenericData.Record(schemaFor()); | |
{ | |
val converter = converters(0).asInstanceOf[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[String]]]; | |
record.put("name", converter.value((t.name: String))) | |
}; | |
{ | |
val converter = converters(1).asInstanceOf[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[Seq[Examples.this.Ingredient]]]]; | |
record.put("ingredients", converter.value((t.ingredients: Seq[Examples.this.Ingredient]))) | |
}; | |
{ | |
val converter = converters(2).asInstanceOf[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[Boolean]]]; | |
record.put("vegetarian", converter.value((t.vegetarian: Boolean))) | |
}; | |
{ | |
val converter = converters(3).asInstanceOf[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[Boolean]]]; | |
record.put("vegan", converter.value((t.vegan: Boolean))) | |
}; | |
{ | |
val converter = converters(4).asInstanceOf[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[Int]]]; | |
record.put("calories", converter.value((t.calories: Int))) | |
}; | |
record | |
} | |
}; | |
new $anon() | |
}) | |
Expr[com.sksamuel.avro4s.ToRecord[Examples.this.Ingredient]]({ | |
final class $anon extends _root_.com.sksamuel.avro4s.ToRecord[Examples.this.Ingredient] { | |
def <init>() = { | |
super.<init>(); | |
() | |
}; | |
private val schemaFor: _root_.com.sksamuel.avro4s.SchemaFor[Examples.this.Ingredient] = { | |
final class $anon extends AnyRef with com.sksamuel.avro4s.SchemaFor[Examples.this.Ingredient] { | |
def <init>(): <$anon: com.sksamuel.avro4s.SchemaFor[Examples.this.Ingredient]> = { | |
$anon.super.<init>(); | |
() | |
}; | |
<synthetic> <artifact> private[this] val x$7: (org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema]) = (com.sksamuel.avro4s.SchemaFor.recordBuilder[Examples.this.Ingredient]("Ingredient", "com.sksamuel.avro4s.examples", shapeless.Lazy.apply[Seq[org.apache.avro.Schema.Field]]({ | |
val selfSchema: org.apache.avro.Schema = $anon.this.incompleteSchema; | |
implicit val _: com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient] = { | |
final class $anon extends AnyRef with com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient] { | |
def <init>(): <$anon: com.sksamuel.avro4s.ToSchema[Examples.this.Ingredient]> = { | |
$anon.super.<init>(); | |
() | |
}; | |
private[this] val schema: org.apache.avro.Schema = selfSchema; | |
<stable> <accessor> def schema: org.apache.avro.Schema = $anon.this.schema | |
}; | |
new $anon() | |
}; | |
collection.this.Seq.apply[org.apache.avro.Schema.Field](com.sksamuel.avro4s.SchemaFor.fieldBuilder[String]("name", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")(shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.StringToSchema.type](inst$macro$39)), com.sksamuel.avro4s.SchemaFor.fieldBuilder[Double]("sugar", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")(shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.DoubleToSchema.type](inst$macro$40)), com.sksamuel.avro4s.SchemaFor.fieldBuilder[Double]("fat", collection.this.Seq.apply[Nothing](), null, "com.sksamuel.avro4s.examples")(shapeless.Lazy.apply[com.sksamuel.avro4s.ToSchema.DoubleToSchema.type](inst$macro$40))) | |
}), collection.this.Seq.apply[Nothing]()): (org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema]) @unchecked) match { | |
case (_1: org.apache.avro.Schema, _2: shapeless.Lazy[org.apache.avro.Schema])(org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema])((incompleteSchema @ (_: org.apache.avro.Schema)), (completeSchema @ (_: shapeless.Lazy[org.apache.avro.Schema]))) => scala.Tuple2.apply[org.apache.avro.Schema, shapeless.Lazy[org.apache.avro.Schema]](incompleteSchema, completeSchema) | |
}; | |
private[this] val incompleteSchema: org.apache.avro.Schema = $anon.this.x$7._1; | |
<stable> <accessor> def incompleteSchema: org.apache.avro.Schema = $anon.this.incompleteSchema; | |
private[this] val completeSchema: shapeless.Lazy[org.apache.avro.Schema] = $anon.this.x$7._2; | |
<stable> <accessor> def completeSchema: shapeless.Lazy[org.apache.avro.Schema] = $anon.this.completeSchema; | |
def apply(): org.apache.avro.Schema = $anon.this.completeSchema.value | |
}; | |
new $anon() | |
}; | |
private val converters: Array[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[_$2] forSome { | |
<synthetic> type _$2 | |
}]] = Array(_root_.com.sksamuel.avro4s.ToRecord.lazyConverter[String], _root_.com.sksamuel.avro4s.ToRecord.lazyConverter[Double], _root_.com.sksamuel.avro4s.ToRecord.lazyConverter[Double]); | |
def apply(t: Examples.this.Ingredient): _root_.org.apache.avro.generic.GenericRecord = { | |
val record = new _root_.org.apache.avro.generic.GenericData.Record(schemaFor()); | |
{ | |
val converter = converters(0).asInstanceOf[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[String]]]; | |
record.put("name", converter.value((t.name: String))) | |
}; | |
{ | |
val converter = converters(1).asInstanceOf[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[Double]]]; | |
record.put("sugar", converter.value((t.sugar: Double))) | |
}; | |
{ | |
val converter = converters(2).asInstanceOf[_root_.shapeless.Lazy[_root_.com.sksamuel.avro4s.ToValue[Double]]]; | |
record.put("fat", converter.value((t.fat: Double))) | |
}; | |
record | |
} | |
}; | |
new $anon() | |
}) | |
[error] symbol value inst$macro$39#81224 does not exist in com.sksamuel.avro4s.examples.Examples$$anonfun$1$$anonfun$apply$mcV$sp$1$$anon$1$anon$lazy$macro$75$1$$anon$2$$anon$8$$anonfun$7$$anonfun$apply$15.apply, which contains locals . | |
[error] Method code: final def apply(): com#9.sksamuel#8242.avro4s#8246.ToSchema$StringToSchema#55746.type = inst$macro$39 | |
[trace] Stack trace suppressed: run last avro4s-core/test:compileIncremental for the full output. | |
[error] (avro4s-core/test:compileIncremental) scala.reflect.internal.FatalError: symbol value inst$macro$39#81224 does not exist in com.sksamuel.avro4s.examples.Examples$$anonfun$1$$anonfun$apply$mcV$sp$1$$anon$1$anon$lazy$macro$75$1$$anon$2$$anon$8$$anonfun$7$$anonfun$apply$15.apply, which contains locals . | |
[error] Method code: final def apply(): com#9.sksamuel#8242.avro4s#8246.ToSchema$StringToSchema#55746.type = inst$macro$39 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment