aboutsummaryrefslogtreecommitdiff
path: root/src/utils/lombok
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2021-02-04 21:59:32 +0100
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2021-02-04 21:59:32 +0100
commitadf30952462ad8380cf92c742e208b72c572cc98 (patch)
treed2550af00ec2b67ba2866a0b9bad7fc8be8eb58e /src/utils/lombok
parent3d3a4c322af4cf7f27679661efaa9dcd685165bb (diff)
downloadlombok-adf30952462ad8380cf92c742e208b72c572cc98.tar.gz
lombok-adf30952462ad8380cf92c742e208b72c572cc98.tar.bz2
lombok-adf30952462ad8380cf92c742e208b72c572cc98.zip
[issue #2730] Javadoc generated by lombok in javac now gets its position set.
This may fix 'IllegalArgumentException' errors when using google errorprone.
Diffstat (limited to 'src/utils/lombok')
-rw-r--r--src/utils/lombok/javac/Javac.java19
1 files changed, 18 insertions, 1 deletions
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() {