1 /*
 2  * Copyright (c) 2024, 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 import java.lang.constant.DirectMethodHandleDesc;
25 import java.lang.runtime.CodeReflection;
26 
27 import static java.lang.constant.DirectMethodHandleDesc.Kind;
28 import static java.lang.constant.DirectMethodHandleDesc.Kind.VIRTUAL;
29 
30 /*
31  * @test
32  * @summary Smoke test for code reflection with enum access.
33  * @build EnumAccessTest
34  * @build CodeReflectionTester
35  * @run main CodeReflectionTester EnumAccessTest
36  */
37 
38 public class EnumAccessTest {
39     @CodeReflection
40     @IR("""
41             func @"test1" (%0 : EnumAccessTest)java.lang.constant.DirectMethodHandleDesc$Kind -> {
42                 %1 : java.lang.constant.DirectMethodHandleDesc$Kind = field.load @"java.lang.constant.DirectMethodHandleDesc$Kind::VIRTUAL()java.lang.constant.DirectMethodHandleDesc$Kind";
43                 return %1;
44             };
45             """)
46     DirectMethodHandleDesc.Kind test1() {
47         return DirectMethodHandleDesc.Kind.VIRTUAL;
48     }
49 
50     @CodeReflection
51     @IR("""
52             func @"test2" (%0 : EnumAccessTest)java.lang.constant.DirectMethodHandleDesc$Kind -> {
53                 %1 : java.lang.constant.DirectMethodHandleDesc$Kind = field.load @"java.lang.constant.DirectMethodHandleDesc$Kind::VIRTUAL()java.lang.constant.DirectMethodHandleDesc$Kind";
54                 return %1;
55             };
56             """)
57     DirectMethodHandleDesc.Kind test2() {
58         return Kind.VIRTUAL;
59     }
60 
61     @CodeReflection
62     @IR("""
63             func @"test3" (%0 : EnumAccessTest)java.lang.constant.DirectMethodHandleDesc$Kind -> {
64                 %1 : java.lang.constant.DirectMethodHandleDesc$Kind = field.load @"java.lang.constant.DirectMethodHandleDesc$Kind::VIRTUAL()java.lang.constant.DirectMethodHandleDesc$Kind";
65                 return %1;
66             };
67             """)
68     DirectMethodHandleDesc.Kind test3() {
69         return VIRTUAL;
70     }
71 }