langtools/test/tools/javac/processing/6634138/T6634138.java
author darcy
Mon, 15 Feb 2010 18:20:57 -0800
changeset 4934 c6a2cf3b6b82
child 5520 86e4b9a9da40
permissions -rw-r--r--
6634138: Source generated in last round not compiled Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4934
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
     1
/*
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
     2
 * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
     4
 *
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
     8
 *
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    13
 * accompanied this code).
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    14
 *
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    18
 *
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    21
 * have any questions.
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    22
 */
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    23
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    24
/*
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    25
 * @test
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    26
 * @bug 6634138
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    27
 * @author  Joseph D. Darcy
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    28
 * @summary Verify source files output after processing is over are compiled
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    29
 * @compile T6634138.java
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    30
 * @compile -processor T6634138 Dummy.java
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    31
 * @run main ExerciseDependency
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    32
 */
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    33
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    34
import java.lang.annotation.Annotation;
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    35
import java.io.*;
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    36
import java.util.Collections;
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    37
import java.util.Set;
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    38
import java.util.HashSet;
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    39
import java.util.List;
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    40
import java.util.ArrayList;
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    41
import java.util.Arrays;
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    42
import javax.annotation.processing.*;
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    43
import javax.lang.model.SourceVersion;
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    44
import javax.lang.model.element.*;
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    45
import javax.lang.model.util.*;
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    46
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    47
@SupportedAnnotationTypes("*")
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    48
public class T6634138 extends AbstractProcessor {
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    49
    private Filer filer;
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    50
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    51
    public boolean process(Set<? extends TypeElement> annotations,
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    52
                           RoundEnvironment roundEnvironment) {
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    53
        // Write out files *after* processing is over.
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    54
        if (roundEnvironment.processingOver()) {
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    55
            System.out.println("Writing out source files.");
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    56
            try {
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    57
                PrintWriter pw = new PrintWriter(filer.createSourceFile("foo.WrittenAfterProcessing").openWriter());
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    58
                try {
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    59
                     pw.println("package foo;");
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    60
                     pw.println("public class WrittenAfterProcessing {");
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    61
                     pw.println("  public WrittenAfterProcessing() {super();}");
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    62
                     pw.println("}");
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    63
                 } finally {
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    64
                     pw.close();
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    65
                 }
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    66
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    67
                pw = new PrintWriter(filer.createSourceFile("foo.package-info").openWriter());
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    68
                try {
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    69
                     pw.println("@Deprecated");
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    70
                     pw.println("package foo;");
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    71
                 } finally {
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    72
                     pw.close();
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    73
                 }
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    74
            } catch(IOException io) {
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    75
                throw new RuntimeException(io);
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    76
            }
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    77
        }
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    78
        return true;
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    79
    }
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    80
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    81
    @Override
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    82
    public SourceVersion getSupportedSourceVersion() {
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    83
        return SourceVersion.latest();
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    84
    }
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    85
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    86
    public void init(ProcessingEnvironment processingEnv) {
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    87
        super.init(processingEnv);
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    88
        filer    = processingEnv.getFiler();
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    89
    }
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    90
}
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    91
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    92
c6a2cf3b6b82 6634138: Source generated in last round not compiled
darcy
parents:
diff changeset
    93