8020556: doclint does not check type variables for @throws
Reviewed-by: mcimadamore
This commit is contained in:
parent
be2ea6f949
commit
0c5c756933
@ -30,7 +30,6 @@ import javax.lang.model.element.Element;
|
||||
import javax.tools.JavaCompiler.CompilationTask;
|
||||
|
||||
import com.sun.source.doctree.DocCommentTree;
|
||||
import com.sun.source.doctree.ReferenceTree;
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
/**
|
||||
|
@ -753,8 +753,7 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
||||
Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName));
|
||||
if (ex == null) {
|
||||
env.messages.error(REFERENCE, tree, "dc.ref.not.found");
|
||||
} else if (ex.asType().getKind() == TypeKind.DECLARED
|
||||
&& env.types.isAssignable(ex.asType(), env.java_lang_Throwable)) {
|
||||
} else if (isThrowable(ex.asType())) {
|
||||
switch (env.currElement.getKind()) {
|
||||
case CONSTRUCTOR:
|
||||
case METHOD:
|
||||
@ -773,6 +772,15 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
||||
return scan(tree.getDescription(), ignore);
|
||||
}
|
||||
|
||||
private boolean isThrowable(TypeMirror tm) {
|
||||
switch (tm.getKind()) {
|
||||
case DECLARED:
|
||||
case TYPEVAR:
|
||||
return env.types.isAssignable(tm, env.java_lang_Throwable);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void checkThrowsDeclared(ReferenceTree tree, TypeMirror t, List<? extends TypeMirror> list) {
|
||||
boolean found = false;
|
||||
for (TypeMirror tl : list) {
|
||||
|
@ -69,7 +69,6 @@ import com.sun.tools.javac.code.Type.ClassType;
|
||||
import com.sun.tools.javac.code.Type.ErrorType;
|
||||
import com.sun.tools.javac.code.Type.UnionClassType;
|
||||
import com.sun.tools.javac.code.Types;
|
||||
import com.sun.tools.javac.code.TypeTag;
|
||||
import com.sun.tools.javac.code.Types.TypeRelation;
|
||||
import com.sun.tools.javac.comp.Attr;
|
||||
import com.sun.tools.javac.comp.AttrContext;
|
||||
@ -358,7 +357,7 @@ public class JavacTrees extends DocTrees {
|
||||
Log.DeferredDiagnosticHandler deferredDiagnosticHandler =
|
||||
new Log.DeferredDiagnosticHandler(log);
|
||||
try {
|
||||
final ClassSymbol tsym;
|
||||
final TypeSymbol tsym;
|
||||
final Name memberName;
|
||||
if (ref.qualifierExpression == null) {
|
||||
tsym = env.enclClass.sym;
|
||||
@ -387,7 +386,7 @@ public class JavacTrees extends DocTrees {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
tsym = (ClassSymbol) t.tsym;
|
||||
tsym = t.tsym;
|
||||
memberName = ref.memberName;
|
||||
}
|
||||
}
|
||||
@ -408,15 +407,17 @@ public class JavacTrees extends DocTrees {
|
||||
paramTypes = lb.toList();
|
||||
}
|
||||
|
||||
Symbol msym = (memberName == tsym.name)
|
||||
? findConstructor(tsym, paramTypes)
|
||||
: findMethod(tsym, memberName, paramTypes);
|
||||
ClassSymbol sym = (ClassSymbol) types.upperBound(tsym.type).tsym;
|
||||
|
||||
Symbol msym = (memberName == sym.name)
|
||||
? findConstructor(sym, paramTypes)
|
||||
: findMethod(sym, memberName, paramTypes);
|
||||
if (paramTypes != null) {
|
||||
// explicit (possibly empty) arg list given, so cannot be a field
|
||||
return msym;
|
||||
}
|
||||
|
||||
VarSymbol vsym = (ref.paramTypes != null) ? null : findField(tsym, memberName);
|
||||
VarSymbol vsym = (ref.paramTypes != null) ? null : findField(sym, memberName);
|
||||
// prefer a field over a method with no parameters
|
||||
if (vsym != null &&
|
||||
(msym == null ||
|
||||
@ -789,6 +790,7 @@ public class JavacTrees extends DocTrees {
|
||||
case METHOD:
|
||||
// System.err.println("METHOD: " + ((JCMethodDecl)tree).sym.getSimpleName());
|
||||
method = (JCMethodDecl)tree;
|
||||
env = memberEnter.getMethodEnv(method, env);
|
||||
break;
|
||||
case VARIABLE:
|
||||
// System.err.println("FIELD: " + ((JCVariableDecl)tree).sym.getSimpleName());
|
||||
@ -800,7 +802,6 @@ public class JavacTrees extends DocTrees {
|
||||
try {
|
||||
Assert.check(method.body == tree);
|
||||
method.body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf());
|
||||
env = memberEnter.getMethodEnv(method, env);
|
||||
env = attribStatToTree(method.body, env, copier.leafCopy);
|
||||
} finally {
|
||||
method.body = (JCBlock) tree;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -124,7 +124,16 @@ public class Env<A> implements Iterable<Env<A>> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Env[" + info + (outer == null ? "" : ",outer=" + outer) + "]";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Env[").append(info);
|
||||
// if (enclMethod != null)
|
||||
// sb.append(",enclMethod=").append(Pretty.toSimpleString(enclMethod));
|
||||
// if (enclClass != null)
|
||||
// sb.append(",enclClass=").append(Pretty.toSimpleString(enclClass));
|
||||
if (outer != null)
|
||||
sb.append(",outer=").append(outer);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Iterator<Env<A>> iterator() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8004832
|
||||
* @bug 8004832 8020556
|
||||
* @summary Add new doclint package
|
||||
* @build DocLintTester
|
||||
* @run main DocLintTester -Xmsgs:-reference ReferenceTest.java
|
||||
@ -48,5 +48,11 @@ public class ReferenceTest {
|
||||
* @throws Exception description
|
||||
*/
|
||||
public void exception_not_thrown() { }
|
||||
|
||||
/**
|
||||
* @param <T> throwable
|
||||
* @throws T description
|
||||
*/
|
||||
public <T extends Throwable> void valid_throws_generic() throws T { }
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user