diff options
author | Rawi01 <Rawi01@users.noreply.github.com> | 2020-12-22 16:45:05 +0100 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2021-01-14 23:54:48 +0100 |
commit | 2e5ea518cc4041f2ef79d5d9cc0f970d805b6e64 (patch) | |
tree | d46395a1cf4be1c1fe8141bcee10e91d11586d82 /src/core | |
parent | b8d49a884ed545176bb491b10b59dde9f481ea95 (diff) | |
download | lombok-2e5ea518cc4041f2ef79d5d9cc0f970d805b6e64.tar.gz lombok-2e5ea518cc4041f2ef79d5d9cc0f970d805b6e64.tar.bz2 lombok-2e5ea518cc4041f2ef79d5d9cc0f970d805b6e64.zip |
[fixes #2443] Remove multiline Javadoc tags
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/lombok/core/handlers/HandlerUtil.java | 17 | ||||
-rw-r--r-- | src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java | 4 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/JavacHandlerUtil.java | 8 |
3 files changed, 19 insertions, 10 deletions
diff --git a/src/core/lombok/core/handlers/HandlerUtil.java b/src/core/lombok/core/handlers/HandlerUtil.java index 9fd38720..14c2d66c 100644 --- a/src/core/lombok/core/handlers/HandlerUtil.java +++ b/src/core/lombok/core/handlers/HandlerUtil.java @@ -761,11 +761,20 @@ public class HandlerUtil { 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) { + public enum JavadocTag { + PARAM("@param(?:eter)?"), + RETURN("@returns?"); + + private Pattern pattern; + + JavadocTag(String regexpFragment) { + pattern = Pattern.compile("\\s?^[ \\t]*\\**[ \\t]*" + regexpFragment + "(\\S|\\s)*?(?=(\\s^\\s*\\**\\s*@|\\Z))", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); + } + } + + public static String stripLinesWithTagFromJavadoc(String javadoc, JavadocTag tag) { if (javadoc == null || javadoc.isEmpty()) return javadoc; - Pattern p = Pattern.compile("^\\s*\\**\\s*" + regexpFragment + "\\s*\\**\\s*$", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); - Matcher m = p.matcher(javadoc); - return m.replaceAll(""); + return tag.pattern.matcher(javadoc).replaceAll(""); } public static String stripSectionsFromJavadoc(String javadoc) { diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index b58c2996..68ba075b 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -2688,7 +2688,7 @@ public class EclipseHandlerUtil { String out = getJavadocSection(javadoc, "GETTER"); final boolean sectionBased = out != null; if (!sectionBased) { - out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), "@param(?:eter)?\\s+.*"); + out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), JavadocTag.PARAM); } return out; } @@ -2718,7 +2718,7 @@ public class EclipseHandlerUtil { String out = getJavadocSection(javadoc, sectionName); final boolean sectionBased = out != null; if (!sectionBased) { - out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), "@returns?\\s+.*"); + out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), JavadocTag.RETURN); } return shouldReturnThis(node) ? addReturnsThisIfNeeded(out) : out; } diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 9b63a523..c33d3c78 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -2044,7 +2044,7 @@ public class JavacHandlerUtil { String out = getJavadocSection(javadoc, "GETTER"); final boolean sectionBased = out != null; if (!sectionBased) { - out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), "@param(?:eter)?\\s+.*"); + out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), JavadocTag.PARAM); } node.getAst().cleanupTask("javadocfilter-getter", n, new CleanupTask() { @Override public void cleanup() { @@ -2052,7 +2052,7 @@ public class JavacHandlerUtil { if (javadoc == null || javadoc.isEmpty()) return; javadoc = stripSectionsFromJavadoc(javadoc); if (!sectionBased) { - javadoc = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), "@returns?\\s+.*"); + javadoc = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), JavadocTag.RETURN); } Javac.setDocComment(cu, n, javadoc); } @@ -2085,7 +2085,7 @@ public class JavacHandlerUtil { String out = getJavadocSection(javadoc, sectionName); final boolean sectionBased = out != null; if (!sectionBased) { - out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), "@returns?\\s+.*"); + out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), JavadocTag.RETURN); } node.getAst().cleanupTask("javadocfilter-setter", n, new CleanupTask() { @Override public void cleanup() { @@ -2093,7 +2093,7 @@ public class JavacHandlerUtil { if (javadoc == null || javadoc.isEmpty()) return; javadoc = stripSectionsFromJavadoc(javadoc); if (!sectionBased) { - javadoc = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), "@param(?:eter)?\\s+.*"); + javadoc = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), JavadocTag.PARAM); } Javac.setDocComment(cu, n, javadoc); } |