aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/delombok/lombok/delombok/DocCommentIntegrator.java6
-rw-r--r--src/utils/lombok/javac/Javac.java19
-rw-r--r--test/core/src/lombok/RunTestsViaDelombok.java4
3 files changed, 25 insertions, 4 deletions
diff --git a/src/delombok/lombok/delombok/DocCommentIntegrator.java b/src/delombok/lombok/delombok/DocCommentIntegrator.java
index bab0abd8..e61968a5 100644
--- a/src/delombok/lombok/delombok/DocCommentIntegrator.java
+++ b/src/delombok/lombok/delombok/DocCommentIntegrator.java
@@ -89,7 +89,7 @@ public class DocCommentIntegrator {
((Map<JCTree, String>) map_).put(node, docCommentContent);
return true;
} else if (Javac.instanceOfDocCommentTable(map_)) {
- CommentAttacher_8.attach(node, docCommentContent, map_);
+ CommentAttacher_8.attach(node, docCommentContent, cmt.pos, map_);
return true;
}
@@ -98,7 +98,7 @@ public class DocCommentIntegrator {
/* Container for code which will cause class loader exceptions on javac below 8. By being in a separate class, we avoid the problem. */
private static class CommentAttacher_8 {
- static void attach(final JCTree node, String docCommentContent, Object map_) {
+ static void attach(final JCTree node, String docCommentContent, final int pos, Object map_) {
final String docCommentContent_ = docCommentContent;
((DocCommentTable) map_).putComment(node, new Comment() {
@Override public String getText() {
@@ -106,7 +106,7 @@ public class DocCommentIntegrator {
}
@Override public int getSourcePos(int index) {
- return -1;
+ return pos + index;
}
@Override public CommentStyle getStyle() {
diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java
index 33bd7265..27926507 100644
--- a/src/utils/lombok/javac/Javac.java
+++ b/src/utils/lombok/javac/Javac.java
@@ -279,6 +279,17 @@ public class Javac {
return null;
}
+ /**
+ * Checks if the javadoc comment associated with {@code tree} has a position set.
+ *
+ * Returns true if there is no javadoc comment on the node, or it has position (position isn't -1).
+ */
+ public static boolean validateDocComment(JCCompilationUnit cu, JCTree tree) {
+ Object dc = getDocComments(cu);
+ if (!instanceOfDocCommentTable(dc)) return true;
+ return JavadocOps_8.validateJavadoc(dc, tree);
+ }
+
@SuppressWarnings("unchecked")
public static void setDocComment(JCCompilationUnit cu, JCTree node, String javadoc) {
if (javadoc == null) return;
@@ -302,6 +313,12 @@ public class Javac {
return javadoc.getText();
}
+ public static boolean validateJavadoc(Object dc, JCTree node) {
+ DocCommentTable dct = (DocCommentTable) dc;
+ Comment javadoc = dct.getComment(node);
+ return javadoc == null || javadoc.getText() == null || javadoc.getSourcePos(0) >= 0;
+ }
+
static void setJavadoc(Object dc, JCTree node, String javadoc) {
DocCommentTable dct = (DocCommentTable) dc;
Comment newCmt = createJavadocComment(javadoc, node);
@@ -315,7 +332,7 @@ public class Javac {
}
@Override public int getSourcePos(int index) {
- return -1;
+ return field == null ? -1 : field.getStartPosition();
}
@Override public CommentStyle getStyle() {
diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java
index 433d8b07..d4df50d7 100644
--- a/test/core/src/lombok/RunTestsViaDelombok.java
+++ b/test/core/src/lombok/RunTestsViaDelombok.java
@@ -99,6 +99,10 @@ public class RunTestsViaDelombok extends AbstractRunTests {
try {
if (tree instanceof JCModifiers) return;
+ if (!Javac.validateDocComment(unit, tree)) {
+ fail("Start position of doc comment (" + Javac.getDocComment(unit, tree) + ") of " + tree + " not set");
+ }
+
if (tree.pos == -1) {
fail("Start position of " + tree + " not set");
}