test/langtools/tools/javac/modules/AnnotationProcessing.java
author jlahoda
Mon, 16 Jul 2018 12:35:25 +0200
changeset 51094 a49d106e9b7c
parent 50967 1e24c7152e47
permissions -rw-r--r--
8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance. Summary: Caching the results of Elements.getTypeElement/getPackageElement Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
50704
1a3f1cf62456 8196425: tools/javac/modules/AnnotationProcessing.java failed
jjg
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
51094
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
    26
 * @bug 8133884 8162711 8133896 8172158 8172262 8173636 8175119 8189747
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;
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
    40
import java.io.UncheckedIOException;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    41
import java.io.Writer;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.nio.file.Files;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import java.nio.file.Path;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    44
import java.nio.file.Paths;
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
    45
import java.util.ArrayList;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import java.util.Arrays;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import java.util.HashMap;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    48
import java.util.HashSet;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
import java.util.List;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
import java.util.Map;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
import java.util.Objects;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
import java.util.Set;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    53
import java.util.concurrent.Callable;
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
    54
import java.util.function.Consumer;
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
    55
import java.util.function.Function;
43149
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
    56
import java.util.regex.Pattern;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
import java.util.stream.Collectors;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
import javax.annotation.processing.AbstractProcessor;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    60
import javax.annotation.processing.Filer;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    61
import javax.annotation.processing.FilerException;
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
    62
import javax.annotation.processing.Messager;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    63
import javax.annotation.processing.ProcessingEnvironment;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
import javax.annotation.processing.RoundEnvironment;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
import javax.annotation.processing.SupportedAnnotationTypes;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    66
import javax.annotation.processing.SupportedOptions;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
import javax.lang.model.SourceVersion;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
import javax.lang.model.element.Element;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    69
import javax.lang.model.element.ElementKind;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
import javax.lang.model.element.ModuleElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
import javax.lang.model.element.ModuleElement.ProvidesDirective;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    72
import javax.lang.model.element.ModuleElement.UsesDirective;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
import javax.lang.model.element.PackageElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
import javax.lang.model.element.TypeElement;
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
    75
import javax.lang.model.element.VariableElement;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
import javax.lang.model.type.TypeKind;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    77
import javax.lang.model.util.ElementFilter;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    78
import javax.lang.model.util.ElementScanner9;
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
    79
import javax.tools.Diagnostic.Kind;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    80
import javax.tools.FileObject;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    81
import javax.tools.JavaCompiler;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    82
import javax.tools.JavaCompiler.CompilationTask;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    83
import javax.tools.JavaFileManager;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    84
import javax.tools.JavaFileManager.Location;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    85
import javax.tools.JavaFileObject;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    86
import javax.tools.StandardJavaFileManager;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    87
import javax.tools.StandardLocation;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    88
import javax.tools.ToolProvider;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    90
import toolbox.JavacTask;
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    91
import toolbox.Task;
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
    92
import toolbox.Task.Mode;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
    93
import toolbox.Task.OutputKind;
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    94
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
public class AnnotationProcessing extends ModuleTestBase {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
    public static void main(String... args) throws Exception {
50967
1e24c7152e47 8205563: modules/AnnotationProcessing.java failed testGenerateSingleModule
jjg
parents: 50704
diff changeset
    98
        System.out.println(System.getProperties());
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        new AnnotationProcessing().runTests();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   103
    public void testAPSingleModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   105
        Path m1 = moduleSrc.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   108
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   112
                          "module m1x { }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
                          "package impl; public class Impl { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   115
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   116
                .options("--module-source-path", moduleSrc.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                         "-processor", AP.class.getName(),
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   118
                         "-AexpectedEnclosedElements=m1x=>impl")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
                .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   123
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
            throw new AssertionError("Unexpected output: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   130
    public void testAPMultiModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   132
        Path m1 = moduleSrc.resolve("m1x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   133
        Path m2 = moduleSrc.resolve("m2x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   140
                          "module m1x { }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
                          "package impl1; public class Impl1 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   143
        tb.writeJavaFiles(m2,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   144
                          "module m2x { }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
                          "package impl2; public class Impl2 { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   147
        String log = new JavacTask(tb)
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 37758
diff changeset
   148
                .options("--module-source-path", moduleSrc.toString(),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
                         "-processor", AP.class.getName(),
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   150
                         "-AexpectedEnclosedElements=m1x=>impl1,m2x=>impl2")
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
                .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   155
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   156
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
            throw new AssertionError("Unexpected output: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
    @SupportedAnnotationTypes("*")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
    @SupportedOptions("expectedEnclosedElements")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
    public static final class AP extends AbstractProcessor {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   165
        private Map<String, List<String>> module2ExpectedEnclosedElements;
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   166
        private Set<String> seenModules = new HashSet<>();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
            if (module2ExpectedEnclosedElements == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
                module2ExpectedEnclosedElements = new HashMap<>();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   173
                String expectedEnclosedElements =
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   174
                        processingEnv.getOptions().get("expectedEnclosedElements");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   175
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   176
                for (String moduleDef : expectedEnclosedElements.split(",")) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   177
                    String[] module2Packages = moduleDef.split("=>");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   178
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   179
                    module2ExpectedEnclosedElements.put(module2Packages[0],
43585
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
   180
                                                        List.of(module2Packages[1].split(":")));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   181
                }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   182
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   183
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   184
            //verify ModuleType and ModuleSymbol behavior:
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   185
            for (Element root : roundEnv.getRootElements()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   186
                ModuleElement module = processingEnv.getElementUtils().getModuleOf(root);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   187
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   188
                assertEquals(TypeKind.MODULE, module.asType().getKind());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   189
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                boolean[] seenModule = new boolean[1];
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   191
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   192
                module.accept(new ElementScanner9<Void, Void>() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   193
                    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   194
                    public Void visitModule(ModuleElement e, Void p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   195
                        seenModule[0] = true;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   196
                        return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   197
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   198
                    @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   199
                    public Void scan(Element e, Void p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   200
                        throw new AssertionError("Shouldn't get here.");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   201
                    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   202
                }, null);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   203
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   204
                assertEquals(true, seenModule[0]);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   205
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   206
                List<String> actualElements =
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   207
                        module.getEnclosedElements()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   208
                              .stream()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   209
                              .map(s -> (PackageElement) s)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   210
                              .map(p -> p.getQualifiedName().toString())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   211
                              .collect(Collectors.toList());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   212
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   213
                String moduleName = module.getQualifiedName().toString();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   214
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   215
                assertEquals(module2ExpectedEnclosedElements.get(moduleName),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   216
                             actualElements);
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   217
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   218
                seenModules.add(moduleName);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   219
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   220
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   221
            if (roundEnv.processingOver()) {
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   222
                assertEquals(module2ExpectedEnclosedElements.keySet(), seenModules);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   223
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   224
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   225
            return false;
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
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   229
        public SourceVersion getSupportedSourceVersion() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   230
            return SourceVersion.latest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   231
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   232
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   233
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   234
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   235
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   236
    public void testVerifyUsesProvides(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   237
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   238
        Path m1 = moduleSrc.resolve("m1x");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   239
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   240
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   241
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   242
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   243
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   245
                          "module m1x { exports api; uses api.Api; provides api.Api with impl.Impl; }",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   246
                          "package api; public class Api { }",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   247
                          "package impl; public class Impl extends api.Api { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   248
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   249
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   250
                .options("-doe", "-processor", VerifyUsesProvidesAP.class.getName())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   251
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   252
                .files(findJavaFiles(moduleSrc))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   253
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   254
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   255
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   256
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   257
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   258
            throw new AssertionError("Unexpected output: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   259
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   260
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   261
    @SupportedAnnotationTypes("*")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   262
    public static final class VerifyUsesProvidesAP extends AbstractProcessor {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   263
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   264
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   265
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   266
            TypeElement api = processingEnv.getElementUtils().getTypeElement("api.Api");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   267
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   268
            assertNonNull("Cannot find api.Api", api);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   269
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   270
            ModuleElement modle = (ModuleElement) processingEnv.getElementUtils().getPackageOf(api).getEnclosingElement();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   271
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   272
            assertNonNull("modle is null", modle);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   273
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   274
            List<? extends UsesDirective> uses = ElementFilter.usesIn(modle.getDirectives());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   275
            assertEquals(1, uses.size());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   276
            assertEquals("api.Api", uses.iterator().next().getService().getQualifiedName().toString());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   277
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   278
            List<? extends ProvidesDirective> provides = ElementFilter.providesIn(modle.getDirectives());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   279
            assertEquals(1, provides.size());
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   280
            assertEquals("api.Api", provides.iterator().next().getService().getQualifiedName().toString());
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40311
diff changeset
   281
            assertEquals("impl.Impl", provides.iterator().next().getImplementations().get(0).getQualifiedName().toString());
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   282
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   283
            return false;
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
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   287
        public SourceVersion getSupportedSourceVersion() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   288
            return SourceVersion.latest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   290
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   291
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   292
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   293
    @Test
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents: 36778
diff changeset
   294
    public void testPackageNoModule(Path base) throws Exception {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   295
        Path src = base.resolve("src");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   296
        Path classes = base.resolve("classes");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   297
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   298
        Files.createDirectories(classes);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   299
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   300
        tb.writeJavaFiles(src,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   301
                          "package api; public class Api { }");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   302
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   303
        String log = new JavacTask(tb)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   304
                .options("-processor", VerifyPackageNoModule.class.getName(),
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   305
                         "-source", "8",
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   306
                         "-Xlint:-options")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   307
                .outdir(classes)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   308
                .files(findJavaFiles(src))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   309
                .run()
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   310
                .writeAll()
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
   311
                .getOutput(Task.OutputKind.DIRECT);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   312
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   313
        if (!log.isEmpty())
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   314
            throw new AssertionError("Unexpected output: " + log);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   315
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   316
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   317
    @SupportedAnnotationTypes("*")
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   318
    public static final class VerifyPackageNoModule extends AbstractProcessor {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   319
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   320
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   321
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   322
            TypeElement api = processingEnv.getElementUtils().getTypeElement("api.Api");
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   323
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   324
            assertNonNull("Cannot find api.Api", api);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   325
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   326
            ModuleElement modle = (ModuleElement) processingEnv.getElementUtils().getPackageOf(api).getEnclosingElement();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   327
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   328
            assertNull("modle is not null", modle);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   329
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   330
            return false;
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
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   334
        public SourceVersion getSupportedSourceVersion() {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   335
            return SourceVersion.latest();
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   336
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   337
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   338
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   339
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   340
    @Test
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   341
    public void testQualifiedClassForProcessing(Path base) throws Exception {
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   342
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   343
        Path m1 = moduleSrc.resolve("m1x");
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   344
        Path m2 = moduleSrc.resolve("m2x");
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   345
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   346
        Path classes = base.resolve("classes");
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   347
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   348
        Files.createDirectories(classes);
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   349
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   350
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   351
                          "module m1x { }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   352
                          "package impl; public class Impl { int m1x; }");
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   353
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   354
        tb.writeJavaFiles(m2,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   355
                          "module m2x { }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   356
                          "package impl; public class Impl { int m2x; }");
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   357
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   358
        new JavacTask(tb)
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   359
            .options("--module-source-path", moduleSrc.toString())
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   360
            .outdir(classes)
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   361
            .files(findJavaFiles(moduleSrc))
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   362
            .run()
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   363
            .writeAll()
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   364
            .getOutput(Task.OutputKind.DIRECT);
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   365
43585
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
   366
        List<String> expected = List.of("Note: field: m1x");
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   367
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   368
        for (Mode mode : new Mode[] {Mode.API, Mode.CMDLINE}) {
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   369
            List<String> log = new JavacTask(tb, mode)
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   370
                    .options("-processor", QualifiedClassForProcessing.class.getName(),
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   371
                             "--module-path", classes.toString())
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   372
                    .classes("m1x/impl.Impl")
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   373
                    .outdir(classes)
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   374
                    .run()
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   375
                    .writeAll()
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   376
                    .getOutputLines(Task.OutputKind.DIRECT);
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
            if (!expected.equals(log))
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   379
                throw new AssertionError("Unexpected output: " + log);
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
    }
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   382
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   383
    @SupportedAnnotationTypes("*")
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   384
    public static final class QualifiedClassForProcessing extends AbstractProcessor {
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
        @Override
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   387
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   388
            if (processingEnv.getElementUtils().getModuleElement("m1x") == null) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   389
                throw new AssertionError("No m1x module found.");
40311
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   390
            }
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   391
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   392
            Messager messager = processingEnv.getMessager();
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
            for (TypeElement clazz : ElementFilter.typesIn(roundEnv.getRootElements())) {
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   395
                for (VariableElement field : ElementFilter.fieldsIn(clazz.getEnclosedElements())) {
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   396
                    messager.printMessage(Kind.NOTE, "field: " + field.getSimpleName());
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
            }
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   399
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   400
            return false;
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
        @Override
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   404
        public SourceVersion getSupportedSourceVersion() {
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   405
            return SourceVersion.latest();
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   406
        }
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   407
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   408
    }
bb76098875c8 8133884: javac moduleName/className and moduleName/packageName options
jlahoda
parents: 40308
diff changeset
   409
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   410
    @Test
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   411
    public void testModuleInRootElements(Path base) throws Exception {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   412
        Path moduleSrc = base.resolve("module-src");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   413
        Path m1 = moduleSrc.resolve("m1");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   414
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   415
        Path classes = base.resolve("classes");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   416
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   417
        Files.createDirectories(classes);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   418
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   419
        tb.writeJavaFiles(m1,
42823
alanb
parents: 42815 42822
diff changeset
   420
                          "module m1x { exports api; }",
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   421
                          "package api; public class Api { }");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   422
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   423
        List<String> log = new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   424
                .options("-processor", ModuleInRootElementsAP.class.getName())
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   425
                .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   426
                .files(findJavaFiles(moduleSrc))
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   427
                .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   428
                .writeAll()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   429
                .getOutputLines(Task.OutputKind.STDERR);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   430
43585
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
   431
        assertEquals(List.of("module: m1x"), log);
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   432
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   433
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   434
    @SupportedAnnotationTypes("*")
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   435
    public static final class ModuleInRootElementsAP extends AbstractProcessor {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   436
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   437
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   438
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   439
            roundEnv.getRootElements()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   440
                    .stream()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   441
                    .filter(el -> el.getKind() == ElementKind.MODULE)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   442
                    .forEach(mod -> System.err.println("module: " + mod.getSimpleName()));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   443
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   444
            return false;
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
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   448
        public SourceVersion getSupportedSourceVersion() {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   449
            return SourceVersion.latest();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   450
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   451
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   452
    }
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
    @Test
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   455
    public void testAnnotationsInModuleInfo(Path base) throws Exception {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   456
        Path moduleSrc = base.resolve("module-src");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   457
        Path m1 = moduleSrc.resolve("m1");
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(m1,
42823
alanb
parents: 42815 42822
diff changeset
   460
                          "@Deprecated module m1x { }");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   461
42823
alanb
parents: 42815 42822
diff changeset
   462
        Path m2 = moduleSrc.resolve("m2x");
42815
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
        tb.writeJavaFiles(m2,
42823
alanb
parents: 42815 42822
diff changeset
   465
                          "@SuppressWarnings(\"\") module m2x { }");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   466
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   467
        Path classes = base.resolve("classes");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   468
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   469
        Files.createDirectories(classes);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   470
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   471
        List<String> log = new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   472
                .options("-processor", AnnotationsInModuleInfoPrint.class.getName())
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   473
                .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   474
                .files(findJavaFiles(m1))
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   475
                .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   476
                .writeAll()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   477
                .getOutputLines(Task.OutputKind.DIRECT);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   478
43585
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
   479
        List<String> expectedLog = List.of("Note: AP Invoked",
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
   480
                                           "Note: AP Invoked");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   481
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   482
        assertEquals(expectedLog, log);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   483
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   484
        new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   485
            .options("-processor", AnnotationsInModuleInfoFail.class.getName())
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   486
            .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   487
            .files(findJavaFiles(m2))
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   488
            .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   489
            .writeAll();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   490
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   491
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   492
    @SupportedAnnotationTypes("java.lang.Deprecated")
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   493
    public static final class AnnotationsInModuleInfoPrint extends AbstractProcessor {
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
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   496
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   497
            processingEnv.getMessager().printMessage(Kind.NOTE, "AP Invoked");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   498
            return false;
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
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   502
        public SourceVersion getSupportedSourceVersion() {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   503
            return SourceVersion.latest();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   504
        }
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
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   507
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   508
    @SupportedAnnotationTypes("java.lang.Deprecated")
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   509
    public static final class AnnotationsInModuleInfoFail extends AbstractProcessor {
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 boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   513
            throw new AssertionError();
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
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   517
        public SourceVersion getSupportedSourceVersion() {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   518
            return SourceVersion.latest();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   519
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   520
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   521
    }
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
    @Test
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   524
    public void testGenerateInMultiModeAPI(Path base) throws Exception {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   525
        Path moduleSrc = base.resolve("module-src");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   526
        Path classes = base.resolve("classes");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   527
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   528
        Files.createDirectories(classes);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   529
42823
alanb
parents: 42815 42822
diff changeset
   530
        Path m1 = moduleSrc.resolve("m1x");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   531
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   532
        tb.writeJavaFiles(m1,
42823
alanb
parents: 42815 42822
diff changeset
   533
                          "module m1x { exports api1; }",
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   534
                          "package api1; public class Api { }",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   535
                          "package clash; public class C { }");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   536
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   537
        writeFile("1", m1, "api1", "api");
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   538
        writeFile("2", m1, "clash", "clash");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   539
42823
alanb
parents: 42815 42822
diff changeset
   540
        Path m2 = moduleSrc.resolve("m2x");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   541
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   542
        tb.writeJavaFiles(m2,
42823
alanb
parents: 42815 42822
diff changeset
   543
                          "module m2x { requires m1x; exports api2; }",
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   544
                          "package api2; public class Api { }",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   545
                          "package clash; public class C { }");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   546
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   547
        writeFile("3", m2, "api2", "api");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   548
        writeFile("4", m2, "clash", "api");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   549
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   550
        //passing testcases:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   551
        for (String module : Arrays.asList("", "m1x/")) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   552
            for (String originating : Arrays.asList("", ", jlObject")) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   553
                tb.writeJavaFiles(m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   554
                                  "package test; class Test { api1.Impl i; }");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   555
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   556
                //source:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   557
                runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   558
                            moduleSrc,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   559
                            classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   560
                            "createSource(() -> filer.createSourceFile(\"" + module + "api1.Impl\"" + originating + "), \"api1.Impl\", \"package api1; public class Impl {}\")",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   561
                            "--module-source-path", moduleSrc.toString());
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   562
                assertFileExists(classes, "m1x", "api1", "Impl.class");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   563
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   564
                //class:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   565
                runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   566
                            moduleSrc,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   567
                            classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   568
                            "createClass(() -> filer.createClassFile(\"" + module + "api1.Impl\"" + originating + "), \"api1.Impl\", \"package api1; public class Impl {}\")",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   569
                            "--module-source-path", moduleSrc.toString());
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   570
                assertFileExists(classes, "m1x", "api1", "Impl.class");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   571
50967
1e24c7152e47 8205563: modules/AnnotationProcessing.java failed testGenerateSingleModule
jjg
parents: 50704
diff changeset
   572
                tb.deleteFiles(m1.resolve("test").resolve("Test.java"));
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   573
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   574
                //resource class output:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   575
                runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   576
                            moduleSrc,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   577
                            classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   578
                            "createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"" + module + "api1\", \"impl\"" + originating + "), \"impl\", \"impl\")",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   579
                            "--module-source-path", moduleSrc.toString());
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   580
                assertFileExists(classes, "m1x", "api1", "impl");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   581
            }
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   582
        }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   583
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   584
        //get resource module source path:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   585
        runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   586
                    m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   587
                    classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   588
                    "doReadResource(() -> filer.getResource(StandardLocation.MODULE_SOURCE_PATH, \"m1x/api1\", \"api\"), \"1\")",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   589
                    "--module-source-path", moduleSrc.toString());
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   590
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   591
        //can generate resources to the single root module:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   592
        runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   593
                    m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   594
                    classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   595
                    "createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"m1x/impl\", \"impl\"), \"impl\", \"impl\")",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   596
                    "--module-source-path", moduleSrc.toString());
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   597
        assertFileExists(classes, "m1x", "impl", "impl");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   598
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   599
        //check --default-module-for-created-files option:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   600
        for (String pack : Arrays.asList("clash", "doesnotexist")) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   601
            tb.writeJavaFiles(m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   602
                              "package test; class Test { " + pack + ".Pass i; }");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   603
            runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   604
                        moduleSrc,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   605
                        classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   606
                        "createSource(() -> filer.createSourceFile(\"" + pack + ".Pass\")," +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   607
                        "                                          \"" + pack + ".Pass\"," +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   608
                        "                                          \"package " + pack + ";" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   609
                        "                                            public class Pass { }\")",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   610
                        "--module-source-path", moduleSrc.toString(),
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   611
                        "--default-module-for-created-files=m1x");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   612
            assertFileExists(classes, "m1x", pack, "Pass.class");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   613
            assertFileNotExists(classes, "m2x", pack, "Pass.class");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   614
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   615
            runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   616
                        moduleSrc,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   617
                        classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   618
                        "createClass(() -> filer.createClassFile(\"" + pack + ".Pass\")," +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   619
                        "                                        \"" + pack + ".Pass\"," +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   620
                        "                                        \"package " + pack + ";" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   621
                        "                                          public class Pass { }\")",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   622
                        "--module-source-path", moduleSrc.toString(),
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   623
                        "--default-module-for-created-files=m1x");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   624
            assertFileExists(classes, "m1x", pack, "Pass.class");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   625
            assertFileNotExists(classes, "m2x", pack, "Pass.class");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   626
50967
1e24c7152e47 8205563: modules/AnnotationProcessing.java failed testGenerateSingleModule
jjg
parents: 50704
diff changeset
   627
            tb.deleteFiles(m1.resolve("test").resolve("Test.java"));
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   628
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   629
            runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   630
                        moduleSrc,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   631
                        classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   632
                        "createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT," +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   633
                        "                                        \"" + pack + "\", \"impl\"), \"impl\", \"impl\")",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   634
                        "--module-source-path", moduleSrc.toString(),
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   635
                        "--default-module-for-created-files=m1x");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   636
            assertFileExists(classes, "m1x", pack, "impl");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   637
            assertFileNotExists(classes, "m2x", pack, "impl");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   638
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   639
            runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   640
                        moduleSrc,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   641
                        classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   642
                        "doReadResource(() -> filer.getResource(StandardLocation.CLASS_OUTPUT," +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   643
                        "                                       \"" + pack + "\", \"resource\"), \"1\")",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   644
                        p -> writeFile("1", p.resolve("m1x"), pack, "resource"),
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   645
                        "--module-source-path", moduleSrc.toString(),
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   646
                        "--default-module-for-created-files=m1x");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   647
        }
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   648
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   649
        //wrong default module:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   650
        runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   651
                    moduleSrc,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   652
                    classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   653
                    "expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT," +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   654
                    "                                                \"clash\", \"impl\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   655
                    "--module-source-path", moduleSrc.toString(),
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   656
                    "--default-module-for-created-files=doesnotexist");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   657
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   658
        String[] failingCases = {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   659
            //must not generate to unnamed package:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   660
            "expectFilerException(() -> filer.createSourceFile(\"Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   661
            "expectFilerException(() -> filer.createClassFile(\"Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   662
            "expectFilerException(() -> filer.createSourceFile(\"m1x/Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   663
            "expectFilerException(() -> filer.createClassFile(\"m1x/Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   664
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   665
            //cannot infer module name, package clash:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   666
            "expectFilerException(() -> filer.createSourceFile(\"clash.Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   667
            "expectFilerException(() -> filer.createClassFile(\"clash.Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   668
            "expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"clash\", \"impl\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   669
            "expectFilerException(() -> filer.getResource(StandardLocation.CLASS_OUTPUT, \"clash\", \"impl\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   670
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   671
            //cannot infer module name, package does not exist:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   672
            "expectFilerException(() -> filer.createSourceFile(\"doesnotexist.Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   673
            "expectFilerException(() -> filer.createClassFile(\"doesnotexist.Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   674
            "expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"doesnotexist\", \"impl\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   675
            "expectFilerException(() -> filer.getResource(StandardLocation.CLASS_OUTPUT, \"doesnotexist\", \"impl\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   676
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   677
            //cannot generate sources/classes to modules that are not root modules:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   678
            "expectFilerException(() -> filer.createSourceFile(\"java.base/fail.Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   679
            "expectFilerException(() -> filer.createClassFile(\"java.base/fail.Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   680
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   681
            //cannot read from module locations if module not given and not inferable:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   682
            "expectFilerException(() -> filer.getResource(StandardLocation.SYSTEM_MODULES, \"fail\", \"Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   683
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   684
            //wrong module given:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   685
            "expectException(() -> filer.getResource(StandardLocation.SYSTEM_MODULES, \"java.compiler/java.lang\", \"Object.class\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   686
        };
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   687
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   688
        for (String failingCode : failingCases) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   689
            System.err.println("failing code: " + failingCode);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   690
            runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   691
                        moduleSrc,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   692
                        classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   693
                        failingCode,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   694
                        "--module-source-path", moduleSrc.toString());
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   695
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   696
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   697
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   698
    public static abstract class GeneratingAP extends AbstractProcessor {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   699
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   700
        public void createSource(CreateFileObject file, String name, String content) {
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   701
            try (Writer out = file.create().openWriter()) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   702
                out.write(content);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   703
            } catch (IOException ex) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   704
                throw new IllegalStateException(ex);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   705
            }
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
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   708
        public void createClass(CreateFileObject file, String name, String content) {
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   709
            String fileNameStub = name.replace(".", File.separator);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   710
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   711
            try (OutputStream out = file.create().openOutputStream()) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   712
                Path scratch = Files.createDirectories(Paths.get(""));
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   713
                Path scratchSrc = scratch.resolve(fileNameStub + ".java").toAbsolutePath();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   714
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   715
                Files.createDirectories(scratchSrc.getParent());
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
                try (Writer w = Files.newBufferedWriter(scratchSrc)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   718
                    w.write(content);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   719
                }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   720
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   721
                Path scratchClasses = scratch.resolve("classes");
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
                Files.createDirectories(scratchClasses);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   724
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   725
                JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   726
                try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
43585
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
   727
                    List<String> options = List.of("-d", scratchClasses.toString());
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   728
                    Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(scratchSrc);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   729
                    CompilationTask task = comp.getTask(null, fm, null, options, null, files);
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
                    if (!task.call()) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   732
                        throw new AssertionError("compilation failed");
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
                }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   735
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   736
                Path classfile = scratchClasses.resolve(fileNameStub + ".class");
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
                Files.copy(classfile, out);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   739
            } catch (IOException ex) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   740
                throw new IllegalStateException(ex);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   741
            }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   742
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   743
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   744
        public void doReadResource(CreateFileObject file, String expectedContent) {
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   745
            try {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   746
                StringBuilder actualContent = new StringBuilder();
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
                try (Reader r = file.create().openReader(true)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   749
                    int read;
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
                    while ((read = r.read()) != (-1)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   752
                        actualContent.append((char) read);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   753
                    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   754
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   755
                }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   756
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   757
                assertEquals(expectedContent, actualContent.toString());
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   758
            } catch (IOException ex) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   759
                throw new IllegalStateException(ex);
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
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   762
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   763
        public void checkResourceExists(CreateFileObject file) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   764
            try {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   765
                file.create().openInputStream().close();
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   766
            } catch (IOException ex) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   767
                throw new IllegalStateException(ex);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   768
            }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   769
        }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   770
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   771
        public interface CreateFileObject {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   772
            public FileObject create() throws IOException;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   773
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   774
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   775
        public void expectFilerException(Callable<Object> c) {
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   776
            try {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   777
                c.call();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   778
                throw new AssertionError("Expected exception not thrown");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   779
            } catch (FilerException ex) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   780
                //expected
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   781
            } catch (Exception ex) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   782
                throw new IllegalStateException(ex);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   783
            }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   784
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   785
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   786
        public void expectException(Callable<Object> c) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   787
            try {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   788
                c.call();
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   789
                throw new AssertionError("Expected exception not thrown");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   790
            } catch (IOException ex) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   791
                //expected
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   792
            } catch (Exception ex) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   793
                throw new IllegalStateException(ex);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   794
            }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   795
        }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   796
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   797
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   798
        public SourceVersion getSupportedSourceVersion() {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   799
            return SourceVersion.latest();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   800
        }
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
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   803
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   804
    @Test
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   805
    public void testGenerateSingleModule(Path base) throws Exception {
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   806
        Path classes = base.resolve("classes");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   807
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   808
        Files.createDirectories(classes);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   809
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   810
        Path src = base.resolve("module-src");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   811
        Path m1 = src.resolve("m1x");
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
        tb.writeJavaFiles(m1,
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   814
                          "module m1x { }",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   815
                          "package test; class Test { impl.Impl i; }");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   816
        Path m2 = src.resolve("m2x");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   817
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   818
        tb.writeJavaFiles(m2,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   819
                          "module m2x { }");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   820
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   821
        for (String[] options : new String[][] {new String[] {"-sourcepath", m1.toString()},
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   822
                                                new String[] {"--module-source-path", src.toString()}}) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   823
            String modulePath = options[0].equals("--module-source-path") ? "m1x" : "";
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   824
            //passing testcases:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   825
            for (String module : Arrays.asList("", "m1x/")) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   826
                for (String originating : Arrays.asList("", ", jlObject")) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   827
                    tb.writeJavaFiles(m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   828
                                      "package test; class Test { impl.Impl i; }");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   829
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   830
                    //source:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   831
                    runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   832
                                m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   833
                                classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   834
                                "createSource(() -> filer.createSourceFile(\"" + module + "impl.Impl\"" + originating + "), \"impl.Impl\", \"package impl; public class Impl {}\")",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   835
                                options);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   836
                    assertFileExists(classes, modulePath, "impl", "Impl.class");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   837
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   838
                    //class:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   839
                    runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   840
                                m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   841
                                classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   842
                                "createClass(() -> filer.createClassFile(\"" + module + "impl.Impl\"" + originating + "), \"impl.Impl\", \"package impl; public class Impl {}\")",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   843
                                options);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   844
                    assertFileExists(classes, modulePath, "impl", "Impl.class");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   845
50967
1e24c7152e47 8205563: modules/AnnotationProcessing.java failed testGenerateSingleModule
jjg
parents: 50704
diff changeset
   846
                    tb.deleteFiles(m1.resolve("test").resolve("Test.java"));
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   847
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   848
                    //resource class output:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   849
                    runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   850
                                m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   851
                                classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   852
                                "createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"impl\", \"impl\"" + originating + "), \"impl\", \"impl\")",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   853
                                options);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   854
                    assertFileExists(classes, modulePath, "impl", "impl");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   855
                }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   856
            }
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   857
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   858
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   859
        //get resource source path:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   860
        writeFile("1", m1, "impl", "resource");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   861
        runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   862
                    m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   863
                    classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   864
                    "doReadResource(() -> filer.getResource(StandardLocation.SOURCE_PATH, \"impl\", \"resource\"), \"1\")",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   865
                    "-sourcepath", m1.toString());
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   866
        //must not specify module when reading non-module oriented locations:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   867
        runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   868
                    m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   869
                    classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   870
                    "expectFilerException(() -> filer.getResource(StandardLocation.SOURCE_PATH, \"m1x/impl\", \"resource\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   871
                    "-sourcepath", m1.toString());
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   872
50967
1e24c7152e47 8205563: modules/AnnotationProcessing.java failed testGenerateSingleModule
jjg
parents: 50704
diff changeset
   873
        tb.deleteFiles(m1.resolve("impl").resolve("resource"));
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   874
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   875
        //can read resources from the system module path if module name given:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   876
        runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   877
                    m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   878
                    classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   879
                    "checkResourceExists(() -> filer.getResource(StandardLocation.SYSTEM_MODULES, \"java.base/java.lang\", \"Object.class\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   880
                    "-sourcepath", m1.toString());
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   881
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   882
        //can read resources from the system module path if module inferable:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   883
        runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   884
                    m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   885
                    classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   886
                    "expectFilerException(() -> filer.getResource(StandardLocation.SYSTEM_MODULES, \"java.lang\", \"Object.class\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   887
                    "-sourcepath", m1.toString());
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   888
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   889
        //cannot generate resources to modules that are not root modules:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   890
        runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   891
                    m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   892
                    classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   893
                    "expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"java.base/fail\", \"Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   894
                    "--module-source-path", src.toString());
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   895
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   896
        //can generate resources to the single root module:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   897
        runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   898
                    m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   899
                    classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   900
                    "createSource(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"impl\", \"impl\"), \"impl\", \"impl\")",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   901
                    "--module-source-path", src.toString());
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   902
        assertFileExists(classes, "m1x", "impl", "impl");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   903
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   904
        String[] failingCases = {
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   905
            //must not generate to unnamed package:
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   906
            "expectFilerException(() -> filer.createSourceFile(\"Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   907
            "expectFilerException(() -> filer.createClassFile(\"Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   908
            "expectFilerException(() -> filer.createSourceFile(\"m1x/Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   909
            "expectFilerException(() -> filer.createClassFile(\"m1x/Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   910
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   911
            //cannot generate sources/classes to modules that are not root modules:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   912
            "expectFilerException(() -> filer.createSourceFile(\"java.base/fail.Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   913
            "expectFilerException(() -> filer.createClassFile(\"java.base/fail.Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   914
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   915
            //cannot specify module name for class output when not in the multi-module mode:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   916
            "expectFilerException(() -> filer.createResource(StandardLocation.CLASS_OUTPUT, \"m1x/fail\", \"Fail\"))",
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   917
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   918
            //cannot read from module locations if module not given:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   919
            "expectFilerException(() -> filer.getResource(StandardLocation.SYSTEM_MODULES, \"fail\", \"Fail\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   920
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   921
            //wrong module given:
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   922
            "expectException(() -> filer.getResource(StandardLocation.SYSTEM_MODULES, \"java.compiler/java.lang\", \"Object.class\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   923
        };
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   924
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   925
        for (String failingCode : failingCases) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   926
            System.err.println("failing code: " + failingCode);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   927
            runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   928
                        m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   929
                        classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   930
                        failingCode,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   931
                        "-sourcepath", m1.toString());
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   932
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
   933
50967
1e24c7152e47 8205563: modules/AnnotationProcessing.java failed testGenerateSingleModule
jjg
parents: 50704
diff changeset
   934
        tb.deleteFiles(m1.resolve("module-info.java"));
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   935
        tb.writeJavaFiles(m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   936
                          "package test; class Test { }");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   937
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   938
        runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   939
                    m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   940
                    classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   941
                    "expectFilerException(() -> filer.createSourceFile(\"m1x/impl.Impl\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   942
                    "-sourcepath", m1.toString(),
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   943
                    "-source", "8");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   944
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   945
        runCompiler(base,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   946
                    m1,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   947
                    classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   948
                    "expectFilerException(() -> filer.createClassFile(\"m1x/impl.Impl\"))",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   949
                    "-sourcepath", m1.toString(),
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   950
                    "-source", "8");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   951
    }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   952
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   953
    private void runCompiler(Path base, Path src, Path classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   954
                             String code, String... options) throws IOException {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   955
        runCompiler(base, src, classes, code, p -> {}, options);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   956
    }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   957
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   958
    private void runCompiler(Path base, Path src, Path classes,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   959
                             String code, Consumer<Path> generateToClasses,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   960
                             String... options) throws IOException {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   961
        Path apClasses = base.resolve("ap-classes");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   962
        if (Files.exists(apClasses)) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   963
            tb.cleanDirectory(apClasses);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   964
        } else {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   965
            Files.createDirectories(apClasses);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   966
        }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   967
        compileAP(apClasses, code);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   968
        if (Files.exists(classes)) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   969
            tb.cleanDirectory(classes);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   970
        } else {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   971
            Files.createDirectories(classes);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   972
        }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   973
        generateToClasses.accept(classes);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   974
        List<String> opts = new ArrayList<>();
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   975
        opts.addAll(Arrays.asList(options));
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   976
        opts.add("-processorpath");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   977
        opts.add(System.getProperty("test.class.path") + File.pathSeparator + apClasses.toString());
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   978
        opts.add("-processor");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   979
        opts.add("AP");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   980
        new JavacTask(tb)
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   981
          .options(opts)
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   982
          .outdir(classes)
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   983
          .files(findJavaFiles(src))
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   984
          .run()
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   985
          .writeAll();
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   986
    }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   987
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   988
    private void compileAP(Path target, String code) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   989
        String processorCode =
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   990
            "import java.util.*;\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   991
            "import javax.annotation.processing.*;\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   992
            "import javax.lang.model.*;\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   993
            "import javax.lang.model.element.*;\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   994
            "import javax.lang.model.type.*;\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   995
            "import javax.lang.model.util.*;\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   996
            "import javax.tools.*;\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   997
            "@SupportedAnnotationTypes(\"*\")\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   998
            "public final class AP extends AnnotationProcessing.GeneratingAP {\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
   999
            "\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1000
            "        int round;\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1001
            "\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1002
            "        @Override\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1003
            "        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1004
            "            if (round++ != 0)\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1005
            "                return false;\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1006
            "            Filer filer = processingEnv.getFiler();\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1007
            "            TypeElement jlObject = processingEnv.getElementUtils().getTypeElement(\"java.lang.Object\");\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1008
            code + ";\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1009
            "            return false;\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1010
            "        }\n" +
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1011
            "    }\n";
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1012
        new JavacTask(tb)
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1013
          .options("-classpath", System.getProperty("test.class.path"))
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1014
          .sources(processorCode)
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1015
          .outdir(target)
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1016
          .run()
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1017
          .writeAll();
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1018
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1019
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1020
    @Test
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1021
    public void testGenerateInUnnamedModeAPI(Path base) throws Exception {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1022
        Path classes = base.resolve("classes");
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
        Files.createDirectories(classes);
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
        Path src = base.resolve("src");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1027
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1028
        tb.writeJavaFiles(src,
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1029
                          "class T {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1030
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1031
        new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1032
          .options("-processor", UnnamedModeAPITestAP.class.getName(),
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1033
                   "-sourcepath", src.toString())
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1034
          .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1035
          .files(findJavaFiles(src))
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1036
          .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1037
          .writeAll();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1038
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1039
        assertFileExists(classes, "Impl1.class");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1040
        assertFileExists(classes, "Impl2.class");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1041
    }
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
    @Test
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1044
    public void testGenerateInNoModeAPI(Path base) throws Exception {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1045
        Path classes = base.resolve("classes");
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
        Files.createDirectories(classes);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1048
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1049
        Path src = base.resolve("src");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1050
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1051
        tb.writeJavaFiles(src,
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1052
                          "class T {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1053
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1054
        new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1055
          .options("-processor", UnnamedModeAPITestAP.class.getName(),
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1056
                   "-source", "8", "-target", "8",
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1057
                   "-sourcepath", src.toString())
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1058
          .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1059
          .files(findJavaFiles(src))
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1060
          .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1061
          .writeAll();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1062
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1063
        assertFileExists(classes, "Impl1.class");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1064
        assertFileExists(classes, "Impl2.class");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1065
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1066
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1067
    @SupportedAnnotationTypes("*")
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1068
    public static final class UnnamedModeAPITestAP extends GeneratingAP {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1069
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1070
        int round;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1071
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1072
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1073
        public synchronized void init(ProcessingEnvironment processingEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1074
            super.init(processingEnv);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1075
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1076
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1077
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1078
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1079
            if (round++ != 0)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1080
                return false;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1081
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1082
            Filer filer = processingEnv.getFiler();
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1083
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1084
            //must not generate to unnamed package:
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1085
            createSource(() -> filer.createSourceFile("Impl1"), "Impl1", "class Impl1 {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1086
            createClass(() -> filer.createClassFile("Impl2"), "Impl2", "class Impl2 {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1087
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1088
            return false;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1089
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1090
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1091
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1092
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1093
    @Test
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1094
    public void testDisambiguateAnnotations(Path base) throws Exception {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1095
        Path classes = base.resolve("classes");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1096
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1097
        Files.createDirectories(classes);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1098
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1099
        Path src = base.resolve("src");
42823
alanb
parents: 42815 42822
diff changeset
  1100
        Path m1 = src.resolve("m1x");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1101
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1102
        tb.writeJavaFiles(m1,
42823
alanb
parents: 42815 42822
diff changeset
  1103
                          "module m1x { exports api; }",
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1104
                          "package api; public @interface A {}",
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1105
                          "package api; public @interface B {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1106
42823
alanb
parents: 42815 42822
diff changeset
  1107
        Path m2 = src.resolve("m2x");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1108
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1109
        tb.writeJavaFiles(m2,
42823
alanb
parents: 42815 42822
diff changeset
  1110
                          "module m2x { exports api; }",
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1111
                          "package api; public @interface A {}",
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1112
                          "package api; public @interface B {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1113
42823
alanb
parents: 42815 42822
diff changeset
  1114
        Path m3 = src.resolve("m3x");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1115
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1116
        tb.writeJavaFiles(m3,
42823
alanb
parents: 42815 42822
diff changeset
  1117
                          "module m3x { requires m1x; }",
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1118
                          "package impl; import api.*; @A @B public class T {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1119
42823
alanb
parents: 42815 42822
diff changeset
  1120
        Path m4 = src.resolve("m4x");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1121
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1122
        tb.writeJavaFiles(m4,
42823
alanb
parents: 42815 42822
diff changeset
  1123
                          "module m4x { requires m2x; }",
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1124
                          "package impl; import api.*; @A @B public class T {}");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1125
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1126
        List<String> log;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1127
        List<String> expected;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1128
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1129
        log = new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1130
            .options("-processor", SelectAnnotationATestAP.class.getName() + "," + SelectAnnotationBTestAP.class.getName(),
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1131
                     "--module-source-path", src.toString(),
42823
alanb
parents: 42815 42822
diff changeset
  1132
                     "-m", "m1x,m2x")
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1133
            .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1134
            .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1135
            .writeAll()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1136
            .getOutputLines(OutputKind.STDERR);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1137
43585
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1138
        expected = List.of("");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1139
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1140
        if (!expected.equals(log)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1141
            throw new AssertionError("Output does not match; output: " + log);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1142
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1143
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1144
        log = new JavacTask(tb)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1145
            .options("-processor", SelectAnnotationATestAP.class.getName() + "," + SelectAnnotationBTestAP.class.getName(),
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1146
                     "--module-source-path", src.toString(),
42823
alanb
parents: 42815 42822
diff changeset
  1147
                     "-m", "m3x")
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1148
            .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1149
            .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1150
            .writeAll()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1151
            .getOutputLines(OutputKind.STDERR);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1152
43585
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1153
        expected = List.of("SelectAnnotationBTestAP",
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1154
                           "SelectAnnotationBTestAP");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1155
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1156
        if (!expected.equals(log)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1157
            throw new AssertionError("Output does not match; output: " + log);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1158
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1159
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1160
        log = new JavacTask(tb)
43585
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1161
            .options("-processor", SelectAnnotationATestAP.class.getName() + "," +
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1162
                                   SelectAnnotationBTestAP.class.getName() + "," +
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1163
                                   SelectAnnotationAStrictTestAP.class.getName(),
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1164
                     "--module-source-path", src.toString(),
42823
alanb
parents: 42815 42822
diff changeset
  1165
                     "-m", "m4x")
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1166
            .outdir(classes)
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1167
            .run()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1168
            .writeAll()
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1169
            .getOutputLines(OutputKind.STDERR);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1170
43585
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1171
        expected = List.of("SelectAnnotationATestAP",
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1172
                           "SelectAnnotationBTestAP",
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1173
                           "SelectAnnotationAStrictTestAP",
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1174
                           "SelectAnnotationATestAP",
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1175
                           "SelectAnnotationBTestAP",
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1176
                           "SelectAnnotationAStrictTestAP");
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1177
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1178
        if (!expected.equals(log)) {
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1179
            throw new AssertionError("Output does not match; output: " + log);
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1180
        }
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1181
    }
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1182
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1183
    @Test
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1184
    public void testDisambiguateAnnotationsUnnamedModule(Path base) throws Exception {
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1185
        Path classes = base.resolve("classes");
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1186
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1187
        Files.createDirectories(classes);
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1188
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1189
        Path src = base.resolve("src");
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1190
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1191
        tb.writeJavaFiles(src,
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1192
                          "package api; public @interface A {}",
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1193
                          "package api; public @interface B {}",
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1194
                          "package impl; import api.*; @A @B public class T {}");
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1195
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1196
        List<String> log = new JavacTask(tb)
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1197
            .options("-processor", SelectAnnotationATestAP.class.getName() + "," +
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1198
                                   SelectAnnotationBTestAP.class.getName() + "," +
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1199
                                   SelectAnnotationAStrictTestAP.class.getName())
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1200
            .outdir(classes)
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1201
            .files(findJavaFiles(src))
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1202
            .run()
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1203
            .writeAll()
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1204
            .getOutputLines(OutputKind.STDERR);
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1205
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1206
        List<String> expected = List.of("SelectAnnotationBTestAP",
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1207
                                        "SelectAnnotationBTestAP");
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1208
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1209
        if (!expected.equals(log)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1210
            throw new AssertionError("Output does not match; output: " + log);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1211
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1212
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1213
43037
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1214
    @Test
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1215
    public void testDisambiguateAnnotationsNoModules(Path base) throws Exception {
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1216
        Path classes = base.resolve("classes");
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1217
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1218
        Files.createDirectories(classes);
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1219
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1220
        Path src = base.resolve("src");
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1221
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1222
        tb.writeJavaFiles(src,
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1223
                          "package api; public @interface A {}",
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1224
                          "package api; public @interface B {}",
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1225
                          "package impl; import api.*; @A @B public class T {}");
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1226
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1227
        List<String> log = new JavacTask(tb)
43585
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1228
            .options("-processor", SelectAnnotationATestAP.class.getName() + "," +
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1229
                                   SelectAnnotationBTestAP.class.getName() + "," +
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1230
                                   SelectAnnotationAStrictTestAP.class.getName(),
43037
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1231
                     "-source", "8", "-target", "8")
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1232
            .outdir(classes)
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1233
            .files(findJavaFiles(src))
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1234
            .run()
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1235
            .writeAll()
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1236
            .getOutputLines(OutputKind.STDERR);
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1237
43585
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1238
        List<String> expected = List.of("SelectAnnotationATestAP",
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1239
                                        "SelectAnnotationBTestAP",
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1240
                                        "SelectAnnotationATestAP",
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1241
                                        "SelectAnnotationBTestAP");
43037
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1242
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1243
        if (!expected.equals(log)) {
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1244
            throw new AssertionError("Output does not match; output: " + log);
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1245
        }
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1246
    }
3e1520a857fa 8172158: Annotation processor not run with -source <= 8
jlahoda
parents: 42824
diff changeset
  1247
42823
alanb
parents: 42815 42822
diff changeset
  1248
    @SupportedAnnotationTypes("m2x/api.A")
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1249
    public static final class SelectAnnotationATestAP extends AbstractProcessor {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1250
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1251
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1252
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1253
            System.err.println("SelectAnnotationATestAP");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1254
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1255
            return false;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1256
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1257
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1258
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1259
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1260
    @SupportedAnnotationTypes("api.B")
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1261
    public static final class SelectAnnotationBTestAP extends AbstractProcessor {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1262
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1263
        @Override
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1264
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1265
            System.err.println("SelectAnnotationBTestAP");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1266
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1267
            return false;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1268
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1269
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1270
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1271
43585
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1272
    public static final class SelectAnnotationAStrictTestAP extends AbstractProcessor {
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1273
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1274
        @Override
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1275
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1276
            System.err.println("SelectAnnotationAStrictTestAP");
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1277
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1278
            return false;
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1279
        }
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1280
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1281
        @Override
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1282
        public Set<String> getSupportedAnnotationTypes() {
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1283
            return Set.of("m2x/api.A");
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1284
        }
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1285
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1286
    }
19e14d35add0 8173636: Results from Processor.getSupportedAnnotationTypes should be intepreted strictly
jlahoda
parents: 43149
diff changeset
  1287
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1288
    private static void writeFile(String content, Path base, String... pathElements) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1289
        try {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1290
            Path file = resolveFile(base, pathElements);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1292
            Files.createDirectories(file.getParent());
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1293
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1294
            try (Writer out = Files.newBufferedWriter(file)) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1295
                out.append(content);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1296
            }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1297
        } catch (IOException ex) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1298
            throw new UncheckedIOException(ex);
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1299
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1300
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1301
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1302
    @Test
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1303
    public void testUnboundLookup(Path base) throws Exception {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1304
        Path src = base.resolve("src");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1305
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1306
        tb.writeJavaFiles(src,
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1307
                          "package impl.conflict.src; public class Impl { }");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1308
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1309
        Path moduleSrc = base.resolve("module-src");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1310
        Path m1 = moduleSrc.resolve("m1x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1311
        Path m2 = moduleSrc.resolve("m2x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1312
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1313
        Path classes = base.resolve("classes");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1314
        Path cpClasses = base.resolve("cpClasses");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1315
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1316
        Files.createDirectories(classes);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1317
        Files.createDirectories(cpClasses);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1318
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1319
        tb.writeJavaFiles(m1,
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1320
                          "module m1x { }",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1321
                          "package impl1; public class Impl { }",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1322
                          "package impl.conflict.module; class Impl { }",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1323
                          "package impl.conflict.clazz; public class pkg { public static class I { } }",
43149
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1324
                          "package impl.conflict.src; public class Impl { }",
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1325
                          "package nested.pack.pack; public class Impl { }",
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1326
                          "package unique.nested; public class Impl { }");
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1327
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1328
        tb.writeJavaFiles(m2,
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1329
                          "module m2x { }",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1330
                          "package impl2; public class Impl { }",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1331
                          "package impl.conflict.module; class Impl { }",
43149
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1332
                          "package impl.conflict; public class clazz { public static class pkg { } }",
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1333
                          "package nested.pack; public class Impl { }");
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1334
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1335
        //from source:
43149
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1336
        String log = new JavacTask(tb)
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1337
            .options("--module-source-path", moduleSrc.toString(),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1338
                     "--source-path", src.toString(),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1339
                     "-processorpath", System.getProperty("test.class.path"),
43149
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1340
                     "-processor", UnboundLookup.class.getName(),
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1341
                     "-XDrawDiagnostics")
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1342
            .outdir(classes)
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1343
            .files(findJavaFiles(moduleSrc))
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1344
            .run()
43149
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1345
            .writeAll()
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1346
            .getOutput(OutputKind.DIRECT);
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1347
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1348
        String moduleImplConflictString =
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1349
                "- compiler.note.multiple.elements: getTypeElement, impl.conflict.module.Impl, m2x, m1x";
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1350
        String srcConflictString =
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1351
                "- compiler.note.multiple.elements: getTypeElement, impl.conflict.src.Impl, m1x, unnamed module";
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1352
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1353
        if (!log.contains(moduleImplConflictString) ||
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1354
            !log.contains(srcConflictString)) {
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1355
            throw new AssertionError("Expected output not found: " + log);
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1356
        }
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1357
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1358
        if (log.split(Pattern.quote(moduleImplConflictString)).length > 2) {
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1359
            throw new AssertionError("Too many warnings in: " + log);
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1360
        }
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1361
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1362
        new JavacTask(tb)
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1363
            .options("--source-path", src.toString())
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1364
            .outdir(cpClasses)
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1365
            .files(findJavaFiles(src))
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1366
            .run()
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1367
            .writeAll();
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1368
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1369
        //from classfiles:
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1370
        new JavacTask(tb)
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1371
            .options("--module-path", classes.toString(),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1372
                     "--class-path", cpClasses.toString(),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1373
                     "--add-modules", "m1x,m2x",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1374
                     "-processorpath", System.getProperty("test.class.path"),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1375
                     "-processor", UnboundLookup.class.getName(),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1376
                     "-proc:only")
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1377
            .classes("java.lang.Object")
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1378
            .run()
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1379
            .writeAll();
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1380
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1381
        //source 8:
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1382
        new JavacTask(tb)
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1383
            .options("--source-path", src.toString(),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1384
                     "-source", "8",
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1385
                     "-processorpath", System.getProperty("test.class.path"),
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1386
                     "-processor", UnboundLookup8.class.getName())
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1387
            .outdir(cpClasses)
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1388
            .files(findJavaFiles(src))
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1389
            .run()
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1390
            .writeAll();
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1391
51094
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1392
        //from source:
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1393
        new JavacTask(tb)
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1394
            .options("--module-source-path", moduleSrc.toString(),
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1395
                     "--source-path", src.toString(),
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1396
                     "-processorpath", System.getProperty("test.class.path"),
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1397
                     "-processor", UnboundLookupGenerate.class.getName(),
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1398
                     "-XDrawDiagnostics")
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1399
            .outdir(classes)
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1400
            .files(findJavaFiles(moduleSrc))
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1401
            .run()
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1402
            .writeAll()
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1403
            .getOutput(OutputKind.DIRECT);
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1404
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1405
    }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1406
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1407
    @SupportedAnnotationTypes("*")
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1408
    public static final class UnboundLookup extends AbstractProcessor {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1409
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1410
        @Override
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1411
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1412
            assertTypeElementExists("impl1.Impl", "m1x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1413
            assertPackageElementExists("impl1", "m1x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1414
            assertTypeElementExists("impl2.Impl", "m2x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1415
            assertTypeElementExists("impl.conflict.clazz.pkg.I", "m1x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1416
            assertTypeElementExists("impl.conflict.clazz", "m2x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1417
            assertPackageElementExists("impl.conflict.clazz", "m1x");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1418
            assertPackageElementExists("impl2", "m2x");
43149
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1419
            assertPackageElementExists("nested.pack.pack", "m1x");
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1420
            assertPackageElementExists("nested.pack", "m2x");
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1421
            assertTypeElementExists("unique.nested.Impl", "m1x");
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1422
            assertTypeElementNotFound("impl.conflict.module.Impl");
43149
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1423
            assertTypeElementNotFound("impl.conflict.module.Impl"); //check that the warning/note is produced only once
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1424
            assertPackageElementNotFound("impl.conflict.module");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1425
            assertTypeElementNotFound("impl.conflict.src.Impl");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1426
            assertPackageElementNotFound("impl.conflict.src");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1427
            assertTypeElementNotFound("impl.conflict.clazz.pkg");
43149
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1428
            assertPackageElementNotFound("unique"); //do not return packages without members in module mode
047a57b0839a 8172262: packages missing from docs build
jlahoda
parents: 43037
diff changeset
  1429
            assertTypeElementNotFound("nested"); //cannot distinguish between m1x and m2x
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1430
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1431
            return false;
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1432
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1433
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1434
        private void assertTypeElementExists(String name, String expectedModule) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1435
            assertElementExists(name, "class", processingEnv.getElementUtils() :: getTypeElement, expectedModule);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1436
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1437
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1438
        private void assertPackageElementExists(String name, String expectedModule) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1439
            assertElementExists(name, "package", processingEnv.getElementUtils() :: getPackageElement, expectedModule);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1440
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1441
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1442
        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
  1443
            Element clazz = getter.apply(name);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1444
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1445
            if (clazz == null) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1446
                throw new AssertionError("No " + name + " " + type + " found.");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1447
            }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1448
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1449
            ModuleElement mod = processingEnv.getElementUtils().getModuleOf(clazz);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1450
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1451
            if (!mod.getQualifiedName().contentEquals(expectedModule)) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1452
                throw new AssertionError(name + " found in an unexpected module: " + mod.getQualifiedName());
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1453
            }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1454
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1455
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1456
        private void assertTypeElementNotFound(String name) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1457
            assertElementNotFound(name, processingEnv.getElementUtils() :: getTypeElement);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1458
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1459
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1460
        private void assertPackageElementNotFound(String name) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1461
            assertElementNotFound(name, processingEnv.getElementUtils() :: getPackageElement);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1462
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1463
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1464
        private void assertElementNotFound(String name, Function<String, Element> getter) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1465
            Element found = getter.apply(name);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1466
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1467
            if (found != null) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1468
                fail("Element found unexpectedly: " + found);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1469
            }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1470
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1471
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1472
        @Override
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1473
        public SourceVersion getSupportedSourceVersion() {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1474
            return SourceVersion.latest();
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1475
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1476
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1477
    }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1478
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1479
    @SupportedAnnotationTypes("*")
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1480
    public static final class UnboundLookup8 extends AbstractProcessor {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1481
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1482
        @Override
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1483
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1484
            if (processingEnv.getElementUtils().getTypeElement("impl.conflict.src.Impl") == null) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1485
                throw new AssertionError("impl.conflict.src.Impl.");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1486
            }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1487
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1488
            if (processingEnv.getElementUtils().getModuleElement("java.base") != null) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1489
                throw new AssertionError("getModuleElement != null for -source 8");
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1490
            }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1491
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1492
            return false;
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1493
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1494
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1495
        @Override
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1496
        public SourceVersion getSupportedSourceVersion() {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1497
            return SourceVersion.latest();
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1498
        }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1499
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1500
    }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1501
51094
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1502
    @SupportedAnnotationTypes("*")
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1503
    public static final class UnboundLookupGenerate extends AbstractProcessor {
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1504
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1505
        @Override
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1506
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1507
            if (processingEnv.getElementUtils().getTypeElement("nue.Nue") == null) {
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1508
                try (Writer w = processingEnv.getFiler().createSourceFile("m1x/nue.Nue").openWriter()) {
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1509
                    w.write("package nue; public class Nue {}");
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1510
                } catch (IOException ex) {
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1511
                    throw new IllegalStateException(ex);
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1512
                }
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1513
            }
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1514
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1515
            return false;
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1516
        }
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1517
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1518
        @Override
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1519
        public SourceVersion getSupportedSourceVersion() {
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1520
            return SourceVersion.latest();
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1521
        }
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1522
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1523
    }
a49d106e9b7c 8189747: JDK9 javax.lang.model.util.Elements#getTypeElement regressed 1000x in performance.
jlahoda
parents: 50967
diff changeset
  1524
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1525
    @Test
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1526
    public void testWrongDefaultTargetModule(Path base) throws Exception {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1527
        Path src = base.resolve("src");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1528
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1529
        tb.writeJavaFiles(src,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1530
                          "package test; public class Test { }");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1531
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1532
        Path classes = base.resolve("classes");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1533
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1534
        Files.createDirectories(classes);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1535
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1536
        List<String> log = new JavacTask(tb)
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1537
            .options("--default-module-for-created-files=m!",
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1538
                     "-XDrawDiagnostics")
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1539
            .outdir(classes)
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1540
            .files(findJavaFiles(src))
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1541
            .run(Task.Expect.FAIL)
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1542
            .writeAll()
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1543
            .getOutputLines(OutputKind.DIRECT);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1544
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1545
        List<String> expected = Arrays.asList(
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1546
            "- compiler.err.bad.name.for.option: --default-module-for-created-files, m!"
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1547
        );
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1548
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1549
        if (!log.equals(expected)) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1550
            throw new AssertionError("Expected output not found.");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1551
        }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1552
    }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1553
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1554
    private static void assertNonNull(String msg, Object val) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1555
        if (val == null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1556
            throw new AssertionError(msg);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1557
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1558
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1559
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1560
    private static void assertNull(String msg, Object val) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1561
        if (val != null) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1562
            throw new AssertionError(msg);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1563
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1564
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1565
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1566
    private static void assertEquals(Object expected, Object actual) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1567
        if (!Objects.equals(expected, actual)) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1568
            throw new AssertionError("expected: " + expected + "; actual=" + actual);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1569
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1570
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1571
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1572
    private static void assertFileExists(Path base, String... pathElements) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1573
        Path file = resolveFile(base, pathElements);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1574
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1575
        if (!Files.exists(file)) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1576
            throw new AssertionError("Expected file: " + file + " exist, but it does not.");
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1577
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1578
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1579
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1580
    private static void assertFileNotExists(Path base, String... pathElements) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1581
        Path file = resolveFile(base, pathElements);
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1582
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1583
        if (Files.exists(file)) {
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1584
            throw new AssertionError("Expected file: " + file + " exist, but it does not.");
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1585
        }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1586
    }
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43585
diff changeset
  1587
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1588
    static Path resolveFile(Path base, String... pathElements) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1589
        Path file = base;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1590
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1591
        for (String el : pathElements) {
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1592
            file = file.resolve(el);
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1593
        }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1594
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1595
        return file;
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1596
    }
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 42407
diff changeset
  1597
42824
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1598
    private static void fail(String msg) {
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1599
        throw new AssertionError(msg);
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1600
    }
89b14017e8d6 8133896: Update javax.lang.model APIs
jlahoda
parents: 42823
diff changeset
  1601
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
  1602
}