forked from joeferner/node-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.java
206 lines (174 loc) · 6.61 KB
/
Test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
public class Test {
private int i;
public int nonstaticInt = 42;
public static int staticFieldInt = 42;
public static double staticFieldDouble = 42.5;
public static Test[] staticArrayObjects = null;
public Test() {}
public Test(Integer i) { this.i = i; }
public Test(Integer i, String... other) { this.i = i; }
public int getInt() { return i; }
public int methodOverload(String a) { return 1; }
public int methodOverload(int a) { return 2; }
public int methodOverload(SuperClass a) { return a.getVal(); }
public static String staticMethod() { return "staticMethod called"; }
public static int staticMethod(int i) { return i + 1; }
public static void staticMethodThrows(Exception ex) throws Exception { throw ex; }
public void methodThrows(Exception ex) throws Exception { throw ex; }
public static void staticMethodThrowsNewException() throws Exception { throw new Exception("my exception"); }
public void methodThrowsNewException() throws Exception { throw new Exception("my exception"); }
public static int staticMethodOverload(String a) { return 1; }
public static int staticMethodOverload(int a) { return 2; }
public static int staticMethodOverload(SuperClass a) { return a.getVal(); }
public static String staticMethodCharArrayToString(char[] a) { return new String(a); }
public static String staticMethodLongToString(java.lang.Long l) { return l.toString(); }
public static long staticMethodReturnLong() { return java.lang.Long.MAX_VALUE; }
public static boolean static2Objects(Object o1, Object o2) { return o1.equals(o2); }
public static int staticByte(byte b) { return (int)b; }
public static int staticShort(short s) { return (int)s; }
public static int staticLong(long l) { return (int)l; }
public static double staticDouble(double s) { return s; }
public static float staticFloat(float s) { return s; }
public static String staticString(String s) { return s; }
public static int staticMethodAmbiguous(Double a) { return 1; }
public static int staticMethodAmbiguous(Integer a) { return 2; }
public int methodAmbiguous(Double a) { return 1; }
public int methodAmbiguous(Integer a) { return 2; }
public static String staticVarargs(Integer i, String... args) {
java.lang.StringBuilder result = new java.lang.StringBuilder();
result.append(i);
for(String arg : args) {
result.append(arg);
}
return result.toString();
}
public static String staticBigDecimalToString(java.math.BigDecimal bigDecimal) { return bigDecimal.toString(); }
public static int staticChar(char ch) { return (int)ch; }
public static short[] staticShortArray(Short[] arg) {
short[] b = new short[arg.length];
for(int i=0; i<arg.length; i++) { b[i] = arg[i]; }
return b;
}
public static short[] staticShortArray(short[] arg) {
short[] b = new short[arg.length];
for(int i=0; i<arg.length; i++) { b[i] = arg[i]; }
return b;
}
public static boolean[] staticBooleanArray(boolean[] arg) {
boolean[] b = new boolean[arg.length];
for(int i=0; i<arg.length; i++) { b[i] = arg[i]; }
return b;
}
public static boolean[] staticBooleanArray(Boolean[] arg) {
boolean[] b = new boolean[arg.length];
for(int i=0; i<arg.length; i++) { b[i] = arg[i]; }
return b;
}
public static double[] staticDoubleArray(double[] arg) {
double[] b = new double[arg.length];
for(int i=0; i<arg.length; i++) { b[i] = arg[i]; }
return b;
}
public static int[] staticIntArray(int[] arg) {
int[] b = new int[arg.length];
for(int i=0; i<arg.length; i++) { b[i] = arg[i]; }
return b;
}
public static class SuperClass {
public int getVal() { return 3; }
}
public static class SubClass extends SuperClass {
public int getVal() { return 4; }
}
public static int[] getArrayOfInts() {
int arr[] = new int[5];
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
arr[3] = 4;
arr[4] = 5;
return arr;
}
public static byte[] getArrayOfBytes() {
byte arr[] = new byte[5];
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
arr[3] = 4;
arr[4] = 5;
return arr;
}
public static boolean[] getArrayOfBools() {
boolean arr[] = new boolean[5];
arr[0] = true;
arr[1] = true;
arr[2] = false;
arr[3] = true;
arr[4] = false;
return arr;
}
public static double[] getArrayOfDoubles() {
double arr[] = new double[5];
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
arr[3] = 4;
arr[4] = 5;
return arr;
}
public static float[] getArrayOfFloats() {
float arr[] = new float[5];
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
arr[3] = 4;
arr[4] = 5;
return arr;
}
public static long[] getArrayOfLongs() {
long arr[] = new long[5];
arr[0] = Long.MAX_VALUE;
arr[1] = Long.MIN_VALUE;
arr[2] = 3;
arr[3] = 4;
arr[4] = 5;
return arr;
}
public static String getUnicodeBMP() {
return new String(Character.toChars(0x2605));
}
public static String getUnicodeSMP() {
return new String(Character.toChars(0x1F596));
}
public static String getUnicodeNull() {
return new String("\0");
}
public static enum StaticEnum {
Value1,
Value2
}
public static String staticEnumToString(StaticEnum e) { return e.toString(); }
public static String varArgsSignature(Object... args) { return "Object..."; }
public static String varArgsSignature(Boolean... args) { return "Boolean..."; }
public static String varArgsSignature(Double... args) { return "Double..."; }
public static String varArgsSignature(Integer... args) { return "Integer..."; }
public static String varArgsSignature(Long... args) { return "Long..."; }
public static String varArgsSignature(Number... args) { return "Number..."; }
public static String varArgsSignature(String... args) { return "String..."; }
// The Javascript object returned by java.import(classname) is a Function object
// so that it can be used as a constructor.
// Javascript reserves some properties of Function as non-writable or non-configurable:
// 'name', 'arguments', 'caller'.
// This means we can't expose a static member such as 'name()' with that name.
// We instead append a suffix (asyncOptions.ifReadOnlySuffix)
// The following static members are used for unit tests involving these cases.
// For testing static member functions with reserved names
public static String name() { return "name"; }
public static String arguments() { return "arguments"; }
public static String caller() { return "caller"; }
// For testing public static fields with reserved names
public enum Enum {
foo, bar, // non-reserved
name, arguments, caller // reserved
};
}