Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/Jsr292/src/com/ibm/j9/jsr292/SamePackageExample.java
6007 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2018 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
package com.ibm.j9.jsr292;
23
24
import java.lang.invoke.MethodHandles;
25
import java.lang.invoke.MethodHandles.Lookup;
26
27
/**
28
* All the fields, constructors and methods in this class are used by test cases that require fields, methods, and constructors of
29
* various behavior from a class in the same package as the test class.
30
*
31
* @author mesbah
32
*
33
*/
34
public class SamePackageExample {
35
public static Lookup publicLookupObjectSamePackage = MethodHandles.publicLookup().in(SamePackageExample.class);
36
public static int publicStaticField_doNotDeclareInSubClasses;
37
38
public int nonStaticPublicField;
39
public final int nonStaticFinalPublicField;
40
public static int staticPublicField;
41
public final static int staticFinalPublicField = 42;
42
43
private int nonStaticPrivateField;
44
private static int staticPrivateField;
45
46
protected int nonStaticProtectedField;
47
48
public SamePackageExample() {
49
super();
50
nonStaticFinalPublicField = 24;
51
}
52
53
public SamePackageExample(int a, int b) {
54
this.nonStaticPublicField = a + b;
55
this.nonStaticFinalPublicField = a + b;
56
}
57
58
public int addPublic(int a, int b) {return a+b;}
59
private int addPrivate(int a, int b) {return a+b;}
60
61
public static int addPublicStatic (int a,int b) {return a+b;}
62
private static int addPrivateStatic (int a,int b) {return a+b;}
63
protected static int addProtectedStatic(int a, int b) {return a+b;}
64
65
protected int addProtected(int a, int b) {return a+b;}
66
67
public int addPublic_Super(int a, int b) {return a+b+5;}
68
69
public static Lookup getLookup() {
70
return MethodHandles.lookup();
71
}
72
73
public class SamePackageInnerClass{
74
75
public int nonStaticPublicField_Inner1;
76
77
private int nonStaticPrivateField_Inner1;
78
79
protected int nonStaticProtectedField_Inner1;
80
81
public int addPublicInner(int a, int b) { return a+b; }
82
83
private int addPrivateInner(int a, int b) { return a+b; }
84
85
public Lookup getLookup() {
86
return MethodHandles.lookup();
87
}
88
89
public class SamePackageInnerClass_Nested_Level2 {
90
91
public int nonStaticPublicField_Inner2;
92
93
private int nonStaticPrivateField_Inner2;
94
95
protected int nonStaticProtectedField_Inner2;
96
97
public int addPublicInner_Level2(int a, int b) { return a+b; }
98
99
public Lookup getLookup() {
100
return MethodHandles.lookup();
101
}
102
}
103
}
104
105
public class SamePackageInnerClass2{
106
107
public int nonStaticPublicField_Inner12;
108
public Lookup getLookup() {
109
return MethodHandles.lookup();
110
}
111
112
public class SamePackageInnerClass2_Nested_Level2 {
113
114
public int nonStaticPublicField_Inner22;
115
116
private int nonStaticPrivateField_Inner22;
117
118
protected int nonStaticProtectedField_Inner22;
119
120
public Lookup getLookup() {
121
return MethodHandles.lookup();
122
}
123
}
124
125
public class SamePackageInnerClass2_Nested_Level2_SubOf_Inner1 extends SamePackageInnerClass {
126
public int addPublicInner(int a, int b) { return a+b+20; } // overridden method
127
}
128
}
129
130
protected class SamePackageInnerClass_Protected {
131
132
protected Lookup getLookup() {
133
return MethodHandles.lookup();
134
}
135
136
public int addPublicInner(int a, int b) { return a+b; }
137
protected int addProtectedInner(int a, int b) { return a+b; }
138
139
protected class SamePackageInnerClass_Nested_Level2 {
140
public Lookup getLookup() {
141
return MethodHandles.lookup();
142
}
143
public int addPublicInner_Level2(int a, int b) { return a+b; }
144
protected int addProtectedInner_Level2(int a, int b) { return a+b; }
145
}
146
}
147
148
static class SamePackageInnerClass_Static {
149
public static Lookup getLookup () {
150
return MethodHandles.lookup();
151
}
152
}
153
154
155
public String arrayToString(String[] o) {
156
String s = "[";
157
158
if ( o == null || o.length == 0 ) {
159
return s + "]";
160
}
161
162
for ( int i = 0 ; i < o.length ; i++ ) {
163
s += o[i];
164
if ( i + 1 < o.length ) {
165
s += ",";
166
}
167
}
168
169
return s + "]";
170
}
171
172
public int getLength(String[] o) {
173
return o.length;
174
}
175
176
public int getLength(int[] o) {
177
return o.length;
178
}
179
180
public int getLength(double[] o) {
181
return o.length;
182
}
183
184
public int getLength(char[] o) {
185
return o.length;
186
}
187
188
public int getLength(float[] o) {
189
return o.length;
190
}
191
192
public int getLength(boolean[] o) {
193
return o.length;
194
}
195
196
public int getLength(byte[] o) {
197
return o.length;
198
}
199
200
public int getLength(short[] o) {
201
return o.length;
202
}
203
204
public int getLength(long[] o) {
205
return o.length;
206
}
207
208
public static int getLengthStatic(String[] o) {
209
return o.length;
210
}
211
212
public int addPublicVariableArity(int... n) {
213
int sum = 0 ;
214
for ( int i = 0 ; i < n.length ; i++ ) {
215
sum += n[i];
216
}
217
return sum;
218
}
219
220
public int addPublicVariableArity(Object... n) {
221
int sum = 0 ;
222
for ( int i = 0 ; i < n.length ; i++ ) {
223
sum += (int)n[i];
224
}
225
return sum;
226
}
227
228
public void takeVariableArityObject(Object... n) {}
229
230
public static String returnOne() {
231
return "1";
232
}
233
234
public static String returnTwo() {
235
return "2";
236
}
237
238
public static String returnThree() {
239
return "3";
240
}
241
242
public int[] makeArray(int...args) { return args; }
243
244
public String arrayToString(Object [] o) {
245
String s = "[";
246
247
if ( o == null || o.length == 0 ) {
248
return s + "]";
249
}
250
251
for ( int i = 0 ; i < o.length ; i++ ) {
252
s += o[i];
253
if ( i + 1 < o.length ) {
254
s += ",";
255
}
256
}
257
258
return s + "]";
259
}
260
261
public String toOjectArrayString(Object objArray) {
262
Object [] o = (Object[])objArray;
263
String s = "[";
264
265
if ( o == null || o.length == 0 ) {
266
return s + "]";
267
}
268
269
for ( int i = 0 ; i < o.length ; i++ ) {
270
s += o[i];
271
if ( i + 1 < o.length ) {
272
s += ",";
273
}
274
}
275
276
return s + "]";
277
}
278
279
/*Variable arity constructor example*/
280
public SamePackageExample(int...n) {
281
nonStaticFinalPublicField = 24;
282
}
283
284
public boolean isReceiverNull() { return this == null; }
285
public String toString() { return "SamePackageExample.toString()" + ((this == null) ? " null" : "notnull"); }
286
}
287
288