langtools/test/tools/javac/annotations/neg/8022765/VerifyErroneousAnnotationsAttributed.java
changeset 27388 d694da45bd7a
parent 22439 4785d87cd2d6
child 30730 d3ce7619db2c
equal deleted inserted replaced
27387:54142fc27e8a 27388:d694da45bd7a
    42 import javax.lang.model.element.Element;
    42 import javax.lang.model.element.Element;
    43 import javax.lang.model.element.ElementKind;
    43 import javax.lang.model.element.ElementKind;
    44 import javax.lang.model.type.TypeKind;
    44 import javax.lang.model.type.TypeKind;
    45 import javax.tools.Diagnostic;
    45 import javax.tools.Diagnostic;
    46 import javax.tools.DiagnosticListener;
    46 import javax.tools.DiagnosticListener;
       
    47 import javax.tools.JavaFileManager;
    47 import javax.tools.JavaFileObject;
    48 import javax.tools.JavaFileObject;
    48 import javax.tools.SimpleJavaFileObject;
    49 import javax.tools.SimpleJavaFileObject;
    49 
    50 
    50 public class VerifyErroneousAnnotationsAttributed {
    51 public class VerifyErroneousAnnotationsAttributed {
    51     public static void main(String... args) throws IOException, URISyntaxException {
    52     public static void main(String... args) throws IOException, URISyntaxException {
    52         new VerifyErroneousAnnotationsAttributed().run();
    53         new VerifyErroneousAnnotationsAttributed().run();
    53     }
    54     }
    54 
    55 
    55     void run() {
    56     void run() throws IOException {
    56         int failCount = 0;
    57         try {
    57         for (String ann : generateAnnotations()) {
    58             int failCount = 0;
    58             String code = PATTERN.replace("PLACEHOLDER", ann);
    59             for (String ann : generateAnnotations()) {
    59             try {
    60                 String code = PATTERN.replace("PLACEHOLDER", ann);
    60                 validate(code);
    61                 try {
    61             } catch (Throwable t) {
    62                     validate(code);
    62                 System.out.println("Failed for: ");
    63                 } catch (Throwable t) {
    63                 System.out.println(code);
    64                     System.out.println("Failed for: ");
    64                 t.printStackTrace(System.out);
    65                     System.out.println(code);
    65                 failCount++;
    66                     t.printStackTrace(System.out);
    66             }
    67                     failCount++;
    67         }
    68                 }
    68 
    69             }
    69         if (failCount > 0) {
    70 
    70             throw new IllegalStateException("failed sub-tests: " + failCount);
    71             if (failCount > 0) {
       
    72                 throw new IllegalStateException("failed sub-tests: " + failCount);
       
    73             }
       
    74         } finally {
       
    75             fm.close();
    71         }
    76         }
    72     }
    77     }
    73 
    78 
    74     List<String> generateAnnotations() {
    79     List<String> generateAnnotations() {
    75         List<String> result = new ArrayList<>();
    80         List<String> result = new ArrayList<>();
   219         }
   224         }
   220 
   225 
   221     }
   226     }
   222 
   227 
   223     final JavacTool tool = JavacTool.create();
   228     final JavacTool tool = JavacTool.create();
       
   229     final JavaFileManager fm = tool.getStandardFileManager(null, null, null);
   224     final DiagnosticListener<JavaFileObject> devNull = new DiagnosticListener<JavaFileObject>() {
   230     final DiagnosticListener<JavaFileObject> devNull = new DiagnosticListener<JavaFileObject>() {
   225         @Override public void report(Diagnostic<? extends JavaFileObject> diagnostic) {}
   231         @Override public void report(Diagnostic<? extends JavaFileObject> diagnostic) {}
   226     };
   232     };
   227 
   233 
   228     void validate(String code) throws IOException, URISyntaxException {
   234     void validate(String code) throws IOException, URISyntaxException {
   229         JavacTask task = tool.getTask(null,
   235         JavacTask task = tool.getTask(null,
   230                                       null,
   236                                       fm,
   231                                       devNull,
   237                                       devNull,
   232                                       Arrays.asList("-XDshouldStopPolicy=FLOW"),
   238                                       Arrays.asList("-XDshouldStopPolicy=FLOW"),
   233                                       null,
   239                                       null,
   234                                       Arrays.asList(new MyFileObject(code)));
   240                                       Arrays.asList(new MyFileObject(code)));
   235 
   241