Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/OpenJ9_Jsr_292_API/src/examples/PackageExamples.java
6004 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 examples;
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 a different package than that of the test class.
30
*
31
* @author mesbah
32
*
33
*/
34
public class PackageExamples {
35
36
public static Lookup getLookup() {
37
return MethodHandles.lookup();
38
}
39
40
public static Lookup getPublicLookup() {
41
return MethodHandles.publicLookup();
42
}
43
44
final protected String finalProtectedMethod() { return "finalProtectedMethod"; }
45
46
protected static String protectedMethod () { return "protectedMethod"; }
47
48
/* default */ static String defaultMethod() { return "defaultMethod"; }
49
50
public int nonStaticPublicField;
51
public static int staticPublicField;
52
53
private int nonStaticPrivateField;
54
private static int staticPrivateField;
55
56
protected int nonStaticProtectedField;
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
64
protected static int addProtectedStatic(int a,int b) {return a+b;}
65
66
public PackageExamples(){
67
super();
68
}
69
70
public PackageExamples(int a, int b){
71
this.nonStaticPublicField = a + b;
72
}
73
74
75
public class CrossPackageInnerClass{
76
public int addPublicInner(int a, int b){ return a+b; }
77
public Lookup getLookup() { return MethodHandles.lookup(); }
78
79
public class CrossPackageInnerClass2_Nested_Level2 {
80
public Lookup getLookup() {
81
return MethodHandles.lookup();
82
}
83
public int addPublicInner_level2(int a, int b){ return a+b; }
84
}
85
}
86
87
public int getLength(String[] o){
88
return o.length;
89
}
90
91
public static int getLengthStatic(String[] o){
92
return o.length;
93
}
94
95
public int addPublicVariableArity(int... n){
96
int sum = 0 ;
97
for ( int i = 0 ; i < n.length ; i++ ){
98
sum += n[i];
99
}
100
return sum;
101
}
102
103
public static int addPublicStaticVariableArity(int... n){
104
int sum = 0 ;
105
for ( int i = 0 ; i < n.length ; i++ ){
106
sum += n[i];
107
}
108
return sum;
109
}
110
111
protected int addProtected(int a, int b) {return a+b;}
112
}
113
114