|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, 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 | + * @bug 8232948 |
| 27 | + * @summary Make sure inner classes are correctly encoded |
| 28 | + * @library /tools/lib |
| 29 | + * @modules jdk.compiler/com.sun.tools.javac.api |
| 30 | + * @modules jdk.compiler/com.sun.tools.javac.main |
| 31 | + * @build toolbox.JavacTask toolbox.TestRunner toolbox.ToolBox |
| 32 | + * @run main EncodeInnerClassNameTest |
| 33 | + */ |
| 34 | + |
| 35 | +import toolbox.JavacTask; |
| 36 | +import toolbox.ToolBox; |
| 37 | + |
| 38 | +import java.nio.file.Files; |
| 39 | +import java.nio.file.Path; |
| 40 | +import java.util.Arrays; |
| 41 | +import java.util.List; |
| 42 | + |
| 43 | +public class EncodeInnerClassNameTest { |
| 44 | + private final ToolBox toolBox = new ToolBox(); |
| 45 | + private final String source = """ |
| 46 | + package p.q; |
| 47 | + public class Outer { |
| 48 | + public class Inner { |
| 49 | + native Inner aMethod(); |
| 50 | + native void aMethod(Inner i); |
| 51 | + native void aMethod(Inner i, Inner j); |
| 52 | + } |
| 53 | + } |
| 54 | + """; |
| 55 | + |
| 56 | + private final String expected = """ |
| 57 | + /* DO NOT EDIT THIS FILE - it is machine generated */ |
| 58 | + #include <jni.h> |
| 59 | + /* Header for class p_q_Outer_Inner */ |
| 60 | +
|
| 61 | + #ifndef _Included_p_q_Outer_Inner |
| 62 | + #define _Included_p_q_Outer_Inner |
| 63 | + #ifdef __cplusplus |
| 64 | + extern "C" { |
| 65 | + #endif |
| 66 | + /* |
| 67 | + * Class: p_q_Outer_Inner |
| 68 | + * Method: aMethod |
| 69 | + * Signature: ()Lp/q/Outer/Inner; |
| 70 | + */ |
| 71 | + JNIEXPORT jobject JNICALL Java_p_q_Outer_00024Inner_aMethod__ |
| 72 | + (JNIEnv *, jobject); |
| 73 | +
|
| 74 | + /* |
| 75 | + * Class: p_q_Outer_Inner |
| 76 | + * Method: aMethod |
| 77 | + * Signature: (Lp/q/Outer/Inner;)V |
| 78 | + */ |
| 79 | + JNIEXPORT void JNICALL Java_p_q_Outer_00024Inner_aMethod__Lp_q_Outer_00024Inner_2 |
| 80 | + (JNIEnv *, jobject, jobject); |
| 81 | +
|
| 82 | + /* |
| 83 | + * Class: p_q_Outer_Inner |
| 84 | + * Method: aMethod |
| 85 | + * Signature: (Lp/q/Outer/Inner;Lp/q/Outer/Inner;)V |
| 86 | + */ |
| 87 | + JNIEXPORT void JNICALL Java_p_q_Outer_00024Inner_aMethod__Lp_q_Outer_00024Inner_2Lp_q_Outer_00024Inner_2 |
| 88 | + (JNIEnv *, jobject, jobject, jobject); |
| 89 | +
|
| 90 | + #ifdef __cplusplus |
| 91 | + } |
| 92 | + #endif |
| 93 | + #endif |
| 94 | + """; |
| 95 | + |
| 96 | + public static void main(String... args) throws Exception { |
| 97 | + new EncodeInnerClassNameTest().runTest(); |
| 98 | + } |
| 99 | + |
| 100 | + public void runTest() throws Exception { |
| 101 | + JavacTask task = new JavacTask(toolBox); |
| 102 | + task.outdir(".") |
| 103 | + .sources(source) |
| 104 | + .options("-h", ".") |
| 105 | + .run() |
| 106 | + .writeAll(); |
| 107 | + |
| 108 | + List<String> expected = Arrays.asList(this.expected.split("\\R")); |
| 109 | + List<String> res = toolBox.readAllLines(Path.of(".", "p_q_Outer_Inner.h")); |
| 110 | + |
| 111 | + toolBox.checkEqual(expected, res); |
| 112 | + } |
| 113 | +} |
0 commit comments