diff --git a/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/diffs/DiffCleaner.java b/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/diffs/DiffCleaner.java index ba9712b50..d89d7b0f2 100644 --- a/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/diffs/DiffCleaner.java +++ b/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/diffs/DiffCleaner.java @@ -81,7 +81,7 @@ public void clean(Path path, Change change) { if (change.getModes().contains(DiffCleanModes.NO_WHITESPACE_ADD)) { String cleanResult = new ExtraWhiteSpaceCleaner() .clean(Files.readString(filePath), lineChange, change, lineEnding); - printResult(filePath, cleanResult); + printResult(filePath, cleanResult, hasLineEnding, lineEnding); } } } @@ -100,7 +100,11 @@ private boolean isDeletedLines(String line) { return line.startsWith("- ") && !line.startsWith("---"); } - private void printResult(Path filePath, String cleanResult) throws IOException { + private void printResult(Path filePath, String cleanResult, boolean hasLineEnding, String lineEnding) + throws IOException { + if (hasLineEnding) { + cleanResult += lineEnding; + } Files.writeString(filePath, cleanResult); } diff --git a/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/diffs/ExtraWhiteSpaceCleaner.java b/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/diffs/ExtraWhiteSpaceCleaner.java index 0e8b502d3..0a20cda18 100644 --- a/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/diffs/ExtraWhiteSpaceCleaner.java +++ b/code-transformation/src/main/java/xyz/keksdose/spoon/code_solver/diffs/ExtraWhiteSpaceCleaner.java @@ -15,7 +15,6 @@ public class ExtraWhiteSpaceCleaner implements GitDiffCleaner { @Override public String clean(@Var String content, GitLineChange gitLineChange, Change change, String lineEnding) { - boolean endsWithLineEnding = endsWithLineEnding(content, lineEnding); Patch patch = DiffUtils.diffInline(gitLineChange.oldContent(), gitLineChange.newContent()); for (AbstractDelta delta : patch.getDeltas()) { logger.atInfo().log("Delta: %s", delta); @@ -30,19 +29,9 @@ public String clean(@Var String content, GitLineChange gitLineChange, Change cha .collect(Collectors.joining(lineEnding)); } } - if (endsWithLineEnding && !patch.getDeltas().isEmpty() && !content.endsWith(lineEnding)) { - content += lineEnding; - } return content; } - /** - * Checks if the content ends with the line ending of the file. - */ - private boolean endsWithLineEnding(String content, String lineEnding) { - return content.endsWith(lineEnding); - } - private String changeIfMatches(ChangeDelta delta, String content, GitLineChange gitLineChange) { if (!gitLineChange.newContent().equals(content)) { return content;