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 */
40
41 public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
42 static final String static_final_v = "foo";
43
44 static String static_v;
45
46 final String final_v = "foo";
47
48 String v;
49
50 VarHandle vhFinalField;
51
52 VarHandle vhField;
53
54 VarHandle vhStaticField;
55
56 VarHandle vhStaticFinalField;
57
58 VarHandle vhArray;
59
60 @BeforeClass
61 public void setup() throws Exception {
62 vhFinalField = MethodHandles.lookup().findVarHandle(
63 VarHandleTestMethodHandleAccessString.class, "final_v", String.class);
64
65 vhField = MethodHandles.lookup().findVarHandle(
66 VarHandleTestMethodHandleAccessString.class, "v", String.class);
67
68 vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
69 VarHandleTestMethodHandleAccessString.class, "static_final_v", String.class);
70
71 vhStaticField = MethodHandles.lookup().findStaticVarHandle(
72 VarHandleTestMethodHandleAccessString.class, "static_v", String.class);
73
74 vhArray = MethodHandles.arrayElementVarHandle(String[].class);
75 }
76
77
78 @DataProvider
79 public Object[][] accessTestCaseProvider() throws Exception {
80 List<AccessTestCase<?>> cases = new ArrayList<>();
81
82 for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
83 cases.add(new MethodHandleAccessTestCase("Instance field",
84 vhField, f, hs -> testInstanceField(this, hs)));
85 cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
86 vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
87 false));
88
89 cases.add(new MethodHandleAccessTestCase("Static field",
90 vhStaticField, f, VarHandleTestMethodHandleAccessString::testStaticField));
91 cases.add(new MethodHandleAccessTestCase("Static field unsupported",
92 vhStaticField, f, VarHandleTestMethodHandleAccessString::testStaticFieldUnsupported,
93 false));
94
|
1 /*
2 * Copyright (c) 2015, 2018, 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 */
40
41 public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest {
42 static final String static_final_v = "foo";
43
44 static String static_v;
45
46 final String final_v = "foo";
47
48 String v;
49
50 VarHandle vhFinalField;
51
52 VarHandle vhField;
53
54 VarHandle vhStaticField;
55
56 VarHandle vhStaticFinalField;
57
58 VarHandle vhArray;
59
60
61 @BeforeClass
62 public void setup() throws Exception {
63 vhFinalField = MethodHandles.lookup().findVarHandle(
64 VarHandleTestMethodHandleAccessString.class, "final_v", String.class);
65
66 vhField = MethodHandles.lookup().findVarHandle(
67 VarHandleTestMethodHandleAccessString.class, "v", String.class);
68
69 vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
70 VarHandleTestMethodHandleAccessString.class, "static_final_v", String.class);
71
72 vhStaticField = MethodHandles.lookup().findStaticVarHandle(
73 VarHandleTestMethodHandleAccessString.class, "static_v", String.class);
74
75 vhArray = MethodHandles.arrayElementVarHandle(String[].class);
76
77 }
78
79
80 @DataProvider
81 public Object[][] accessTestCaseProvider() throws Exception {
82 List<AccessTestCase<?>> cases = new ArrayList<>();
83
84 for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
85 cases.add(new MethodHandleAccessTestCase("Instance field",
86 vhField, f, hs -> testInstanceField(this, hs)));
87 cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
88 vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
89 false));
90
91 cases.add(new MethodHandleAccessTestCase("Static field",
92 vhStaticField, f, VarHandleTestMethodHandleAccessString::testStaticField));
93 cases.add(new MethodHandleAccessTestCase("Static field unsupported",
94 vhStaticField, f, VarHandleTestMethodHandleAccessString::testStaticFieldUnsupported,
95 false));
96
|