Skip to content

Commit

Permalink
Support parsing inner class instantiation via this
Browse files Browse the repository at this point in the history
Properly support parsing expressions like `this.Foo()` where `Foo` is the name of an inner class declared in the scope of the type denoted by `this`.
  • Loading branch information
knutwannheden committed Feb 7, 2024
1 parent 43a3ef4 commit b26d6fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2490,7 +2490,7 @@ public J visitDotQualifiedExpression(KtDotQualifiedExpression expression, Execut
.withPrefix(prefix);
} else if (j instanceof J.NewClass) {
J.NewClass n = (J.NewClass) j;
if (receiver instanceof J.FieldAccess || receiver instanceof J.Identifier || receiver instanceof J.NewClass) {
if (receiver instanceof J.FieldAccess || receiver instanceof J.Identifier || receiver instanceof J.NewClass || receiver instanceof K.This) {
n = n.withPrefix(prefix);
if (n.getClazz() instanceof J.ParameterizedType) {
J.ParameterizedType pt = (J.ParameterizedType) n.getClazz();
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/org/openrewrite/kotlin/tree/ThisTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,18 @@ override fun iterator(): MutableIterator<MutableEntry<K, V>> {
)
);
}

@Test
void innerClass() {
rewriteRun(
kotlin(
"""
class Foo {
fun bar() = this.Bar()
inner class Bar
}
"""
)
);
}
}

0 comments on commit b26d6fa

Please sign in to comment.