langtools/test/tools/javac/diags/Example.java
changeset 10454 9d5584396849
parent 8615 11d80b55b0ed
child 10638 c8e9604cf151
equal deleted inserted replaced
10453:41fe3e16698a 10454:9d5584396849
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    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
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 import com.sun.tools.javac.file.JavacFileManager;
       
    25 import java.io.*;
    24 import java.io.*;
       
    25 import java.net.URL;
       
    26 import java.net.URLClassLoader;
    26 import java.util.*;
    27 import java.util.*;
    27 import java.util.regex.*;
    28 import java.util.regex.*;
       
    29 import javax.annotation.processing.Processor;
    28 import javax.tools.Diagnostic;
    30 import javax.tools.Diagnostic;
    29 import javax.tools.DiagnosticCollector;
    31 import javax.tools.DiagnosticCollector;
    30 import javax.tools.JavaCompiler;
    32 import javax.tools.JavaCompiler;
    31 import javax.tools.JavaCompiler.CompilationTask;
    33 import javax.tools.JavaCompiler.CompilationTask;
    32 import javax.tools.JavaFileObject;
    34 import javax.tools.JavaFileObject;
    35 
    37 
    36 // The following two classes are both used, but cannot be imported directly
    38 // The following two classes are both used, but cannot be imported directly
    37 // import com.sun.tools.javac.Main
    39 // import com.sun.tools.javac.Main
    38 // import com.sun.tools.javac.main.Main
    40 // import com.sun.tools.javac.main.Main
    39 
    41 
       
    42 import com.sun.tools.javac.api.ClientCodeWrapper;
       
    43 import com.sun.tools.javac.file.JavacFileManager;
    40 import com.sun.tools.javac.util.Context;
    44 import com.sun.tools.javac.util.Context;
    41 import com.sun.tools.javac.util.JavacMessages;
    45 import com.sun.tools.javac.util.JavacMessages;
    42 import com.sun.tools.javac.util.JCDiagnostic;
    46 import com.sun.tools.javac.util.JCDiagnostic;
    43 import java.net.URL;
       
    44 import java.net.URLClassLoader;
       
    45 import javax.annotation.processing.Processor;
       
    46 
    47 
    47 /**
    48 /**
    48  * Class to handle example code designed to illustrate javac diagnostic messages.
    49  * Class to handle example code designed to illustrate javac diagnostic messages.
    49  */
    50  */
    50 class Example implements Comparable<Example> {
    51 class Example implements Comparable<Example> {
   395             CompilationTask t = c.getTask(out, fm, dc, opts, null, fos);
   396             CompilationTask t = c.getTask(out, fm, dc, opts, null, fos);
   396             Boolean ok = t.call();
   397             Boolean ok = t.call();
   397 
   398 
   398             if (keys != null) {
   399             if (keys != null) {
   399                 for (Diagnostic<? extends JavaFileObject> d: dc.getDiagnostics()) {
   400                 for (Diagnostic<? extends JavaFileObject> d: dc.getDiagnostics()) {
   400                     scanForKeys((JCDiagnostic) d, keys);
   401                     scanForKeys(unwrap(d), keys);
   401                 }
   402                 }
   402             }
   403             }
   403 
   404 
   404             return ok;
   405             return ok;
   405         }
   406         }
   415                     scanForKeys((JCDiagnostic) o, keys);
   416                     scanForKeys((JCDiagnostic) o, keys);
   416                 }
   417                 }
   417             }
   418             }
   418             for (JCDiagnostic sd: d.getSubdiagnostics())
   419             for (JCDiagnostic sd: d.getSubdiagnostics())
   419                 scanForKeys(sd, keys);
   420                 scanForKeys(sd, keys);
       
   421         }
       
   422 
       
   423         private JCDiagnostic unwrap(Diagnostic<? extends JavaFileObject> diagnostic) {
       
   424             if (diagnostic instanceof JCDiagnostic)
       
   425                 return (JCDiagnostic) diagnostic;
       
   426             if (diagnostic instanceof ClientCodeWrapper.DiagnosticSourceUnwrapper)
       
   427                 return ((ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic).d;
       
   428             throw new IllegalArgumentException();
   420         }
   429         }
   421     }
   430     }
   422 
   431 
   423     /**
   432     /**
   424      * Run the test using the standard simple entry point.
   433      * Run the test using the standard simple entry point.