Skip to content

Commit

Permalink
fixing identity origin + adding test to check it
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagobstr committed Feb 11, 2025
1 parent a20fa9a commit 4bed72b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ val IDENTTITY_TRANSFORMATION: (

val newInstance = primaryConstructor.callBy(params) as Node
newInstance.parent = parent
newInstance.origin = source
listOf(newInstance)
}
else -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,30 @@ class ASTTransformerTest {
transformer1.transform(original) as AA
)
}
}

@Test
fun testIdentityTransformationOfIntermediateNodesWithOrigin() {
val transformer1 = ASTTransformer(defaultTransformation = IDENTTITY_TRANSFORMATION)
transformer1.registerNodeFactory(AA::class) { original, t, _ ->
BA("your_" + original.a.removePrefix("my_"), t.translateCasted(original.child))
}
val original = AA(
a = "my_a",
child = AB(
b = "my_b",
child = AC(
c = "my_c",
children = mutableListOf(
AD("my_d1")
)
)
)
)
val transformedAST = transformer1.transform(original) as AA
// verify that the origin is set correctly
assert(transformedAST.origin == original)
}
}
data class BazRoot(var stmts: MutableList<BazStmt> = mutableListOf()) : Node()

data class BazStmt(val desc: String? = null) : Node()
Expand Down

0 comments on commit 4bed72b

Please sign in to comment.