Skip to content

Commit

Permalink
Retain whitespace before annotations in NoFinalizedLocalVariables
Browse files Browse the repository at this point in the history
Fixes #431
  • Loading branch information
timtebeek committed Jan 7, 2025
1 parent 9d252a1 commit dfdb3eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private J.VariableDeclarations removeFinal(J.VariableDeclarations mv) {
m -> m.getType() == J.Modifier.Type.Final ? null : m));
if (v.getModifiers().isEmpty() && v.getTypeExpression() != null) {
v = v.withTypeExpression(v.getTypeExpression().withPrefix(v.getTypeExpression().getPrefix()
.withWhitespace("")));
.withWhitespace(v.getLeadingAnnotations().isEmpty() ? "" : " ")));
}
return v;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,25 @@ public String get() {
)
);
}

@Test
void retainPrefix() {
rewriteRun(
//language=java
java(
"""
class T {
public void test(@SuppressWarnings final String s) {
}
}
""",
"""
class T {
public void test(@SuppressWarnings String s) {
}
}
"""
)
);
}
}

0 comments on commit dfdb3eb

Please sign in to comment.