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