Skip to content
Closed
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
14 changes: 14 additions & 0 deletions src/main/java/org/checkstyle/autofix/recipe/Header.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand All @@ -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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>

<module name="Header">
<property name="headerFile" value="src/test/resources/org/checkstyle/autofix/recipe/header/header.txt"/>
<property name="fileExtensions" value="java"/>
<property name="ignoreLines" value="3"/>
<property name="charset" value="UTF-8"/>
</module>

</module>
Loading