37
import javax.annotation.processing.*;
38
import javax.lang.model.element.*;
41
import com.sun.source.util.JavacTask;
42
import com.sun.tools.javac.api.JavacTool;
43
import com.sun.tools.javac.file.JavacFileManager;
44
import com.sun.tools.javac.main.JavaCompiler;
45
import com.sun.tools.javac.util.*;
46
import com.sun.tools.javac.util.List;
49
@SupportedAnnotationTypes("*")
50
public class T6358168 extends AbstractProcessor {
51
private static final String testClasses = System.getProperty("test.classes");
52
private static final String testSrc = System.getProperty("test.src");
53
private static final String self = T6358168.class.getName();
55
public static void main(String... args) throws Throwable {
57
JavacFileManager fm = new JavacFileManager(new Context(), false, null);
58
List<JavaFileObject> files = toList(fm.getJavaFileObjects(new File(testSrc, self + ".java")));
62
testNoAnnotationProcessing(fm, files);
65
testAnnotationProcessing(fm, files);
68
throw new AssertionError(t);
72
static void testNoAnnotationProcessing(JavacFileManager fm, List<JavaFileObject> files) throws Throwable {
73
Context context = new Context();
75
String[] args = { "-d", "." };
77
JavacTool tool = JavacTool.create();
78
JavacTask task = tool.getTask(null, fm, null, List.from(args), null, files, context);
81
JavaCompiler compiler = JavaCompiler.instance(context);
82
compiler.compile(files);
84
compiler.compile(files);
85
throw new Error("Error: AssertionError not thrown after second call of compile");
86
} catch (AssertionError e) {
87
System.err.println("Exception from compiler (expected): " + e);
91
static void testAnnotationProcessing(JavacFileManager fm, List<JavaFileObject> files) throws Throwable {
92
Context context = new Context();
96
"-processorpath", testClasses,
101
JavacTool tool = JavacTool.create();
102
JavacTask task = tool.getTask(null, fm, null, List.from(args), null, files, context);
105
JavaCompiler compiler = JavaCompiler.instance(context);
106
compiler.compile(files);
108
compiler.compile(files);
109
throw new Error("Error: AssertionError not thrown after second call of compile");
110
} catch (AssertionError e) {
111
System.err.println("Exception from compiler (expected): " + e);
115
private static List<JavaFileObject> toList(Iterable<? extends JavaFileObject> iter) {
116
ListBuffer<JavaFileObject> files = new ListBuffer<>();
117
for (JavaFileObject file: iter)
119
return files.toList();
123
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {