jdk

Форк
0
/
SubpackageTest.java 
122 строки · 4.0 Кб
1
/*
2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.
8
 *
9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 * version 2 for more details (a copy is included in the LICENSE file that
13
 * accompanied this code).
14
 *
15
 * You should have received a copy of the GNU General Public License version
16
 * 2 along with this work; if not, write to the Free Software Foundation,
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
 * or visit www.oracle.com if you need additional information or have any
21
 * questions.
22
 */
23

24
/*
25
 * @test
26
 * @summary tests for subpackage issues
27
 * @library /tools/lib
28
 * @modules
29
 *      jdk.compiler/com.sun.tools.javac.api
30
 *      jdk.compiler/com.sun.tools.javac.main
31
 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
32
 * @run main SubpackageTest
33
 */
34

35
import java.nio.file.Files;
36
import java.nio.file.Path;
37
import java.util.ArrayList;
38
import java.util.Arrays;
39
import java.util.Collections;
40
import java.util.List;
41
import java.util.stream.Collectors;
42

43
import toolbox.JavacTask;
44
import toolbox.Task;
45
import toolbox.ToolBox;
46

47
public class SubpackageTest extends ModuleTestBase {
48

49
    public static void main(String... args) throws Exception {
50
        SubpackageTest t = new SubpackageTest();
51
        t.runTests();
52
    }
53

54
    @Test // based on JDK-8075435
55
    public void testUnnamedModule(Path base) throws Exception {
56
        Path libsrc = base.resolve("lib/src");
57
        tb.writeJavaFiles(libsrc,
58
            "package p; public class E extends Error { }");
59
        Path libclasses = base.resolve("lib/classes");
60
        Files.createDirectories(libclasses);
61
        new JavacTask(tb)
62
                .outdir(libclasses)
63
                .files(findJavaFiles(libsrc))
64
                .run()
65
                .writeAll();
66

67
        Path src = base.resolve("src");
68
        tb.writeJavaFiles(src,
69
            """
70
                package p.q;
71
                import p.E;
72
                class Test {
73
                  void m() { throw new E(); }
74
                }""");
75
        Path classes = base.resolve("classes");
76
        Files.createDirectories(classes);
77

78
        new JavacTask(tb)
79
                .classpath(libclasses)
80
                .outdir(classes)
81
                .files(findJavaFiles(src))
82
                .run()
83
                .writeAll();
84
    }
85

86
    @Test
87
    public void testSimpleMulti(Path base) throws Exception {
88
        Path src = base.resolve("src");
89
        tb.writeJavaFiles(src.resolve("mp"),
90
                "module mp { exports p; }",
91
                "package p; public class C1 { }");
92
        tb.writeJavaFiles(src.resolve("mpq"),
93
                "module mpq { exports p.q; }",
94
                "package p.q; public class C2 { }");
95
        tb.writeJavaFiles(src.resolve("mpqr"),
96
                "module mpqr { exports p.q.r; }",
97
                "package p.q.r; public class C3 { }");
98
        tb.writeJavaFiles(src.resolve("m"),
99
                """
100
                    module m {  requires mp;
101
                      requires mpq;
102
                      requires mpqr;
103
                    }""",
104
                """
105
                    package x;
106
                    class C {
107
                      p.C1 c1;
108
                      p.q.C2 c2;
109
                      p.q.r.C3 c3;
110
                    }""");
111
        Path modules = base.resolve("modules");
112
        Files.createDirectories(modules);
113

114
        new JavacTask(tb)
115
                .options("--module-source-path", src.toString())
116
                .outdir(modules)
117
                .files(findJavaFiles(src))
118
                .run()
119
                .writeAll();
120
    }
121

122
}
123

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.