8265253: javac -Xdoclint:all gives "no comment" warning for code that can't be commented

Reviewed-by: hannesw
This commit is contained in:
Jonathan Gibbons 2021-08-23 17:31:29 +00:00
parent 594e5161b4
commit 1884072474
3 changed files with 60 additions and 1 deletions

View File

@ -45,9 +45,12 @@ import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Name;
import javax.lang.model.element.NestingKind;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.tools.Diagnostic.Kind;
import javax.tools.JavaFileObject;
@ -188,7 +191,7 @@ public class Checker extends DocTreePathScanner<Void, Void> {
if (isNormalClass(p.getParentPath())) {
reportMissing("dc.default.constructor");
}
} else if (!isOverridingMethod) {
} else if (!isOverridingMethod && !isSynthetic() && !isAnonymous()) {
reportMissing("dc.missing.comment");
}
return null;
@ -1158,6 +1161,15 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|| env.types.isAssignable(t, env.java_lang_RuntimeException));
}
private boolean isSynthetic() {
return env.elements.getOrigin(env.currElement) == Elements.Origin.SYNTHETIC;
}
private boolean isAnonymous() {
return (env.currElement instanceof TypeElement te)
&& te.getNestingKind() == NestingKind.ANONYMOUS;
}
private boolean isDefaultConstructor() {
switch (env.currElement.getKind()) {
case CONSTRUCTOR:

View File

@ -0,0 +1,37 @@
/*
* @test /nodynamiccopyright/
* @modules jdk.javadoc/jdk.javadoc.internal.doclint
* @build DocLintTester
* @run main DocLintTester -Xmsgs:-missing AnonClassTest.java
* @run main DocLintTester -Xmsgs:missing -ref AnonClassTest.out AnonClassTest.java
*/
/** Class comment. */
public enum AnonClassTest {
/**
* E1 comment.
* This member uses an anonymous class, which should not trigger a warning.
*/
E1 {
// no comment: should give warning
int field;
// no comment: should give warning
void m() { }
// no comment required: should not give warning
@java.lang.Override
public void m1() { }
},
// This member also uses an anonymous class,
// but there should only be a single warning for the member itself.
E2 { },
/** E3 comment. This member does not use an anonymous class. */
E3;
/** Method comment. */
public void m1() { }
}

View File

@ -0,0 +1,10 @@
AnonClassTest.java:18: warning: no comment
int field;
^
AnonClassTest.java:21: warning: no comment
void m() { }
^
AnonClassTest.java:30: warning: no comment
E2 { },
^
3 warnings