From ed6d1fbb09be8fbda6d80380d4d24eca8d2469e2 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 1 Jun 2015 16:39:10 +0200 Subject: When generating javadoc for setters, a @return this is added if needed. --- src/core/lombok/javac/handlers/JavacHandlerUtil.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 0db59da1..c3607d37 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -1485,6 +1485,18 @@ public class JavacHandlerUtil { } catch (Exception ignore) {} } + private static final Pattern FIND_RETURN = Pattern.compile("^\\s*\\**\\s*@returns?\\s+.*$", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); + static String addReturnsThisIfNeeded(String in) { + if (FIND_RETURN.matcher(in).find()) return in; + + return addJavadocLine(in, "@return this"); + } + + static String addJavadocLine(String in, String line) { + if (in.endsWith("\n")) return in + line + "\n"; + return in + "\n" + line; + } + private static class CopyJavadoc_8 { static void copyJavadoc(JavacNode from, JCTree to, CopyJavadoc copyMode, Object dc) { DocCommentTable dct = (DocCommentTable) dc; @@ -1492,6 +1504,9 @@ public class JavacHandlerUtil { if (javadoc != null) { String[] filtered = copyMode.split(javadoc.getText()); + if (copyMode == CopyJavadoc.SETTER && shouldReturnThis(from)) { + filtered[0] = addReturnsThisIfNeeded(filtered[0]); + } dct.putComment(to, createJavadocComment(filtered[0], from)); dct.putComment(from.get(), createJavadocComment(filtered[1], from)); } @@ -1525,6 +1540,9 @@ public class JavacHandlerUtil { if (javadoc != null) { String[] filtered = copyMode.split(javadoc); + if (copyMode == CopyJavadoc.SETTER && shouldReturnThis(from)) { + filtered[0] = addReturnsThisIfNeeded(filtered[0]); + } docComments.put(to, filtered[0]); docComments.put(from.get(), filtered[1]); } -- cgit