jjg@937: /* jjg@937: * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. jjg@937: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@937: * jjg@937: * This code is free software; you can redistribute it and/or modify it jjg@937: * under the terms of the GNU General Public License version 2 only, as jjg@937: * published by the Free Software Foundation. jjg@937: * jjg@937: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@937: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@937: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@937: * version 2 for more details (a copy is included in the LICENSE file that jjg@937: * accompanied this code). jjg@937: * jjg@937: * You should have received a copy of the GNU General Public License version jjg@937: * 2 along with this work; if not, write to the Free Software Foundation, jjg@937: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@937: * jjg@937: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jjg@937: * or visit www.oracle.com if you need additional information or have any jjg@937: * questions. jjg@937: */ jjg@937: jjg@937: /* jjg@937: * @test jjg@937: * @bug 6930508 jjg@937: * @summary Passing nested class names on javac command line interfere with subsequent name -> class lookup darcy@1466: * @library /tools/javac/lib jjg@937: * @build JavacTestingAbstractProcessor p.NestedExamples Test jjg@937: * @run main Test jjg@937: */ jjg@937: jjg@937: import java.io.*; jjg@937: import java.util.*; jjg@937: import javax.annotation.processing.RoundEnvironment; jjg@937: import javax.lang.model.element.TypeElement; jjg@937: import javax.lang.model.util.ElementFilter; jjg@937: import javax.tools.*; jjg@937: jjg@937: import p.NestedExamples; jjg@937: jjg@937: public class Test extends JavacTestingAbstractProcessor { jjg@937: public static void main(String... args) throws Exception { jjg@937: new Test().run(); jjg@937: } jjg@937: jjg@937: void run() throws Exception { jjg@937: NestedExamples e = new NestedExamples(); jjg@937: List names = getNames(e.getClasses()); jjg@937: test(names); jjg@937: test(reverse(names)); jjg@937: names = Arrays.asList(e.getClassNames()); jjg@937: test(names); jjg@937: test(reverse(names)); jjg@937: jjg@937: if (errors > 0) jjg@937: throw new RuntimeException(errors + " errors occurred"); jjg@937: } jjg@937: jjg@937: List getNames(Class[] classes) { jjg@937: List names = new ArrayList(); jjg@937: for (Class c: classes) jjg@937: names.add(c.getName()); jjg@937: return names; jjg@937: } jjg@937: jjg@937: void test(List names) throws Exception { jjg@937: System.err.println("test: " + names); jjg@937: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); jjg@937: StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); jjg@937: File testClasses = new File(System.getProperty("test.classes")); jjg@937: fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(testClasses)); jjg@937: JavaCompiler.CompilationTask task = compiler.getTask( jjg@937: null, null, null, Arrays.asList("-proc:only"), names, null); jjg@937: task.setProcessors(Arrays.asList(new Test())); jjg@937: boolean ok = task.call(); jjg@937: if (!ok) jjg@937: error("compilation failed"); jjg@937: System.err.println(); jjg@937: } jjg@937: jjg@937: List reverse(List list) { jjg@937: List newList = new ArrayList(list); jjg@937: Collections.reverse(newList); jjg@937: return newList; jjg@937: } jjg@937: jjg@937: int errors = 0; jjg@937: jjg@937: void error(String msg) { jjg@937: System.out.println("Error: " + msg); jjg@937: errors++; jjg@937: } jjg@937: jjg@937: //---------- jjg@937: jjg@937: public boolean process(Set annotations, jjg@937: RoundEnvironment roundEnv) { jjg@937: if (!roundEnv.processingOver()) { jjg@937: for (TypeElement typeElt : ElementFilter.typesIn(roundEnv.getRootElements())) { jjg@937: messager.printMessage(Diagnostic.Kind.NOTE, "processing " + typeElt); jjg@937: } jjg@937: } jjg@937: return true; jjg@937: } jjg@937: }