Skip to content

Commit

Permalink
Use System.lineSeparator()
Browse files Browse the repository at this point in the history
  • Loading branch information
jevanlingen committed Nov 19, 2024
1 parent 21f09ca commit 6beb846
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static java.lang.System.lineSeparator;
import static org.openrewrite.Cursor.ROOT_VALUE;
import static org.openrewrite.internal.ListUtils.*;
import static org.openrewrite.yaml.MergeYaml.REMOVE_PREFIX;
Expand Down Expand Up @@ -108,7 +109,7 @@ public Yaml visitMapping(Yaml.Mapping existingMapping, P p) {

if (getCursor().getMessage(REMOVE_PREFIX, false)) {
List<Yaml.Mapping.Entry> entries = ((Yaml.Mapping) getCursor().getValue()).getEntries();
return mapping.withEntries(mapLast(mapping.getEntries(), it -> it.withPrefix("\n" + grabAfterFirstLineBreak(entries.get(entries.size() - 1)))));
return mapping.withEntries(mapLast(mapping.getEntries(), it -> it.withPrefix(lineSeparator() + grabAfterFirstLineBreak(entries.get(entries.size() - 1)))));
}

return mapping;
Expand Down Expand Up @@ -153,7 +154,7 @@ private Mapping mergeMapping(Yaml.Mapping m1, Yaml.Mapping m2, P p, Cursor curso
}
// workaround: autoFormat cannot handle new inserted values very well
if (!mergedEntries.isEmpty() && it.getValue() instanceof Yaml.Scalar && hasLineBreak(mergedEntries.get(0), 2)) {
return it.withPrefix("\n" + grabAfterFirstLineBreak(mergedEntries.get(0)));
return it.withPrefix(lineSeparator() + grabAfterFirstLineBreak(mergedEntries.get(0)));
}
return shouldAutoFormat ? MergeYamlVisitor.this.autoFormat(it, p, cursor) : it;
}));
Expand Down Expand Up @@ -214,7 +215,7 @@ private void removePrefixForDirectChildren(List<Yaml.Mapping.Entry> m1Entries, L
for (int i = 0; i < m1Entries.size() - 1; i++) {
if (m1Entries.get(i).getValue() instanceof Yaml.Mapping && mutatedEntries.get(i).getValue() instanceof Yaml.Mapping &&
((Yaml.Mapping) m1Entries.get(i).getValue()).getEntries().size() < ((Yaml.Mapping) mutatedEntries.get(i).getValue()).getEntries().size()) {
mutatedEntries.set(i + 1, mutatedEntries.get(i + 1).withPrefix("\n" + grabAfterFirstLineBreak(mutatedEntries.get(i + 1))));
mutatedEntries.set(i + 1, mutatedEntries.get(i + 1).withPrefix(lineSeparator() + grabAfterFirstLineBreak(mutatedEntries.get(i + 1))));
}
}
}
Expand Down Expand Up @@ -295,7 +296,7 @@ private String grabBeforeFirstLineBreak(Yaml.Mapping.Entry entry) {

private String grabAfterFirstLineBreak(Yaml.Mapping.Entry entry) {
String[] parts = LINE_BREAK.split(entry.getPrefix());
return parts.length > 1 ? String.join("\n", Arrays.copyOfRange(parts, 1, parts.length)) : "";
return parts.length > 1 ? String.join(lineSeparator(), Arrays.copyOfRange(parts, 1, parts.length)) : "";
}

private Scalar mergeScalar(Yaml.Scalar y1, Yaml.Scalar y2) {
Expand Down

0 comments on commit 6beb846

Please sign in to comment.