test/tools/javac/processing/6634138/T6634138.java

changeset 494
af18e3956985
child 554
9d9f26857129
equal deleted inserted replaced
493:7d9e3a15d2b3 494:af18e3956985
1 /*
2 * Copyright 2010 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 6634138
27 * @author Joseph D. Darcy
28 * @summary Verify source files output after processing is over are compiled
29 * @compile T6634138.java
30 * @compile -processor T6634138 Dummy.java
31 * @run main ExerciseDependency
32 */
33
34 import java.lang.annotation.Annotation;
35 import java.io.*;
36 import java.util.Collections;
37 import java.util.Set;
38 import java.util.HashSet;
39 import java.util.List;
40 import java.util.ArrayList;
41 import java.util.Arrays;
42 import javax.annotation.processing.*;
43 import javax.lang.model.SourceVersion;
44 import javax.lang.model.element.*;
45 import javax.lang.model.util.*;
46
47 @SupportedAnnotationTypes("*")
48 public class T6634138 extends AbstractProcessor {
49 private Filer filer;
50
51 public boolean process(Set<? extends TypeElement> annotations,
52 RoundEnvironment roundEnvironment) {
53 // Write out files *after* processing is over.
54 if (roundEnvironment.processingOver()) {
55 System.out.println("Writing out source files.");
56 try {
57 PrintWriter pw = new PrintWriter(filer.createSourceFile("foo.WrittenAfterProcessing").openWriter());
58 try {
59 pw.println("package foo;");
60 pw.println("public class WrittenAfterProcessing {");
61 pw.println(" public WrittenAfterProcessing() {super();}");
62 pw.println("}");
63 } finally {
64 pw.close();
65 }
66
67 pw = new PrintWriter(filer.createSourceFile("foo.package-info").openWriter());
68 try {
69 pw.println("@Deprecated");
70 pw.println("package foo;");
71 } finally {
72 pw.close();
73 }
74 } catch(IOException io) {
75 throw new RuntimeException(io);
76 }
77 }
78 return true;
79 }
80
81 @Override
82 public SourceVersion getSupportedSourceVersion() {
83 return SourceVersion.latest();
84 }
85
86 public void init(ProcessingEnvironment processingEnv) {
87 super.init(processingEnv);
88 filer = processingEnv.getFiler();
89 }
90 }
91
92
93

mercurial