jjg@519: /* ohair@554: * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. jjg@519: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@519: * jjg@519: * This code is free software; you can redistribute it and/or modify it jjg@519: * under the terms of the GNU General Public License version 2 only, as jjg@519: * published by the Free Software Foundation. jjg@519: * jjg@519: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@519: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@519: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@519: * version 2 for more details (a copy is included in the LICENSE file that jjg@519: * accompanied this code). jjg@519: * jjg@519: * You should have received a copy of the GNU General Public License version jjg@519: * 2 along with this work; if not, write to the Free Software Foundation, jjg@519: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@519: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. jjg@519: */ jjg@519: jjg@519: /** jjg@519: * @test jjg@519: * @bug 6930108 jjg@519: * @summary IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.java jjg@519: * @library ./lib jjg@519: * @build ToolTester jjg@519: * @run main TestResolveError jjg@519: */ jjg@519: jjg@519: import java.io.*; jjg@519: import javax.lang.model.element.Element; jjg@519: import javax.lang.model.element.TypeElement; jjg@519: import javax.lang.model.type.DeclaredType; jjg@519: import javax.lang.model.type.TypeMirror; jjg@519: import javax.lang.model.util.Elements; jjg@519: import javax.lang.model.util.Types; jjg@519: import javax.tools.*; jjg@519: jjg@519: import com.sun.tools.javac.api.JavacTaskImpl; jjg@519: jjg@519: /* jjg@519: * This is a cut down version of TestJavacTaskScanner, which as originally written jjg@519: * caused an IllegalArgumentException in AbstractDiagnosticFormatter as a result jjg@519: * of calling task.parseType with a name whose resolution depended on the setting jjg@519: * of the bootclasspath. jjg@519: * This test has the same call, task.parseType("List", clazz), but checks jjg@519: * that the error is handled in a reasonable way by javac. jjg@519: */ jjg@519: public class TestResolveError extends ToolTester { jjg@519: public static void main(String... args) throws Exception { jjg@519: new TestResolveError().run(); jjg@519: } jjg@519: jjg@519: void run() throws Exception { jjg@519: StringWriter sw = new StringWriter(); jjg@519: PrintWriter pw = new PrintWriter(sw); jjg@519: File file = new File(test_src, "TestResolveError.java"); jjg@519: final Iterable compilationUnits = jjg@519: fm.getJavaFileObjects(new File[] {file}); jjg@519: task = (JavacTaskImpl)tool.getTask(pw, fm, null, null, null, compilationUnits); jjg@519: elements = task.getElements(); jjg@519: types = task.getTypes(); jjg@519: jjg@519: Iterable toplevels; jjg@519: try { jjg@519: toplevels = task.enter(task.parse()); jjg@519: } catch (IOException ex) { jjg@519: throw new AssertionError(ex); jjg@519: } jjg@519: jjg@519: for (TypeElement clazz : toplevels) { jjg@519: System.out.format("Testing %s:%n%n", clazz.getSimpleName()); jjg@519: // this should not cause any exception from the compiler, jjg@519: // such as IllegalArgumentException jjg@519: testParseType(clazz); jjg@519: } jjg@519: jjg@519: pw.close(); jjg@519: jjg@519: String out = sw.toString(); jjg@519: System.out.println(out); jjg@519: jjg@519: if (out.contains("com.sun.tools.javac.util")) jjg@519: throw new Exception("Unexpected output from compiler"); jjg@519: } jjg@519: jjg@519: void testParseType(TypeElement clazz) { jjg@519: DeclaredType type = (DeclaredType)task.parseType("List", clazz); jjg@519: for (Element member : elements.getAllMembers((TypeElement)type.asElement())) { jjg@519: TypeMirror mt = types.asMemberOf(type, member); jjg@519: System.out.format("%s : %s -> %s%n", member.getSimpleName(), member.asType(), mt); jjg@519: } jjg@519: } jjg@519: jjg@519: JavacTaskImpl task; jjg@519: Elements elements; jjg@519: Types types; jjg@519: }