langtools/test/tools/javac/modules/QueryBeforeEnter.java
author jjg
Thu, 31 Mar 2016 15:20:50 -0700
changeset 36778 e04318f39f92
parent 36526 3b41f1c69604
child 37758 3ecf9b414e05
permissions -rw-r--r--
8152897: refactor ToolBox to allow reduced documented dependencies Reviewed-by: vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @summary tests for module resolution
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @library /tools/lib
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @modules
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 *      jdk.compiler/com.sun.tools.javac.api
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 *      jdk.compiler/com.sun.tools.javac.main
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    31
 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 * @run main QueryBeforeEnter
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.io.File;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.io.OutputStream;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.nio.file.*;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.util.Set;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import javax.annotation.processing.AbstractProcessor;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import javax.annotation.processing.RoundEnvironment;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import javax.annotation.processing.SupportedAnnotationTypes;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import javax.annotation.processing.SupportedSourceVersion;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import javax.lang.model.SourceVersion;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import javax.lang.model.element.TypeElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import javax.tools.JavaCompiler;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import javax.tools.StandardJavaFileManager;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
import javax.tools.ToolProvider;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    51
// import com.sun.source.util.JavacTask;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
import com.sun.source.util.Plugin;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
import com.sun.source.util.TaskEvent;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
import com.sun.source.util.TaskListener;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
import com.sun.tools.javac.Main;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    57
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    58
import toolbox.Task;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    59
import toolbox.ToolBox;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    60
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
public class QueryBeforeEnter extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
        QueryBeforeEnter t = new QueryBeforeEnter();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
        t.runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
    void testEmpty(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
        JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    70
        com.sun.source.util.JavacTask task =
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    71
            (com.sun.source.util.JavacTask) javaCompiler.getTask(null, null, null, null, null, null);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        TypeElement jlString = task.getElements().getTypeElement("java.lang.String");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        assertNotNull(jlString);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    75
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
    void testUnnamed(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        Path moduleSrc = base.resolve("module-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
        Path m1 = moduleSrc.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
        tb.writeJavaFiles(m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                          "module m1 { exports m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
                          "package m1; public class M1 {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        Path m2 = moduleSrc.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        tb.writeJavaFiles(m2,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
                          "module m2 { exports m2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
                          "package m2; public class M2 {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    96
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
                .options("-modulesourcepath", moduleSrc.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
                .outdir(modulePath)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
                .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
        Path cpSrc = base.resolve("cp-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
        tb.writeJavaFiles(cpSrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
                          "package cp; public class CP {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
        Path cp = base.resolve("cp");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        Files.createDirectories(cp);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   112
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
                .outdir(cp)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                .files(findJavaFiles(cpSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                          "package test; public class Test1 {}",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                          "package test; public class Test2 {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        Path out = base.resolve("out");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        Files.createDirectories(out);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   130
            com.sun.source.util.JavacTask task =
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   131
                (com.sun.source.util.JavacTask) javaCompiler.getTask(null,
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
                                                              null,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
                                                              d -> { throw new IllegalStateException(d.toString()); },
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
                                                              Arrays.asList("-modulepath", modulePath.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                                                                            "-classpath", cp.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                                                                            "-sourcepath", src.toString()),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                                                              null,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                                                              fm.getJavaFileObjects(src.resolve("test").resolve("Test2.java")));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
            assertNotNull(task.getElements().getTypeElement("java.lang.String"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
            assertNotNull(task.getElements().getTypeElement("javax.tools.ToolProvider"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
            assertNull(task.getElements().getTypeElement("m1.M1"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
            assertNull(task.getElements().getTypeElement("m2.M2"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
            assertNotNull(task.getElements().getTypeElement("cp.CP"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
            assertNotNull(task.getElements().getTypeElement("test.Test1"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
            assertNotNull(task.getElements().getTypeElement("test.Test2"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
            assertNotNull(task.getElements().getModuleElement("java.base"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
            assertNotNull(task.getElements().getModuleElement("java.compiler"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
            assertNull(task.getElements().getModuleElement("m1"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
            assertNull(task.getElements().getModuleElement("m2"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
    void testSingleNamed(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        Path moduleSrc = base.resolve("module-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
        Path m1 = moduleSrc.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        tb.writeJavaFiles(m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                          "module m1 { exports m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
                          "package m1; public class M1 {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
        Path m2 = moduleSrc.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
        tb.writeJavaFiles(m2,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
                          "module m2 { exports m2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
                          "package m2; public class M2 {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   172
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                .options("-modulesourcepath", moduleSrc.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                .outdir(modulePath)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
                .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
        Path cpSrc = base.resolve("cp-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
        tb.writeJavaFiles(cpSrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
                          "package cp; public class CP {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
        Path cp = base.resolve("cp");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        Files.createDirectories(cp);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   188
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
                .outdir(cp)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                .files(findJavaFiles(cpSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
                          "module test { requires java.base; requires m1; } ",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
                          "package test; public class Test {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
        Path out = base.resolve("out");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        Files.createDirectories(out);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
        JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   206
            com.sun.source.util.JavacTask task =
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   207
                (com.sun.source.util.JavacTask) javaCompiler.getTask(null,
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
                                                              null,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
                                                              d -> { throw new IllegalStateException(d.toString()); },
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
                                                              Arrays.asList("-modulepath", modulePath.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                                                                            "-classpath", cp.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
                                                                            "-sourcepath", src.toString()),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
                                                              null,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
                                                              fm.getJavaFileObjects(findJavaFiles(src)));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
            assertNotNull(task.getElements().getTypeElement("java.lang.String"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
            assertNull(task.getElements().getTypeElement("javax.tools.ToolProvider"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
            assertNotNull(task.getElements().getTypeElement("m1.M1"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
            assertNull(task.getElements().getTypeElement("m2.M2"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
            assertNotNull(task.getElements().getTypeElement("test.Test"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
            assertNotNull(task.getElements().getModuleElement("java.base"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
            assertNull(task.getElements().getModuleElement("java.compiler"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
            assertNotNull(task.getElements().getModuleElement("m1"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
            assertNull(task.getElements().getModuleElement("m2"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
            assertNotNull(task.getElements().getModuleElement("test"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
    void testMultiModule(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        Path modulePathSrc = base.resolve("module-path-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
        Path m1 = modulePathSrc.resolve("m1");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
        tb.writeJavaFiles(m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
                          "module m1 { exports m1; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
                          "package m1; public class M1 {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
        Path m2 = modulePathSrc.resolve("m2");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        tb.writeJavaFiles(m2,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
                          "module m2 { exports m2; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
                          "package m2; public class M2 {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   247
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
                .options("-modulesourcepath", modulePathSrc.toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                .outdir(modulePath)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
                .files(findJavaFiles(modulePathSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
        Path cpSrc = base.resolve("cp-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
        tb.writeJavaFiles(cpSrc,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
                          "package cp; public class CP {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
        Path cp = base.resolve("cp");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
        Files.createDirectories(cp);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   263
        new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
                .outdir(cp)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
                .files(findJavaFiles(cpSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
        Path moduleSrc = base.resolve("module-src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
        Path m3 = moduleSrc.resolve("m3");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
        tb.writeJavaFiles(m3,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
                          "module m3 { requires m1; exports m3; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                          "package m3; public class M3 {  }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
        Path m4 = moduleSrc.resolve("m4");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
        tb.writeJavaFiles(m4,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
                          "module m4 { exports m4; }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
                          "package m4; public class M4 {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
        Path out = base.resolve("out");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
        Files.createDirectories(out);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
        try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   288
            com.sun.source.util.JavacTask task =
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   289
                (com.sun.source.util.JavacTask) javaCompiler.getTask(null,
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
                                                              null,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
                                                              d -> { throw new IllegalStateException(d.toString()); },
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
                                                              Arrays.asList("-modulepath", modulePath.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
                                                                            "-classpath", cp.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
                                                                            "-modulesourcepath", moduleSrc.toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
                                                                            "-d", out.toString()),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
                                                              null,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
                                                              fm.getJavaFileObjects(findJavaFiles(moduleSrc)));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   298
            assertNotNull(task.getElements().getTypeElement("java.lang.String"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
            assertNull(task.getElements().getTypeElement("javax.tools.ToolProvider"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
            assertNotNull(task.getElements().getTypeElement("m1.M1"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   301
            assertNull(task.getElements().getTypeElement("m2.M2"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
            assertNotNull(task.getElements().getTypeElement("m3.M3"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   303
            assertNotNull(task.getElements().getTypeElement("m4.M4"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   304
            assertNotNull(task.getElements().getModuleElement("java.base"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   305
            assertNull(task.getElements().getModuleElement("java.compiler"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   306
            assertNotNull(task.getElements().getModuleElement("m1"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   307
            assertNull(task.getElements().getModuleElement("m2"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   308
            assertNotNull(task.getElements().getModuleElement("m3"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
            assertNotNull(task.getElements().getModuleElement("m4"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   312
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   313
    @Test
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   314
    void testTooSoon(Path base) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   315
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   316
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   317
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   318
                          "package test; public class Test {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   319
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
        Path out = base.resolve("out");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   321
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
        Files.createDirectories(out);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   323
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   324
        Path reg = base.resolve("reg");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   325
        Path regFile = reg.resolve("META-INF").resolve("services").resolve(Plugin.class.getName());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   326
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   327
        Files.createDirectories(regFile.getParent());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   328
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   329
        try (OutputStream regOut = Files.newOutputStream(regFile)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   330
            regOut.write(PluginImpl.class.getName().getBytes());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   331
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   332
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   333
        String processorPath = System.getProperty("test.class.path") + File.pathSeparator + reg.toString();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   335
        JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   336
        Path testSource = src.resolve("test").resolve("Test.java");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   337
        try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   338
            com.sun.source.util.JavacTask task =
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   339
                (com.sun.source.util.JavacTask) javaCompiler.getTask(null,
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   340
                                                              null,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   341
                                                              d -> { throw new IllegalStateException(d.toString()); },
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   342
                                                              Arrays.asList("-processorpath", processorPath,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   343
                                                                            "-processor", AP.class.getName(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   344
                                                                            "-Xplugin:test"),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   345
                                                              null,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   346
                                                              fm.getJavaFileObjects(testSource));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   347
            task.call();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   348
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   349
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   350
        Main.compile(new String[] {"-processorpath", processorPath,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   351
                                   "-Xplugin:test",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   352
                                   testSource.toString()});
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   353
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   354
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   355
    public static class PluginImpl implements Plugin {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   356
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   357
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   358
        public String getName() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   359
            return "test";
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   360
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   361
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   362
        @Override
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   363
        public void init(com.sun.source.util.JavacTask task, String... args) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   364
            task.addTaskListener(new TaskListener() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   365
                boolean wasEntered;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   366
                @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   367
                public void started(TaskEvent e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   368
                    switch (e.getKind()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   369
                        case COMPILATION: case PARSE:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   370
                            shouldFail(e.getKind());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   371
                            break;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   372
                        case ANNOTATION_PROCESSING: case ENTER:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   373
                            if (wasEntered) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   374
                                shouldPass(e.getKind());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   375
                            } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   376
                                shouldFail(e.getKind());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   377
                            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   378
                            break;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   379
                        default:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   380
                            shouldPass(e.getKind());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   381
                            break;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   382
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   383
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   384
                @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   385
                public void finished(TaskEvent e) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   386
                    switch (e.getKind()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   387
                        case PARSE:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   388
                            shouldFail(e.getKind());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   389
                            break;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   390
                        case ENTER:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   391
                            wasEntered = true;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   392
                            //fall-through:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   393
                        default:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   394
                            shouldPass(e.getKind());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   395
                            break;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   396
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   397
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   398
                private void shouldFail(TaskEvent.Kind kind) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   399
                    try {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   400
                        task.getElements().getTypeElement("java.lang.String");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   401
                        throw new AssertionError("Expected exception not observed; kind=" + kind.name());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   402
                    } catch (IllegalStateException ex) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   403
                        //correct
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   404
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   405
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   406
                private void shouldPass(TaskEvent.Kind kind) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   407
                    assertNotNull(task.getElements().getTypeElement("java.lang.String"));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   408
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   409
            });
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   410
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   411
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   412
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   413
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   414
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   415
    @SupportedAnnotationTypes("*")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   416
    public static final class AP extends AbstractProcessor {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   417
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   418
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   419
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   420
            return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   421
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   422
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   423
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   424
        public SourceVersion getSupportedSourceVersion() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   425
            return SourceVersion.latest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   426
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   427
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   428
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   429
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   430
    private static void assertNotNull(Object actual) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   431
        if (actual == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   432
            throw new AssertionError("unexpected null!");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   433
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   434
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   435
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   436
    private static void assertNull(Object actual) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   437
        if (actual != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   438
            throw new AssertionError("unexpected non null!");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   439
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   440
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   441
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   442
}