Skip to content

Commit f070ddb

Browse files
committed
style: format migration builder code
1 parent 669167f commit f070ddb

3 files changed

Lines changed: 43 additions & 26 deletions

File tree

‎schema/shared/src/main/scala-2/zio/blocks/schema/migration/MigrationBuilder.scala‎

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import scala.language.experimental.macros
44
import zio.blocks.schema.{DynamicOptic, Schema, SchemaExpr}
55

66
/**
7-
* Phantom type wrapper to preserve literal string types through macro expansion.
8-
* Direct use of ConstantType causes literal types to widen to String.
9-
* By wrapping in FieldName[N], the type argument is preserved when using appliedType.
7+
* Phantom type wrapper to preserve literal string types through macro
8+
* expansion. Direct use of ConstantType causes literal types to widen to
9+
* String. By wrapping in FieldName[N], the type argument is preserved when
10+
* using appliedType.
1011
*/
1112
sealed trait FieldName[N]
1213

@@ -49,7 +50,8 @@ final class MigrationBuilder[A, B, SourceHandled, TargetProvided](
4950
def addField(
5051
target: B => Any,
5152
default: SchemaExpr[_, _]
52-
): MigrationBuilder[A, B, SourceHandled, _] = macro MigrationBuilderMacros.addFieldImpl[A, B, SourceHandled, TargetProvided]
53+
): MigrationBuilder[A, B, SourceHandled, _] = macro
54+
MigrationBuilderMacros.addFieldImpl[A, B, SourceHandled, TargetProvided]
5355

5456
/**
5557
* Drop a field from the source.
@@ -63,7 +65,8 @@ final class MigrationBuilder[A, B, SourceHandled, TargetProvided](
6365
def dropField(
6466
source: A => Any,
6567
defaultForReverse: SchemaExpr[_, _]
66-
): MigrationBuilder[A, B, _, TargetProvided] = macro MigrationBuilderMacros.dropFieldImpl[A, B, SourceHandled, TargetProvided]
68+
): MigrationBuilder[A, B, _, TargetProvided] = macro
69+
MigrationBuilderMacros.dropFieldImpl[A, B, SourceHandled, TargetProvided]
6770

6871
/**
6972
* Rename a field from source to target.
@@ -111,7 +114,8 @@ final class MigrationBuilder[A, B, SourceHandled, TargetProvided](
111114
def optionalizeField(
112115
source: A => Any,
113116
target: B => Option[_]
114-
): MigrationBuilder[A, B, _, _] = macro MigrationBuilderMacros.optionalizeFieldImpl[A, B, SourceHandled, TargetProvided]
117+
): MigrationBuilder[A, B, _, _] = macro
118+
MigrationBuilderMacros.optionalizeFieldImpl[A, B, SourceHandled, TargetProvided]
115119

116120
/**
117121
* Change the type of a field (primitive-to-primitive only).
@@ -127,7 +131,8 @@ final class MigrationBuilder[A, B, SourceHandled, TargetProvided](
127131
source: A => Any,
128132
target: B => Any,
129133
converter: SchemaExpr[_, _]
130-
): MigrationBuilder[A, B, _, _] = macro MigrationBuilderMacros.changeFieldTypeImpl[A, B, SourceHandled, TargetProvided]
134+
): MigrationBuilder[A, B, _, _] = macro
135+
MigrationBuilderMacros.changeFieldTypeImpl[A, B, SourceHandled, TargetProvided]
131136

132137
// ----- Enum operations -----
133138

@@ -169,7 +174,8 @@ final class MigrationBuilder[A, B, SourceHandled, TargetProvided](
169174
def transformElements(
170175
at: A => Iterable[_],
171176
transform: SchemaExpr[_, _]
172-
): MigrationBuilder[A, B, SourceHandled, TargetProvided] = macro MigrationBuilderMacros.transformElementsImpl[A, B, SourceHandled, TargetProvided]
177+
): MigrationBuilder[A, B, SourceHandled, TargetProvided] = macro
178+
MigrationBuilderMacros.transformElementsImpl[A, B, SourceHandled, TargetProvided]
173179

174180
// ----- Maps -----
175181

@@ -184,7 +190,8 @@ final class MigrationBuilder[A, B, SourceHandled, TargetProvided](
184190
def transformKeys(
185191
at: A => Map[_, _],
186192
transform: SchemaExpr[_, _]
187-
): MigrationBuilder[A, B, SourceHandled, TargetProvided] = macro MigrationBuilderMacros.transformKeysImpl[A, B, SourceHandled, TargetProvided]
193+
): MigrationBuilder[A, B, SourceHandled, TargetProvided] = macro
194+
MigrationBuilderMacros.transformKeysImpl[A, B, SourceHandled, TargetProvided]
188195

189196
/**
190197
* Transform each value in a map.
@@ -197,13 +204,14 @@ final class MigrationBuilder[A, B, SourceHandled, TargetProvided](
197204
def transformValues(
198205
at: A => Map[_, _],
199206
transform: SchemaExpr[_, _]
200-
): MigrationBuilder[A, B, SourceHandled, TargetProvided] = macro MigrationBuilderMacros.transformValuesImpl[A, B, SourceHandled, TargetProvided]
207+
): MigrationBuilder[A, B, SourceHandled, TargetProvided] = macro
208+
MigrationBuilderMacros.transformValuesImpl[A, B, SourceHandled, TargetProvided]
201209

202210
// ----- Build -----
203211

204212
/**
205-
* Build migration with full macro validation.
206-
* Requires implicit evidence that all source fields are handled and all target fields are provided.
213+
* Build migration with full macro validation. Requires implicit evidence that
214+
* all source fields are handled and all target fields are provided.
207215
*/
208216
def build(implicit ev: MigrationComplete[A, B, SourceHandled, TargetProvided]): Migration[A, B] =
209217
new Migration(sourceSchema, targetSchema, new DynamicMigration(actions))
@@ -229,8 +237,8 @@ object MigrationBuilder {
229237
}
230238

231239
/**
232-
* Evidence that a migration is complete.
233-
* All source fields must be handled and all target fields must be provided.
240+
* Evidence that a migration is complete. All source fields must be handled and
241+
* all target fields must be provided.
234242
*/
235243
trait MigrationComplete[-A, -B, -SourceHandled, -TargetProvided]
236244

@@ -241,6 +249,6 @@ object MigrationComplete {
241249
private val instance: MigrationComplete[Any, Any, Any, Any] =
242250
new MigrationComplete[Any, Any, Any, Any] {}
243251

244-
implicit def derive[A, B, SH, TP]: MigrationComplete[A, B, SH, TP] =
245-
macro MigrationValidationMacros.validateMigrationImpl[A, B, SH, TP]
252+
implicit def derive[A, B, SH, TP]: MigrationComplete[A, B, SH, TP] = macro
253+
MigrationValidationMacros.validateMigrationImpl[A, B, SH, TP]
246254
}

‎schema/shared/src/main/scala-2/zio/blocks/schema/migration/MigrationBuilderSyntax.scala‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import scala.reflect.macros.whitebox
44
import zio.blocks.schema.SchemaExpr
55

66
/**
7-
* Macro implementations for MigrationBuilder methods.
8-
* Each macro returns a refined type that accumulates field names in the type parameters.
7+
* Macro implementations for MigrationBuilder methods. Each macro returns a
8+
* refined type that accumulates field names in the type parameters.
99
*/
1010
object MigrationBuilderMacros {
1111

@@ -27,7 +27,8 @@ object MigrationBuilderMacros {
2727
}
2828

2929
/**
30-
* Create a FieldName[fieldName] type wrapped in a refined type with the current type.
30+
* Create a FieldName[fieldName] type wrapped in a refined type with the
31+
* current type.
3132
*/
3233
private def createRefinedType(c: whitebox.Context)(currentType: c.Type, fieldName: String): c.Type = {
3334
import c.universe._
@@ -199,7 +200,9 @@ object MigrationBuilderMacros {
199200
}"""
200201
}
201202

202-
def optionalizeFieldImpl[A: c.WeakTypeTag, B: c.WeakTypeTag, SH: c.WeakTypeTag, TP: c.WeakTypeTag](c: whitebox.Context)(
203+
def optionalizeFieldImpl[A: c.WeakTypeTag, B: c.WeakTypeTag, SH: c.WeakTypeTag, TP: c.WeakTypeTag](
204+
c: whitebox.Context
205+
)(
203206
source: c.Expr[A => Any],
204207
target: c.Expr[B => Option[_]]
205208
): c.Tree = {
@@ -230,7 +233,9 @@ object MigrationBuilderMacros {
230233
}"""
231234
}
232235

233-
def changeFieldTypeImpl[A: c.WeakTypeTag, B: c.WeakTypeTag, SH: c.WeakTypeTag, TP: c.WeakTypeTag](c: whitebox.Context)(
236+
def changeFieldTypeImpl[A: c.WeakTypeTag, B: c.WeakTypeTag, SH: c.WeakTypeTag, TP: c.WeakTypeTag](
237+
c: whitebox.Context
238+
)(
234239
source: c.Expr[A => Any],
235240
target: c.Expr[B => Any],
236241
converter: c.Expr[SchemaExpr[_, _]]
@@ -265,7 +270,9 @@ object MigrationBuilderMacros {
265270
}"""
266271
}
267272

268-
def transformElementsImpl[A: c.WeakTypeTag, B: c.WeakTypeTag, SH: c.WeakTypeTag, TP: c.WeakTypeTag](c: whitebox.Context)(
273+
def transformElementsImpl[A: c.WeakTypeTag, B: c.WeakTypeTag, SH: c.WeakTypeTag, TP: c.WeakTypeTag](
274+
c: whitebox.Context
275+
)(
269276
at: c.Expr[A => Iterable[_]],
270277
transform: c.Expr[SchemaExpr[_, _]]
271278
): c.Tree = {
@@ -317,7 +324,9 @@ object MigrationBuilderMacros {
317324
}"""
318325
}
319326

320-
def transformValuesImpl[A: c.WeakTypeTag, B: c.WeakTypeTag, SH: c.WeakTypeTag, TP: c.WeakTypeTag](c: whitebox.Context)(
327+
def transformValuesImpl[A: c.WeakTypeTag, B: c.WeakTypeTag, SH: c.WeakTypeTag, TP: c.WeakTypeTag](
328+
c: whitebox.Context
329+
)(
321330
at: c.Expr[A => Map[_, _]],
322331
transform: c.Expr[SchemaExpr[_, _]]
323332
): c.Tree = {

‎schema/shared/src/main/scala-3/zio/blocks/schema/migration/MigrationValidationMacros.scala‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ object MigrationValidationMacros {
6161
def extract(tpe: TypeRepr): Set[String] = {
6262
val dealiased = tpe.dealias
6363
dealiased match {
64-
case AndType(left, right) => extract(left) ++ extract(right)
65-
case ConstantType(StringConstant(s)) => Set(s)
66-
case t if t =:= TypeRepr.of[Any] => Set.empty
64+
case AndType(left, right) => extract(left) ++ extract(right)
65+
case ConstantType(StringConstant(s)) => Set(s)
66+
case t if t =:= TypeRepr.of[Any] => Set.empty
6767
case AppliedType(tycon, List(field)) if tycon.typeSymbol.name == "FieldName" =>
6868
extract(field)
6969
case _ => Set.empty

0 commit comments

Comments
 (0)