Wed, 14 Oct 2015 12:05:16 -0700
Merge
1.1 --- a/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java Wed Oct 14 11:57:56 2015 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java Wed Oct 14 12:05:16 2015 -0700 1.3 @@ -124,19 +124,14 @@ 1.4 * Returns the flags of a ClassSymbol in terms of javac's flags 1.5 */ 1.6 static long getFlags(ClassSymbol clazz) { 1.7 - while (true) { 1.8 - try { 1.9 - return clazz.flags(); 1.10 - } catch (CompletionFailure ex) { 1.11 - /* Quietly ignore completion failures. 1.12 - * Note that a CompletionFailure can only 1.13 - * occur as a result of calling complete(), 1.14 - * which will always remove the current 1.15 - * completer, leaving it to be null or 1.16 - * follow-up completer. Thus the loop 1.17 - * is guaranteed to eventually terminate. 1.18 - */ 1.19 - } 1.20 + try { 1.21 + return clazz.flags(); 1.22 + } catch (CompletionFailure ex) { 1.23 + /* Quietly ignore completion failures and try again - the type 1.24 + * for which the CompletionFailure was thrown shouldn't be completed 1.25 + * again by the completer that threw the CompletionFailure. 1.26 + */ 1.27 + return getFlags(clazz); 1.28 } 1.29 } 1.30
2.1 --- a/src/share/classes/com/sun/tools/javadoc/MethodDocImpl.java Wed Oct 14 11:57:56 2015 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javadoc/MethodDocImpl.java Wed Oct 14 12:05:16 2015 -0700 2.3 @@ -128,7 +128,7 @@ 2.4 t.hasTag(CLASS); 2.5 t = env.types.supertype(t)) { 2.6 ClassSymbol c = (ClassSymbol)t.tsym; 2.7 - for (Scope.Entry e = c.members().lookup(sym.name); e.scope != null; e = e.next()) { 2.8 + for (Scope.Entry e = membersOf(c).lookup(sym.name); e.scope != null; e = e.next()) { 2.9 if (sym.overrides(e.sym, origin, env.types, true)) { 2.10 return TypeMaker.getType(env, t); 2.11 } 2.12 @@ -160,7 +160,7 @@ 2.13 t.hasTag(CLASS); 2.14 t = env.types.supertype(t)) { 2.15 ClassSymbol c = (ClassSymbol)t.tsym; 2.16 - for (Scope.Entry e = c.members().lookup(sym.name); e.scope != null; e = e.next()) { 2.17 + for (Scope.Entry e = membersOf(c).lookup(sym.name); e.scope != null; e = e.next()) { 2.18 if (sym.overrides(e.sym, origin, env.types, true)) { 2.19 return env.getMethodDoc((MethodSymbol)e.sym); 2.20 } 2.21 @@ -169,6 +169,19 @@ 2.22 return null; 2.23 } 2.24 2.25 + /**Retrieve members of c, ignoring any CompletionFailures that occur. */ 2.26 + private Scope membersOf(ClassSymbol c) { 2.27 + try { 2.28 + return c.members(); 2.29 + } catch (CompletionFailure cf) { 2.30 + /* Quietly ignore completion failures and try again - the type 2.31 + * for which the CompletionFailure was thrown shouldn't be completed 2.32 + * again by the completer that threw the CompletionFailure. 2.33 + */ 2.34 + return membersOf(c); 2.35 + } 2.36 + } 2.37 + 2.38 /** 2.39 * Tests whether this method overrides another. 2.40 * The overridden method may be one declared in a superclass or
3.1 --- a/src/share/classes/com/sun/tools/javadoc/TypeMaker.java Wed Oct 14 11:57:56 2015 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javadoc/TypeMaker.java Wed Oct 14 12:05:16 2015 -0700 3.3 @@ -28,6 +28,7 @@ 3.4 import com.sun.javadoc.*; 3.5 import com.sun.tools.javac.code.Symbol; 3.6 import com.sun.tools.javac.code.Symbol.ClassSymbol; 3.7 +import com.sun.tools.javac.code.Symbol.CompletionFailure; 3.8 import com.sun.tools.javac.code.Type; 3.9 import com.sun.tools.javac.code.Type.ArrayType; 3.10 import com.sun.tools.javac.code.Type.ClassType; 3.11 @@ -56,8 +57,21 @@ 3.12 return getType(env, t, errorToClassDoc, true); 3.13 } 3.14 3.15 + public static com.sun.javadoc.Type getType(DocEnv env, Type t, 3.16 + boolean errToClassDoc, boolean considerAnnotations) { 3.17 + try { 3.18 + return getTypeImpl(env, t, errToClassDoc, considerAnnotations); 3.19 + } catch (CompletionFailure cf) { 3.20 + /* Quietly ignore completion failures and try again - the type 3.21 + * for which the CompletionFailure was thrown shouldn't be completed 3.22 + * again by the completer that threw the CompletionFailure. 3.23 + */ 3.24 + return getType(env, t, errToClassDoc, considerAnnotations); 3.25 + } 3.26 + } 3.27 + 3.28 @SuppressWarnings("fallthrough") 3.29 - public static com.sun.javadoc.Type getType(DocEnv env, Type t, 3.30 + private static com.sun.javadoc.Type getTypeImpl(DocEnv env, Type t, 3.31 boolean errToClassDoc, boolean considerAnnotations) { 3.32 if (env.legacyDoclet) { 3.33 t = env.types.erasure(t);
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javadoc/CompletionError.java Wed Oct 14 12:05:16 2015 -0700 4.3 @@ -0,0 +1,174 @@ 4.4 +/* 4.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +/* 4.28 + * @test 4.29 + * @bug 8135307 4.30 + * @summary Check that CompletionFailures for missing classes are not incorrectly passed to 4.31 + * the javadoc API clients. 4.32 + * @modules jdk.javadoc 4.33 + * @run main CompletionError 4.34 + */ 4.35 + 4.36 +import java.io.File; 4.37 +import java.net.URI; 4.38 +import java.nio.file.Files; 4.39 +import java.nio.file.Paths; 4.40 +import java.util.Arrays; 4.41 +import java.util.List; 4.42 + 4.43 +import javax.tools.JavaCompiler; 4.44 +import javax.tools.JavaFileObject; 4.45 +import javax.tools.SimpleJavaFileObject; 4.46 +import javax.tools.ToolProvider; 4.47 + 4.48 +import com.sun.javadoc.*; 4.49 +import com.sun.tools.javadoc.Main; 4.50 + 4.51 +public class CompletionError extends Doclet 4.52 +{ 4.53 + private static final String template = 4.54 + "public class CompletionErrorAuxiliary #extends CompletionErrorMissing# #implements CompletionErrorIntfMissing# {" + 4.55 + " #public CompletionErrorMissing tf;#" + 4.56 + " #public CompletionErrorMissing tm() { return null; }#" + 4.57 + " #public void tm(CompletionErrorMissing m) {}#" + 4.58 + " #public void tm() throws CompletionErrorExcMissing {}#" + 4.59 + " #public <T extends CompletionErrorMissing> void tm() {}#" + 4.60 + " public String toString() { return null; }" + 4.61 + "}"; 4.62 + 4.63 + public static void main(String[] args) throws Exception { 4.64 + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 4.65 + String[] templateParts = template.split("#"); 4.66 + int sources = templateParts.length / 2; 4.67 + for (int source = 0; source < sources; source++) { 4.68 + StringBuilder testSource = new StringBuilder(); 4.69 + for (int i = 0; i < templateParts.length; i += 2) { 4.70 + testSource.append(templateParts[i]); 4.71 + if (i == 2 * source) { 4.72 + testSource.append(templateParts[i + 1]); 4.73 + } 4.74 + } 4.75 + test = 0; 4.76 + testsDone = false; 4.77 + while (!testsDone) { 4.78 + List<JavaSource> fileObjects = 4.79 + Arrays.asList(new JavaSource("CompletionErrorAuxiliary", testSource.toString()), 4.80 + new JavaSource("CompletionErrorMissing", "public class CompletionErrorMissing {}"), 4.81 + new JavaSource("CompletionErrorIntfMissing", "public interface CompletionErrorIntfMissing {}"), 4.82 + new JavaSource("CompletionErrorExcMissing", "public class CompletionErrorExcMissing extends Exception {}")); 4.83 + Boolean result = compiler.getTask(null, null, null, Arrays.asList("-d", "."), null, fileObjects).call(); 4.84 + if (!result) 4.85 + throw new Error(); 4.86 + for (String delete : new String[] {"CompletionErrorMissing.class", "CompletionErrorIntfMissing.class", "CompletionErrorExcMissing.class"}) { 4.87 + Files.delete(Paths.get(delete)); 4.88 + } 4.89 + // run javadoc: 4.90 + if (Main.execute("javadoc", "CompletionError", CompletionError.class.getClassLoader(), 4.91 + "-classpath", ".", 4.92 + System.getProperty("test.src", ".") + File.separatorChar + "CompletionError.java") != 0) 4.93 + throw new Error(); 4.94 + } 4.95 + } 4.96 + } 4.97 + 4.98 + private static int test; 4.99 + private static boolean testsDone; 4.100 + 4.101 + public static boolean start(com.sun.javadoc.RootDoc root) { 4.102 + ClassDoc aux = root.classNamed("CompletionErrorAuxiliary"); 4.103 + if (aux == null) 4.104 + throw new AssertionError("Cannot find CompletionErrorAuxiliary"); 4.105 + 4.106 + FieldDoc tf = findField(aux, "tf"); 4.107 + MethodDoc tm = findMethod(aux, "tm"); 4.108 + MethodDoc cm = findMethod(aux, "toString"); 4.109 + switch (test) { 4.110 + case 0: aux.superclass(); break; 4.111 + case 1: aux.superclassType(); break; 4.112 + case 2: aux.interfaces(); break; 4.113 + case 3: aux.interfaceTypes(); break; 4.114 + case 4: if (tf != null) tf.type(); break; 4.115 + case 5: if (tm != null) tm.overriddenClass(); break; 4.116 + case 6: if (tm != null) tm.overriddenMethod(); break; 4.117 + case 7: if (tm != null) tm.overriddenType(); break; 4.118 + case 8: 4.119 + if (tm != null) { 4.120 + for (Parameter p : tm.parameters()) { 4.121 + p.type(); 4.122 + } 4.123 + } 4.124 + break; 4.125 + case 9: if (tm != null) tm.receiverType(); break; 4.126 + case 10: if (tm != null) tm.returnType(); break; 4.127 + case 11: if (tm != null) tm.thrownExceptionTypes(); break; 4.128 + case 12: if (tm != null) tm.thrownExceptions(); break; 4.129 + case 13: 4.130 + if (tm != null) { 4.131 + for (TypeVariable tv : tm.typeParameters()) { 4.132 + tv.bounds(); 4.133 + } 4.134 + } 4.135 + break; 4.136 + case 14: if (cm != null) cm.overriddenClass(); break; 4.137 + case 15: if (cm != null) cm.overriddenMethod(); break; 4.138 + case 16: if (cm != null) cm.overriddenType(); testsDone = true; break; 4.139 + default: 4.140 + throw new IllegalStateException("Unrecognized test!"); 4.141 + } 4.142 + test++; 4.143 + return true; 4.144 + } 4.145 + 4.146 + private static MethodDoc findMethod(ClassDoc cd, String name) { 4.147 + for (MethodDoc m : cd.methods()) { 4.148 + if (name.equals(m.name())) 4.149 + return m; 4.150 + } 4.151 + 4.152 + return null; 4.153 + } 4.154 + 4.155 + private static FieldDoc findField(ClassDoc cd, String name) { 4.156 + for (FieldDoc m : cd.fields()) { 4.157 + if (name.equals(m.name())) 4.158 + return m; 4.159 + } 4.160 + 4.161 + return null; 4.162 + } 4.163 + 4.164 + static class JavaSource extends SimpleJavaFileObject { 4.165 + final String source; 4.166 + 4.167 + public JavaSource(String name, String source) { 4.168 + super(URI.create("myfo:/" + name + ".java"), JavaFileObject.Kind.SOURCE); 4.169 + this.source = source; 4.170 + } 4.171 + 4.172 + @Override 4.173 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 4.174 + return source; 4.175 + } 4.176 + } 4.177 +}