Skip to content

Commit

Permalink
Fix 376
Browse files Browse the repository at this point in the history
  • Loading branch information
kunli2 committed Nov 10, 2023
1 parent 4f67c21 commit 4fb2f02
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2278,9 +2278,29 @@ public J visitDotQualifiedExpression(KtDotQualifiedExpression expression, Execut
assert expression.getSelectorExpression() != null;
if (expression.getSelectorExpression() instanceof KtCallExpression) {
KtCallExpression callExpression = (KtCallExpression) expression.getSelectorExpression();
J j = callExpression.accept(this, data);
Expression receiver = convertToExpression(expression.getReceiverExpression().accept(this, data));

if (j instanceof J.ParameterizedType) {
J.ParameterizedType pt = (J.ParameterizedType) j;
if (pt != null) {
pt = pt.withClazz(pt.getClazz().withPrefix(prefix(callExpression)));
J.FieldAccess newName = new J.FieldAccess(
randomId(),
receiver.getPrefix(),
Markers.EMPTY,
receiver.withPrefix(Space.EMPTY),
padLeft(suffix(expression.getReceiverExpression()), (J.Identifier) pt.getClazz()),
pt.getType()
);
pt = pt.withClazz(newName);
}

return pt;
}

MethodCall methodInvocation = (MethodCall) callExpression.accept(this, data);

Expression receiver = convertToExpression(expression.getReceiverExpression().accept(this, data));
if (methodInvocation instanceof J.MethodInvocation) {
methodInvocation = ((J.MethodInvocation) methodInvocation).getPadding().withSelect(padRight(receiver, suffix(expression.getReceiverExpression())))
.withName(((J.MethodInvocation) methodInvocation).getName().withPrefix(prefix(callExpression)))
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/openrewrite/kotlin/tree/MethodReferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,17 @@ void anonymousClassArgument() {
)
);
}

@Issue("https://github.com/openrewrite/rewrite-kotlin/issues/376")
@Test
void memberReferenceWithParameterizedType() {
rewriteRun(
kotlin(
"""
val x: MutableMap<String, String> = hashMapOf()
val keys = x.entries.map(MutableMap.MutableEntry<String, String>::key)
"""
)
);
}
}

1 comment on commit 4fb2f02

@kunli2
Copy link
Contributor Author

@kunli2 kunli2 commented on 4fb2f02 Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes #376

Please sign in to comment.