langtools/test/tools/javac/processing/errors/TestSuppression.java
changeset 27319 030080f03e4f
parent 10454 9d5584396849
child 30730 d3ce7619db2c
equal deleted inserted replaced
27318:4660a5da7d90 27319:030080f03e4f
     1 /*
     1 /*
     2  * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    98 
    98 
    99         File x = writeFile(new File(srcDir, "X.java"), src);
    99         File x = writeFile(new File(srcDir, "X.java"), src);
   100 
   100 
   101         DiagListener dl = new DiagListener();
   101         DiagListener dl = new DiagListener();
   102         JavacTool tool = JavacTool.create();
   102         JavacTool tool = JavacTool.create();
   103         StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
   103         try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
   104         fm.setLocation(StandardLocation.CLASS_PATH,
   104             fm.setLocation(StandardLocation.CLASS_PATH,
   105                 Arrays.asList(classesDir, new File(System.getProperty("test.classes"))));
   105                     Arrays.asList(classesDir, new File(System.getProperty("test.classes"))));
   106         fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir));
   106             fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir));
   107         fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir));
   107             fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir));
   108         List<String> args = new ArrayList<String>();
   108             List<String> args = new ArrayList<String>();
   109 //        args.add("-XprintProcessorInfo");
   109     //        args.add("-XprintProcessorInfo");
   110         args.add("-XprintRounds");
   110             args.add("-XprintRounds");
   111         args.add("-Agen=" + gen);
   111             args.add("-Agen=" + gen);
   112         if (wk == WarningKind.YES)
   112             if (wk == WarningKind.YES)
   113             args.add("-Xlint:serial");
   113                 args.add("-Xlint:serial");
   114         Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x);
   114             Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x);
   115 
   115 
   116         StringWriter sw = new StringWriter();
   116             StringWriter sw = new StringWriter();
   117         PrintWriter pw = new PrintWriter(sw);
   117             PrintWriter pw = new PrintWriter(sw);
   118         JavacTask task = tool.getTask(pw, fm, dl, args, null, files);
   118             JavacTask task = tool.getTask(pw, fm, dl, args, null, files);
   119         task.setProcessors(Arrays.asList(new AnnoProc()));
   119             task.setProcessors(Arrays.asList(new AnnoProc()));
   120         boolean ok = task.call();
   120             boolean ok = task.call();
   121         pw.close();
   121             pw.close();
   122 
   122 
   123         System.err.println("ok:" + ok + " diags:" + dl.counts);
   123             System.err.println("ok:" + ok + " diags:" + dl.counts);
   124         if (sw.toString().length() > 0) {
   124             if (sw.toString().length() > 0) {
   125             System.err.println("output:\n" + sw.toString());
   125                 System.err.println("output:\n" + sw.toString());
   126         }
   126             }
   127 
   127 
   128         for (Diagnostic.Kind dk: Diagnostic.Kind.values()) {
   128             for (Diagnostic.Kind dk: Diagnostic.Kind.values()) {
   129             Integer v = dl.counts.get(dk);
   129                 Integer v = dl.counts.get(dk);
   130             int found = (v == null) ? 0 : v;
   130                 int found = (v == null) ? 0 : v;
   131             int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0;
   131                 int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0;
   132             if (found != expect) {
   132                 if (found != expect) {
   133                 error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found);
   133                     error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found);
   134             }
   134                 }
   135         }
   135             }
   136 
   136 
   137         System.err.println();
   137             System.err.println();
       
   138         }
   138     }
   139     }
   139 
   140 
   140     File createDir(File parent, String name) {
   141     File createDir(File parent, String name) {
   141         File dir = new File(parent, name);
   142         File dir = new File(parent, name);
   142         dir.mkdirs();
   143         dir.mkdirs();