1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/processing/options/testCommandLineClasses/Test.java Wed Mar 16 17:21:52 2011 -0700 1.3 @@ -0,0 +1,106 @@ 1.4 +/* 1.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 6930508 1.30 + * @summary Passing nested class names on javac command line interfere with subsequent name -> class lookup 1.31 + * @library ../../../lib 1.32 + * @build JavacTestingAbstractProcessor p.NestedExamples Test 1.33 + * @run main Test 1.34 + */ 1.35 + 1.36 +import java.io.*; 1.37 +import java.util.*; 1.38 +import javax.annotation.processing.RoundEnvironment; 1.39 +import javax.lang.model.element.TypeElement; 1.40 +import javax.lang.model.util.ElementFilter; 1.41 +import javax.tools.*; 1.42 + 1.43 +import p.NestedExamples; 1.44 + 1.45 +public class Test extends JavacTestingAbstractProcessor { 1.46 + public static void main(String... args) throws Exception { 1.47 + new Test().run(); 1.48 + } 1.49 + 1.50 + void run() throws Exception { 1.51 + NestedExamples e = new NestedExamples(); 1.52 + List<String> names = getNames(e.getClasses()); 1.53 + test(names); 1.54 + test(reverse(names)); 1.55 + names = Arrays.asList(e.getClassNames()); 1.56 + test(names); 1.57 + test(reverse(names)); 1.58 + 1.59 + if (errors > 0) 1.60 + throw new RuntimeException(errors + " errors occurred"); 1.61 + } 1.62 + 1.63 + List<String> getNames(Class<?>[] classes) { 1.64 + List<String> names = new ArrayList<String>(); 1.65 + for (Class<?> c: classes) 1.66 + names.add(c.getName()); 1.67 + return names; 1.68 + } 1.69 + 1.70 + void test(List<String> names) throws Exception { 1.71 + System.err.println("test: " + names); 1.72 + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 1.73 + StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); 1.74 + File testClasses = new File(System.getProperty("test.classes")); 1.75 + fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(testClasses)); 1.76 + JavaCompiler.CompilationTask task = compiler.getTask( 1.77 + null, null, null, Arrays.asList("-proc:only"), names, null); 1.78 + task.setProcessors(Arrays.asList(new Test())); 1.79 + boolean ok = task.call(); 1.80 + if (!ok) 1.81 + error("compilation failed"); 1.82 + System.err.println(); 1.83 + } 1.84 + 1.85 + <T> List<T> reverse(List<T> list) { 1.86 + List<T> newList = new ArrayList<T>(list); 1.87 + Collections.reverse(newList); 1.88 + return newList; 1.89 + } 1.90 + 1.91 + int errors = 0; 1.92 + 1.93 + void error(String msg) { 1.94 + System.out.println("Error: " + msg); 1.95 + errors++; 1.96 + } 1.97 + 1.98 + //---------- 1.99 + 1.100 + public boolean process(Set<? extends TypeElement> annotations, 1.101 + RoundEnvironment roundEnv) { 1.102 + if (!roundEnv.processingOver()) { 1.103 + for (TypeElement typeElt : ElementFilter.typesIn(roundEnv.getRootElements())) { 1.104 + messager.printMessage(Diagnostic.Kind.NOTE, "processing " + typeElt); 1.105 + } 1.106 + } 1.107 + return true; 1.108 + } 1.109 +}