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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * 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 | 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * 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 * @library ../../lib 30 * @build JavacTestingAbstractProcessor 31 * @compile T6634138.java 32 * @compile -processor T6634138 Dummy.java 33 * @run main ExerciseDependency 34 */ 35 36 import java.lang.annotation.Annotation; 37 import java.io.*; 38 import java.util.Collections; 39 import java.util.Set; 40 import java.util.HashSet; 41 import java.util.List; 42 import java.util.ArrayList; 43 import java.util.Arrays; 44 import javax.annotation.processing.*; 45 import javax.lang.model.SourceVersion; 46 import javax.lang.model.element.*; 47 import javax.lang.model.util.*; 48 49 public class T6634138 extends JavacTestingAbstractProcessor { 50 public boolean process(Set<? extends TypeElement> annotations, 51 RoundEnvironment roundEnvironment) { 52 // Write out files *after* processing is over. 53 if (roundEnvironment.processingOver()) { 54 System.out.println("Writing out source files."); 55 try { 56 PrintWriter pw = new PrintWriter(filer.createSourceFile("foo.WrittenAfterProcessing").openWriter()); 57 try { 58 pw.println("package foo;"); 59 pw.println("public class WrittenAfterProcessing {"); 60 pw.println(" public WrittenAfterProcessing() {super();}"); 61 pw.println("}"); 62 } finally { 63 pw.close(); 64 } 65 66 pw = new PrintWriter(filer.createSourceFile("foo.package-info").openWriter()); 67 try { 68 pw.println("@Deprecated"); 69 pw.println("package foo;"); 70 } finally { 71 pw.close(); 72 } 73 } catch(IOException io) { 74 throw new RuntimeException(io); 75 } 76 } 77 return true; 78 } 79 } 80 81 82 |