diff --git a/src/main/java/org/checkstyle/autofix/recipe/Header.java b/src/main/java/org/checkstyle/autofix/recipe/Header.java index 725e5ad..bbd243e 100644 --- a/src/main/java/org/checkstyle/autofix/recipe/Header.java +++ b/src/main/java/org/checkstyle/autofix/recipe/Header.java @@ -148,6 +148,8 @@ public J visit(Tree tree, ExecutionContext ctx) { final String fixedHeader = fixHeaderLines(licenseHeader, currentHeader, ignoreLines); + System.out.println(escapeString(fixedHeader)); + sourceFile = sourceFile.withPrefix( Space.format(fixedHeader + System.lineSeparator())); } @@ -156,6 +158,18 @@ public J visit(Tree tree, ExecutionContext ctx) { return result; } + public static String escapeString(String input) { + return input + .replace("\\", "\\\\") + .replace("\n", "\\n") + .replace("\t", "\\t") + .replace("\r", "\\r") + .replace("\b", "\\b") + .replace("\f", "\\f") + .replace("\"", "\\\"") + .replace("\'", "\\'"); + } + private String extractCurrentHeader(JavaSourceFile sourceFile) { return sourceFile.getComments().stream() .map(comment -> comment.printComment(getCursor())) diff --git a/src/test/resources/org/checkstyle/autofix/recipe/header/config.xml b/src/test/resources/org/checkstyle/autofix/recipe/header/config.xml index eb94d5d..bbb3b02 100644 --- a/src/test/resources/org/checkstyle/autofix/recipe/header/config.xml +++ b/src/test/resources/org/checkstyle/autofix/recipe/header/config.xml @@ -3,13 +3,11 @@ "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd"> - - \ No newline at end of file