Skip to content

Commit 91adc23

Browse files
hansonrhansonr
authored andcommitted
adds Class.getConstructors()
1 parent dda5491 commit 91adc23

File tree

1 file changed

+50
-6
lines changed
  • sources/net.sf.j2s.java.core/src/java/lang

1 file changed

+50
-6
lines changed

sources/net.sf.j2s.java.core/src/java/lang/Class.java

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,7 @@ public Method[] getMethods() throws SecurityException {
17711771
* @since JDK1.1
17721772
*/
17731773
public Constructor<?>[] getConstructors() throws SecurityException {
1774-
return null;// TODO
1774+
return /*copyMethods*/(privateGetConstructors());
17751775
// // be very careful not to change the stack depth of this
17761776
// // checkMemberAccess call for security reasons
17771777
// // see java.lang.SecurityManager.checkMemberAccess
@@ -2043,12 +2043,7 @@ public Method getMethod(String name, Class<?>... paramTypes) throws NoSuchMethod
20432043
* @since JDK1.1
20442044
*/
20452045
public Constructor<T> getConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
2046-
// be very careful not to change the stack depth of this
2047-
// checkMemberAccess call for security reasons
2048-
// see java.lang.SecurityManager.checkMemberAccess
2049-
// checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader());
20502046
return new Constructor(this, parameterTypes, new Class<?>[0], Member.PUBLIC);
2051-
// return getConstructor0(parameterTypes, Member.PUBLIC);
20522047
}
20532048

20542049
/**
@@ -3111,6 +3106,7 @@ private Method[] privateGetPublicMethods(boolean isAll) {
31113106

31123107
return ms;
31133108

3109+
31143110
// checkInitted();
31153111
// Method[] res = null;
31163112
// if (useCaches) {
@@ -3172,6 +3168,54 @@ private Method[] privateGetPublicMethods(boolean isAll) {
31723168
// return res;
31733169
}
31743170

3171+
3172+
public Constructor[] $constructors$;
3173+
3174+
3175+
// Returns an array of "root" methods. These Method objects must NOT
3176+
// be propagated to the outside world, but must instead be copied
3177+
// via ReflectionFactory.copyMethod.
3178+
private Constructor[] privateGetConstructors() {
3179+
Constructor[] ms;
3180+
if ($constructors$ != null) {
3181+
// interface hack
3182+
ms = new Constructor[$constructors$.length];
3183+
for (int i = ms.length; --i >= 0;) {
3184+
ms[i] = new Constructor(this, $constructors$[i].getParameterTypes(), null, java.lang.reflect.Modifier.PUBLIC);
3185+
}
3186+
return ms;
3187+
}
3188+
3189+
ms = new Constructor[0];
3190+
String attr = null;
3191+
Object o = null;
3192+
/**
3193+
* @j2sNative
3194+
*
3195+
*
3196+
* var p = this.$clazz$;
3197+
*
3198+
* for (attr in p) { o = p[attr]; if (
3199+
* typeof o == "function"
3200+
* && o.exName && o.exName.startsWith("c$")
3201+
* && !o.__CLASS_NAME__
3202+
* && (o.exClazz == this.$clazz$)
3203+
* ) {
3204+
*/
3205+
3206+
Constructor m = new Constructor(this, UNKNOWN_PARAMETERS, null, Modifier.PUBLIC);
3207+
m._setJSMethod(o, Modifier.PUBLIC);
3208+
3209+
/**
3210+
* @j2sNative
3211+
*
3212+
* ms.push(m);
3213+
* }}
3214+
*/
3215+
3216+
return ms;
3217+
}
3218+
31753219
// //
31763220
// // Helpers for fetchers of one field, method, or constructor
31773221
// //

0 commit comments

Comments
 (0)