langtools/test/tools/javac/modules/EdgeCases.java
author jlahoda
Tue, 14 Mar 2017 07:11:45 +0100
changeset 44289 842ccb558d7d
parent 43369 aafd33c96bac
child 44290 202973b2d1ae
permissions -rw-r--r--
8175057: module-info on patch path should not produce an error Summary: Allowing module-infos on patch paths during compilation. Reviewed-by: jjg, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
43269
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
36526
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
43369
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
    26
 * @bug 8154283 8167320 8171098 8172809 8173068 8173117
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @summary tests for multi-module mode compilation
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @library /tools/lib
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 * @modules
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 *      jdk.compiler/com.sun.tools.javac.api
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 *      jdk.compiler/com.sun.tools.javac.code
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 *      jdk.compiler/com.sun.tools.javac.main
43369
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
    33
 *      jdk.compiler/com.sun.tools.javac.processing
43271
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    34
 *      jdk.compiler/com.sun.tools.javac.util
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    35
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
 * @run main EdgeCases
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.io.Writer;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.nio.file.Path;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.nio.file.Paths;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import java.util.HashSet;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import java.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import java.util.Objects;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import java.util.Set;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
43271
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    49
import javax.annotation.processing.AbstractProcessor;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    50
import javax.annotation.processing.RoundEnvironment;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    51
import javax.annotation.processing.SupportedAnnotationTypes;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    52
import javax.annotation.processing.SupportedOptions;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    53
import javax.lang.model.SourceVersion;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
import javax.lang.model.element.Element;
43271
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    55
import javax.lang.model.element.ModuleElement;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    56
import javax.lang.model.element.ModuleElement.RequiresDirective;
43369
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
    57
import javax.lang.model.element.PackageElement;
43271
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    58
import javax.lang.model.element.TypeElement;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
    59
import javax.lang.model.util.ElementFilter;
43369
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
    60
import javax.lang.model.util.Elements;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
import javax.tools.JavaCompiler;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
import javax.tools.JavaFileObject;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
import javax.tools.StandardJavaFileManager;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
import javax.tools.ToolProvider;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
import com.sun.source.tree.CompilationUnitTree;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    67
//import com.sun.source.util.JavacTask; // conflicts with toolbox.JavacTask
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
import com.sun.tools.javac.api.JavacTaskImpl;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
import com.sun.tools.javac.code.Symbol.ModuleSymbol;
43369
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
    70
import com.sun.tools.javac.code.Symbol.PackageSymbol;
41516
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
    71
import com.sun.tools.javac.code.Symtab;
43369
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
    72
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
    73
import com.sun.tools.javac.util.Context;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    75
import toolbox.JarTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    76
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    77
import toolbox.Task;
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
    78
import toolbox.Task.Expect;
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
    79
import toolbox.Task.OutputKind;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    80
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
public class EdgeCases extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
        new EdgeCases().runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    87
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
    88
    public void testAddExportUndefinedModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        Path src = base.resolve("src");
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
    90
        tb.writeJavaFiles(src, "package test; import undefPackage.Any; public class Test {}");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    94
        List<String> log = new JavacTask(tb)
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
    95
                .options("--add-exports", "undefModule/undefPackage=ALL-UNNAMED",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
    96
                         "-XDrawDiagnostics")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    99
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   101
                .getOutputLines(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
41938
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   103
        List<String> expected = Arrays.asList("- compiler.warn.module.for.option.not.found: --add-exports, undefModule",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   104
                                              "Test.java:1:34: compiler.err.doesnt.exist: undefPackage",
8e66bf10fcec 8167975: align javac --add-* modules options with launcher
jjg
parents: 41932
diff changeset
   105
                                              "1 error", "1 warning");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        if (!expected.equals(log))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
            throw new Exception("expected output not found: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   112
    public void testModuleSymbolOutterMostClass(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
            Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   116
            Path m1 = moduleSrc.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   118
            tb.writeJavaFiles(m1, "module m1x { }");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(moduleSrc));
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   121
            com.sun.source.util.JavacTask task =
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   122
                (com.sun.source.util.JavacTask) compiler.getTask(null, fm, null, null, null, files);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
            task.analyze();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   126
            ModuleSymbol msym = (ModuleSymbol) task.getElements().getModuleElement("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
            msym.outermostClass();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   133
    public void testParseEnterAnalyze(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
        try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
            Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   137
            Path m1 = moduleSrc.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   139
            tb.writeJavaFiles(m1, "module m1x { }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
                                  "package p;",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
                                  "package p; class T { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
            Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(moduleSrc));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
            List<String> options = Arrays.asList("-d", classes.toString(), "-Xpkginfo:always");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
            JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, fm, null, options, null, files);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
            Iterable<? extends CompilationUnitTree> parsed = task.parse();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
            Iterable<? extends Element> entered = task.enter(parsed);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
            Iterable<? extends Element> analyzed = task.analyze(entered);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
            Iterable<? extends JavaFileObject> generatedFiles = task.generate(analyzed);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
            Set<String> generated = new HashSet<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
            for (JavaFileObject jfo : generatedFiles) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                generated.add(jfo.getName());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
            Set<String> expected = new HashSet<>(
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
                    Arrays.asList(Paths.get("testParseEnterAnalyze", "classes", "p", "package-info.class").toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
                                  Paths.get("testParseEnterAnalyze", "classes", "module-info.class").toString(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
                                  Paths.get("testParseEnterAnalyze", "classes", "p", "T.class").toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
            );
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
            if (!Objects.equals(expected, generated))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
                throw new AssertionError("Incorrect generated files: " + generated);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   171
    public void testModuleImplicitModuleBoundaries(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   173
        Path src_m1 = src.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
        tb.writeJavaFiles(src_m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   175
                          "module m1x { exports api1; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
                          "package api1; public class Api1 { public void call() { } }");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   177
        Path src_m2 = src.resolve("m2x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        tb.writeJavaFiles(src_m2,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   179
                          "module m2x { requires m1x; exports api2; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
                          "package api2; public class Api2 { public static api1.Api1 get() { return null; } }");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   181
        Path src_m3 = src.resolve("m3x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        tb.writeJavaFiles(src_m3,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   183
                          "module m3x { requires m2x; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
                          "package test; public class Test { { api2.Api2.get().call(); api2.Api2.get().toString(); } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        tb.createDirectories(classes);
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
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
                .options("-XDrawDiagnostics",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   190
                         "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                .files(findJavaFiles(src))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   193
                .run(Task.Expect.FAIL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   195
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
43138
680d378b9d64 8169197: Improve error reporting for compiling against unexported package
jlahoda
parents: 42822
diff changeset
   197
        if (!log.contains("Test.java:1:52: compiler.err.not.def.access.class.intf.cant.access.reason: call(), api1.Api1, api1, (compiler.misc.not.def.access.does.not.read: m3x, api1, m1x)") ||
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
            !log.contains("Test.java:1:76: compiler.err.not.def.access.class.intf.cant.access: toString(), java.lang.Object"))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
            throw new Exception("expected output not found");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   203
    public void testAssignClassToAutomaticModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
        //check that if a ClassSymbol belongs to an automatic module, it is properly assigned and not
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        //duplicated when being accessed through a classfile.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        Path automaticSrc = base.resolve("automaticSrc");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        tb.writeJavaFiles(automaticSrc, "package api1; public class Api1 {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
        Path automaticClasses = base.resolve("automaticClasses");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        tb.createDirectories(automaticClasses);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   211
        String automaticLog = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
                                .outdir(automaticClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   213
                                .files(findJavaFiles(automaticSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
                                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
                                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   216
                                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   217
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
        if (!automaticLog.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
            throw new Exception("expected output not found: " + automaticLog);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
        Path modulePath = base.resolve("module-path");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
        Files.createDirectories(modulePath);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   225
        Path automaticJar = modulePath.resolve("a-1.0.jar");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   227
        new JarTask(tb, automaticJar)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
          .baseDir(automaticClasses)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
          .files("api1/Api1.class")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
          .run();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   233
        Path src_m2 = src.resolve("m2x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
        tb.writeJavaFiles(src_m2,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   235
                          "module m2x { requires a; exports api2; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
                          "package api2; public class Api2 { public static api1.Api1 get() { return null; } }");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   237
        Path src_m3 = src.resolve("m3x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
        tb.writeJavaFiles(src_m3,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   239
                          "module m3x { requires a; requires m2x; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
                          "package test; public class Test { { api2.Api2.get(); api1.Api1 a1; } }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   244
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   245
                .options("--module-path", modulePath.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   246
                         "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
                .files(findJavaFiles(src_m2))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   252
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   253
                .options("--module-path", modulePath.toString(),
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   254
                         "--module-source-path", src.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
                .files(findJavaFiles(src_m3))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   262
    public void testEmptyImplicitModuleInfo(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   264
        Path src_m1 = src.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
        Files.createDirectories(src_m1);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
        try (Writer w = Files.newBufferedWriter(src_m1.resolve("module-info.java"))) {}
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
        tb.writeJavaFiles(src_m1,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
                          "package test; public class Test {}");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
        tb.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   272
        List<String> log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   273
                .options("--source-path", src_m1.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                         "-XDrawDiagnostics")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
                .files(findJavaFiles(src_m1.resolve("test")))
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   277
                .run(Task.Expect.FAIL)
44289
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   278
                .writeAll()
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   279
                .getOutputLines(OutputKind.DIRECT);
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   280
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   281
        List<String> expected = Arrays.asList(
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   282
                "- compiler.err.cant.access: module-info, (compiler.misc.bad.source.file.header: module-info.java, (compiler.misc.file.does.not.contain.module))",
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   283
                "1 error");
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   284
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   285
        if (!expected.equals(log)) {
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   286
            throw new AssertionError("Unexpected output: " + log);
842ccb558d7d 8175057: module-info on patch path should not produce an error
jlahoda
parents: 43369
diff changeset
   287
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        tb.writeJavaFiles(src_m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   290
                          "module m1x {}");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   292
        new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   293
                .options("--source-path", src_m1.toString())
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
                .files(findJavaFiles(src_m1.resolve("test")))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
                .writeAll();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   298
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   301
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 37744
diff changeset
   302
    public void testClassPackageClash(Path base) throws Exception {
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   303
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   304
        Path src_m1 = src.resolve("m1x");
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   305
        tb.writeJavaFiles(src_m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   306
                          "module m1x { exports test.m1x; }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   307
                          "package test.m1x;\n" +
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   308
                          "public class Test {}\n");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   309
        Path src_m2 = src.resolve("m2x");
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   310
        tb.writeJavaFiles(src_m2,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   311
                          "module m2x { requires m1x; }",
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   312
                          "package test;\n" +
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   313
                          "public class m1x {}\n");
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   314
        Path classes = base.resolve("classes");
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   315
        tb.createDirectories(classes);
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   316
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   317
        List<String> log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   318
                .options("--module-source-path", src.toString(),
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   319
                         "-XDrawDiagnostics")
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   320
                .outdir(classes)
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   321
                .files(findJavaFiles(src))
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   322
                .run(Task.Expect.FAIL)
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   323
                .writeAll()
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   324
                .getOutputLines(Task.OutputKind.DIRECT);
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   325
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   326
        List<String> expected = Arrays.asList(
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   327
            "m1x.java:2:8: compiler.err.clash.with.pkg.of.same.name: kindname.class, test.m1x",
37744
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   328
            "1 error"
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   329
        );
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   330
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   331
        if (!expected.equals(log)) {
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   332
            throw new IllegalStateException(log.toString());
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   333
        }
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   334
    }
bf4fd5e022c5 8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents: 36778
diff changeset
   335
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   336
    @Test
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   337
    public void testImplicitJavaBase(Path base) throws Exception {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   338
        Path src = base.resolve("src");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   339
        Path src_java_base = src.resolve("java.base");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   340
        Files.createDirectories(src_java_base);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   341
        tb.writeJavaFiles(src_java_base, "module java.base { exports java.lang; }");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   342
        tb.writeJavaFiles(src_java_base,
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   343
                          "package java.lang; public class Object {}");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   344
        Path classes = base.resolve("classes");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   345
        tb.createDirectories(classes);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   346
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   347
        //module-info from source:
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   348
        new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   349
            .options("-sourcepath", src_java_base.toString())
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   350
            .outdir(classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   351
            .files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java")))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   352
            .run()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   353
            .writeAll();
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   354
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   355
        //module-info from class:
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   356
        if (!Files.exists(classes.resolve("module-info.class"))) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   357
            throw new AssertionError("module-info.class not created!");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   358
        }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   359
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   360
        new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   361
            .outdir(classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   362
            .files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java")))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   363
            .run()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   364
            .writeAll();
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   365
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   366
        //broken module-info.class:
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   367
        Files.newOutputStream(classes.resolve("module-info.class")).close();
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   368
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   369
        List<String> log = new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   370
            .options("-XDrawDiagnostics")
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   371
            .outdir(classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   372
            .files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java")))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   373
            .run(Expect.FAIL)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   374
            .writeAll()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   375
            .getOutputLines(OutputKind.DIRECT);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   376
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   377
        List<String> expected = Arrays.asList(
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   378
                "- compiler.err.cant.access: <error>.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.illegal.start.of.class.file))",
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   379
                "1 error");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   380
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   381
        if (!expected.equals(log)) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   382
            throw new AssertionError("Unexpected output: " + log);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   383
        }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   384
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   385
        //broken module-info.java:
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   386
        Files.delete(classes.resolve("module-info.class"));
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   387
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   388
        try (Writer out = Files.newBufferedWriter(src_java_base.resolve("module-info.java"))) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   389
            out.write("class Broken {}");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   390
        }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   391
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   392
        log = new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   393
            .options("-sourcepath", src_java_base.toString(),
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   394
                                "-XDrawDiagnostics")
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   395
            .outdir(classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   396
            .files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java")))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   397
            .run(Expect.FAIL)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   398
            .writeAll()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   399
            .getOutputLines(OutputKind.DIRECT);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   400
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   401
        expected = Arrays.asList("X");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   402
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   403
        if (expected.equals(log)) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   404
            throw new AssertionError("Unexpected output: " + log);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   405
        }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   406
    }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   407
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   408
    @Test
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   409
    public void testModuleInfoNameMismatchSource(Path base) throws Exception {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   410
        Path src = base.resolve("src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   411
        Path m1 = src.resolve("m1x");
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   412
        Files.createDirectories(m1);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   413
        tb.writeJavaFiles(m1, "module other { }",
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   414
                              "package test; public class Test {}");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   415
        Path classes = base.resolve("classes");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   416
        tb.createDirectories(classes);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   417
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   418
        List<String> log = new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   419
            .options("--module-source-path", src.toString(),
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   420
                     "-XDrawDiagnostics")
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   421
            .outdir(classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   422
            .files(findJavaFiles(m1.resolve("test").resolve("Test.java")))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   423
            .run(Expect.FAIL)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   424
            .writeAll()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   425
            .getOutputLines(OutputKind.DIRECT);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   426
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   427
        List<String> expected = Arrays.asList(
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   428
                "module-info.java:1:1: compiler.err.module.name.mismatch: other, m1x",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   429
                "- compiler.err.cant.access: m1x.module-info, (compiler.misc.cant.resolve.modules)",
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   430
                "2 errors");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   431
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   432
        if (!expected.equals(log)) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   433
            throw new AssertionError("Unexpected output: " + log);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   434
        }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   435
    }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   436
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   437
    @Test
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   438
    public void testModuleInfoNameMismatchClass(Path base) throws Exception {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   439
        Path src = base.resolve("src");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   440
        Files.createDirectories(src);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   441
        tb.writeJavaFiles(src, "module other { }",
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   442
                               "package test; public class Test {}");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   443
        Path classes = base.resolve("classes");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   444
        Path m1Classes = classes.resolve("m1x");
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   445
        tb.createDirectories(m1Classes);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   446
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   447
        new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   448
            .outdir(m1Classes)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   449
            .files(findJavaFiles(src))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   450
            .run()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   451
            .writeAll()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   452
            .getOutputLines(OutputKind.DIRECT);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   453
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   454
        Path src2 = base.resolve("src2");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   455
        Files.createDirectories(src2);
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   456
        tb.writeJavaFiles(src2, "module use { requires m1x; }");
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   457
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   458
        Path classes2 = base.resolve("classes2");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   459
        tb.createDirectories(classes2);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   460
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   461
        List<String> log = new JavacTask(tb)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   462
            .options("--module-path", classes.toString(),
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   463
                     "-XDrawDiagnostics")
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   464
            .outdir(classes2)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   465
            .files(findJavaFiles(src2))
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   466
            .run(Expect.FAIL)
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   467
            .writeAll()
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   468
            .getOutputLines(OutputKind.DIRECT);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   469
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   470
        List<String> expected = Arrays.asList(
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   471
                "- compiler.err.cant.access: m1x.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.module.name.mismatch: other, m1x))",
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   472
                "1 error");
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   473
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   474
        if (!expected.equals(log)) {
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   475
            throw new AssertionError("Unexpected output: " + log);
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   476
        }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   477
    }
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40308
diff changeset
   478
41516
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   479
    @Test
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   480
    public void testGetDirectivesComplete(Path base) throws Exception {
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   481
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   482
        JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, null, null, null, null, null);
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   483
        Symtab syms = Symtab.instance(task.getContext());
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   484
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   485
        syms.java_base.getDirectives();
0a5838f027a4 8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents: 41254
diff changeset
   486
    }
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   487
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   488
    @Test
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   489
    public void testPackageInModuleInfo(Path base) throws Exception {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   490
        Path src = base.resolve("src");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   491
        Files.createDirectories(src);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   492
        tb.writeJavaFiles(src, "package p; module foo { }");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   493
        Path classes = base.resolve("classes");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   494
        tb.createDirectories(classes);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   495
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   496
        List<String> log = new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   497
            .options("-XDrawDiagnostics", "-XDshould-stop.ifError=FLOW")
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   498
            .outdir(classes)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   499
            .files(findJavaFiles(src))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   500
            .run(Expect.FAIL)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   501
            .writeAll()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   502
            .getOutputLines(OutputKind.DIRECT);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   503
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   504
        List<String> expected = Arrays.asList(
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   505
                "module-info.java:1:1: compiler.err.no.pkg.in.module-info.java",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   506
                "1 error");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   507
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   508
        if (!expected.equals(log)) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   509
            throw new AssertionError("Unexpected output: " + log);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   510
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41938
diff changeset
   511
    }
43269
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   512
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   513
    @Test
43272
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   514
    public void testInvisibleClassVisiblePackageClash(Path base) throws Exception {
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   515
        Path src = base.resolve("src");
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   516
        Path src_m1 = src.resolve("m1x");
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   517
        tb.writeJavaFiles(src_m1,
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   518
                          "module m1x { }",
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   519
                          "package m1x;\n" +
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   520
                          "import m1x.a.*; public class Test { A a; }\n",
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   521
                          "package m1x.a;\n" +
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   522
                          "public class A { }\n");
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   523
        Path src_m2 = src.resolve("m2x");
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   524
        tb.writeJavaFiles(src_m2,
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   525
                          "module m2x { }",
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   526
                          "package m1x;\n" +
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   527
                          "public class a { public static class A { } }\n");
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   528
        Path classes = base.resolve("classes");
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   529
        tb.createDirectories(classes);
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   530
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   531
        new JavacTask(tb)
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   532
            .options("--module-source-path", src.toString(),
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   533
                     "-XDrawDiagnostics")
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   534
            .outdir(classes)
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   535
            .files(findJavaFiles(src))
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   536
            .run()
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   537
            .writeAll();
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   538
    }
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   539
421ae1e38d2d 8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents: 43271
diff changeset
   540
    @Test
43271
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   541
    public void testStripUnknownRequired(Path base) throws Exception {
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   542
        Path src = base.resolve("src");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   543
        Path src_m1 = src.resolve("m1x");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   544
        tb.writeJavaFiles(src_m1,
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   545
                          "module m1x { }");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   546
        Path src_m2 = src.resolve("m2x");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   547
        tb.writeJavaFiles(src_m2,
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   548
                          "module m2x { }");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   549
        Path src_m3 = src.resolve("m3x");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   550
        tb.writeJavaFiles(src_m3,
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   551
                          "module m3x { }");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   552
        Path src_m4 = src.resolve("m4x");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   553
        tb.writeJavaFiles(src_m4,
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   554
                          "module m4x { }");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   555
        Path src_test = src.resolve("test");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   556
        tb.writeJavaFiles(src_test,
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   557
                          "module test { requires m1x; requires m2x; requires java.base; requires m3x; requires m4x; }");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   558
        Path src_compile = src.resolve("compile");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   559
        tb.writeJavaFiles(src_compile,
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   560
                          "module compile { exports p to test; }",
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   561
                          "package p; public class Test { }");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   562
        Path classes = base.resolve("classes");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   563
        tb.createDirectories(classes);
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   564
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   565
        List<String> log = new JavacTask(tb)
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   566
                .options("-processor", ListRequires.class.getName(),
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   567
                         "--module-source-path", src.toString(),
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   568
                         "--limit-modules", "compile",
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   569
                         "-XDaccessInternalAPI=true")
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   570
                .outdir(classes)
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   571
                .files(findJavaFiles(src_compile))
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   572
                .run(Expect.FAIL)
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   573
                .writeAll()
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   574
                .getOutputLines(Task.OutputKind.STDOUT);
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   575
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   576
        List<String> expected = Arrays.asList(
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   577
                "from directives:",
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   578
                "java.base",
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   579
                "from requires:",
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   580
                "java.base"
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   581
        );
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   582
        if (!Objects.equals(log, expected))
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   583
            throw new AssertionError("Unexpected output: " + log);
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   584
    }
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   585
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   586
    @SupportedAnnotationTypes("*")
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   587
    @SupportedOptions("expectedEnclosedElements")
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   588
    public static final class ListRequires extends AbstractProcessor {
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   589
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   590
        private int round;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   591
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   592
        @Override
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   593
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   594
            if (round++ == 0) {
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   595
                ModuleElement compileE = processingEnv.getElementUtils().getModuleElement("compile");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   596
                ModuleElement testE = ElementFilter.exportsIn(compileE.getDirectives()).get(0).getTargetModules().get(0);
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   597
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   598
                System.out.println("from directives:");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   599
                for (RequiresDirective rd : ElementFilter.requiresIn(testE.getDirectives())) {
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   600
                    System.out.println(rd.getDependency().getSimpleName());
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   601
                }
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   602
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   603
                System.out.println("from requires:");
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   604
                for (RequiresDirective rd : ((ModuleSymbol) testE).requires) {
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   605
                    System.out.println(rd.getDependency().getSimpleName());
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   606
                }
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   607
            }
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   608
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   609
            return false;
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   610
        }
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   611
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   612
        @Override
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   613
        public SourceVersion getSupportedSourceVersion() {
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   614
            return SourceVersion.latest();
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   615
        }
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   616
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   617
    }
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   618
ce89609dde7c 8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents: 43269
diff changeset
   619
    @Test
43269
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   620
    public void testOnDemandCompletionModuleInfoJava(Path base) throws Exception {
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   621
        Path src = base.resolve("src");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   622
        Path src_m1 = src.resolve("m1x");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   623
        tb.writeJavaFiles(src_m1,
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   624
                          "@Deprecated module m1x { }");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   625
        Path src_m2 = src.resolve("m2x");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   626
        tb.writeJavaFiles(src_m2,
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   627
                          "module m2x { requires m1x; }");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   628
        Path src_m3 = src.resolve("m3x");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   629
        tb.writeJavaFiles(src_m3,
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   630
                          "module m3x { requires m2x; requires m1x; }");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   631
        Path classes = base.resolve("classes");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   632
        tb.createDirectories(classes);
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   633
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   634
        List<String> log;
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   635
        List<String> expected;
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   636
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   637
        log = new JavacTask(tb)
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   638
                .options("--module-source-path", src.toString())
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   639
                .outdir(classes)
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   640
                .files(findJavaFiles(src_m1))
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   641
                .run()
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   642
                .writeAll()
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   643
                .getOutputLines(Task.OutputKind.DIRECT);
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   644
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   645
        expected = Arrays.asList("");
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   646
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   647
        if (!expected.equals(log)) {
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   648
            throw new IllegalStateException(log.toString());
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   649
        }
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   650
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   651
        log = new JavacTask(tb)
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   652
                .options("--module-source-path", src.toString(),
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   653
                         "-XDrawDiagnostics",
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   654
                         "-Xlint:deprecation")
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   655
                .outdir(classes)
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   656
                .files(findJavaFiles(src_m3))
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   657
                .run()
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   658
                .writeAll()
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   659
                .getOutputLines(Task.OutputKind.DIRECT);
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   660
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   661
        expected = Arrays.asList(
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   662
                "module-info.java:1:23: compiler.warn.has.been.deprecated.module: m1x",
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   663
                "module-info.java:1:37: compiler.warn.has.been.deprecated.module: m1x",
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   664
                "2 warnings"
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   665
        );
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   666
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   667
        if (!expected.equals(log)) {
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   668
            throw new IllegalStateException(log.toString());
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   669
        }
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   670
    }
12f989542165 8171098: NPE when --add-modules java.corba is used
jlahoda
parents: 43138
diff changeset
   671
43369
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   672
    @Test
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   673
    public void testUnnamedPackage(Path base) throws Exception {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   674
        List<String> out;
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   675
        List<String> expected;
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   676
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   677
        //-source 8:
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   678
        Path src8 = base.resolve("src8");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   679
        Files.createDirectories(src8);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   680
        tb.writeJavaFiles(src8,
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   681
                          "package test; public class Test {}");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   682
        Path classes = base.resolve("classes");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   683
        tb.createDirectories(classes);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   684
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   685
        out = new JavacTask(tb)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   686
                .options("--source-path", src8.toString(),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   687
                         "-processor", UnnamedPackageProcessor.class.getName(),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   688
                         "-source", "8")
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   689
                .outdir(classes)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   690
                .files(findJavaFiles(src8))
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   691
                .run()
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   692
                .writeAll()
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   693
                .getOutputLines(OutputKind.STDOUT);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   694
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   695
        expected = Arrays.asList("noModule");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   696
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   697
        if (!expected.equals(out)) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   698
            throw new AssertionError("Unexpected output: " + out);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   699
        }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   700
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   701
        //-source 9, unnamed:
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   702
        Path srcUnnamed = base.resolve("srcUnnamed");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   703
        Files.createDirectories(srcUnnamed);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   704
        tb.writeJavaFiles(srcUnnamed,
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   705
                          "public class Test {}");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   706
        Path classesUnnamed = base.resolve("classesUnnamed");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   707
        tb.createDirectories(classesUnnamed);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   708
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   709
        out = new JavacTask(tb)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   710
                .options("--source-path", srcUnnamed.toString(),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   711
                         "-processor", UnnamedPackageProcessor.class.getName())
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   712
                .outdir(classesUnnamed)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   713
                .files(findJavaFiles(srcUnnamed))
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   714
                .run()
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   715
                .writeAll()
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   716
                .getOutputLines(OutputKind.STDOUT);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   717
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   718
        expected = Arrays.asList("unnamedModule");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   719
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   720
        if (!expected.equals(out)) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   721
            throw new AssertionError("Unexpected output: " + out);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   722
        }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   723
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   724
        //-source 9, named:
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   725
        Path srcNamed = base.resolve("srcNamed");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   726
        Files.createDirectories(srcNamed);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   727
        tb.writeJavaFiles(srcNamed,
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   728
                          "module m {}",
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   729
                          "public class Test {}");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   730
        Path classesNamed = base.resolve("classesNamed");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   731
        tb.createDirectories(classesNamed);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   732
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   733
        out = new JavacTask(tb)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   734
                .options("--source-path", srcNamed.toString(),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   735
                         "-classpath", "",
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   736
                         "-processorpath", System.getProperty("test.class.path"),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   737
                         "-processor", UnnamedPackageProcessor.class.getName())
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   738
                .outdir(classesNamed)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   739
                .files(findJavaFiles(srcNamed))
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   740
                .run()
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   741
                .writeAll()
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   742
                .getOutputLines(OutputKind.STDOUT);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   743
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   744
        expected = Arrays.asList("m");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   745
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   746
        if (!expected.equals(out)) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   747
            throw new AssertionError("Unexpected output: " + out);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   748
        }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   749
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   750
        //-source 9, conflict:
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   751
        Path srcNamed2 = base.resolve("srcNamed2");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   752
        Path srcNamed2m1 = srcNamed2.resolve("m1x");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   753
        Files.createDirectories(srcNamed2m1);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   754
        tb.writeJavaFiles(srcNamed2m1,
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   755
                          "module m1x {}",
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   756
                          "public class Test {}");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   757
        Path srcNamed2m2 = srcNamed2.resolve("m2x");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   758
        Files.createDirectories(srcNamed2m2);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   759
        tb.writeJavaFiles(srcNamed2m2,
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   760
                          "module m2x {}",
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   761
                          "public class Test {}");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   762
        Path classesNamed2 = base.resolve("classesNamed2");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   763
        tb.createDirectories(classesNamed2);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   764
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   765
        out = new JavacTask(tb)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   766
                .options("--module-source-path", srcNamed2.toString(),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   767
                         "-classpath", "",
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   768
                         "-processorpath", System.getProperty("test.class.path"),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   769
                         "-processor", UnnamedPackageProcessor.class.getName(),
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   770
                         "-XDshould-stop.ifError=FLOW")
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   771
                .outdir(classesNamed2)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   772
                .files(findJavaFiles(srcNamed2))
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   773
                .run(Expect.FAIL)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   774
                .writeAll()
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   775
                .getOutputLines(OutputKind.STDOUT);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   776
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   777
        expected = Arrays.asList("null",
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   778
                                 "m1x: true",
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   779
                                 "m2x: true");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   780
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   781
        if (!expected.equals(out)) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   782
            throw new AssertionError("Unexpected output: " + out);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   783
        }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   784
    }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   785
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   786
    @SupportedAnnotationTypes("*")
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   787
    public static final class UnnamedPackageProcessor extends AbstractProcessor {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   788
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   789
        int round = 0;
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   790
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   791
        @Override
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   792
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   793
            if (round++ != 0)
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   794
                return false;
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   795
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   796
            Elements elements = processingEnv.getElementUtils();
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   797
            PackageElement pe = elements.getPackageElement("");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   798
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   799
            if (pe == null) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   800
                System.out.println("null");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   801
            } else {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   802
                ModuleElement mod = (ModuleElement) pe.getEnclosingElement();
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   803
                if (mod == null) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   804
                    System.out.println("noModule");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   805
                } else if (mod.isUnnamed()) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   806
                    System.out.println("unnamedModule");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   807
                } else {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   808
                    System.out.println(mod);
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   809
                }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   810
            }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   811
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   812
            ModuleElement m1x = elements.getModuleElement("m1x");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   813
            ModuleElement m2x = elements.getModuleElement("m2x");
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   814
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   815
            if (m1x != null && m2x != null) {
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   816
                System.out.println("m1x: " + (elements.getPackageElement(m1x, "") != null));
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   817
                System.out.println("m2x: " + (elements.getPackageElement(m2x, "") != null));
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   818
            }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   819
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   820
            return false;
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   821
        }
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   822
aafd33c96bac 8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents: 43272
diff changeset
   823
    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   824
}