Closed traceyyoshima closed 5 months ago
this is a full test
@Test
void innerClassInvocation() {
rewriteRun(
kotlin(
"""
class Pony2 {
inner class Builder
companion object {
fun newBuilder() = Pony2().Builder()
}
}
"""
)
);
}
The root cause here is both Pony2()
and Builder()
are KtCallExpression
, we translate KtCallExpression
to different LST models by types from FIR, for this case, both are CONSTRUCTOR
types here, so they are all turned into two J.NewClass
here.
@traceyyoshima , what do you think about the solution for this?
For context here is the diff this test produces:
diff --git a/openRewriteFile.kt b/openRewriteFile.kt
index e84a1aa..79e2d9d 100644
--- a/openRewriteFile.kt
+++ b/openRewriteFile.kt
@@ -2,6 +2,6 @@
inner class Builder
companion object {
- fun newBuilder() = Pony2().Builder()
+ fun newBuilder() = Builder()
}
}
Reference: https://github.com/evitwilly/Kotlin-Algorithms-and-Design-Patterns/blob/develop/src/main/kotlin/design_patterns/Builder.kt