-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathClass.java
More file actions
348 lines (304 loc) · 13.1 KB
/
Class.java
File metadata and controls
348 lines (304 loc) · 13.1 KB
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*
* Copyright (c) 2012, Codename One and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Codename One designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Codename One through http://www.codenameone.com/ if you
* need additional information or have any questions.
*/
package java.lang;
import java.lang.annotation.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
/**
* Instances of the class Class represent classes and interfaces in a running
* Java application. Every array also belongs to a class that is reflected as a
* Class object that is shared by all arrays with the same element type and
* number of dimensions. Class has no public constructor. Instead Class objects
* are constructed automatically by the Java Virtual Machine as classes are
* loaded. The following example uses a Class object to print the class name of
* an object: Since: JDK1.0, CLDC 1.0
*/
public final class Class<T> implements java.lang.reflect.Type {
public ClassLoader getClassLoader() {
return ClassLoader.getSystemClassLoader();
}
/**
* Returns the Class object associated with the class with the given string
* name. Given the fully-qualified name for a class or interface, this
* method attempts to locate, load and link the class. For example, the
* following code fragment returns the runtime Class descriptor for the
* class named java.lang.Thread: Classt= Class.forName("java.lang.Thread")
*/
public static java.lang.Class forName(java.lang.String className) throws java.lang.ClassNotFoundException {
className = className.replace('$', '.');
Class c = forNameImpl(className);
if(c == null) {
throw new ClassNotFoundException(className);
}
return c;
}
private native static java.lang.Class forNameImpl(java.lang.String className) throws java.lang.ClassNotFoundException;
/**
* Returns the fully-qualified name of the entity (class, interface, array
* class, primitive type, or void) represented by this Class object, as a
* String. If this Class object represents a class of arrays, then the
* internal form of the name consists of the name of the element type in
* Java signature format, preceded by one or more "[" characters
* representing the depth of array nesting. Thus: (new
* Object[3]).getClass().getName() returns "[Ljava.lang.Object;" and: (new
* int[3][4][5][6][7][8][9]).getClass().getName() returns "[[[[[[[I". The
* encoding of element type names is as follows: B byte C char D double F
* float I int J long L class or interface S short Z boolean The class or
* interface name is given in fully qualified form as shown in the example
* above.
*/
public native java.lang.String getName();/* {
if (this.name == null) {
String name = getNameImpl();
if (name.endsWith("[]")) {
String componentType = name.substring(name.indexOf("["));
int dimension = (name.length() - componentType.length())/2;
String type = null;
StringBuilder sb = new StringBuilder();
while (dimension-- > 0) {
sb.append("[");
}
if (componentType.indexOf(".") != -1) {
sb.append("L").append(componentType).append(";");
} else if ("int".equals(componentType)) {
sb.append("I");
} else if ("float".equals(componentType)) {
sb.append("F");
} else if ("boolean".equals(componentType)) {
sb.append("Z");
} else if ("byte".equals(componentType)) {
sb.append("B");
} else if ("char".equals(componentType)) {
sb.append("C");
} else if ("short".equals(componentType)) {
sb.append("S");
} else if ("long".equals(componentType)) {
sb.append("J");
} else if ("double".equals(componentType)) {
sb.append("D");
} else {
sb.append(name);
}
this.name = sb.toString();
} else {
this.name = name;
}
}
return this.name;
}
native java.lang.String getNameImpl();
*/
/**
* Finds a resource with a given name in the application's JAR file. This
* method returns null if no resource with this name is found in the
* application's JAR file. The resource names can be represented in two
* different formats: absolute or relative. Absolute format:
* /packagePathName/resourceName Relative format: resourceName In the
* absolute format, the programmer provides a fully qualified name that
* includes both the full path and the name of the resource inside the JAR
* file. In the path names, the character "/" is used as the separator. In
* the relative format, the programmer provides only the name of the actual
* resource. Relative names are converted to absolute names by the system by
* prepending the resource name with the fully qualified package name of
* class upon which the getResourceAsStream method was called.
*/
public java.io.InputStream getResourceAsStream(java.lang.String name){
return null;
}
/**
* Determines if this Class object represents an array class.
*/
public native boolean isArray();
/**
* Determines if the class or interface represented by this Class object is
* either the same as, or is a superclass or superinterface of, the class or
* interface represented by the specified Class parameter. It returns true
* if so; otherwise it returns false. If this Class object represents a
* primitive type, this method returns true if the specified Class parameter
* is exactly this Class object; otherwise it returns false. Specifically,
* this method tests whether the type represented by the specified Class
* parameter can be converted to the type represented by this Class object
* via an identity conversion or via a widening reference conversion. See
* The Java Language Specification, sections 5.1.1 and 5.1.4 , for details.
*/
public native boolean isAssignableFrom(java.lang.Class cls);
/**
* Determines if the specified Object is assignment-compatible with the
* object represented by this Class. This method is the dynamic equivalent
* of the Java language instanceof operator. The method returns true if the
* specified Object argument is non-null and can be cast to the reference
* type represented by this Class object without raising a
* ClassCastException. It returns false otherwise. Specifically, if this
* Class object represents a declared class, this method returns true if the
* specified Object argument is an instance of the represented class (or of
* any of its subclasses); it returns false otherwise. If this Class object
* represents an array class, this method returns true if the specified
* Object argument can be converted to an object of the array class by an
* identity conversion or by a widening reference conversion; it returns
* false otherwise. If this Class object represents an interface, this
* method returns true if the class or any superclass of the specified
* Object argument implements this interface; it returns false otherwise. If
* this Class object represents a primitive type, this method returns false.
*/
public native boolean isInstance(java.lang.Object obj);
/**
* Determines if the specified Class object represents an interface type.
*/
public native boolean isInterface();
/**
* Creates a new instance of a class.
*/
public java.lang.Object newInstance() throws java.lang.InstantiationException, java.lang.IllegalAccessException {
Object o = newInstanceImpl();
if(o == null) {
throw new InstantiationException();
}
return o;
}
private native java.lang.Object newInstanceImpl();
/**
* Converts the object to a string. The string representation is the string
* "class" or "interface", followed by a space, and then by the fully
* qualified name of the class in the format returned by getName. If this
* Class object represents a primitive type, this method returns the name of
* the primitive type. If this Class object represents void this method
* returns "void".
*/
public java.lang.String toString() {
return getName() + " class";
}
public native boolean isAnnotation();
/**
* Returns this element's annotation for the specified type if such an
* annotation is present, else null.
*
*/
public <T extends Annotation> T getAnnotation(Class annotationType) {
if (annotationType == null) {
throw new NullPointerException("Null annotationType");
}
return null;
}
/**
* Returns all annotations present on this element.
*/
public Annotation[] getAnnotations() {
return null;
}
/**
* Returns all annotations that are directly present on this element.
*/
public Annotation[] getDeclaredAnnotations() {
return null;
}
/**
* Returns true if an annotation for the specified type is present on this
* element, else false.
*/
public boolean isAnnotationPresent(Class annotationType) {
return false;
}
/**
* Replacement for Class.asSubclass(Class).
*
* @param c a Class
* @param superclass another Class which must be a superclass of <i>c</i>
* @return <i>c</i>
* @throws java.lang.ClassCastException if <i>c</i> is
*/
public Class asSubclass(Class superclass) {
return null;
}
/**
* Replacement for Class.cast(Object). Throws a ClassCastException if
* <i>obj</i>
* is not an instance of class <var>c</var>, or a subtype of <var>c</var>.
*
* @param c Class we want to cast <var>obj</var> to
* @param object object we want to cast
* @return The object, or <code>null</code> if the object is
* <code>null</code>.
* @throws java.lang.ClassCastException if <var>obj</var> is not
* <code>null</code> or an instance of <var>c</var>
*/
public Object cast(Object object) {
if (object == null) {
return null;
}
if (!isAssignableFrom(object.getClass())) {
throw new java.lang.ClassCastException("Cannot cast "+object.getClass()+" to "+this);
}
return object;
}
/**
* Replacement for Class.isEnum().
*
* @param class_ class we want to test.
* @return true if the class was declared as an Enum.
*/
public native boolean isEnum();
/**
* replacement for Class.isAnonymousClass()
*/
public native boolean isAnonymousClass();
/**
* replacement for Class.getSimpleName()
*/
public String getSimpleName() {
String n = getName();
return n.substring(n.lastIndexOf('.') + 1);
}
/**
* replacement for Class.isSynthetic()
*/
public native boolean isSynthetic();
public String getCanonicalName() {
return getName();
}
@Override
public native int hashCode();
@Override
public boolean equals(Object obj) {
return this == obj;
}
public boolean desiredAssertionStatus() {
return false;
}
public native Class getComponentType();
public java.lang.reflect.Type[] getGenericInterfaces() {
throw new UnsupportedOperationException("Class.getGenericInterfaces() not supported on this platform");
}
public native boolean isPrimitive();
public Method getEnclosingMethod() {
return null;
}
public Constructor getEnclosingConstructor() {
return null;
}
public boolean isLocalClass() {
return false;
}
public boolean isRecord() {
return this != java.lang.Record.class && java.lang.Record.class.isAssignableFrom(this);
}
}