10
|
1 |
/*
|
|
2 |
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 6358168
|
|
27 |
* @summary JavaCompiler.hasBeenUsed is not set in delegateCompiler
|
|
28 |
*/
|
|
29 |
|
|
30 |
import java.io.*;
|
|
31 |
import java.net.*;
|
|
32 |
import java.util.*;
|
|
33 |
import javax.annotation.processing.*;
|
|
34 |
import javax.lang.model.element.*;
|
|
35 |
import javax.tools.*;
|
|
36 |
import com.sun.tools.javac.main.JavaCompiler;
|
|
37 |
import com.sun.tools.javac.main.*;
|
|
38 |
import com.sun.tools.javac.util.*;
|
|
39 |
import com.sun.tools.javac.util.List; // disambiguate
|
|
40 |
|
|
41 |
|
|
42 |
@SupportedAnnotationTypes("*")
|
|
43 |
public class T6358168 extends AbstractProcessor {
|
|
44 |
private static String testClasses = System.getProperty("test.classes");
|
|
45 |
private static String testSrc = System.getProperty("test.src");
|
|
46 |
private static String self = T6358168.class.getName();
|
|
47 |
|
|
48 |
public static void main(String... args) throws Throwable {
|
|
49 |
|
|
50 |
JavacFileManager fm = new JavacFileManager(new Context(), false, null);
|
|
51 |
JavaFileObject f = fm.getFileForInput(testSrc + File.separatorChar + T6358168.class.getName() + ".java");
|
|
52 |
|
|
53 |
try {
|
|
54 |
// first, test case with no annotation processing
|
|
55 |
testNoAnnotationProcessing(fm, f);
|
|
56 |
|
|
57 |
// now, test case with annotation processing
|
|
58 |
testAnnotationProcessing(fm, f);
|
|
59 |
}
|
|
60 |
catch (Throwable t) {
|
|
61 |
AssertionError e = new AssertionError();
|
|
62 |
e.initCause(t);
|
|
63 |
throw e;
|
|
64 |
}
|
|
65 |
}
|
|
66 |
|
|
67 |
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
|
|
68 |
Context context = new Context();
|
|
69 |
fm.setContext(context);
|
|
70 |
|
|
71 |
Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
|
|
72 |
compilerMain.setOptions(Options.instance(context));
|
|
73 |
compilerMain.filenames = new ListBuffer<File>();
|
|
74 |
compilerMain.processArgs(new String[] { "-d", "." });
|
|
75 |
|
|
76 |
JavaCompiler compiler = JavaCompiler.instance(context);
|
|
77 |
compiler.compile(List.of(f));
|
|
78 |
try {
|
|
79 |
compiler.compile(List.of(f));
|
|
80 |
throw new Error("Error: AssertionError not thrown after second call of compile");
|
|
81 |
} catch (AssertionError e) {
|
|
82 |
System.err.println("Exception from compiler (expected): " + e);
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
static void testAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
|
|
87 |
Context context = new Context();
|
|
88 |
fm.setContext(context);
|
|
89 |
|
|
90 |
Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
|
|
91 |
compilerMain.setOptions(Options.instance(context));
|
|
92 |
compilerMain.filenames = new ListBuffer<File>();
|
|
93 |
compilerMain.processArgs(new String[] {
|
|
94 |
"-XprintRounds",
|
|
95 |
"-processorpath", testClasses,
|
|
96 |
"-processor", self,
|
|
97 |
"-d", "."});
|
|
98 |
|
|
99 |
JavaCompiler compiler = JavaCompiler.instance(context);
|
|
100 |
compiler.initProcessAnnotations(null);
|
|
101 |
JavaCompiler compiler2 = compiler.processAnnotations(compiler.enterTrees(compiler.parseFiles(List.of(f))));
|
|
102 |
try {
|
|
103 |
compiler2.compile(List.of(f));
|
|
104 |
throw new Error("Error: AssertionError not thrown after second call of compile");
|
|
105 |
} catch (AssertionError e) {
|
|
106 |
System.err.println("Exception from compiler (expected): " + e);
|
|
107 |
}
|
|
108 |
}
|
|
109 |
|
|
110 |
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
|
|
111 |
return true;
|
|
112 |
}
|
|
113 |
}
|