Skip to content

Commit

Permalink
refactor for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Nov 11, 2024
1 parent d156026 commit abe7c7e
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ private def renderUnion(u: Type.Union): String = {
// format: on
}

val instanceMethods =
show"""extension (node: $name) {
|${projections.mkString_("\n").indentTrim(2)}
|}""".stripMargin

val applyMethod = {
val cases = u
.subtypes
Expand All @@ -69,9 +74,7 @@ private def renderUnion(u: Type.Union): String = {
|
|object $name {
|
| extension (node: $name) {
|${projections.mkString_("\n").indentTrim(4)}
| }
|${instanceMethods.indentTrim(2)}
|
|${applyMethod.indentTrim(2)}
|
Expand Down Expand Up @@ -164,7 +167,7 @@ private def renderProduct(p: Type.Product): String = {
show"""def ${fieldType.asChildName.render}: $fieldTypeAnnotation = $childValue""".stripMargin
}

val methods =
val instanceMethods =
if (fieldGetters.nonEmpty || typedChildren.nonEmpty || typedChildrenPrecise.nonEmpty) {
show"""extension (node: $name) {
| // fields
Expand All @@ -185,7 +188,7 @@ private def renderProduct(p: Type.Product): String = {
|opaque type $name <: Node = Node
|
|object $name {
|${methods.indentTrim(2)}
|${instanceMethods.indentTrim(2)}
|
| def apply(node: Node): Either[String, $name] =
| if node.tpe == ${p.name.value.literal}
Expand Down

0 comments on commit abe7c7e

Please sign in to comment.