Sat, 07 Nov 2020 10:30:02 +0800
Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe
jlahoda@2906 | 1 | /* |
jlahoda@2906 | 2 | * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
jlahoda@2906 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jlahoda@2906 | 4 | * |
jlahoda@2906 | 5 | * This code is free software; you can redistribute it and/or modify it |
jlahoda@2906 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jlahoda@2906 | 7 | * published by the Free Software Foundation. |
jlahoda@2906 | 8 | * |
jlahoda@2906 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jlahoda@2906 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jlahoda@2906 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jlahoda@2906 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jlahoda@2906 | 13 | * accompanied this code). |
jlahoda@2906 | 14 | * |
jlahoda@2906 | 15 | * You should have received a copy of the GNU General Public License version |
jlahoda@2906 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jlahoda@2906 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jlahoda@2906 | 18 | * |
jlahoda@2906 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jlahoda@2906 | 20 | * or visit www.oracle.com if you need additional information or have any |
jlahoda@2906 | 21 | * questions. |
jlahoda@2906 | 22 | */ |
jlahoda@2906 | 23 | |
jlahoda@2906 | 24 | /* |
jlahoda@2906 | 25 | * @test |
jlahoda@2906 | 26 | * @bug 8135307 |
jlahoda@2906 | 27 | * @summary Check that CompletionFailures for missing classes are not incorrectly passed to |
jlahoda@2906 | 28 | * the javadoc API clients. |
jlahoda@2906 | 29 | * @modules jdk.javadoc |
jlahoda@2906 | 30 | * @run main CompletionError |
jlahoda@2906 | 31 | */ |
jlahoda@2906 | 32 | |
jlahoda@2906 | 33 | import java.io.File; |
jlahoda@2906 | 34 | import java.net.URI; |
jlahoda@2906 | 35 | import java.nio.file.Files; |
jlahoda@2906 | 36 | import java.nio.file.Paths; |
jlahoda@2906 | 37 | import java.util.Arrays; |
jlahoda@2906 | 38 | import java.util.List; |
jlahoda@2906 | 39 | |
jlahoda@2906 | 40 | import javax.tools.JavaCompiler; |
jlahoda@2906 | 41 | import javax.tools.JavaFileObject; |
jlahoda@2906 | 42 | import javax.tools.SimpleJavaFileObject; |
jlahoda@2906 | 43 | import javax.tools.ToolProvider; |
jlahoda@2906 | 44 | |
jlahoda@2906 | 45 | import com.sun.javadoc.*; |
jlahoda@2906 | 46 | import com.sun.tools.javadoc.Main; |
jlahoda@2906 | 47 | |
jlahoda@2906 | 48 | public class CompletionError extends Doclet |
jlahoda@2906 | 49 | { |
jlahoda@2906 | 50 | private static final String template = |
jlahoda@2906 | 51 | "public class CompletionErrorAuxiliary #extends CompletionErrorMissing# #implements CompletionErrorIntfMissing# {" + |
jlahoda@2906 | 52 | " #public CompletionErrorMissing tf;#" + |
jlahoda@2906 | 53 | " #public CompletionErrorMissing tm() { return null; }#" + |
jlahoda@2906 | 54 | " #public void tm(CompletionErrorMissing m) {}#" + |
jlahoda@2906 | 55 | " #public void tm() throws CompletionErrorExcMissing {}#" + |
jlahoda@2906 | 56 | " #public <T extends CompletionErrorMissing> void tm() {}#" + |
jlahoda@2906 | 57 | " public String toString() { return null; }" + |
jlahoda@2906 | 58 | "}"; |
jlahoda@2906 | 59 | |
jlahoda@2906 | 60 | public static void main(String[] args) throws Exception { |
jlahoda@2906 | 61 | JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
jlahoda@2906 | 62 | String[] templateParts = template.split("#"); |
jlahoda@2906 | 63 | int sources = templateParts.length / 2; |
jlahoda@2906 | 64 | for (int source = 0; source < sources; source++) { |
jlahoda@2906 | 65 | StringBuilder testSource = new StringBuilder(); |
jlahoda@2906 | 66 | for (int i = 0; i < templateParts.length; i += 2) { |
jlahoda@2906 | 67 | testSource.append(templateParts[i]); |
jlahoda@2906 | 68 | if (i == 2 * source) { |
jlahoda@2906 | 69 | testSource.append(templateParts[i + 1]); |
jlahoda@2906 | 70 | } |
jlahoda@2906 | 71 | } |
jlahoda@2906 | 72 | test = 0; |
jlahoda@2906 | 73 | testsDone = false; |
jlahoda@2906 | 74 | while (!testsDone) { |
jlahoda@2906 | 75 | List<JavaSource> fileObjects = |
jlahoda@2906 | 76 | Arrays.asList(new JavaSource("CompletionErrorAuxiliary", testSource.toString()), |
jlahoda@2906 | 77 | new JavaSource("CompletionErrorMissing", "public class CompletionErrorMissing {}"), |
jlahoda@2906 | 78 | new JavaSource("CompletionErrorIntfMissing", "public interface CompletionErrorIntfMissing {}"), |
jlahoda@2906 | 79 | new JavaSource("CompletionErrorExcMissing", "public class CompletionErrorExcMissing extends Exception {}")); |
jlahoda@2906 | 80 | Boolean result = compiler.getTask(null, null, null, Arrays.asList("-d", "."), null, fileObjects).call(); |
jlahoda@2906 | 81 | if (!result) |
jlahoda@2906 | 82 | throw new Error(); |
jlahoda@2906 | 83 | for (String delete : new String[] {"CompletionErrorMissing.class", "CompletionErrorIntfMissing.class", "CompletionErrorExcMissing.class"}) { |
jlahoda@2906 | 84 | Files.delete(Paths.get(delete)); |
jlahoda@2906 | 85 | } |
jlahoda@2906 | 86 | // run javadoc: |
jlahoda@2906 | 87 | if (Main.execute("javadoc", "CompletionError", CompletionError.class.getClassLoader(), |
jlahoda@2906 | 88 | "-classpath", ".", |
jlahoda@2906 | 89 | System.getProperty("test.src", ".") + File.separatorChar + "CompletionError.java") != 0) |
jlahoda@2906 | 90 | throw new Error(); |
jlahoda@2906 | 91 | } |
jlahoda@2906 | 92 | } |
jlahoda@2906 | 93 | } |
jlahoda@2906 | 94 | |
jlahoda@2906 | 95 | private static int test; |
jlahoda@2906 | 96 | private static boolean testsDone; |
jlahoda@2906 | 97 | |
jlahoda@2906 | 98 | public static boolean start(com.sun.javadoc.RootDoc root) { |
jlahoda@2906 | 99 | ClassDoc aux = root.classNamed("CompletionErrorAuxiliary"); |
jlahoda@2906 | 100 | if (aux == null) |
jlahoda@2906 | 101 | throw new AssertionError("Cannot find CompletionErrorAuxiliary"); |
jlahoda@2906 | 102 | |
jlahoda@2906 | 103 | FieldDoc tf = findField(aux, "tf"); |
jlahoda@2906 | 104 | MethodDoc tm = findMethod(aux, "tm"); |
jlahoda@2906 | 105 | MethodDoc cm = findMethod(aux, "toString"); |
jlahoda@2906 | 106 | switch (test) { |
jlahoda@2906 | 107 | case 0: aux.superclass(); break; |
jlahoda@2906 | 108 | case 1: aux.superclassType(); break; |
jlahoda@2906 | 109 | case 2: aux.interfaces(); break; |
jlahoda@2906 | 110 | case 3: aux.interfaceTypes(); break; |
jlahoda@2906 | 111 | case 4: if (tf != null) tf.type(); break; |
jlahoda@2906 | 112 | case 5: if (tm != null) tm.overriddenClass(); break; |
jlahoda@2906 | 113 | case 6: if (tm != null) tm.overriddenMethod(); break; |
jlahoda@2906 | 114 | case 7: if (tm != null) tm.overriddenType(); break; |
jlahoda@2906 | 115 | case 8: |
jlahoda@2906 | 116 | if (tm != null) { |
jlahoda@2906 | 117 | for (Parameter p : tm.parameters()) { |
jlahoda@2906 | 118 | p.type(); |
jlahoda@2906 | 119 | } |
jlahoda@2906 | 120 | } |
jlahoda@2906 | 121 | break; |
jlahoda@2906 | 122 | case 9: if (tm != null) tm.receiverType(); break; |
jlahoda@2906 | 123 | case 10: if (tm != null) tm.returnType(); break; |
jlahoda@2906 | 124 | case 11: if (tm != null) tm.thrownExceptionTypes(); break; |
jlahoda@2906 | 125 | case 12: if (tm != null) tm.thrownExceptions(); break; |
jlahoda@2906 | 126 | case 13: |
jlahoda@2906 | 127 | if (tm != null) { |
jlahoda@2906 | 128 | for (TypeVariable tv : tm.typeParameters()) { |
jlahoda@2906 | 129 | tv.bounds(); |
jlahoda@2906 | 130 | } |
jlahoda@2906 | 131 | } |
jlahoda@2906 | 132 | break; |
jlahoda@2906 | 133 | case 14: if (cm != null) cm.overriddenClass(); break; |
jlahoda@2906 | 134 | case 15: if (cm != null) cm.overriddenMethod(); break; |
jlahoda@2906 | 135 | case 16: if (cm != null) cm.overriddenType(); testsDone = true; break; |
jlahoda@2906 | 136 | default: |
jlahoda@2906 | 137 | throw new IllegalStateException("Unrecognized test!"); |
jlahoda@2906 | 138 | } |
jlahoda@2906 | 139 | test++; |
jlahoda@2906 | 140 | return true; |
jlahoda@2906 | 141 | } |
jlahoda@2906 | 142 | |
jlahoda@2906 | 143 | private static MethodDoc findMethod(ClassDoc cd, String name) { |
jlahoda@2906 | 144 | for (MethodDoc m : cd.methods()) { |
jlahoda@2906 | 145 | if (name.equals(m.name())) |
jlahoda@2906 | 146 | return m; |
jlahoda@2906 | 147 | } |
jlahoda@2906 | 148 | |
jlahoda@2906 | 149 | return null; |
jlahoda@2906 | 150 | } |
jlahoda@2906 | 151 | |
jlahoda@2906 | 152 | private static FieldDoc findField(ClassDoc cd, String name) { |
jlahoda@2906 | 153 | for (FieldDoc m : cd.fields()) { |
jlahoda@2906 | 154 | if (name.equals(m.name())) |
jlahoda@2906 | 155 | return m; |
jlahoda@2906 | 156 | } |
jlahoda@2906 | 157 | |
jlahoda@2906 | 158 | return null; |
jlahoda@2906 | 159 | } |
jlahoda@2906 | 160 | |
jlahoda@2906 | 161 | static class JavaSource extends SimpleJavaFileObject { |
jlahoda@2906 | 162 | final String source; |
jlahoda@2906 | 163 | |
jlahoda@2906 | 164 | public JavaSource(String name, String source) { |
jlahoda@2906 | 165 | super(URI.create("myfo:/" + name + ".java"), JavaFileObject.Kind.SOURCE); |
jlahoda@2906 | 166 | this.source = source; |
jlahoda@2906 | 167 | } |
jlahoda@2906 | 168 | |
jlahoda@2906 | 169 | @Override |
jlahoda@2906 | 170 | public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
jlahoda@2906 | 171 | return source; |
jlahoda@2906 | 172 | } |
jlahoda@2906 | 173 | } |
jlahoda@2906 | 174 | } |