提交 d46936ac 编写于 作者: J jjg

8020556: doclint does not check type variables for @throws

Reviewed-by: mcimadamore
上级 1d0a5a90
...@@ -30,7 +30,6 @@ import javax.lang.model.element.Element; ...@@ -30,7 +30,6 @@ import javax.lang.model.element.Element;
import javax.tools.JavaCompiler.CompilationTask; import javax.tools.JavaCompiler.CompilationTask;
import com.sun.source.doctree.DocCommentTree; import com.sun.source.doctree.DocCommentTree;
import com.sun.source.doctree.ReferenceTree;
import javax.tools.Diagnostic; import javax.tools.Diagnostic;
/** /**
......
...@@ -753,8 +753,7 @@ public class Checker extends DocTreePathScanner<Void, Void> { ...@@ -753,8 +753,7 @@ public class Checker extends DocTreePathScanner<Void, Void> {
Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName)); Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName));
if (ex == null) { if (ex == null) {
env.messages.error(REFERENCE, tree, "dc.ref.not.found"); env.messages.error(REFERENCE, tree, "dc.ref.not.found");
} else if (ex.asType().getKind() == TypeKind.DECLARED } else if (isThrowable(ex.asType())) {
&& env.types.isAssignable(ex.asType(), env.java_lang_Throwable)) {
switch (env.currElement.getKind()) { switch (env.currElement.getKind()) {
case CONSTRUCTOR: case CONSTRUCTOR:
case METHOD: case METHOD:
...@@ -773,6 +772,15 @@ public class Checker extends DocTreePathScanner<Void, Void> { ...@@ -773,6 +772,15 @@ public class Checker extends DocTreePathScanner<Void, Void> {
return scan(tree.getDescription(), ignore); 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) { private void checkThrowsDeclared(ReferenceTree tree, TypeMirror t, List<? extends TypeMirror> list) {
boolean found = false; boolean found = false;
for (TypeMirror tl : list) { for (TypeMirror tl : list) {
......
...@@ -69,7 +69,6 @@ import com.sun.tools.javac.code.Type.ClassType; ...@@ -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.ErrorType;
import com.sun.tools.javac.code.Type.UnionClassType; import com.sun.tools.javac.code.Type.UnionClassType;
import com.sun.tools.javac.code.Types; 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.code.Types.TypeRelation;
import com.sun.tools.javac.comp.Attr; import com.sun.tools.javac.comp.Attr;
import com.sun.tools.javac.comp.AttrContext; import com.sun.tools.javac.comp.AttrContext;
...@@ -358,7 +357,7 @@ public class JavacTrees extends DocTrees { ...@@ -358,7 +357,7 @@ public class JavacTrees extends DocTrees {
Log.DeferredDiagnosticHandler deferredDiagnosticHandler = Log.DeferredDiagnosticHandler deferredDiagnosticHandler =
new Log.DeferredDiagnosticHandler(log); new Log.DeferredDiagnosticHandler(log);
try { try {
final ClassSymbol tsym; final TypeSymbol tsym;
final Name memberName; final Name memberName;
if (ref.qualifierExpression == null) { if (ref.qualifierExpression == null) {
tsym = env.enclClass.sym; tsym = env.enclClass.sym;
...@@ -387,7 +386,7 @@ public class JavacTrees extends DocTrees { ...@@ -387,7 +386,7 @@ public class JavacTrees extends DocTrees {
return null; return null;
} }
} else { } else {
tsym = (ClassSymbol) t.tsym; tsym = t.tsym;
memberName = ref.memberName; memberName = ref.memberName;
} }
} }
...@@ -408,15 +407,17 @@ public class JavacTrees extends DocTrees { ...@@ -408,15 +407,17 @@ public class JavacTrees extends DocTrees {
paramTypes = lb.toList(); paramTypes = lb.toList();
} }
Symbol msym = (memberName == tsym.name) ClassSymbol sym = (ClassSymbol) types.upperBound(tsym.type).tsym;
? findConstructor(tsym, paramTypes)
: findMethod(tsym, memberName, paramTypes); Symbol msym = (memberName == sym.name)
? findConstructor(sym, paramTypes)
: findMethod(sym, memberName, paramTypes);
if (paramTypes != null) { if (paramTypes != null) {
// explicit (possibly empty) arg list given, so cannot be a field // explicit (possibly empty) arg list given, so cannot be a field
return msym; 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 // prefer a field over a method with no parameters
if (vsym != null && if (vsym != null &&
(msym == null || (msym == null ||
...@@ -789,6 +790,7 @@ public class JavacTrees extends DocTrees { ...@@ -789,6 +790,7 @@ public class JavacTrees extends DocTrees {
case METHOD: case METHOD:
// System.err.println("METHOD: " + ((JCMethodDecl)tree).sym.getSimpleName()); // System.err.println("METHOD: " + ((JCMethodDecl)tree).sym.getSimpleName());
method = (JCMethodDecl)tree; method = (JCMethodDecl)tree;
env = memberEnter.getMethodEnv(method, env);
break; break;
case VARIABLE: case VARIABLE:
// System.err.println("FIELD: " + ((JCVariableDecl)tree).sym.getSimpleName()); // System.err.println("FIELD: " + ((JCVariableDecl)tree).sym.getSimpleName());
...@@ -800,7 +802,6 @@ public class JavacTrees extends DocTrees { ...@@ -800,7 +802,6 @@ public class JavacTrees extends DocTrees {
try { try {
Assert.check(method.body == tree); Assert.check(method.body == tree);
method.body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf()); method.body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf());
env = memberEnter.getMethodEnv(method, env);
env = attribStatToTree(method.body, env, copier.leafCopy); env = attribStatToTree(method.body, env, copier.leafCopy);
} finally { } finally {
method.body = (JCBlock) tree; method.body = (JCBlock) tree;
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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>> { ...@@ -124,7 +124,16 @@ public class Env<A> implements Iterable<Env<A>> {
@Override @Override
public String toString() { 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() { public Iterator<Env<A>> iterator() {
......
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @bug 8004832 * @bug 8004832 8020556
* @summary Add new doclint package * @summary Add new doclint package
* @build DocLintTester * @build DocLintTester
* @run main DocLintTester -Xmsgs:-reference ReferenceTest.java * @run main DocLintTester -Xmsgs:-reference ReferenceTest.java
...@@ -48,5 +48,11 @@ public class ReferenceTest { ...@@ -48,5 +48,11 @@ public class ReferenceTest {
* @throws Exception description * @throws Exception description
*/ */
public void exception_not_thrown() { } public void exception_not_thrown() { }
/**
* @param <T> throwable
* @throws T description
*/
public <T extends Throwable> void valid_throws_generic() throws T { }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册