mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-15 02:17:12 +00:00
[issue #2730] Javadoc generated by lombok in javac now gets its position set.
This may fix 'IllegalArgumentException' errors when using google errorprone.
This commit is contained in:
3 files changed
+25
-4
No files matched your search
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user