Skip to content

Commit

Permalink
Take J.Case statements into account in JavaTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurens-W committed Dec 4, 2024
1 parent c30f37d commit e5e68c4
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,17 @@ private void contextTemplate(Cursor cursor, J prior, StringBuilder before, Strin
// If prior is a type parameter, wrap in __M__.anyT<prior>()
// For anything else, ignore the invocation
J.MethodInvocation m = (J.MethodInvocation) j;
J firstEnclosing = cursor.getParentOrThrow().firstEnclosing(J.class);
if (m.getArguments().stream().anyMatch(arg -> referToSameElement(prior, arg))) {
before.insert(0, "__M__.any(");
if (cursor.getParentOrThrow().firstEnclosing(J.class) instanceof J.Block) {
if (firstEnclosing instanceof J.Block || firstEnclosing instanceof J.Case) {
after.append(");");
} else {
after.append(")");
}
} else if (m.getTypeParameters() != null && m.getTypeParameters().stream().anyMatch(tp -> referToSameElement(prior, tp))) {
before.insert(0, "__M__.anyT<");
if (cursor.getParentOrThrow().firstEnclosing(J.class) instanceof J.Block) {
if (firstEnclosing instanceof J.Block || firstEnclosing instanceof J.Case) {
after.append(">();");
} else {
after.append(">()");
Expand All @@ -481,7 +482,7 @@ private void contextTemplate(Cursor cursor, J prior, StringBuilder before, Strin
List<Comment> comments = new ArrayList<>(1);
comments.add(new TextComment(true, STOP_COMMENT, "", Markers.EMPTY));
after.append(".").append(m.withSelect(null).withComments(comments).printTrimmed(cursor.getParentOrThrow()));
if (cursor.getParentOrThrow().firstEnclosing(J.class) instanceof J.Block) {
if (firstEnclosing instanceof J.Block || firstEnclosing instanceof J.Case) {
after.append(";");
}
}
Expand Down

0 comments on commit e5e68c4

Please sign in to comment.