langtools/test/tools/javac/classreader/T7031108.java
changeset 27319 030080f03e4f
parent 14963 974d4423c999
child 30730 d3ce7619db2c
equal deleted inserted replaced
27318:4660a5da7d90 27319:030080f03e4f
     1 /*
     1 /*
     2  * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2011, 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.
    66             new JavaSource("Dummy.java",
    66             new JavaSource("Dummy.java",
    67                 "class Dummy { }");
    67                 "class Dummy { }");
    68 
    68 
    69     void run() throws Exception {
    69     void run() throws Exception {
    70         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
    70         JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
    71         StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
    71         try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
    72 
    72 
    73         // step 1: compile test classes
    73             // step 1: compile test classes
    74         File cwd = new File(".");
    74             File cwd = new File(".");
    75         fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(cwd));
    75             fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(cwd));
    76         compile(comp, fm, null, null, pC);
    76             compile(comp, fm, null, null, pC);
    77 
    77 
    78         // step 2: verify functioning of processor
    78             // step 2: verify functioning of processor
    79         fm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH,
    79             fm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH,
    80                 fm.getLocation(StandardLocation.CLASS_PATH));
    80                     fm.getLocation(StandardLocation.CLASS_PATH));
    81         fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(cwd));
    81             fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(cwd));
    82         compile(comp, fm, null, getClass().getName(), dummy);
    82             compile(comp, fm, null, getClass().getName(), dummy);
    83 
    83 
    84         File pC_class = new File(new File("p"), "C.class");
    84             File pC_class = new File(new File("p"), "C.class");
    85         pC_class.delete();
    85             pC_class.delete();
    86 
    86 
    87         DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
    87             DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
    88         compile(comp, fm, dc, getClass().getName(), dummy);
    88             compile(comp, fm, dc, getClass().getName(), dummy);
    89         List<Diagnostic<? extends JavaFileObject>> diags =dc.getDiagnostics();
    89             List<Diagnostic<? extends JavaFileObject>> diags =dc.getDiagnostics();
    90 
    90 
    91         System.err.println(diags);
    91             System.err.println(diags);
    92         switch (diags.size()) {
    92             switch (diags.size()) {
    93             case 0:
    93                 case 0:
    94                 throw new Exception("no diagnostics received");
    94                     throw new Exception("no diagnostics received");
    95             case 1:
    95                 case 1:
    96                 String code = diags.get(0).getCode();
    96                     String code = diags.get(0).getCode();
    97                 String expect = "compiler.err.proc.cant.access.1";
    97                     String expect = "compiler.err.proc.cant.access.1";
    98                 if (!expect.equals(code))
    98                     if (!expect.equals(code))
    99                     throw new Exception("unexpected diag code: " + code
    99                         throw new Exception("unexpected diag code: " + code
   100                             + ", expected: " + expect);
   100                                 + ", expected: " + expect);
   101                 break;
   101                     break;
   102             default:
   102                 default:
   103                 throw new Exception("unexpected diags received");
   103                     throw new Exception("unexpected diags received");
       
   104             }
   104         }
   105         }
   105     }
   106     }
   106 
   107 
   107     void compile(JavaCompiler comp, JavaFileManager fm,
   108     void compile(JavaCompiler comp, JavaFileManager fm,
   108             DiagnosticListener<JavaFileObject> dl,
   109             DiagnosticListener<JavaFileObject> dl,