aboutsummaryrefslogtreecommitdiff
path: root/src/delombok/lombok
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2013-07-08 04:58:00 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2013-07-08 04:58:00 +0200
commita6c1be550fd1911084faaf7f54ae7bbbd5673642 (patch)
treeb6c433593952e46ce5b1db9c4c9123e445769220 /src/delombok/lombok
parent4923506d737718cec49e35aa9a273b3a999eefc6 (diff)
downloadlombok-a6c1be550fd1911084faaf7f54ae7bbbd5673642.tar.gz
lombok-a6c1be550fd1911084faaf7f54ae7bbbd5673642.tar.bz2
lombok-a6c1be550fd1911084faaf7f54ae7bbbd5673642.zip
A lot of refactoring on how javadoc is handled, to prepare for copying javadoc from field to setter/getter in javac.
Diffstat (limited to 'src/delombok/lombok')
-rw-r--r--src/delombok/lombok/delombok/PrettyCommentsPrinter.java32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java
index 9c6a2bd7..342e3323 100644
--- a/src/delombok/lombok/delombok/PrettyCommentsPrinter.java
+++ b/src/delombok/lombok/delombok/PrettyCommentsPrinter.java
@@ -224,12 +224,21 @@ public class PrettyCommentsPrinter extends JCTree.Visitor {
return tree.getEndPosition(cu.endPositions);
}
- private void consumeComments(int till) throws IOException {
+ private void consumeComments(int until) throws IOException {
+ consumeComments(until, null);
+ }
+ private void consumeComments(int until, JCTree tree) throws IOException {
boolean prevNewLine = onNewLine;
boolean found = false;
CommentInfo head = comments.head;
- while (comments.nonEmpty() && head.pos < till) {
- printComment(head);
+ while (comments.nonEmpty() && head.pos < until) {
+ if (tree != null && docComments != null && docComments.containsKey(tree) && head.isJavadoc() && noFurtherJavadocForthcoming(until)) {
+ // This is (presumably) the exact same javadoc that has already been associated with the node that we're just about to
+ // print. These javadoc can be modified by lombok handlers, and as such we should NOT print them from the consumed comments db,
+ // and instead print the actual javadoc associated with the upcoming node (which the visit method for that node will take care of).
+ } else {
+ printComment(head);
+ }
comments = comments.tail;
head = comments.head;
}
@@ -237,6 +246,17 @@ public class PrettyCommentsPrinter extends JCTree.Visitor {
println();
}
}
+
+ private boolean noFurtherJavadocForthcoming(int until) {
+ List<CommentInfo> c = comments;
+ if (c.nonEmpty()) c = c.tail;
+ while (c.nonEmpty()) {
+ if (c.head.pos >= until) return true;
+ if (c.head.isJavadoc()) return false;
+ c = c.tail;
+ }
+ return true;
+ }
private void consumeTrailingComments(int from) throws IOException {
boolean prevNewLine = onNewLine;
@@ -408,7 +428,7 @@ public class PrettyCommentsPrinter extends JCTree.Visitor {
this.prec = prec;
if (tree == null) print("/*missing*/");
else {
- consumeComments(tree.pos);
+ consumeComments(tree.pos, tree);
tree.accept(this);
int endPos = endPos(tree);
consumeTrailingComments(endPos);
@@ -620,7 +640,7 @@ public class PrettyCommentsPrinter extends JCTree.Visitor {
docComments = tree.docComments;
printDocComment(tree);
if (tree.pid != null) {
- consumeComments(tree.pos);
+ consumeComments(tree.pos, tree);
print("package ");
printExpr(tree.pid);
print(";");
@@ -694,7 +714,7 @@ public class PrettyCommentsPrinter extends JCTree.Visitor {
public void visitClassDef(JCClassDecl tree) {
try {
- consumeComments(tree.pos);
+ consumeComments(tree.pos, tree);
println(); align();
printDocComment(tree);
printAnnotations(tree.mods.annotations);