From 79c3d383fd7d46ec1c6c5cf83d8b05f2238529a2 Mon Sep 17 00:00:00 2001 From: Rostislav Krasny <45571812+rosti-il@users.noreply.github.com> Date: Tue, 18 Aug 2020 04:03:23 +0300 Subject: Fix tests under Windows, fix test.javac11 and test.javac14, fix issue #1745 The change of the TestConfiguration.java is based on the fact that Git for Windows is configured with 'core.autocrlf=true' by default. --- AUTHORS | 1 + buildScripts/tests.ant.xml | 1 + .../lombok/javac/handlers/JavacHandlerUtil.java | 19 +++++++++------- src/delombok/lombok/delombok/PrettyPrinter.java | 26 +++++++++------------- .../core/configuration/TestConfiguration.java | 4 ++-- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/AUTHORS b/AUTHORS index 8a2902ad..9adf2005 100755 --- a/AUTHORS +++ b/AUTHORS @@ -35,6 +35,7 @@ Robbert Jan Grootjans Robert Wertman Roel Spilker Roland Praml +Rostislav Krasny <45571812+rosti-il@users.noreply.github.com> Samuel Pereira Sander Koning Szymon Pacanowski diff --git a/buildScripts/tests.ant.xml b/buildScripts/tests.ant.xml index f78bfae9..cb840048 100644 --- a/buildScripts/tests.ant.xml +++ b/buildScripts/tests.ant.xml @@ -119,6 +119,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn + diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index e0af0e52..2523103f 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -1964,6 +1964,7 @@ public class JavacHandlerUtil { } private static final Pattern SECTION_FINDER = Pattern.compile("^\\s*\\**\\s*[-*][-*]+\\s*([GS]ETTER|WITH(?:ER)?)\\s*[-*][-*]+\\s*\\**\\s*$", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); + private static final Pattern LINE_BREAK_FINDER = Pattern.compile("(\\r?\\n)?"); public static String stripLinesWithTagFromJavadoc(String javadoc, String regexpFragment) { Pattern p = Pattern.compile("^\\s*\\**\\s*" + regexpFragment + "\\s*\\**\\s*$", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); @@ -1972,27 +1973,29 @@ public class JavacHandlerUtil { } public static String stripSectionsFromJavadoc(String javadoc) { - Matcher m = SECTION_FINDER.matcher(javadoc); - if (!m.find()) return javadoc; + Matcher sectionMatcher = SECTION_FINDER.matcher(javadoc); + if (!sectionMatcher.find()) return javadoc; - return javadoc.substring(0, m.start()); + return javadoc.substring(0, sectionMatcher.start()); } public static String getJavadocSection(String javadoc, String sectionNameSpec) { String[] sectionNames = sectionNameSpec.split("\\|"); - Matcher m = SECTION_FINDER.matcher(javadoc); + Matcher sectionMatcher = SECTION_FINDER.matcher(javadoc); + Matcher lineBreakMatcher = LINE_BREAK_FINDER.matcher(javadoc); int sectionStart = -1; int sectionEnd = -1; - while (m.find()) { + while (sectionMatcher.find()) { boolean found = false; - for (String sectionName : sectionNames) if (m.group(1).equalsIgnoreCase(sectionName)) { + for (String sectionName : sectionNames) if (sectionMatcher.group(1).equalsIgnoreCase(sectionName)) { found = true; break; } if (found) { - sectionStart = m.end() + 1; + lineBreakMatcher.find(sectionMatcher.end()); + sectionStart = lineBreakMatcher.end(); } else if (sectionStart != -1) { - sectionEnd = m.start(); + sectionEnd = sectionMatcher.start(); } } diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java index 208b215f..54fa4ebf 100644 --- a/src/delombok/lombok/delombok/PrettyPrinter.java +++ b/src/delombok/lombok/delombok/PrettyPrinter.java @@ -188,12 +188,6 @@ public class PrettyPrinter extends JCTree.Visitor { return getEndPosition(tree, compilationUnit); } - private static int lineEndPos(String s, int start) { - int pos = s.indexOf('\n', start); - if (pos < 0) pos = s.length(); - return pos; - } - private boolean needsAlign, needsNewLine, onNewLine = true, needsSpace, aligned; public static final class UncheckedIOException extends RuntimeException { @@ -434,23 +428,25 @@ public class PrettyPrinter extends JCTree.Visitor { private void printDocComment(JCTree tree) { String dc = getJavadocFor(tree); if (dc == null) return; + aPrintln("/**"); - int pos = 0; - int endpos = lineEndPos(dc, pos); boolean atStart = true; - while (pos < dc.length()) { - String line = dc.substring(pos, endpos); - if (line.trim().isEmpty() && atStart) { + + for (String line : dc.split("\\r?\\n")) { + if (atStart && line.trim().isEmpty()) { atStart = false; continue; } + atStart = false; aPrint(" *"); - if (pos < dc.length() && dc.charAt(pos) > ' ') print(" "); - println(dc.substring(pos, endpos)); - pos = endpos + 1; - endpos = lineEndPos(dc, pos); + if (!line.isEmpty() && !Character.isWhitespace(line.charAt(0))) { + print(" "); + } + + println(line); } + aPrintln(" */"); } diff --git a/test/configuration/src/lombok/core/configuration/TestConfiguration.java b/test/configuration/src/lombok/core/configuration/TestConfiguration.java index 3032daf3..504c36b2 100644 --- a/test/configuration/src/lombok/core/configuration/TestConfiguration.java +++ b/test/configuration/src/lombok/core/configuration/TestConfiguration.java @@ -65,8 +65,8 @@ public class TestConfiguration { outStream.flush(); errStream.flush(); - String out = new String(rawOut.toByteArray()).replace("\r\n", "\n").replace('\\', '/').replaceAll(Pattern.quote(normalizedName) + "|" + Pattern.quote(baseName), "BASE/").trim(); - String err = new String(rawErr.toByteArray()).replace("\r\n", "\n").replace('\\', '/').replaceAll(Pattern.quote(normalizedName) + "|" + Pattern.quote(baseName), "BASE/").trim(); + String out = new String(rawOut.toByteArray()).replace('\\', '/').replaceAll(Pattern.quote(normalizedName) + "|" + Pattern.quote(baseName), "BASE/").trim(); + String err = new String(rawErr.toByteArray()).replace('\\', '/').replaceAll(Pattern.quote(normalizedName) + "|" + Pattern.quote(baseName), "BASE/").trim(); checkContent(directory, out, "out"); checkContent(directory, err, "err"); -- cgit