langtools/test/tools/javac/modules/AnnotationProcessing.java
author jlahoda
Fri, 06 Jan 2017 14:16:45 +0100
changeset 43037 3e1520a857fa
parent 42824 89b14017e8d6
child 43149 047a57b0839a
permissions -rw-r--r--
8172158: Annotation processor not run with -source <= 8 Summary: Avoiding use of module prefix to map annotations to processors when running without modules. Reviewed-by: darcy, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
43037
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
    26
 * @bug 8133884 8162711 8133896 8172158
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @summary Verify that annotation processing works.
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.main
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    32
 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 * @run main AnnotationProcessing
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    36
import java.io.File;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    37
import java.io.IOException;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    38
import java.io.OutputStream;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    39
import java.io.Reader;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    40
import java.io.Writer;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.nio.file.Path;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    43
import java.nio.file.Paths;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import java.util.HashMap;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    46
import java.util.HashSet;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import java.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import java.util.Map;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
import java.util.Objects;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
import java.util.Set;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    51
import java.util.concurrent.Callable;
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
    52
import java.util.function.Function;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
import java.util.stream.Collectors;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
import javax.annotation.processing.AbstractProcessor;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    56
import javax.annotation.processing.Filer;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    57
import javax.annotation.processing.FilerException;
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
    58
import javax.annotation.processing.Messager;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    59
import javax.annotation.processing.ProcessingEnvironment;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
import javax.annotation.processing.RoundEnvironment;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
import javax.annotation.processing.SupportedAnnotationTypes;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
import javax.annotation.processing.SupportedOptions;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
import javax.lang.model.SourceVersion;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
import javax.lang.model.element.Element;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    65
import javax.lang.model.element.ElementKind;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
import javax.lang.model.element.ModuleElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
import javax.lang.model.element.ModuleElement.ProvidesDirective;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
import javax.lang.model.element.ModuleElement.UsesDirective;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
import javax.lang.model.element.PackageElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
import javax.lang.model.element.TypeElement;
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
    71
import javax.lang.model.element.VariableElement;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
import javax.lang.model.type.TypeKind;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
import javax.lang.model.util.ElementFilter;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
import javax.lang.model.util.ElementScanner9;
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
    75
import javax.tools.Diagnostic.Kind;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    76
import javax.tools.FileObject;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    77
import javax.tools.JavaCompiler;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    78
import javax.tools.JavaCompiler.CompilationTask;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    79
import javax.tools.JavaFileManager;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    80
import javax.tools.JavaFileManager.Location;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    81
import javax.tools.JavaFileObject;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    82
import javax.tools.StandardJavaFileManager;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    83
import javax.tools.StandardLocation;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    84
import javax.tools.ToolProvider;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    86
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    87
import toolbox.Task;
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
    88
import toolbox.Task.Mode;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    89
import toolbox.Task.OutputKind;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    90
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
public class AnnotationProcessing extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    92
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
    public static void main(String... args) throws Exception {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        new AnnotationProcessing().runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
    98
    public void testAPSingleModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   100
        Path m1 = moduleSrc.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   103
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   107
                          "module m1x { }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
                          "package impl; public class Impl { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   110
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   111
                .options("--module-source-path", moduleSrc.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
                         "-processor", AP.class.getName(),
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   113
                         "-AexpectedEnclosedElements=m1x=>impl")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
                .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   118
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
            throw new AssertionError("Unexpected output: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   125
    public void testAPMultiModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   127
        Path m1 = moduleSrc.resolve("m1x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   128
        Path m2 = moduleSrc.resolve("m2x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   135
                          "module m1x { }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                          "package impl1; public class Impl1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
        tb.writeJavaFiles(m2,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   139
                          "module m2x { }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
                          "package impl2; public class Impl2 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   142
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   143
                .options("--module-source-path", moduleSrc.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
                         "-processor", AP.class.getName(),
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   145
                         "-AexpectedEnclosedElements=m1x=>impl1,m2x=>impl2")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
                .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   150
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
            throw new AssertionError("Unexpected output: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
    @SupportedAnnotationTypes("*")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
    @SupportedOptions("expectedEnclosedElements")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
    public static final class AP extends AbstractProcessor {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        private Map<String, List<String>> module2ExpectedEnclosedElements;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   161
        private Set<String> seenModules = new HashSet<>();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
            if (module2ExpectedEnclosedElements == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
                module2ExpectedEnclosedElements = new HashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
                String expectedEnclosedElements =
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
                        processingEnv.getOptions().get("expectedEnclosedElements");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
                for (String moduleDef : expectedEnclosedElements.split(",")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
                    String[] module2Packages = moduleDef.split("=>");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                    module2ExpectedEnclosedElements.put(module2Packages[0],
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
                                                        Arrays.asList(module2Packages[1].split(":")));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
            //verify ModuleType and ModuleSymbol behavior:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   180
            for (Element root : roundEnv.getRootElements()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
                ModuleElement module = processingEnv.getElementUtils().getModuleOf(root);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
                assertEquals(TypeKind.MODULE, module.asType().getKind());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
                boolean[] seenModule = new boolean[1];
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
                module.accept(new ElementScanner9<Void, Void>() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
                    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
                    public Void visitModule(ModuleElement e, Void p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                        seenModule[0] = true;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
                        return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
                    public Void scan(Element e, Void p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
                        throw new AssertionError("Shouldn't get here.");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
                }, null);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
                assertEquals(true, seenModule[0]);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
                List<String> actualElements =
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
                        module.getEnclosedElements()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
                              .stream()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
                              .map(s -> (PackageElement) s)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
                              .map(p -> p.getQualifiedName().toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
                              .collect(Collectors.toList());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   208
                String moduleName = module.getQualifiedName().toString();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   209
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   210
                assertEquals(module2ExpectedEnclosedElements.get(moduleName),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                             actualElements);
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   212
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   213
                seenModules.add(moduleName);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   214
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   215
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
            if (roundEnv.processingOver()) {
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   217
                assertEquals(module2ExpectedEnclosedElements.keySet(), seenModules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   218
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
            return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   222
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
        public SourceVersion getSupportedSourceVersion() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
            return SourceVersion.latest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   226
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   227
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   228
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   231
    public void testVerifyUsesProvides(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   233
        Path m1 = moduleSrc.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   236
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   238
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   240
                          "module m1x { exports api; uses api.Api; provides api.Api with impl.Impl; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
                          "package api; public class Api { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
                          "package impl; public class Impl extends api.Api { }");
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
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   245
                .options("-doe", "-processor", VerifyUsesProvidesAP.class.getName())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
                .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   250
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
            throw new AssertionError("Unexpected output: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   255
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
    @SupportedAnnotationTypes("*")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
    public static final class VerifyUsesProvidesAP extends AbstractProcessor {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
            TypeElement api = processingEnv.getElementUtils().getTypeElement("api.Api");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
            assertNonNull("Cannot find api.Api", api);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
            ModuleElement modle = (ModuleElement) processingEnv.getElementUtils().getPackageOf(api).getEnclosingElement();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
            assertNonNull("modle is null", modle);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
            List<? extends UsesDirective> uses = ElementFilter.usesIn(modle.getDirectives());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
            assertEquals(1, uses.size());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
            assertEquals("api.Api", uses.iterator().next().getService().getQualifiedName().toString());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
            List<? extends ProvidesDirective> provides = ElementFilter.providesIn(modle.getDirectives());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
            assertEquals(1, provides.size());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
            assertEquals("api.Api", provides.iterator().next().getService().getQualifiedName().toString());
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40311
diff changeset
   276
            assertEquals("impl.Impl", provides.iterator().next().getImplementations().get(0).getQualifiedName().toString());
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
            return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   281
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
        public SourceVersion getSupportedSourceVersion() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
            return SourceVersion.latest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   284
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   285
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   286
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   289
    public void testPackageNoModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   294
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
                          "package api; public class Api { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   298
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
                .options("-processor", VerifyPackageNoModule.class.getName(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
                         "-source", "8",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   301
                         "-Xlint:-options")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   303
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   304
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   305
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   306
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   307
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   308
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
            throw new AssertionError("Unexpected output: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   311
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   312
    @SupportedAnnotationTypes("*")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   313
    public static final class VerifyPackageNoModule extends AbstractProcessor {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   314
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   315
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   316
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   317
            TypeElement api = processingEnv.getElementUtils().getTypeElement("api.Api");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   318
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   319
            assertNonNull("Cannot find api.Api", api);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   321
            ModuleElement modle = (ModuleElement) processingEnv.getElementUtils().getPackageOf(api).getEnclosingElement();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   323
            assertNull("modle is not null", modle);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   324
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   325
            return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   326
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   327
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   328
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   329
        public SourceVersion getSupportedSourceVersion() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   330
            return SourceVersion.latest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   331
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   332
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   333
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   335
    @Test
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   336
    public void testQualifiedClassForProcessing(Path base) throws Exception {
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   337
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   338
        Path m1 = moduleSrc.resolve("m1x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   339
        Path m2 = moduleSrc.resolve("m2x");
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   340
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   341
        Path classes = base.resolve("classes");
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   342
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   343
        Files.createDirectories(classes);
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   344
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   345
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   346
                          "module m1x { }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   347
                          "package impl; public class Impl { int m1x; }");
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   348
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   349
        tb.writeJavaFiles(m2,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   350
                          "module m2x { }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   351
                          "package impl; public class Impl { int m2x; }");
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   352
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   353
        new JavacTask(tb)
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   354
            .options("--module-source-path", moduleSrc.toString())
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   355
            .outdir(classes)
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   356
            .files(findJavaFiles(moduleSrc))
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   357
            .run()
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   358
            .writeAll()
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   359
            .getOutput(Task.OutputKind.DIRECT);
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   360
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   361
        List<String> expected = Arrays.asList("Note: field: m1x");
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   362
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   363
        for (Mode mode : new Mode[] {Mode.API, Mode.CMDLINE}) {
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   364
            List<String> log = new JavacTask(tb, mode)
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   365
                    .options("-processor", QualifiedClassForProcessing.class.getName(),
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   366
                             "--module-path", classes.toString())
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   367
                    .classes("m1x/impl.Impl")
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   368
                    .outdir(classes)
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   369
                    .run()
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   370
                    .writeAll()
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   371
                    .getOutputLines(Task.OutputKind.DIRECT);
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   372
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   373
            if (!expected.equals(log))
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   374
                throw new AssertionError("Unexpected output: " + log);
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   375
        }
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   376
    }
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   377
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   378
    @SupportedAnnotationTypes("*")
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   379
    public static final class QualifiedClassForProcessing extends AbstractProcessor {
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   380
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   381
        @Override
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   382
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   383
            if (processingEnv.getElementUtils().getModuleElement("m1x") == null) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   384
                throw new AssertionError("No m1x module found.");
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   385
            }
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   386
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   387
            Messager messager = processingEnv.getMessager();
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   388
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   389
            for (TypeElement clazz : ElementFilter.typesIn(roundEnv.getRootElements())) {
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   390
                for (VariableElement field : ElementFilter.fieldsIn(clazz.getEnclosedElements())) {
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   391
                    messager.printMessage(Kind.NOTE, "field: " + field.getSimpleName());
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   392
                }
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   393
            }
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   394
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   395
            return false;
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   396
        }
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   397
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   398
        @Override
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   399
        public SourceVersion getSupportedSourceVersion() {
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   400
            return SourceVersion.latest();
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   401
        }
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   402
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   403
    }
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   404
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   405
    @Test
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   406
    public void testModuleInRootElements(Path base) throws Exception {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   407
        Path moduleSrc = base.resolve("module-src");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   408
        Path m1 = moduleSrc.resolve("m1");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   409
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   410
        Path classes = base.resolve("classes");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   411
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   412
        Files.createDirectories(classes);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   413
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   414
        tb.writeJavaFiles(m1,
42823
alanb
parents: 42815 42822
diff changeset
   415
                          "module m1x { exports api; }",
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   416
                          "package api; public class Api { }");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   417
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   418
        List<String> log = new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   419
                .options("-processor", ModuleInRootElementsAP.class.getName())
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   420
                .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   421
                .files(findJavaFiles(moduleSrc))
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   422
                .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   423
                .writeAll()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   424
                .getOutputLines(Task.OutputKind.STDERR);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   425
42823
alanb
parents: 42815 42822
diff changeset
   426
        assertEquals(Arrays.asList("module: m1x"), log);
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   427
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   428
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   429
    @SupportedAnnotationTypes("*")
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   430
    public static final class ModuleInRootElementsAP extends AbstractProcessor {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   431
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   432
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   433
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   434
            roundEnv.getRootElements()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   435
                    .stream()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   436
                    .filter(el -> el.getKind() == ElementKind.MODULE)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   437
                    .forEach(mod -> System.err.println("module: " + mod.getSimpleName()));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   438
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   439
            return false;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   440
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   441
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   442
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   443
        public SourceVersion getSupportedSourceVersion() {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   444
            return SourceVersion.latest();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   445
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   446
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   447
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   448
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   449
    @Test
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   450
    public void testAnnotationsInModuleInfo(Path base) throws Exception {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   451
        Path moduleSrc = base.resolve("module-src");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   452
        Path m1 = moduleSrc.resolve("m1");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   453
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   454
        tb.writeJavaFiles(m1,
42823
alanb
parents: 42815 42822
diff changeset
   455
                          "@Deprecated module m1x { }");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   456
42823
alanb
parents: 42815 42822
diff changeset
   457
        Path m2 = moduleSrc.resolve("m2x");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   458
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   459
        tb.writeJavaFiles(m2,
42823
alanb
parents: 42815 42822
diff changeset
   460
                          "@SuppressWarnings(\"\") module m2x { }");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   461
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   462
        Path classes = base.resolve("classes");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   463
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   464
        Files.createDirectories(classes);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   465
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   466
        List<String> log = new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   467
                .options("-processor", AnnotationsInModuleInfoPrint.class.getName())
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   468
                .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   469
                .files(findJavaFiles(m1))
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   470
                .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   471
                .writeAll()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   472
                .getOutputLines(Task.OutputKind.DIRECT);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   473
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   474
        List<String> expectedLog = Arrays.asList("Note: AP Invoked",
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   475
                                                 "Note: AP Invoked");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   476
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   477
        assertEquals(expectedLog, log);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   478
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   479
        new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   480
            .options("-processor", AnnotationsInModuleInfoFail.class.getName())
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   481
            .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   482
            .files(findJavaFiles(m2))
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   483
            .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   484
            .writeAll();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   485
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   486
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   487
    @SupportedAnnotationTypes("java.lang.Deprecated")
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   488
    public static final class AnnotationsInModuleInfoPrint extends AbstractProcessor {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   489
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   490
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   491
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   492
            processingEnv.getMessager().printMessage(Kind.NOTE, "AP Invoked");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   493
            return false;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   494
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   495
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   496
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   497
        public SourceVersion getSupportedSourceVersion() {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   498
            return SourceVersion.latest();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   499
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   500
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   501
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   502
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   503
    @SupportedAnnotationTypes("java.lang.Deprecated")
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   504
    public static final class AnnotationsInModuleInfoFail extends AbstractProcessor {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   505
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   506
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   507
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   508
            throw new AssertionError();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   509
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   510
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   511
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   512
        public SourceVersion getSupportedSourceVersion() {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   513
            return SourceVersion.latest();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   514
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   515
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   516
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   517
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   518
    @Test
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   519
    public void testGenerateInMultiModeAPI(Path base) throws Exception {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   520
        Path moduleSrc = base.resolve("module-src");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   521
        Path classes = base.resolve("classes");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   522
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   523
        Files.createDirectories(classes);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   524
42823
alanb
parents: 42815 42822
diff changeset
   525
        Path m1 = moduleSrc.resolve("m1x");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   526
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   527
        tb.writeJavaFiles(m1,
42823
alanb
parents: 42815 42822
diff changeset
   528
                          "module m1x { exports api1; }",
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   529
                          "package api1; public class Api { GenApi ga; impl.Impl i; }");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   530
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   531
        writeFile("1", m1, "api1", "api");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   532
        writeFile("1", m1, "impl", "impl");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   533
42823
alanb
parents: 42815 42822
diff changeset
   534
        Path m2 = moduleSrc.resolve("m2x");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   535
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   536
        tb.writeJavaFiles(m2,
42823
alanb
parents: 42815 42822
diff changeset
   537
                          "module m2x { requires m1x; exports api2; }",
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   538
                          "package api2; public class Api { api1.GenApi ga1; GenApi qa2; impl.Impl i;}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   539
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   540
        writeFile("2", m2, "api2", "api");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   541
        writeFile("2", m2, "impl", "impl");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   542
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   543
        for (FileType fileType : FileType.values()) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   544
            if (Files.isDirectory(classes)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   545
                tb.cleanDirectory(classes);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   546
            } else {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   547
                Files.createDirectories(classes);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   548
            }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   549
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   550
            new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   551
              .options("-processor", MultiModeAPITestAP.class.getName(),
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   552
                       "--module-source-path", moduleSrc.toString(),
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   553
                       "-Afiletype=" + fileType.name())
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   554
              .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   555
              .files(findJavaFiles(moduleSrc))
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   556
              .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   557
              .writeAll();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   558
42823
alanb
parents: 42815 42822
diff changeset
   559
            assertFileExists(classes, "m1x", "api1", "GenApi.class");
alanb
parents: 42815 42822
diff changeset
   560
            assertFileExists(classes, "m1x", "impl", "Impl.class");
alanb
parents: 42815 42822
diff changeset
   561
            assertFileExists(classes, "m1x", "api1", "gen1");
alanb
parents: 42815 42822
diff changeset
   562
            assertFileExists(classes, "m2x", "api2", "GenApi.class");
alanb
parents: 42815 42822
diff changeset
   563
            assertFileExists(classes, "m2x", "impl", "Impl.class");
alanb
parents: 42815 42822
diff changeset
   564
            assertFileExists(classes, "m2x", "api2", "gen1");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   565
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   566
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   567
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   568
    enum FileType {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   569
        SOURCE,
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   570
        CLASS;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   571
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   572
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   573
    public static abstract class GeneratingAP extends AbstractProcessor {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   574
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   575
        void createSource(CreateFileObject file, String name, String content) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   576
            try (Writer out = file.create().openWriter()) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   577
                out.write(content);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   578
            } catch (IOException ex) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   579
                throw new IllegalStateException(ex);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   580
            }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   581
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   582
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   583
        void createClass(CreateFileObject file, String name, String content) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   584
            String fileNameStub = name.replace(".", File.separator);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   585
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   586
            try (OutputStream out = file.create().openOutputStream()) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   587
                Path scratch = Files.createDirectories(Paths.get(""));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   588
                Path scratchSrc = scratch.resolve(fileNameStub + ".java").toAbsolutePath();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   589
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   590
                Files.createDirectories(scratchSrc.getParent());
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   591
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   592
                try (Writer w = Files.newBufferedWriter(scratchSrc)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   593
                    w.write(content);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   594
                }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   595
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   596
                Path scratchClasses = scratch.resolve("classes");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   597
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   598
                Files.createDirectories(scratchClasses);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   599
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   600
                JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   601
                try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   602
                    List<String> options = Arrays.asList("-d", scratchClasses.toString());
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   603
                    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(scratchSrc);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   604
                    CompilationTask task = comp.getTask(null, fm, null, options, null, files);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   605
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   606
                    if (!task.call()) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   607
                        throw new AssertionError("compilation failed");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   608
                    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   609
                }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   610
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   611
                Path classfile = scratchClasses.resolve(fileNameStub + ".class");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   612
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   613
                Files.copy(classfile, out);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   614
            } catch (IOException ex) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   615
                throw new IllegalStateException(ex);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   616
            }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   617
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   618
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   619
        void doReadResource(CreateFileObject file, String expectedContent) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   620
            try {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   621
                StringBuilder actualContent = new StringBuilder();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   622
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   623
                try (Reader r = file.create().openReader(true)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   624
                    int read;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   625
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   626
                    while ((read = r.read()) != (-1)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   627
                        actualContent.append((char) read);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   628
                    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   629
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   630
                }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   631
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   632
                assertEquals(expectedContent, actualContent.toString());
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   633
            } catch (IOException ex) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   634
                throw new IllegalStateException(ex);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   635
            }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   636
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   637
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   638
        public interface CreateFileObject {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   639
            public FileObject create() throws IOException;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   640
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   641
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   642
        void expectFilerException(Callable<Object> c) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   643
            try {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   644
                c.call();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   645
                throw new AssertionError("Expected exception not thrown");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   646
            } catch (FilerException ex) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   647
                //expected
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   648
            } catch (Exception ex) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   649
                throw new IllegalStateException(ex);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   650
            }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   651
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   652
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   653
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   654
        public SourceVersion getSupportedSourceVersion() {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   655
            return SourceVersion.latest();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   656
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   657
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   658
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   659
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   660
    @SupportedAnnotationTypes("*")
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   661
    @SupportedOptions({"filetype", "modulename"})
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   662
    public static final class MultiModeAPITestAP extends GeneratingAP {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   663
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   664
        int round;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   665
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   666
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   667
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   668
            if (round++ != 0)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   669
                return false;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   670
42823
alanb
parents: 42815 42822
diff changeset
   671
            createClass("m1x", "api1.GenApi", "package api1; public class GenApi {}");
alanb
parents: 42815 42822
diff changeset
   672
            createClass("m1x", "impl.Impl", "package impl; public class Impl {}");
alanb
parents: 42815 42822
diff changeset
   673
            createClass("m2x", "api2.GenApi", "package api2; public class GenApi {}");
alanb
parents: 42815 42822
diff changeset
   674
            createClass("m2x", "impl.Impl", "package impl; public class Impl {}");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   675
42823
alanb
parents: 42815 42822
diff changeset
   676
            createResource("m1x", "api1", "gen1");
alanb
parents: 42815 42822
diff changeset
   677
            createResource("m2x", "api2", "gen1");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   678
42823
alanb
parents: 42815 42822
diff changeset
   679
            readResource("m1x", "api1", "api", "1");
alanb
parents: 42815 42822
diff changeset
   680
            readResource("m1x", "impl", "impl", "1");
alanb
parents: 42815 42822
diff changeset
   681
            readResource("m2x", "api2", "api", "2");
alanb
parents: 42815 42822
diff changeset
   682
            readResource("m2x", "impl", "impl", "2");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   683
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   684
            Filer filer = processingEnv.getFiler();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   685
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   686
            expectFilerException(() -> filer.createSourceFile("fail.Fail"));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   687
            expectFilerException(() -> filer.createClassFile("fail.Fail"));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   688
            expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, "fail", "fail"));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   689
            expectFilerException(() -> filer.getResource(StandardLocation.MODULE_SOURCE_PATH, "fail", "fail"));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   690
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   691
            //must not generate to unnamed package:
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   692
            expectFilerException(() -> filer.createSourceFile("m1/Fail"));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   693
            expectFilerException(() -> filer.createClassFile("m1/Fail"));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   694
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   695
            //cannot generate resources to modules that are not root modules:
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   696
            expectFilerException(() -> filer.createSourceFile("java.base/fail.Fail"));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   697
            expectFilerException(() -> filer.createClassFile("java.base/fail.Fail"));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   698
            expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, "java.base/fail", "Fail"));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   699
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   700
            return false;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   701
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   702
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   703
        void createClass(String expectedModule, String name, String content) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   704
            Filer filer = processingEnv.getFiler();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   705
            FileType filetype = FileType.valueOf(processingEnv.getOptions().getOrDefault("filetype", ""));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   706
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   707
            switch (filetype) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   708
                case SOURCE:
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   709
                    createSource(() -> filer.createSourceFile(expectedModule + "/" + name), name, content);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   710
                    break;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   711
                case CLASS:
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   712
                    createClass(() -> filer.createClassFile(expectedModule + "/" + name), name, content);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   713
                    break;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   714
                default:
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   715
                    throw new AssertionError("Unexpected filetype: " + filetype);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   716
            }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   717
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   718
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   719
        void createResource(String expectedModule, String pkg, String relName) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   720
            try {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   721
                Filer filer = processingEnv.getFiler();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   722
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   723
                filer.createResource(StandardLocation.CLASS_OUTPUT, expectedModule + "/" + pkg, relName)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   724
                     .openOutputStream()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   725
                     .close();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   726
            } catch (IOException ex) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   727
                throw new IllegalStateException(ex);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   728
            }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   729
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   730
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   731
        void readResource(String expectedModule, String pkg, String relName, String expectedContent) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   732
            Filer filer = processingEnv.getFiler();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   733
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   734
            doReadResource(() -> filer.getResource(StandardLocation.MODULE_SOURCE_PATH, expectedModule + "/" + pkg, relName),
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   735
                           expectedContent);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   736
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   737
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   738
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   739
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   740
    @Test
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   741
    public void testGenerateInSingleNameModeAPI(Path base) throws Exception {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   742
        Path classes = base.resolve("classes");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   743
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   744
        Files.createDirectories(classes);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   745
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   746
        Path m1 = base.resolve("module-src");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   747
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   748
        tb.writeJavaFiles(m1,
42823
alanb
parents: 42815 42822
diff changeset
   749
                          "module m1x { }");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   750
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   751
        writeFile("3", m1, "impl", "resource");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   752
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   753
        new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   754
          .options("-processor", SingleNameModeAPITestAP.class.getName(),
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   755
                   "-sourcepath", m1.toString())
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   756
          .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   757
          .files(findJavaFiles(m1))
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   758
          .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   759
          .writeAll();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   760
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   761
        assertFileExists(classes, "impl", "Impl1.class");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   762
        assertFileExists(classes, "impl", "Impl2.class");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   763
        assertFileExists(classes, "impl", "Impl3");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   764
        assertFileExists(classes, "impl", "Impl4.class");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   765
        assertFileExists(classes, "impl", "Impl5.class");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   766
        assertFileExists(classes, "impl", "Impl6");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   767
        assertFileExists(classes, "impl", "Impl7.class");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   768
        assertFileExists(classes, "impl", "Impl8.class");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   769
        assertFileExists(classes, "impl", "Impl9");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   770
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   771
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   772
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   773
    @SupportedAnnotationTypes("*")
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   774
    public static final class SingleNameModeAPITestAP extends GeneratingAP {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   775
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   776
        int round;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   777
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   778
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   779
        public synchronized void init(ProcessingEnvironment processingEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   780
            super.init(processingEnv);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   781
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   782
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   783
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   784
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   785
            if (round++ != 0)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   786
                return false;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   787
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   788
            Filer filer = processingEnv.getFiler();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   789
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   790
            createSource(() -> filer.createSourceFile("impl.Impl1"), "impl.Impl1", "package impl; class Impl1 {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   791
            createClass(() -> filer.createClassFile("impl.Impl2"), "impl.Impl2", "package impl; class Impl2 {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   792
            createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, "impl", "Impl3"), "impl.Impl3", "");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   793
            doReadResource(() -> filer.getResource(StandardLocation.SOURCE_PATH, "impl", "resource"), "3");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   794
42823
alanb
parents: 42815 42822
diff changeset
   795
            createSource(() -> filer.createSourceFile("m1x/impl.Impl4"), "impl.Impl4", "package impl; class Impl4 {}");
alanb
parents: 42815 42822
diff changeset
   796
            createClass(() -> filer.createClassFile("m1x/impl.Impl5"), "impl.Impl5", "package impl; class Impl5 {}");
alanb
parents: 42815 42822
diff changeset
   797
            createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, "m1x/impl", "Impl6"), "impl.Impl6", "");
alanb
parents: 42815 42822
diff changeset
   798
            doReadResource(() -> filer.getResource(StandardLocation.SOURCE_PATH, "m1x/impl", "resource"), "3");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   799
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   800
            TypeElement jlObject = processingEnv.getElementUtils().getTypeElement("java.lang.Object");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   801
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   802
            //"broken" originating element:
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   803
            createSource(() -> filer.createSourceFile("impl.Impl7", jlObject), "impl.Impl7", "package impl; class Impl7 {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   804
            createClass(() -> filer.createClassFile("impl.Impl8", jlObject), "impl.Impl8", "package impl; class Impl8 {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   805
            createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, "impl", "Impl9", jlObject), "impl.Impl9", "");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   806
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   807
            //must not generate to unnamed package:
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   808
            expectFilerException(() -> filer.createSourceFile("Fail"));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   809
            expectFilerException(() -> filer.createClassFile("Fail"));
42823
alanb
parents: 42815 42822
diff changeset
   810
            expectFilerException(() -> filer.createSourceFile("m1x/Fail"));
alanb
parents: 42815 42822
diff changeset
   811
            expectFilerException(() -> filer.createClassFile("m1x/Fail"));
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   812
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   813
            //cannot generate resources to modules that are not root modules:
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   814
            expectFilerException(() -> filer.createSourceFile("java.base/fail.Fail"));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   815
            expectFilerException(() -> filer.createClassFile("java.base/fail.Fail"));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   816
            expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, "java.base/fail", "Fail"));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   817
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   818
            return false;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   819
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   820
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   821
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   822
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   823
    @Test
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   824
    public void testGenerateInUnnamedModeAPI(Path base) throws Exception {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   825
        Path classes = base.resolve("classes");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   826
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   827
        Files.createDirectories(classes);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   828
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   829
        Path src = base.resolve("src");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   830
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   831
        tb.writeJavaFiles(src,
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   832
                          "class T {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   833
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   834
        new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   835
          .options("-processor", UnnamedModeAPITestAP.class.getName(),
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   836
                   "-sourcepath", src.toString())
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   837
          .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   838
          .files(findJavaFiles(src))
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   839
          .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   840
          .writeAll();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   841
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   842
        assertFileExists(classes, "Impl1.class");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   843
        assertFileExists(classes, "Impl2.class");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   844
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   845
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   846
    @Test
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   847
    public void testGenerateInNoModeAPI(Path base) throws Exception {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   848
        Path classes = base.resolve("classes");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   849
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   850
        Files.createDirectories(classes);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   851
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   852
        Path src = base.resolve("src");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   853
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   854
        tb.writeJavaFiles(src,
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   855
                          "class T {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   856
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   857
        new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   858
          .options("-processor", UnnamedModeAPITestAP.class.getName(),
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   859
                   "-source", "8", "-target", "8",
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   860
                   "-sourcepath", src.toString())
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   861
          .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   862
          .files(findJavaFiles(src))
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   863
          .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   864
          .writeAll();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   865
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   866
        assertFileExists(classes, "Impl1.class");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   867
        assertFileExists(classes, "Impl2.class");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   868
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   869
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   870
    @SupportedAnnotationTypes("*")
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   871
    public static final class UnnamedModeAPITestAP extends GeneratingAP {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   872
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   873
        int round;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   874
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   875
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   876
        public synchronized void init(ProcessingEnvironment processingEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   877
            super.init(processingEnv);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   878
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   879
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   880
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   881
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   882
            if (round++ != 0)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   883
                return false;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   884
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   885
            Filer filer = processingEnv.getFiler();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   886
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   887
            //must not generate to unnamed package:
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   888
            createSource(() -> filer.createSourceFile("Impl1"), "Impl1", "class Impl1 {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   889
            createClass(() -> filer.createClassFile("Impl2"), "Impl2", "class Impl2 {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   890
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   891
            return false;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   892
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   893
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   894
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   895
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   896
    @Test
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   897
    public void testDisambiguateAnnotations(Path base) throws Exception {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   898
        Path classes = base.resolve("classes");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   899
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   900
        Files.createDirectories(classes);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   901
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   902
        Path src = base.resolve("src");
42823
alanb
parents: 42815 42822
diff changeset
   903
        Path m1 = src.resolve("m1x");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   904
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   905
        tb.writeJavaFiles(m1,
42823
alanb
parents: 42815 42822
diff changeset
   906
                          "module m1x { exports api; }",
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   907
                          "package api; public @interface A {}",
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   908
                          "package api; public @interface B {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   909
42823
alanb
parents: 42815 42822
diff changeset
   910
        Path m2 = src.resolve("m2x");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   911
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   912
        tb.writeJavaFiles(m2,
42823
alanb
parents: 42815 42822
diff changeset
   913
                          "module m2x { exports api; }",
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   914
                          "package api; public @interface A {}",
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   915
                          "package api; public @interface B {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   916
42823
alanb
parents: 42815 42822
diff changeset
   917
        Path m3 = src.resolve("m3x");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   918
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   919
        tb.writeJavaFiles(m3,
42823
alanb
parents: 42815 42822
diff changeset
   920
                          "module m3x { requires m1x; }",
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   921
                          "package impl; import api.*; @A @B public class T {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   922
42823
alanb
parents: 42815 42822
diff changeset
   923
        Path m4 = src.resolve("m4x");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   924
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   925
        tb.writeJavaFiles(m4,
42823
alanb
parents: 42815 42822
diff changeset
   926
                          "module m4x { requires m2x; }",
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   927
                          "package impl; import api.*; @A @B public class T {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   928
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   929
        List<String> log;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   930
        List<String> expected;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   931
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   932
        log = new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   933
            .options("-processor", SelectAnnotationATestAP.class.getName() + "," + SelectAnnotationBTestAP.class.getName(),
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   934
                     "--module-source-path", src.toString(),
42823
alanb
parents: 42815 42822
diff changeset
   935
                     "-m", "m1x,m2x")
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   936
            .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   937
            .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   938
            .writeAll()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   939
            .getOutputLines(OutputKind.STDERR);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   940
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   941
        expected = Arrays.asList("");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   942
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   943
        if (!expected.equals(log)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   944
            throw new AssertionError("Output does not match; output: " + log);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   945
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   946
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   947
        log = new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   948
            .options("-processor", SelectAnnotationATestAP.class.getName() + "," + SelectAnnotationBTestAP.class.getName(),
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   949
                     "--module-source-path", src.toString(),
42823
alanb
parents: 42815 42822
diff changeset
   950
                     "-m", "m3x")
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   951
            .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   952
            .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   953
            .writeAll()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   954
            .getOutputLines(OutputKind.STDERR);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   955
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   956
        expected = Arrays.asList("SelectAnnotationBTestAP",
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   957
                                 "SelectAnnotationBTestAP");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   958
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   959
        if (!expected.equals(log)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   960
            throw new AssertionError("Output does not match; output: " + log);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   961
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   962
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   963
        log = new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   964
            .options("-processor", SelectAnnotationATestAP.class.getName() + "," + SelectAnnotationBTestAP.class.getName(),
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   965
                     "--module-source-path", src.toString(),
42823
alanb
parents: 42815 42822
diff changeset
   966
                     "-m", "m4x")
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   967
            .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   968
            .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   969
            .writeAll()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   970
            .getOutputLines(OutputKind.STDERR);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   971
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   972
        expected = Arrays.asList("SelectAnnotationATestAP",
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   973
                                 "SelectAnnotationBTestAP",
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   974
                                 "SelectAnnotationATestAP",
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   975
                                 "SelectAnnotationBTestAP");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   976
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   977
        if (!expected.equals(log)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   978
            throw new AssertionError("Output does not match; output: " + log);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   979
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   980
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   981
43037
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   982
    @Test
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   983
    public void testDisambiguateAnnotationsNoModules(Path base) throws Exception {
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   984
        Path classes = base.resolve("classes");
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   985
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   986
        Files.createDirectories(classes);
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   987
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   988
        Path src = base.resolve("src");
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   989
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   990
        tb.writeJavaFiles(src,
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   991
                          "package api; public @interface A {}",
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   992
                          "package api; public @interface B {}",
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   993
                          "package impl; import api.*; @A @B public class T {}");
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   994
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   995
        List<String> log = new JavacTask(tb)
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   996
            .options("-processor", SelectAnnotationATestAP.class.getName() + "," + SelectAnnotationBTestAP.class.getName(),
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   997
                     "-source", "8", "-target", "8")
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   998
            .outdir(classes)
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
   999
            .files(findJavaFiles(src))
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1000
            .run()
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1001
            .writeAll()
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1002
            .getOutputLines(OutputKind.STDERR);
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1003
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1004
        List<String> expected = Arrays.asList("SelectAnnotationATestAP",
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1005
                                              "SelectAnnotationBTestAP",
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1006
                                              "SelectAnnotationATestAP",
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1007
                                              "SelectAnnotationBTestAP");
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1008
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1009
        if (!expected.equals(log)) {
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1010
            throw new AssertionError("Output does not match; output: " + log);
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1011
        }
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1012
    }
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1013
42823
alanb
parents: 42815 42822
diff changeset
  1014
    @SupportedAnnotationTypes("m2x/api.A")
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1015
    public static final class SelectAnnotationATestAP extends AbstractProcessor {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1016
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1017
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1018
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1019
            System.err.println("SelectAnnotationATestAP");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1020
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1021
            return false;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1022
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1023
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1024
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1025
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1026
    @SupportedAnnotationTypes("api.B")
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1027
    public static final class SelectAnnotationBTestAP extends AbstractProcessor {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1028
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1029
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1030
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1031
            System.err.println("SelectAnnotationBTestAP");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1032
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1033
            return false;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1034
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1035
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1036
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1037
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1038
    private static void writeFile(String content, Path base, String... pathElements) throws IOException {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1039
        Path file = resolveFile(base, pathElements);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1040
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1041
        Files.createDirectories(file.getParent());
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1042
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1043
        try (Writer out = Files.newBufferedWriter(file)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1044
            out.append(content);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1045
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1046
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1047
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1048
    @Test
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1049
    public void testUnboundLookup(Path base) throws Exception {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1050
        Path src = base.resolve("src");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1051
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1052
        tb.writeJavaFiles(src,
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1053
                          "package impl.conflict.src; public class Impl { }");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1054
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1055
        Path moduleSrc = base.resolve("module-src");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1056
        Path m1 = moduleSrc.resolve("m1x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1057
        Path m2 = moduleSrc.resolve("m2x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1058
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1059
        Path classes = base.resolve("classes");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1060
        Path cpClasses = base.resolve("cpClasses");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1061
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1062
        Files.createDirectories(classes);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1063
        Files.createDirectories(cpClasses);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1064
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1065
        tb.writeJavaFiles(m1,
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1066
                          "module m1x { }",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1067
                          "package impl1; public class Impl { }",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1068
                          "package impl.conflict.module; class Impl { }",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1069
                          "package impl.conflict.clazz; public class pkg { public static class I { } }",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1070
                          "package impl.conflict.src; public class Impl { }");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1071
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1072
        tb.writeJavaFiles(m2,
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1073
                          "module m2x { }",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1074
                          "package impl2; public class Impl { }",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1075
                          "package impl.conflict.module; class Impl { }",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1076
                          "package impl.conflict; public class clazz { public static class pkg { } }");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1077
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1078
        //from source:
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1079
        new JavacTask(tb)
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1080
            .options("--module-source-path", moduleSrc.toString(),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1081
                     "--source-path", src.toString(),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1082
                     "-processorpath", System.getProperty("test.class.path"),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1083
                     "-processor", UnboundLookup.class.getName())
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1084
            .outdir(classes)
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1085
            .files(findJavaFiles(moduleSrc))
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1086
            .run()
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1087
            .writeAll();
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1088
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1089
        new JavacTask(tb)
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1090
            .options("--source-path", src.toString())
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1091
            .outdir(cpClasses)
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1092
            .files(findJavaFiles(src))
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1093
            .run()
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1094
            .writeAll();
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1095
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1096
        //from classfiles:
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1097
        new JavacTask(tb)
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1098
            .options("--module-path", classes.toString(),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1099
                     "--class-path", cpClasses.toString(),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1100
                     "--add-modules", "m1x,m2x",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1101
                     "-processorpath", System.getProperty("test.class.path"),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1102
                     "-processor", UnboundLookup.class.getName(),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1103
                     "-proc:only")
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1104
            .classes("java.lang.Object")
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1105
            .run()
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1106
            .writeAll();
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1107
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1108
        //source 8:
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1109
        new JavacTask(tb)
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1110
            .options("--source-path", src.toString(),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1111
                     "-source", "8",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1112
                     "-processorpath", System.getProperty("test.class.path"),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1113
                     "-processor", UnboundLookup8.class.getName())
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1114
            .outdir(cpClasses)
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1115
            .files(findJavaFiles(src))
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1116
            .run()
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1117
            .writeAll();
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1118
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1119
    }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1120
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1121
    @SupportedAnnotationTypes("*")
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1122
    public static final class UnboundLookup extends AbstractProcessor {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1123
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1124
        @Override
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1125
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1126
            assertTypeElementExists("impl1.Impl", "m1x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1127
            assertPackageElementExists("impl1", "m1x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1128
            assertTypeElementExists("impl2.Impl", "m2x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1129
            assertTypeElementExists("impl.conflict.clazz.pkg.I", "m1x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1130
            assertTypeElementExists("impl.conflict.clazz", "m2x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1131
            assertPackageElementExists("impl.conflict.clazz", "m1x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1132
            assertPackageElementExists("impl2", "m2x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1133
            assertTypeElementNotFound("impl.conflict.module.Impl");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1134
            assertPackageElementNotFound("impl.conflict.module");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1135
            assertTypeElementNotFound("impl.conflict.src.Impl");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1136
            assertPackageElementNotFound("impl.conflict.src");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1137
            assertTypeElementNotFound("impl.conflict.clazz.pkg");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1138
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1139
            return false;
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1140
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1141
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1142
        private void assertTypeElementExists(String name, String expectedModule) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1143
            assertElementExists(name, "class", processingEnv.getElementUtils() :: getTypeElement, expectedModule);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1144
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1145
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1146
        private void assertPackageElementExists(String name, String expectedModule) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1147
            assertElementExists(name, "package", processingEnv.getElementUtils() :: getPackageElement, expectedModule);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1148
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1149
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1150
        private void assertElementExists(String name, String type, Function<String, Element> getter, String expectedModule) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1151
            Element clazz = getter.apply(name);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1152
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1153
            if (clazz == null) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1154
                throw new AssertionError("No " + name + " " + type + " found.");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1155
            }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1156
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1157
            ModuleElement mod = processingEnv.getElementUtils().getModuleOf(clazz);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1158
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1159
            if (!mod.getQualifiedName().contentEquals(expectedModule)) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1160
                throw new AssertionError(name + " found in an unexpected module: " + mod.getQualifiedName());
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1161
            }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1162
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1163
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1164
        private void assertTypeElementNotFound(String name) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1165
            assertElementNotFound(name, processingEnv.getElementUtils() :: getTypeElement);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1166
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1167
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1168
        private void assertPackageElementNotFound(String name) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1169
            assertElementNotFound(name, processingEnv.getElementUtils() :: getPackageElement);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1170
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1171
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1172
        private void assertElementNotFound(String name, Function<String, Element> getter) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1173
            Element found = getter.apply(name);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1174
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1175
            if (found != null) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1176
                fail("Element found unexpectedly: " + found);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1177
            }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1178
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1179
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1180
        @Override
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1181
        public SourceVersion getSupportedSourceVersion() {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1182
            return SourceVersion.latest();
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1183
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1184
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1185
    }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1186
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1187
    @SupportedAnnotationTypes("*")
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1188
    public static final class UnboundLookup8 extends AbstractProcessor {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1189
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1190
        @Override
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1191
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1192
            if (processingEnv.getElementUtils().getTypeElement("impl.conflict.src.Impl") == null) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1193
                throw new AssertionError("impl.conflict.src.Impl.");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1194
            }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1195
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1196
            if (processingEnv.getElementUtils().getModuleElement("java.base") != null) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1197
                throw new AssertionError("getModuleElement != null for -source 8");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1198
            }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1199
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1200
            return false;
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1201
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1202
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1203
        @Override
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1204
        public SourceVersion getSupportedSourceVersion() {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1205
            return SourceVersion.latest();
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1206
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1207
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1208
    }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1209
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1210
    private static void assertNonNull(String msg, Object val) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1211
        if (val == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1212
            throw new AssertionError(msg);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1213
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1214
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1215
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1216
    private static void assertNull(String msg, Object val) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1217
        if (val != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1218
            throw new AssertionError(msg);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1219
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1220
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1221
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1222
    private static void assertEquals(Object expected, Object actual) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1223
        if (!Objects.equals(expected, actual)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1224
            throw new AssertionError("expected: " + expected + "; actual=" + actual);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1225
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1226
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1227
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1228
    private static void assertFileExists(Path base, String... pathElements) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1229
        Path file = resolveFile(base, pathElements);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1230
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1231
        if (!Files.exists(file)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1232
            throw new AssertionError("Expected file: " + file + " exist, but it does not.");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1233
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1234
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1235
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1236
    static Path resolveFile(Path base, String... pathElements) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1237
        Path file = base;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1238
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1239
        for (String el : pathElements) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1240
            file = file.resolve(el);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1241
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1242
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1243
        return file;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1244
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1245
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1246
    private static void fail(String msg) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1247
        throw new AssertionError(msg);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1248
    }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1249
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1250
}