@@ -646,6 +646,7 @@ public String getName() {
646646
647647 // cache the name to reduce the number of calls into the VM
648648 private transient String name ;
649+ private Field [] fields ;
649650
650651 private String getName0 () {
651652 String code = "" ;
@@ -1534,12 +1535,15 @@ public Class<?>[] getClasses() {
15341535 * @since JDK1.1
15351536 */
15361537 public Field [] getFields () throws SecurityException {
1537- return null ;
1538- // // be very careful not to change the stack depth of this
1539- // // checkMemberAccess call for security reasons
1540- // // see java.lang.SecurityManager.checkMemberAccess
1541- //// checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader());
1542- // return copyFields(privateGetPublicFields(null));
1538+ if (fields != null )
1539+ return fields ;
1540+ fields = new Field [0 ];
1541+ int _static = Modifier .STATIC ;
1542+ Object cl = /** @j2sNative this.$clazz$ || */ null ;
1543+ Object proto = /** @j2sNative cl.prototype || */ null ;
1544+ addFields (proto , this .fields , 0 );
1545+ addFields (cl , this .fields , _static );
1546+ return fields ;
15431547 }
15441548
15451549 /**
@@ -1686,10 +1690,13 @@ public Constructor<?>[] getConstructors() throws SecurityException {
16861690 * @since JDK1.1
16871691 */
16881692 public Field getField (String name ) throws NoSuchFieldException , SecurityException {
1689- // TODO
1690- {
1691- return null ;
1693+ getFields ();
1694+ for (int i = fields .length ; --i >= 0 ;) {
1695+ if (fields [i ].jsName == name )
1696+ return fields [i ];
16921697 }
1698+ throw new NoSuchFieldException ("field " + name );
1699+
16931700// // be very careful not to change the stack depth of this
16941701// // checkMemberAccess call for security reasons
16951702// // see java.lang.SecurityManager.checkMemberAccess
@@ -1701,6 +1708,46 @@ public Field getField(String name) throws NoSuchFieldException, SecurityExceptio
17011708// return field;
17021709 }
17031710
1711+ private void addFields (Object c , Field [] f , int modifiers ) {
1712+ String m = null ;
1713+ /**
1714+ * @j2sNative
1715+ *
1716+ * for (m in c) {
1717+ * if (!modifiers && this.$clazz$[m])
1718+ * continue;
1719+ * if (this.excludeField$S(m)) continue;
1720+ * var o = c[m];
1721+ * switch (typeof o) {
1722+ * case "object": if (o.__CLASS_NAME__) continue;
1723+ * case "number": case "boolean": case "string":
1724+ */
1725+
1726+ addField (f , m , modifiers );
1727+
1728+ /**
1729+ * @j2sNative
1730+ * break;
1731+ * }
1732+ * }
1733+ */
1734+
1735+ }
1736+
1737+ private boolean excludeField (String name ) {
1738+ return (name == "prototype" || name .startsWith ("__" ));
1739+ }
1740+
1741+ private void addField (Field [] fields , String m , int modifiers ) {
1742+
1743+ @ SuppressWarnings ("unused" )
1744+ Field f = new Field (this , m , modifiers );
1745+ /**
1746+ * @j2sNative
1747+ *
1748+ * fields.push(f);
1749+ */
1750+ }
17041751 /**
17051752 * Returns a {@code Method} object that reflects the specified public member
17061753 * method of the class or interface represented by this {@code Class}
@@ -1781,15 +1828,32 @@ public Method getMethod(String name, Class<?>... paramTypes) throws NoSuchMethod
17811828 // see java.lang.SecurityManager.checkMemberAccess
17821829// checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader());
17831830
1784- /**
1785- * @j2sNative
1786- *
1787- * return Clazz.new_(java.lang.reflect.Method.c$$Class$S$ClassA$Class$ClassA$I, [this, name,
1788- * paramTypes, java.lang.Void, [], 0]);
1789- */
1790- {
1791- return null ;
1831+ // note that we cannot check the method at this time, as it could be an interface,
1832+ // and interfaces will not have elaborated methods.
1833+
1834+ Method m = new Method (this , name , paramTypes , null , null , 0 );
1835+ if (!isInterface ()) {
1836+ Object o = null ;
1837+ String qname = name + argumentTypesToString (paramTypes );
1838+ /**
1839+ * @j2sNative
1840+ *
1841+ * o = this.$clazz$;
1842+ * o = o[qname] || o.prototype && o.prototype[qname];
1843+ */
1844+ if (o == null )
1845+ throw new NoSuchMethodException (getName () + "." + qname );
17921846 }
1847+ return m ;
1848+ // /**
1849+ // * @j2sNative
1850+ // *
1851+ // * return Clazz.new_(Clazz.load('java.lang.reflect.Method').c$$Class$S$ClassA$Class$ClassA$I, [this, name,
1852+ // * paramTypes, java.lang.Void, [], 0]);
1853+ // */
1854+ // {
1855+ // return null;
1856+ // }
17931857//
17941858//
17951859//
@@ -3094,6 +3158,20 @@ private static boolean arrayContentsEq(Object[] a1, Object[] a2) {
30943158// return buf.toString();
30953159// }
30963160
3161+ /**
3162+ * Java2Script style here
3163+ *
3164+ * @param parameterTypes
3165+ * @return
3166+ */
3167+ public static String argumentTypesToString (Class <?>[] parameterTypes ) {
3168+ String s = "" ;
3169+ if (parameterTypes != null )
3170+ for (int i = 0 ; i < parameterTypes .length ; i ++)
3171+ s += "$" + /** @j2sNative Clazz._getParamCode(parameterTypes[i]) || */ null ;
3172+ return s ;
3173+ }
3174+
30973175// /** use serialVersionUID from JDK 1.1 for interoperability */
30983176 private static final long serialVersionUID = 3206093459760846163L ;
30993177//
@@ -3452,4 +3530,20 @@ public boolean equals(Object o) {
34523530 */
34533531 return false ;
34543532 }
3533+
3534+ /**
3535+ * A SwingJS method for Constructor and Method
3536+ *
3537+ * @param parameterTypes
3538+ * @param args
3539+ * @return
3540+ */
3541+ public static Object [] getArgumentArray (Class <?>[] types , Object [] args , boolean isProxy ) {
3542+ Object [] a = new Object [args == null ? 0 : args .length ];
3543+ if (args != null && (types != null || isProxy ))
3544+ for (int i = args .length ; --i >= 0 ;)
3545+ a [i ] = (isProxy ? args [i ] : /** @j2sNative (types[i].__PRIMITIVE && args[i].valueOf ? args[i].valueOf() : args[i]) || */ null );
3546+ return a ;
3547+ }
3548+
34553549}
0 commit comments