Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,12 @@ public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations m
.allMatch(privateFieldsToBeFinalized::contains);

if (canAllVariablesBeFinalized) {
mv = autoFormat(mv.withVariables(ListUtils.map(mv.getVariables(), v -> {
return mv.withVariables(ListUtils.map(mv.getVariables(), v -> {
JavaType.Variable type = v.getVariableType();
return type != null ? v.withVariableType(type.withFlags(
Flag.bitMapToFlags(type.getFlagsBitMap() | Flag.Final.getBitMask()))) : null;
return type != null ? v.withVariableType(type.withFlags(Flag.bitMapToFlags(type.getFlagsBitMap() | Flag.Final.getBitMask()))) : null;
})).withModifiers(ListUtils.concat(mv.getModifiers(),
new J.Modifier(Tree.randomId(), Space.EMPTY, Markers.EMPTY, isInstanceOfCs(topLevel) ? "readonly" : "final",
isInstanceOfCs(topLevel) ? J.Modifier.Type.LanguageExtension : J.Modifier.Type.Final, emptyList()))), ctx);
new J.Modifier(Tree.randomId(), mv.getModifiers().isEmpty() ? Space.EMPTY : Space.SINGLE_SPACE, Markers.EMPTY, isInstanceOfCs(topLevel) ? "readonly" : "final",
isInstanceOfCs(topLevel) ? J.Modifier.Type.LanguageExtension : J.Modifier.Type.Final, emptyList())));
}

return mv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,4 +896,34 @@ public class Reproducer {
)
);
}

@Test
void keepIndentation() {
rewriteRun(
//language=java
java(
"""
import java.io.InputStream;

class A {
private InputStream in;

public A(InputStream aInputStream) {
in = aInputStream;
}
}
""",
"""
import java.io.InputStream;

class A {
private final InputStream in;

public A(InputStream aInputStream) {
in = aInputStream;
}
}
"""
));
}
}