8265253: javac -Xdoclint:all gives "no comment" warning for code that can't be commented
Reviewed-by: hannesw
This commit is contained in:
parent
594e5161b4
commit
1884072474
@ -45,9 +45,12 @@ import javax.lang.model.element.Element;
|
|||||||
import javax.lang.model.element.ElementKind;
|
import javax.lang.model.element.ElementKind;
|
||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
import javax.lang.model.element.Name;
|
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.element.VariableElement;
|
||||||
import javax.lang.model.type.TypeKind;
|
import javax.lang.model.type.TypeKind;
|
||||||
import javax.lang.model.type.TypeMirror;
|
import javax.lang.model.type.TypeMirror;
|
||||||
|
import javax.lang.model.util.Elements;
|
||||||
import javax.tools.Diagnostic.Kind;
|
import javax.tools.Diagnostic.Kind;
|
||||||
import javax.tools.JavaFileObject;
|
import javax.tools.JavaFileObject;
|
||||||
|
|
||||||
@ -188,7 +191,7 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
|||||||
if (isNormalClass(p.getParentPath())) {
|
if (isNormalClass(p.getParentPath())) {
|
||||||
reportMissing("dc.default.constructor");
|
reportMissing("dc.default.constructor");
|
||||||
}
|
}
|
||||||
} else if (!isOverridingMethod) {
|
} else if (!isOverridingMethod && !isSynthetic() && !isAnonymous()) {
|
||||||
reportMissing("dc.missing.comment");
|
reportMissing("dc.missing.comment");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -1158,6 +1161,15 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
|||||||
|| env.types.isAssignable(t, env.java_lang_RuntimeException));
|
|| 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() {
|
private boolean isDefaultConstructor() {
|
||||||
switch (env.currElement.getKind()) {
|
switch (env.currElement.getKind()) {
|
||||||
case CONSTRUCTOR:
|
case CONSTRUCTOR:
|
||||||
|
37
test/langtools/tools/doclint/AnonClassTest.java
Normal file
37
test/langtools/tools/doclint/AnonClassTest.java
Normal 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() { }
|
||||||
|
}
|
10
test/langtools/tools/doclint/AnonClassTest.out
Normal file
10
test/langtools/tools/doclint/AnonClassTest.out
Normal 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
|
Loading…
x
Reference in New Issue
Block a user