langtools/test/tools/javac/6341866/T6341866.java
changeset 27319 030080f03e4f
parent 22444 c79ee1e6742f
child 30730 d3ce7619db2c
equal deleted inserted replaced
27318:4660a5da7d90 27319:030080f03e4f
     1 /*
     1 /*
     2  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2006, 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.
   111         }
   111         }
   112 
   112 
   113 
   113 
   114         JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
   114         JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
   115         MyDiagListener dl = new MyDiagListener();
   115         MyDiagListener dl = new MyDiagListener();
   116         StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null);
   116         try (StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null)) {
   117 
   117 
   118         // Note: class A references class B, so compile A if we want implicit compilation
   118             // Note: class A references class B, so compile A if we want implicit compilation
   119         File file =  (implicitType != ImplicitType.NONE) ? a_java : b_java;
   119             File file =  (implicitType != ImplicitType.NONE) ? a_java : b_java;
   120         Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
   120             Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
   121 
   121 
   122         //System.err.println("compile: " + opts + " " + files);
   122             //System.err.println("compile: " + opts + " " + files);
   123 
   123 
   124         boolean ok = javac.getTask(null, fm, dl, opts, null, files).call();
   124             boolean ok = javac.getTask(null, fm, dl, opts, null, files).call();
   125         if (!ok) {
   125             if (!ok) {
   126             error("compilation failed");
   126                 error("compilation failed");
   127             return false;
       
   128         }
       
   129 
       
   130         // check implicit compilation results if necessary
       
   131         if (implicitType != ImplicitType.NONE) {
       
   132             boolean expectClass = (implicitType != ImplicitType.OPT_NONE);
       
   133             if (b_class.exists() != expectClass) {
       
   134                 if (b_class.exists())
       
   135                     error("B implicitly compiled unexpectedly");
       
   136                 else
       
   137                     error("B not impliictly compiled");
       
   138                 return false;
   127                 return false;
   139             }
   128             }
   140         }
   129 
   141 
   130             // check implicit compilation results if necessary
   142         // check message key results
   131             if (implicitType != ImplicitType.NONE) {
   143         String expectKey = null;
   132                 boolean expectClass = (implicitType != ImplicitType.OPT_NONE);
   144         if (implicitType == ImplicitType.OPT_UNSET) {
   133                 if (b_class.exists() != expectClass) {
   145             switch (annoType) {
   134                     if (b_class.exists())
   146             case SERVICE:
   135                         error("B implicitly compiled unexpectedly");
   147                 expectKey = "compiler.warn.proc.use.proc.or.implicit";
   136                     else
   148                 break;
   137                         error("B not impliictly compiled");
   149             case SPECIFY:
   138                     return false;
   150                 expectKey = "compiler.warn.proc.use.implicit";
   139                 }
   151                 break;
   140             }
   152             }
   141 
   153         }
   142             // check message key results
   154 
   143             String expectKey = null;
   155         if (expectKey == null) {
   144             if (implicitType == ImplicitType.OPT_UNSET) {
   156             if (dl.diagCodes.size() != 0) {
   145                 switch (annoType) {
   157                 error("no diagnostics expected");
   146                 case SERVICE:
   158                 return false;
   147                     expectKey = "compiler.warn.proc.use.proc.or.implicit";
   159             }
   148                     break;
   160         } else {
   149                 case SPECIFY:
   161             if (!(dl.diagCodes.size() == 1 && dl.diagCodes.get(0).equals(expectKey))) {
   150                     expectKey = "compiler.warn.proc.use.implicit";
   162                 error("unexpected diagnostics generated");
   151                     break;
   163                 return false;
   152                 }
   164             }
   153             }
   165         }
   154 
   166 
   155             if (expectKey == null) {
   167         return true;
   156                 if (dl.diagCodes.size() != 0) {
       
   157                     error("no diagnostics expected");
       
   158                     return false;
       
   159                 }
       
   160             } else {
       
   161                 if (!(dl.diagCodes.size() == 1 && dl.diagCodes.get(0).equals(expectKey))) {
       
   162                     error("unexpected diagnostics generated");
       
   163                     return false;
       
   164                 }
       
   165             }
       
   166 
       
   167             return true;
       
   168         }
   168     }
   169     }
   169 
   170 
   170     static void createProcessorServices(String name) throws IOException {
   171     static void createProcessorServices(String name) throws IOException {
   171         processorServices.getParentFile().mkdirs();
   172         processorServices.getParentFile().mkdirs();
   172 
   173