Wed, 12 Feb 2014 11:16:22 -0800
Added tag jdk8u11-b00 for changeset c9db8c800797
jjg@519 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
jjg@519 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@519 | 4 | * |
jjg@519 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@519 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@519 | 7 | * published by the Free Software Foundation. |
jjg@519 | 8 | * |
jjg@519 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@519 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@519 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@519 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@519 | 13 | * accompanied this code). |
jjg@519 | 14 | * |
jjg@519 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@519 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@519 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@519 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
jjg@519 | 22 | */ |
jjg@519 | 23 | |
jjg@519 | 24 | /** |
jjg@519 | 25 | * @test |
jjg@519 | 26 | * @bug 6930108 |
jjg@519 | 27 | * @summary IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.java |
jjg@519 | 28 | * @library ./lib |
jjg@519 | 29 | * @build ToolTester |
jjg@519 | 30 | * @run main TestResolveError |
jjg@519 | 31 | */ |
jjg@519 | 32 | |
jjg@519 | 33 | import java.io.*; |
jjg@519 | 34 | import javax.lang.model.element.Element; |
jjg@519 | 35 | import javax.lang.model.element.TypeElement; |
jjg@519 | 36 | import javax.lang.model.type.DeclaredType; |
jjg@519 | 37 | import javax.lang.model.type.TypeMirror; |
jjg@519 | 38 | import javax.lang.model.util.Elements; |
jjg@519 | 39 | import javax.lang.model.util.Types; |
jjg@519 | 40 | import javax.tools.*; |
jjg@519 | 41 | |
jjg@519 | 42 | import com.sun.tools.javac.api.JavacTaskImpl; |
jjg@519 | 43 | |
jjg@519 | 44 | /* |
jjg@519 | 45 | * This is a cut down version of TestJavacTaskScanner, which as originally written |
jjg@519 | 46 | * caused an IllegalArgumentException in AbstractDiagnosticFormatter as a result |
jjg@519 | 47 | * of calling task.parseType with a name whose resolution depended on the setting |
jjg@519 | 48 | * of the bootclasspath. |
jjg@519 | 49 | * This test has the same call, task.parseType("List<String>", clazz), but checks |
jjg@519 | 50 | * that the error is handled in a reasonable way by javac. |
jjg@519 | 51 | */ |
jjg@519 | 52 | public class TestResolveError extends ToolTester { |
jjg@519 | 53 | public static void main(String... args) throws Exception { |
jjg@519 | 54 | new TestResolveError().run(); |
jjg@519 | 55 | } |
jjg@519 | 56 | |
jjg@519 | 57 | void run() throws Exception { |
jjg@519 | 58 | StringWriter sw = new StringWriter(); |
jjg@519 | 59 | PrintWriter pw = new PrintWriter(sw); |
jjg@519 | 60 | File file = new File(test_src, "TestResolveError.java"); |
jjg@519 | 61 | final Iterable<? extends JavaFileObject> compilationUnits = |
jjg@519 | 62 | fm.getJavaFileObjects(new File[] {file}); |
jjg@519 | 63 | task = (JavacTaskImpl)tool.getTask(pw, fm, null, null, null, compilationUnits); |
jjg@519 | 64 | elements = task.getElements(); |
jjg@519 | 65 | types = task.getTypes(); |
jjg@519 | 66 | |
jjg@519 | 67 | Iterable<? extends TypeElement> toplevels; |
jjg@519 | 68 | try { |
jjg@519 | 69 | toplevels = task.enter(task.parse()); |
jjg@519 | 70 | } catch (IOException ex) { |
jjg@519 | 71 | throw new AssertionError(ex); |
jjg@519 | 72 | } |
jjg@519 | 73 | |
jjg@519 | 74 | for (TypeElement clazz : toplevels) { |
jjg@519 | 75 | System.out.format("Testing %s:%n%n", clazz.getSimpleName()); |
jjg@519 | 76 | // this should not cause any exception from the compiler, |
jjg@519 | 77 | // such as IllegalArgumentException |
jjg@519 | 78 | testParseType(clazz); |
jjg@519 | 79 | } |
jjg@519 | 80 | |
jjg@519 | 81 | pw.close(); |
jjg@519 | 82 | |
jjg@519 | 83 | String out = sw.toString(); |
jjg@519 | 84 | System.out.println(out); |
jjg@519 | 85 | |
jjg@519 | 86 | if (out.contains("com.sun.tools.javac.util")) |
jjg@519 | 87 | throw new Exception("Unexpected output from compiler"); |
jjg@519 | 88 | } |
jjg@519 | 89 | |
jjg@519 | 90 | void testParseType(TypeElement clazz) { |
jjg@519 | 91 | DeclaredType type = (DeclaredType)task.parseType("List<String>", clazz); |
jjg@519 | 92 | for (Element member : elements.getAllMembers((TypeElement)type.asElement())) { |
jjg@519 | 93 | TypeMirror mt = types.asMemberOf(type, member); |
jjg@519 | 94 | System.out.format("%s : %s -> %s%n", member.getSimpleName(), member.asType(), mt); |
jjg@519 | 95 | } |
jjg@519 | 96 | } |
jjg@519 | 97 | |
jjg@519 | 98 | JavacTaskImpl task; |
jjg@519 | 99 | Elements elements; |
jjg@519 | 100 | Types types; |
jjg@519 | 101 | } |