2010-03-06 00:12:33 +00:00
|
|
|
/*
|
2015-05-21 18:41:04 +00:00
|
|
|
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
|
2010-03-06 00:12:33 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-25 22:54:51 +00:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2010-03-06 00:12:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @bug 6930108
|
|
|
|
* @summary IllegalArgumentException in AbstractDiagnosticFormatter for tools/javac/api/TestJavacTaskScanner.java
|
|
|
|
* @library ./lib
|
2015-05-21 18:41:04 +00:00
|
|
|
* @modules jdk.compiler/com.sun.tools.javac.api
|
|
|
|
* jdk.compiler/com.sun.tools.javac.code
|
2010-03-06 00:12:33 +00:00
|
|
|
* @build ToolTester
|
|
|
|
* @run main TestResolveError
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import javax.lang.model.element.Element;
|
|
|
|
import javax.lang.model.element.TypeElement;
|
|
|
|
import javax.lang.model.type.DeclaredType;
|
|
|
|
import javax.lang.model.type.TypeMirror;
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: Vicente Romero <vicente.romero@oracle.com>
Co-authored-by: Andreas Lundblad <andreas.lundblad@oracle.com>
Co-authored-by: Andrey Nazarov <andrey.x.nazarov@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Kumar Srinivasan <kumar.x.srinivasan@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs
2016-03-17 19:04:28 +00:00
|
|
|
import javax.lang.model.util.ElementFilter;
|
2010-03-06 00:12:33 +00:00
|
|
|
import javax.lang.model.util.Elements;
|
|
|
|
import javax.lang.model.util.Types;
|
|
|
|
import javax.tools.*;
|
|
|
|
|
|
|
|
import com.sun.tools.javac.api.JavacTaskImpl;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a cut down version of TestJavacTaskScanner, which as originally written
|
|
|
|
* caused an IllegalArgumentException in AbstractDiagnosticFormatter as a result
|
|
|
|
* of calling task.parseType with a name whose resolution depended on the setting
|
|
|
|
* of the bootclasspath.
|
|
|
|
* This test has the same call, task.parseType("List<String>", clazz), but checks
|
|
|
|
* that the error is handled in a reasonable way by javac.
|
|
|
|
*/
|
|
|
|
public class TestResolveError extends ToolTester {
|
|
|
|
public static void main(String... args) throws Exception {
|
2014-10-30 02:07:34 +00:00
|
|
|
try (TestResolveError t = new TestResolveError()) {
|
|
|
|
t.run();
|
|
|
|
}
|
2010-03-06 00:12:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void run() throws Exception {
|
|
|
|
StringWriter sw = new StringWriter();
|
|
|
|
PrintWriter pw = new PrintWriter(sw);
|
|
|
|
File file = new File(test_src, "TestResolveError.java");
|
|
|
|
final Iterable<? extends JavaFileObject> compilationUnits =
|
|
|
|
fm.getJavaFileObjects(new File[] {file});
|
|
|
|
task = (JavacTaskImpl)tool.getTask(pw, fm, null, null, null, compilationUnits);
|
|
|
|
elements = task.getElements();
|
|
|
|
types = task.getTypes();
|
|
|
|
|
|
|
|
Iterable<? extends TypeElement> toplevels;
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: Vicente Romero <vicente.romero@oracle.com>
Co-authored-by: Andreas Lundblad <andreas.lundblad@oracle.com>
Co-authored-by: Andrey Nazarov <andrey.x.nazarov@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Kumar Srinivasan <kumar.x.srinivasan@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs
2016-03-17 19:04:28 +00:00
|
|
|
toplevels = ElementFilter.typesIn(task.enter(task.parse()));
|
2010-03-06 00:12:33 +00:00
|
|
|
|
|
|
|
for (TypeElement clazz : toplevels) {
|
|
|
|
System.out.format("Testing %s:%n%n", clazz.getSimpleName());
|
|
|
|
// this should not cause any exception from the compiler,
|
|
|
|
// such as IllegalArgumentException
|
|
|
|
testParseType(clazz);
|
|
|
|
}
|
|
|
|
|
|
|
|
pw.close();
|
|
|
|
|
|
|
|
String out = sw.toString();
|
|
|
|
System.out.println(out);
|
|
|
|
|
|
|
|
if (out.contains("com.sun.tools.javac.util"))
|
|
|
|
throw new Exception("Unexpected output from compiler");
|
|
|
|
}
|
|
|
|
|
|
|
|
void testParseType(TypeElement clazz) {
|
|
|
|
DeclaredType type = (DeclaredType)task.parseType("List<String>", clazz);
|
|
|
|
for (Element member : elements.getAllMembers((TypeElement)type.asElement())) {
|
|
|
|
TypeMirror mt = types.asMemberOf(type, member);
|
|
|
|
System.out.format("%s : %s -> %s%n", member.getSimpleName(), member.asType(), mt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JavacTaskImpl task;
|
|
|
|
Elements elements;
|
|
|
|
Types types;
|
|
|
|
}
|