test/langtools/tools/javac/modules/AnnotationsOnModules.java
author darcy
Thu, 13 Jun 2019 11:50:45 -0700
changeset 55387 761b86d5563d
parent 47216 71c04702a3d5
permissions -rw-r--r--
8164819: Make javac's toString() on annotation objects consistent with core reflection Reviewed-by: jjg, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     1
/*
55387
761b86d5563d 8164819: Make javac's toString() on annotation objects consistent with core reflection
darcy
parents: 47216
diff changeset
     2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     4
 *
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     8
 *
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    13
 * accompanied this code).
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    14
 *
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    18
 *
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    21
 * questions.
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    22
 */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    23
42829
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
    24
/*
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    25
 * @test
43279
9afb33b0a3ab 8171322: AssertionError in TypeSymbol.getAnnotationTypeMetadata.
sadayapalam
parents: 42839
diff changeset
    26
 * @bug 8159602 8170549 8171255 8171322
42829
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
    27
 * @summary Test annotations on module declaration.
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    28
 * @library /tools/lib
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.javac.api
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.main
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    31
 *          jdk.jdeps/com.sun.tools.classfile
42829
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
    32
 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    33
 * @run main AnnotationsOnModules
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    34
 */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    35
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    36
import java.io.File;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    37
import java.nio.file.Files;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    38
import java.nio.file.Path;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    39
import java.util.Arrays;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    40
import java.util.HashSet;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    41
import java.util.List;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    42
import java.util.Objects;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    43
import java.util.Set;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    44
import java.util.stream.Collectors;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    45
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    46
import javax.annotation.processing.AbstractProcessor;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    47
import javax.annotation.processing.RoundEnvironment;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    48
import javax.annotation.processing.SupportedAnnotationTypes;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    49
import javax.annotation.processing.SupportedOptions;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    50
import javax.lang.model.element.AnnotationMirror;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    51
import javax.lang.model.element.ModuleElement;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    52
import javax.lang.model.element.TypeElement;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    53
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    54
import com.sun.tools.classfile.Attribute;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    55
import com.sun.tools.classfile.ClassFile;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    56
import com.sun.tools.classfile.RuntimeInvisibleAnnotations_attribute;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    57
import com.sun.tools.classfile.RuntimeVisibleAnnotations_attribute;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    58
import toolbox.JavacTask;
42829
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
    59
import toolbox.Task;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    60
import toolbox.Task.OutputKind;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    61
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    62
public class AnnotationsOnModules extends ModuleTestBase {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    63
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    64
    public static void main(String... args) throws Exception {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    65
        AnnotationsOnModules t = new AnnotationsOnModules();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    66
        t.runTests();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    67
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    68
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    69
    @Test
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    70
    public void testSimpleAnnotation(Path base) throws Exception {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    71
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
    72
        Path m1 = moduleSrc.resolve("m1x");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    73
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    74
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
    75
                          "@Deprecated module m1x { }");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    76
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    77
        Path modulePath = base.resolve("module-path");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    78
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    79
        Files.createDirectories(modulePath);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    80
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    81
        new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    82
                .options("--module-source-path", moduleSrc.toString())
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    83
                .outdir(modulePath)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    84
                .files(findJavaFiles(m1))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    85
                .run()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    86
                .writeAll();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    87
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
    88
        ClassFile cf = ClassFile.read(modulePath.resolve("m1x").resolve("module-info.class"));
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    89
        RuntimeVisibleAnnotations_attribute annotations = (RuntimeVisibleAnnotations_attribute) cf.attributes.map.get(Attribute.RuntimeVisibleAnnotations);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    90
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    91
        if (annotations == null || annotations.annotations.length != 1) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    92
            throw new AssertionError("Annotations not correct!");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    93
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    94
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    95
42839
33f705c03879 8171255: Javac generates Deprecated class file attribute for @deprecated javadoc tag on module declaration.
jjg
parents: 42829
diff changeset
    96
    @Test
42829
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
    97
    public void testSimpleJavadocDeprecationTag(Path base) throws Exception {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
    98
        Path moduleSrc = base.resolve("module-src");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
    99
        Path m1 = moduleSrc.resolve("src1/A");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   100
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   101
        tb.writeJavaFiles(m1,
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   102
                "/** @deprecated */ module A { }");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   103
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   104
        Path modulePath = base.resolve("module-path");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   105
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   106
        Files.createDirectories(modulePath);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   107
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   108
        List<String> warning = new JavacTask(tb)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   109
                .options("--module-source-path", m1.getParent().toString(),
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   110
                        "-XDrawDiagnostics")
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   111
                .outdir(modulePath)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   112
                .files(findJavaFiles(m1))
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   113
                .run()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   114
                .writeAll()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   115
                .getOutputLines(OutputKind.DIRECT);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   116
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   117
        List<String> expected = List.of(
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   118
                "module-info.java:1:20: compiler.warn.missing.deprecated.annotation",
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   119
                "1 warning");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   120
        if (!warning.containsAll(expected)) {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   121
            throw new AssertionError("Expected output not found. Expected: " + expected);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   122
        }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   123
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   124
        Path m2 = base.resolve("src2/B");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   125
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   126
        tb.writeJavaFiles(m2,
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   127
                "module B { requires A; }");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   128
        String log = new JavacTask(tb)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   129
                .options("--module-source-path", m2.getParent().toString(),
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   130
                        "--module-path", modulePath.toString(),
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   131
                        "-XDrawDiagnostics")
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   132
                .outdir(modulePath)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   133
                .files(findJavaFiles(m2))
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   134
                .run()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   135
                .writeAll()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   136
                .getOutput(OutputKind.DIRECT);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   137
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   138
        if (!log.isEmpty()) {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   139
            throw new AssertionError("Output is not empty. Expected no output and no warnings.");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   140
        }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   141
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   142
        ClassFile cf = ClassFile.read(modulePath.resolve("A").resolve("module-info.class"));
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   143
        RuntimeVisibleAnnotations_attribute annotations = (RuntimeVisibleAnnotations_attribute) cf.attributes.map.get(Attribute.RuntimeVisibleAnnotations);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   144
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   145
        if (annotations != null && annotations.annotations.length > 0) {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   146
            throw new AssertionError("Found annotation attributes. Expected no annotations for javadoc @deprecated tag.");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   147
        }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   148
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   149
        if (cf.attributes.map.get(Attribute.Deprecated) != null) {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   150
            throw new AssertionError("Found Deprecated attribute. Expected no Deprecated attribute for javadoc @deprecated tag.");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   151
        }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   152
    }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   153
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   154
    @Test
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   155
    public void testEnhancedDeprecatedAnnotation(Path base) throws Exception {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   156
        Path moduleSrc = base.resolve("module-src");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   157
        Path m1 = moduleSrc.resolve("src1/A");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   158
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   159
        tb.writeJavaFiles(m1,
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   160
                "@Deprecated(since=\"10.X\", forRemoval=true) module A { }");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   161
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   162
        Path modulePath = base.resolve("module-path");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   163
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   164
        Files.createDirectories(modulePath);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   165
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   166
        new JavacTask(tb)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   167
                .options("--module-source-path", m1.getParent().toString())
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   168
                .outdir(modulePath)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   169
                .files(findJavaFiles(m1))
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   170
                .run()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   171
                .writeAll();
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   172
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   173
        Path m2 = base.resolve("src2/B");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   174
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   175
        tb.writeJavaFiles(m2,
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   176
                "module B { requires A; }");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   177
        List<String> log = new JavacTask(tb)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   178
                .options("--module-source-path", m2.getParent().toString(),
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   179
                        "--module-path", modulePath.toString(),
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   180
                        "-XDrawDiagnostics")
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   181
                .outdir(modulePath)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   182
                .files(findJavaFiles(m2))
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   183
                .run()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   184
                .writeAll()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   185
                .getOutputLines(OutputKind.DIRECT);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   186
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   187
        List<String> expected = List.of("module-info.java:1:21: compiler.warn.has.been.deprecated.for.removal.module: A",
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   188
                "1 warning");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   189
        if (!log.containsAll(expected)) {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   190
            throw new AssertionError("Expected output not found. Expected: " + expected);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   191
        }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   192
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   193
        ClassFile cf = ClassFile.read(modulePath.resolve("A").resolve("module-info.class"));
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   194
        RuntimeVisibleAnnotations_attribute annotations = (RuntimeVisibleAnnotations_attribute) cf.attributes.map.get(Attribute.RuntimeVisibleAnnotations);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   195
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   196
        if (annotations == null ) {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   197
            throw new AssertionError("Annotations not found!");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   198
        }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   199
        int length = annotations.annotations.length;
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   200
        if (length != 1 ) {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   201
            throw new AssertionError("Incorrect number of annotations: " + length);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   202
        }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   203
        int pairsCount = annotations.annotations[0].num_element_value_pairs;
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   204
        if (pairsCount != 2) {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   205
            throw new AssertionError("Incorrect number of key-value pairs in annotation: " + pairsCount + " Expected two: forRemoval and since.");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   206
        }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   207
    }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   208
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   209
    @Test
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   210
    public void testDeprecatedModuleRequiresDeprecatedForRemovalModule(Path base) throws Exception {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   211
        Path moduleSrc = base.resolve("module-src");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   212
        Path m1 = moduleSrc.resolve("src1/A");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   213
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   214
        tb.writeJavaFiles(m1,
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   215
                "@Deprecated(forRemoval=true) module A { }");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   216
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   217
        Path modulePath = base.resolve("module-path");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   218
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   219
        Files.createDirectories(modulePath);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   220
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   221
        new JavacTask(tb)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   222
                .options("--module-source-path", m1.getParent().toString())
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   223
                .outdir(modulePath)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   224
                .files(findJavaFiles(m1))
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   225
                .run()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   226
                .writeAll();
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   227
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   228
        Path m2 = base.resolve("src2/B");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   229
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   230
        tb.writeJavaFiles(m2,
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   231
                "@Deprecated(forRemoval=false) module B { requires A; }");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   232
        List<String> log = new JavacTask(tb)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   233
                .options("--module-source-path", m2.getParent().toString(),
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   234
                        "--module-path", modulePath.toString(),
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   235
                        "-XDrawDiagnostics")
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   236
                .outdir(modulePath)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   237
                .files(findJavaFiles(m2))
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   238
                .run()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   239
                .writeAll()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   240
                .getOutputLines(OutputKind.DIRECT);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   241
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   242
        List<String> expected = List.of("module-info.java:1:51: compiler.warn.has.been.deprecated.for.removal.module: A",
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   243
                "1 warning");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   244
        if (!log.containsAll(expected)) {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   245
            throw new AssertionError("Expected output not found. Expected: " + expected);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   246
        }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   247
    }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   248
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   249
    @Test
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   250
    public void testExportsAndOpensToDeprecatedModule(Path base) throws Exception {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   251
        Path moduleSrc = base.resolve("module-src");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   252
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   253
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   254
        tb.writeJavaFiles(moduleSrc.resolve("B"),
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   255
                "@Deprecated module B { }");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   256
        tb.writeJavaFiles(moduleSrc.resolve("C"),
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   257
                "@Deprecated(forRemoval=true) module C { }");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   258
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   259
        Path modulePath = base.resolve("module-path");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   260
        Files.createDirectories(modulePath);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   261
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   262
        new JavacTask(tb)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   263
                .options("--module-source-path", moduleSrc.toString())
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   264
                .outdir(modulePath)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   265
                .files(findJavaFiles(moduleSrc))
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   266
                .run()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   267
                .writeAll();
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   268
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   269
        Path m1 = base.resolve("src1/A");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   270
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   271
        tb.writeJavaFiles(m1,
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   272
                "module A { " +
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   273
                        "exports p1 to B; opens p1 to B;" +
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   274
                        "exports p2 to C; opens p2 to C;" +
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   275
                        "exports p3 to B,C; opens p3 to B,C;" +
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   276
                        "}",
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   277
                "package p1; public class A { }",
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   278
                "package p2; public class A { }",
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   279
                "package p3; public class A { }");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   280
        String log = new JavacTask(tb)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   281
                .options("--module-source-path", m1.getParent().toString(),
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   282
                        "--module-path", modulePath.toString(),
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   283
                        "-XDrawDiagnostics")
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   284
                .outdir(modulePath)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   285
                .files(findJavaFiles(m1))
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   286
                .run()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   287
                .writeAll()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   288
                .getOutput(OutputKind.DIRECT);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   289
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   290
        if (!log.isEmpty()) {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   291
            throw new AssertionError("Output is not empty! " + log);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   292
        }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   293
    }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   294
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   295
    @Test
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   296
    public void testAnnotationWithImport(Path base) throws Exception {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   297
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   298
        Path m1 = moduleSrc.resolve("m1x");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   299
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   300
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   301
                          "import m1x.A; @A module m1x { }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   302
                          "package m1x; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface A {}");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   303
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   304
        Path modulePath = base.resolve("module-path");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   305
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   306
        Files.createDirectories(modulePath);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   307
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   308
        new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   309
                .options("--module-source-path", moduleSrc.toString())
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   310
                .outdir(modulePath)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   311
                .files(findJavaFiles(m1))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   312
                .run()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   313
                .writeAll();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   314
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   315
        ClassFile cf = ClassFile.read(modulePath.resolve("m1x").resolve("module-info.class"));
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   316
        RuntimeInvisibleAnnotations_attribute annotations = (RuntimeInvisibleAnnotations_attribute) cf.attributes.map.get(Attribute.RuntimeInvisibleAnnotations);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   317
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   318
        if (annotations == null || annotations.annotations.length != 1) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   319
            throw new AssertionError("Annotations not correct!");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   320
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   321
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   322
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   323
    @Test
42829
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   324
    public void testAnnotationWithImportFromAnotherModule(Path base) throws Exception {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   325
        Path moduleSrc = base.resolve("module-src");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   326
        Path m1 = moduleSrc.resolve("src1/A");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   327
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   328
        tb.writeJavaFiles(m1,
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   329
                "module A { exports p1; exports p2; }",
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   330
                "package p1; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface A { }",
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   331
                "package p2; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface B { }");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   332
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   333
        Path modulePath = base.resolve("module-path");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   334
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   335
        Files.createDirectories(modulePath);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   336
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   337
        new JavacTask(tb)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   338
                .options("--module-source-path", m1.getParent().toString())
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   339
                .outdir(modulePath)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   340
                .files(findJavaFiles(m1))
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   341
                .run()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   342
                .writeAll();
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   343
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   344
        Path m2 = base.resolve("src2/B");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   345
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   346
        tb.writeJavaFiles(m2,
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   347
                "import p1.A; @A @p2.B module B { requires A; }");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   348
        new JavacTask(tb)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   349
                .options("--module-source-path", m2.getParent().toString(),
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   350
                        "--module-path", modulePath.toString()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   351
                )
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   352
                .outdir(modulePath)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   353
                .files(findJavaFiles(m2))
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   354
                .run()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   355
                .writeAll();
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   356
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   357
        ClassFile cf = ClassFile.read(modulePath.resolve("B").resolve("module-info.class"));
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   358
        RuntimeInvisibleAnnotations_attribute annotations = (RuntimeInvisibleAnnotations_attribute) cf.attributes.map.get(Attribute.RuntimeInvisibleAnnotations);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   359
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   360
        if (annotations == null ) {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   361
            throw new AssertionError("Annotations not found!");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   362
        }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   363
        int length = annotations.annotations.length;
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   364
        if (length != 2 ) {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   365
            throw new AssertionError("Incorrect number of annotations: " + length);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   366
        }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   367
    }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   368
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   369
    @Test
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   370
    public void testAnnotationWithImportAmbiguity(Path base) throws Exception {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   371
        Path moduleSrc = base.resolve("module-src");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   372
        Path m1 = moduleSrc.resolve("src1/A");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   373
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   374
        tb.writeJavaFiles(m1,
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   375
                "module A { exports p1; exports p2; }",
43279
9afb33b0a3ab 8171322: AssertionError in TypeSymbol.getAnnotationTypeMetadata.
sadayapalam
parents: 42839
diff changeset
   376
                "package p1; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface AAA { }",
9afb33b0a3ab 8171322: AssertionError in TypeSymbol.getAnnotationTypeMetadata.
sadayapalam
parents: 42839
diff changeset
   377
                "package p2; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface AAA { }");
42829
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   378
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   379
        Path modulePath = base.resolve("module-path");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   380
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   381
        Files.createDirectories(modulePath);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   382
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   383
        new JavacTask(tb)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   384
                .options("--module-source-path", m1.getParent().toString())
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   385
                .outdir(modulePath)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   386
                .files(findJavaFiles(m1))
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   387
                .run()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   388
                .writeAll();
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   389
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   390
        Path m2 = base.resolve("src2/B");
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   391
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   392
        tb.writeJavaFiles(m2,
43279
9afb33b0a3ab 8171322: AssertionError in TypeSymbol.getAnnotationTypeMetadata.
sadayapalam
parents: 42839
diff changeset
   393
                "import p1.*; import p2.*; @AAA module B { requires A; }");
42829
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   394
        List<String> log = new JavacTask(tb)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   395
                .options("--module-source-path", m2.getParent().toString(),
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   396
                        "--module-path", modulePath.toString(),
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   397
                        "-XDrawDiagnostics"
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   398
                )
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   399
                .outdir(modulePath)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   400
                .files(findJavaFiles(m2))
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   401
                .run(Task.Expect.FAIL)
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   402
                .writeAll()
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   403
                .getOutputLines(OutputKind.DIRECT);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   404
43279
9afb33b0a3ab 8171322: AssertionError in TypeSymbol.getAnnotationTypeMetadata.
sadayapalam
parents: 42839
diff changeset
   405
        List<String> expected = List.of("module-info.java:1:28: compiler.err.ref.ambiguous: AAA, kindname.class, p2.AAA, p2, kindname.class, p1.AAA, p1",
9afb33b0a3ab 8171322: AssertionError in TypeSymbol.getAnnotationTypeMetadata.
sadayapalam
parents: 42839
diff changeset
   406
                "1 error");
42829
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   407
        if (!log.containsAll(expected)) {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   408
            throw new AssertionError("Expected output not found. Expected: " + expected);
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   409
        }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   410
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   411
    }
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   412
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   413
    @Test
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   414
    public void testModuleInfoAnnotationsInAPI(Path base) throws Exception {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   415
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   416
        Path m1 = moduleSrc.resolve("m1x");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   417
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   418
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   419
                          "import m1x.*; @A @Deprecated @E @E module m1x { }",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   420
                          "package m1x; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface A {}",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   421
                          "package m1x; import java.lang.annotation.*; @Target(ElementType.MODULE) @Repeatable(C.class) public @interface E {}",
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   422
                          "package m1x; import java.lang.annotation.*; @Target(ElementType.MODULE) public @interface C { public E[] value(); }");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   423
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   424
        Path modulePath = base.resolve("module-path");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   425
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   426
        Files.createDirectories(modulePath);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   427
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   428
        new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   429
                .options("--module-source-path", moduleSrc.toString(),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   430
                         "-processor", AP.class.getName())
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   431
                .outdir(modulePath)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   432
                .files(findJavaFiles(m1))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   433
                .run()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   434
                .writeAll();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   435
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   436
        Path src = base.resolve("src");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   437
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   438
        tb.writeJavaFiles(src,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   439
                          "class T {}");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   440
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   441
        Path out = base.resolve("out");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   442
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   443
        Files.createDirectories(out);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   444
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   445
        new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   446
                .options("--module-path", modulePath.toString(),
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   447
                         "--add-modules", "m1x",
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   448
                         "-processor", AP.class.getName())
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   449
                .outdir(out)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   450
                .files(findJavaFiles(src))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   451
                .run()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   452
                .writeAll();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   453
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   454
        new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   455
                .options("--module-path", modulePath.toString() + File.pathSeparator + out.toString(),
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   456
                         "--add-modules", "m1x",
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   457
                         "-processor", AP.class.getName(),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   458
                         "-proc:only")
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   459
                .classes("m1x/m1x.A")
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   460
                .files(findJavaFiles(src))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   461
                .run()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   462
                .writeAll();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   463
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   464
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   465
    @SupportedAnnotationTypes("*")
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   466
    public static final class AP extends AbstractProcessor {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   467
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   468
        @Override
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   469
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   470
            ModuleElement m1 = processingEnv.getElementUtils().getModuleElement("m1x");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   471
            Set<String> actualAnnotations = new HashSet<>();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   472
            Set<String> expectedAnnotations =
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   473
                    new HashSet<>(Arrays.asList("@m1x.A", "@java.lang.Deprecated", "@m1x.C({@m1x.E, @m1x.E})"));
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   474
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   475
            for (AnnotationMirror am : m1.getAnnotationMirrors()) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   476
                actualAnnotations.add(am.toString());
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   477
            }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   478
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   479
            if (!expectedAnnotations.equals(actualAnnotations)) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   480
                throw new AssertionError("Incorrect annotations: " + actualAnnotations);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   481
            }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   482
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   483
            return false;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   484
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   485
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   486
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   487
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   488
    @Test
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   489
    public void testModuleDeprecation(Path base) throws Exception {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   490
        Path moduleSrc = base.resolve("module-src");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   491
        Path m1 = moduleSrc.resolve("m1x");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   492
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   493
        tb.writeJavaFiles(m1,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   494
                          "@Deprecated module m1x { }");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   495
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   496
        Path m2 = moduleSrc.resolve("m2x");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   497
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   498
        tb.writeJavaFiles(m2,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   499
                          "@Deprecated module m2x { }");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   500
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   501
        Path m3 = moduleSrc.resolve("m3x");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   502
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   503
        Path modulePath = base.resolve("module-path");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   504
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   505
        Files.createDirectories(modulePath);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   506
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   507
        List<String> actual;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   508
        List<String> expected;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   509
42829
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   510
        String DEPRECATED_JAVADOC = "/** @deprecated */";
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   511
        for (String suppress : new String[] {"", DEPRECATED_JAVADOC, "@Deprecated ", "@SuppressWarnings(\"deprecation\") "}) {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   512
            tb.writeJavaFiles(m3,
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   513
                              suppress + "module m3x {\n" +
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   514
                              "    requires m1x;\n" +
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   515
                              "    exports api to m1x, m2x;\n" +
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   516
                              "}",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   517
                              "package api; public class Api { }");
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   518
            System.err.println("compile m3x");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   519
            actual = new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   520
                    .options("--module-source-path", moduleSrc.toString(),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   521
                             "-XDrawDiagnostics")
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   522
                    .outdir(modulePath)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   523
                    .files(findJavaFiles(moduleSrc))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   524
                    .run()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   525
                    .writeAll()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   526
                    .getOutputLines(OutputKind.DIRECT);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   527
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   528
            if (suppress.isEmpty()) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   529
                expected = Arrays.asList(
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   530
                        "- compiler.note.deprecated.filename: module-info.java",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   531
                        "- compiler.note.deprecated.recompile");
42829
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   532
            } else if (suppress.equals(DEPRECATED_JAVADOC)) {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   533
                expected = Arrays.asList(
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   534
                        "module-info.java:1:19: compiler.warn.missing.deprecated.annotation",
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   535
                        "- compiler.note.deprecated.filename: module-info.java",
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   536
                        "- compiler.note.deprecated.recompile",
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   537
                        "1 warning");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   538
            } else {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   539
                expected = Arrays.asList("");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   540
            }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   541
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   542
            if (!expected.equals(actual)) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   543
                throw new AssertionError("Unexpected output: " + actual + "; suppress: " + suppress);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   544
            }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   545
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   546
            System.err.println("compile m3x with -Xlint:-deprecation");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   547
            actual = new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   548
                    .options("--module-source-path", moduleSrc.toString(),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   549
                             "-XDrawDiagnostics",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   550
                             "-Xlint:deprecation")
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   551
                    .outdir(modulePath)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   552
                    .files(findJavaFiles(moduleSrc))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   553
                    .run()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   554
                    .writeAll()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   555
                    .getOutputLines(OutputKind.DIRECT);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   556
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   557
            if (suppress.isEmpty()) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   558
                expected = Arrays.asList(
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   559
                        "module-info.java:2:14: compiler.warn.has.been.deprecated.module: m1x",
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   560
                        "1 warning");
42829
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   561
            } else if (suppress.equals(DEPRECATED_JAVADOC)) {
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   562
                expected = Arrays.asList(
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   563
                        "module-info.java:1:19: compiler.warn.missing.deprecated.annotation",
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   564
                        "module-info.java:2:14: compiler.warn.has.been.deprecated.module: m1x",
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   565
                        "2 warnings");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   566
            } else {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   567
                expected = Arrays.asList("");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   568
            }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   569
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   570
            if (!expected.equals(actual)) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   571
                throw new AssertionError("Unexpected output: " + actual + "; suppress: " + suppress);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   572
            }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   573
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   574
            //load the deprecated module-infos from classfile:
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   575
            System.err.println("compile m3x with -Xlint:-deprecation, loading deprecated modules from classes");
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   576
            actual = new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   577
                    .options("--module-path", modulePath.toString(),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   578
                             "-XDrawDiagnostics",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   579
                             "-Xlint:deprecation")
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   580
                    .outdir(modulePath.resolve("m3x"))
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   581
                    .files(findJavaFiles(moduleSrc.resolve("m3x")))
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   582
                    .run()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   583
                    .writeAll()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   584
                    .getOutputLines(OutputKind.DIRECT);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   585
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   586
            if (!expected.equals(actual)) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   587
                throw new AssertionError("Unexpected output: " + actual + "; suppress: " + suppress);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   588
            }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   589
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   590
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   591
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   592
    @Test
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   593
    public void testAttributeValues(Path base) throws Exception {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   594
        class TestCase {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   595
            public final String extraDecl;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   596
            public final String decl;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   597
            public final String use;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   598
            public final String expectedAnnotations;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   599
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   600
            public TestCase(String extraDecl, String decl, String use, String expectedAnnotations) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   601
                this.extraDecl = extraDecl;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   602
                this.decl = decl;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   603
                this.use = use;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   604
                this.expectedAnnotations = expectedAnnotations;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   605
            }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   606
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   607
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   608
        TestCase[] testCases = new TestCase[] {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   609
            new TestCase("package test; public enum E {A, B;}",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   610
                         "public E value();",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   611
                         "test.E.A",
55387
761b86d5563d 8164819: Make javac's toString() on annotation objects consistent with core reflection
darcy
parents: 47216
diff changeset
   612
                         "@test.A(A)"),
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   613
            new TestCase("package test; public enum E {A, B;}",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   614
                         "public E[] value();",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   615
                         "{test.E.A, test.E.B}",
55387
761b86d5563d 8164819: Make javac's toString() on annotation objects consistent with core reflection
darcy
parents: 47216
diff changeset
   616
                         "@test.A({A, B})"),
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   617
            new TestCase("package test; public class Extra {}",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   618
                         "public Class value();",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   619
                         "test.Extra.class",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   620
                         "@test.A(test.Extra.class)"),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   621
            new TestCase("package test; public class Extra {}",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   622
                         "public Class[] value();",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   623
                         "{test.Extra.class, String.class}",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   624
                         "@test.A({test.Extra.class, java.lang.String.class})"),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   625
            new TestCase("package test; public @interface Extra { public Class value(); }",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   626
                         "public test.Extra value();",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   627
                         "@test.Extra(String.class)",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   628
                         "@test.A(@test.Extra(java.lang.String.class))"),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   629
            new TestCase("package test; public @interface Extra { public Class value(); }",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   630
                         "public test.Extra[] value();",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   631
                         "{@test.Extra(String.class), @test.Extra(Integer.class)}",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   632
                         "@test.A({@test.Extra(java.lang.String.class), @test.Extra(java.lang.Integer.class)})"),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   633
            new TestCase("package test; public class Any { }",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   634
                         "public int value();",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   635
                         "1",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   636
                         "@test.A(1)"),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   637
            new TestCase("package test; public class Any { }",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   638
                         "public int[] value();",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   639
                         "{1, 2}",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   640
                         "@test.A({1, 2})"),
42829
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   641
            new TestCase("package test; public enum E {A;}",
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   642
                        "int integer(); boolean flag(); double value(); String string(); E enumeration(); ",
37fa35ab1907 8170549: Improve testing of annotations on modules
anazarov
parents: 42822
diff changeset
   643
                        "enumeration = test.E.A, integer = 42, flag = true, value = 3.5, string = \"Text\"",
55387
761b86d5563d 8164819: Make javac's toString() on annotation objects consistent with core reflection
darcy
parents: 47216
diff changeset
   644
                        "@test.A(enumeration=A, integer=42, flag=true, value=3.5, string=\"Text\")"),
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   645
        };
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   646
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   647
        Path extraSrc = base.resolve("extra-src");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   648
        tb.writeJavaFiles(extraSrc,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   649
                          "class Any {}");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   650
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   651
        int count = 0;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   652
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   653
        for (TestCase tc : testCases) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   654
            Path testBase = base.resolve(String.valueOf(count));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   655
            Path moduleSrc = testBase.resolve("module-src");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   656
            Path m = moduleSrc.resolve("m");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   657
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   658
            tb.writeJavaFiles(m,
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   659
                              "@test.A(" + tc.use + ") module m { }",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   660
                              "package test; @java.lang.annotation.Target(java.lang.annotation.ElementType.MODULE) public @interface A { " + tc.decl + "}",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   661
                              tc.extraDecl);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   662
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   663
            Path modulePath = testBase.resolve("module-path");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   664
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   665
            Files.createDirectories(modulePath);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   666
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   667
            new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   668
                .options("--module-source-path", moduleSrc.toString())
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   669
                .outdir(modulePath)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   670
                .files(findJavaFiles(moduleSrc))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   671
                .run()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   672
                .writeAll();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   673
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   674
            Path classes = testBase.resolve("classes");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   675
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   676
            Files.createDirectories(classes);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   677
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   678
            new JavacTask(tb)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   679
                .options("--module-path", modulePath.toString(),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   680
                         "--add-modules", "m",
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   681
                         "-processorpath", System.getProperty("test.classes"),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   682
                         "-processor", ProxyTypeValidator.class.getName(),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   683
                         "-A" + OPT_EXPECTED_ANNOTATIONS + "=" + tc.expectedAnnotations)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   684
                .outdir(classes)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   685
                .files(findJavaFiles(extraSrc))
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   686
                .run()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   687
                .writeAll();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   688
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   689
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   690
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   691
    private static final String OPT_EXPECTED_ANNOTATIONS = "expectedAnnotations";
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   692
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   693
    @SupportedAnnotationTypes("*")
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   694
    @SupportedOptions(OPT_EXPECTED_ANNOTATIONS)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   695
    public static final class ProxyTypeValidator extends AbstractProcessor {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   696
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   697
        @Override
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   698
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   699
            ModuleElement m = processingEnv.getElementUtils().getModuleElement("m");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   700
            String actualTypes = m.getAnnotationMirrors()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   701
                                  .stream()
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   702
                                  .map(am -> am.toString())
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   703
                                  .collect(Collectors.joining(", "));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   704
            if (!Objects.equals(actualTypes, processingEnv.getOptions().get(OPT_EXPECTED_ANNOTATIONS))) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   705
                throw new IllegalStateException("Expected annotations not found, actual: " + actualTypes);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   706
            }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   707
            return false;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   708
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   709
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   710
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   711
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   712
}