diff options
-rw-r--r-- | doc/changelog.markdown | 1 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/JavacHandlerUtil.java | 18 |
2 files changed, 15 insertions, 4 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown index a9a7490c..7cd75718 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -2,6 +2,7 @@ Lombok Changelog ---------------- ### v1.12.5 "Edgy Guinea Pig" +* BUGFIX: Copying javadoc to getters / setters / withers would copy non-relevant sections too. [Issue #585](https://code.google.com/p/projectlombok/issues/detail?id=585). * DETAIL: {Delombok} Inside enum bodies the delombok formatter didn't respect the emptyLines directive [Issue #629](https://code.google.com/p/projectlombok/issues/detail?id=629). * DETAIL: Use smaller primes (<127) for generating hashcodes [Issue #625](https://code.google.com/p/projectlombok/issues/detail?id=625) diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 80ba9405..bc4dda8e 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -1294,6 +1294,13 @@ public class JavacHandlerUtil { return m.replaceAll(""); } + public static String stripSectionsFromJavadoc(String javadoc) { + Matcher m = SECTION_FINDER.matcher(javadoc); + if (!m.find()) return javadoc; + + return javadoc.substring(0, m.start()); + } + public static String[] splitJavadocOnSectionIfPresent(String javadoc, String sectionName) { Matcher m = SECTION_FINDER.matcher(javadoc); int getterSectionHeaderStart = -1; @@ -1320,15 +1327,17 @@ public class JavacHandlerUtil { } public static enum CopyJavadoc { - VERBATIM, GETTER { + VERBATIM, + GETTER { @Override public String[] split(String javadoc) { // step 1: Check if there is a 'GETTER' section. If yes, that becomes the new method's javadoc and we strip that from the original. String[] out = splitJavadocOnSectionIfPresent(javadoc, "GETTER"); if (out != null) return out; - // failing that, create a copy, but strip @return from the original and @param from the copy. + // failing that, create a copy, but strip @return from the original and @param from the copy, as well as other sections. String copy = javadoc; javadoc = stripLinesWithTagFromJavadoc(javadoc, "@returns?\\s+.*"); copy = stripLinesWithTagFromJavadoc(copy, "@param(?:eter)?\\s+.*"); + copy = stripSectionsFromJavadoc(copy); return new String[] {copy, javadoc}; } }, @@ -1351,6 +1360,7 @@ public class JavacHandlerUtil { String copy = javadoc; javadoc = stripLinesWithTagFromJavadoc(javadoc, "@param(?:eter)?\\s+.*"); copy = stripLinesWithTagFromJavadoc(copy, "@returns?\\s+.*"); + copy = stripSectionsFromJavadoc(copy); return new String[] {copy, javadoc}; } @@ -1364,8 +1374,8 @@ public class JavacHandlerUtil { * Copies javadoc on one node to the other. * * in 'GETTER' copyMode, first a 'GETTER' segment is searched for. If it exists, that will become the javadoc for the 'to' node, and this section is - * stripped out of the 'from' node. If no 'GETTER' segment is found, then the entire javadoc is taken minus any {@code @param} lines. any {@code @return} lines - * are stripped from 'from'. + * stripped out of the 'from' node. If no 'GETTER' segment is found, then the entire javadoc is taken minus any {@code @param} lines and other sections. + * any {@code @return} lines are stripped from 'from'. * * in 'SETTER' mode, stripping works similarly to 'GETTER' mode, except {@code param} are copied and stripped from the original and {@code @return} are skipped. */ |