4242import java .util .Arrays ;
4343import java .util .Enumeration ;
4444import java .util .HashMap ;
45+ import java .util .HashSet ;
4546import java .util .LinkedHashMap ;
4647import java .util .List ;
4748import java .util .Map ;
@@ -450,6 +451,8 @@ public boolean isInstance(Object obj) {
450451 */
451452 @ SuppressWarnings ("unused" )
452453 public boolean isAssignableFrom (Class <?> cls ) {
454+ if (cls == null )
455+ return false ;
453456 Object a = cls .$clazz$ ;
454457 Object me = $clazz$ ;
455458 return /** @j2sNative Clazz.instanceOf(a, me) || */ false ;
@@ -689,6 +692,8 @@ public String getName() {
689692 // cache the name to reduce the number of calls into the VM
690693 private transient String name ;
691694 private Field [] fields ;
695+ private Class <?>[] implementz ;
696+ private int modifiers = -1 ;
692697
693698 private String getName0 () {
694699 String code = "" ;
@@ -928,23 +933,22 @@ public Class<? super T> getSuperclass() {
928933// }
929934
930935 /**
931- * Determines the interfaces implemented by the class or interface
932- * represented by this object.
936+ * Determines the interfaces implemented by the class or interface represented
937+ * by this object.
933938 *
934939 * <p>
935- * If this object represents a class, the return value is an array
936- * containing objects representing all interfaces implemented by the class.
937- * The order of the interface objects in the array corresponds to the order
938- * of the interface names in the {@code implements} clause of the
939- * declaration of the class represented by this object. For example, given
940- * the declaration: <blockquote> {@code class Shimmer implements FloorWax,
941- * DessertTopping { ... }} </blockquote> suppose the value of {@code s} is
942- * an instance of {@code Shimmer}; the value of the expression: <blockquote>
943- * {@code s.getClass().getInterfaces()[0]} </blockquote> is the
944- * {@code Class} object that represents interface {@code FloorWax}; and the
945- * value of: <blockquote> {@code s.getClass().getInterfaces()[1]}
946- * </blockquote> is the {@code Class} object that represents interface
947- * {@code DessertTopping}.
940+ * If this object represents a class, the return value is an array containing
941+ * objects representing all interfaces implemented by the class. The order of
942+ * the interface objects in the array corresponds to the order of the interface
943+ * names in the {@code implements} clause of the declaration of the class
944+ * represented by this object. For example, given the declaration: <blockquote>
945+ * {@code class Shimmer implements FloorWax, DessertTopping { ... }}
946+ * </blockquote> suppose the value of {@code s} is an instance of
947+ * {@code Shimmer}; the value of the expression: <blockquote>
948+ * {@code s.getClass().getInterfaces()[0]} </blockquote> is the {@code Class}
949+ * object that represents interface {@code FloorWax}; and the value of:
950+ * <blockquote> {@code s.getClass().getInterfaces()[1]} </blockquote> is the
951+ * {@code Class} object that represents interface {@code DessertTopping}.
948952 *
949953 * <p>
950954 * If this object represents an interface, the array contains objects
@@ -954,19 +958,33 @@ public Class<? super T> getSuperclass() {
954958 * represented by this object.
955959 *
956960 * <p>
957- * If this object represents a class or interface that implements no
958- * interfaces, the method returns an array of length 0.
961+ * If this object represents a class or interface that implements no interfaces,
962+ * the method returns an array of length 0.
959963 *
960964 * <p>
961965 * If this object represents a primitive type or void, the method returns an
962966 * array of length 0.
963967 *
964968 * @return an array of interfaces implemented by this class.
965969 */
970+ @ SuppressWarnings ("unused" )
966971 public Class <?>[] getInterfaces () {
967- JSUtil .notImplemented (null );
968- return new Class <?>[0 ];
969- }
972+ if (implementz == null ) {
973+ Class <?>[] a = new Class <?>[0 ];
974+ Object me = $clazz$ ;
975+ Class <?>[] list = /** @j2sNative me.implementz || */ null ;
976+ if (list != null ) {
977+ for (int i = 0 , n = list .length ; i < n ; i ++) {
978+ /**
979+ * @j2sNative a.push(Clazz.getClass(list[i]));
980+ */
981+ }
982+ }
983+ implementz = a ;
984+ }
985+ return implementz ;
986+ }
987+
970988
971989// /**
972990// * Returns the {@code Type}s representing the interfaces directly
@@ -1065,11 +1083,18 @@ public Class<?> getComponentType() {
10651083 * @see java.lang.reflect.Modifier
10661084 * @since JDK1.1
10671085 */
1068- @ SuppressWarnings ("unused" )
10691086 public int getModifiers () {
1070- return Modifier .PUBLIC
1087+ return ( modifiers >= 0 ? modifiers : Modifier .PUBLIC
10711088 | (isEnum () ? ENUM : isInterface () ? Modifier .INTERFACE : 0 )
1072- | (isAnnotation () ? ANNOTATION : 0 );
1089+ | (isAnnotation () ? ANNOTATION : 0 ));
1090+ }
1091+
1092+ /**
1093+ * From AnnotationParser.JSAnnotationObject
1094+ * @param m
1095+ */
1096+ public void _setModifiers (int m ) {
1097+ modifiers = m ;
10731098 }
10741099
10751100 /**
@@ -1542,33 +1567,36 @@ private boolean isLocalOrAnonymousClass() {
15421567 * @since JDK1.1
15431568 */
15441569 public Class <?>[] getClasses () {
1545- return null ;
1546- // // be very careful not to change the stack depth of this
1547- // // checkMemberAccess call for security reasons
1548- // // see java.lang.SecurityManager.checkMemberAccess
1549- //// checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader());
1550- //
1551- // // Privileged so this implementation can look at DECLARED classes,
1552- // // something the caller might not have privilege to do. The code here
1553- // // is allowed to look at DECLARED classes because (1) it does not hand
1554- // // out anything other than public members and (2) public member access
1555- // // has already been ok'd by the SecurityManager.
1556- //
1557- // Class[] result = (Class[]) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
1570+ // be very careful not to change the stack depth of this
1571+ // checkMemberAccess call for security reasons
1572+ // see java.lang.SecurityManager.checkMemberAccess
1573+ // checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader());
1574+
1575+ // Privileged so this implementation can look at DECLARED classes,
1576+ // something the caller might not have privilege to do. The code here
1577+ // is allowed to look at DECLARED classes because (1) it does not hand
1578+ // out anything other than public members and (2) public member access
1579+ // has already been ok'd by the SecurityManager.
1580+
1581+ // Class[] result;
1582+ // (Class[]) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
15581583// public Object run() {
1559- // java.util.List<Class> list = new java.util.ArrayList();
1560- // Class currentClass = Class.this;
1561- // while (currentClass != null) {
1562- // Class[] members = currentClass.getDeclaredClasses();
1563- // for (int i = 0; i < members.length; i++) {
1564- // if (Modifier.isPublic(members[i].getModifiers())) {
1565- // list.add(members[i]);
1566- // }
1567- // }
1568- // currentClass = currentClass.getSuperclass();
1569- // }
1584+ java .util .List <Class > list = new java .util .ArrayList ();
1585+ Class currentClass = this ;
1586+ while (currentClass != null ) {
1587+ Class [] members = currentClass .getDeclaredClasses ();
1588+ for (int i = 0 ; i < members .length ; i ++) {
1589+ //if (Modifier.isPublic(members[i].getModifiers())) {
1590+ // public only
1591+ list .add (members [i ]);
1592+ //}
1593+ }
1594+ currentClass = currentClass .getSuperclass ();
1595+ }
15701596// Class[] empty = {};
1571- // return list.toArray(empty);
1597+ // result =
1598+
1599+ return list .toArray (new Class [list .size ()]);
15721600// }
15731601// });
15741602//
@@ -2044,12 +2072,11 @@ public Constructor<T> getConstructor(Class<?>... parameterTypes) throws NoSuchMe
20442072 * @since JDK1.1
20452073 */
20462074 public Class <?>[] getDeclaredClasses () throws SecurityException {
2047- return getClasses ();
20482075// // be very careful not to change the stack depth of this
20492076// // checkMemberAccess call for security reasons
20502077// // see java.lang.SecurityManager.checkMemberAccess
20512078//// checkMemberAccess(Member.DECLARED, ClassLoader.getCallerClassLoader());
2052- // return getDeclaredClasses0();
2079+ return getDeclaredClasses0 ();
20532080 }
20542081
20552082 /**
@@ -2179,6 +2206,9 @@ public Method[] getDeclaredMethods() throws SecurityException {
21792206 */
21802207 public Constructor <?>[] getDeclaredConstructors () throws SecurityException {
21812208 return getConstructors ();
2209+
2210+ // TODO
2211+
21822212// // be very careful not to change the stack depth of this
21832213// // checkMemberAccess call for security reasons
21842214// // see java.lang.SecurityManager.checkMemberAccess
@@ -3021,12 +3051,11 @@ private Method[] privateGetPublicMethods() {
30213051 * @j2sNative
30223052 *
30233053 *
3024- * var p = this.$clazz$.prototype;
3054+ * var p = this.$clazz$.prototype;
30253055 *
3026- * for (attr in p) { o = p[attr]; if (o.exName && typeof
3027- * o == "function" && o.exName && !o.__CLASS_NAME__ &&
3028- * o != this.$clazz$[attr] && o.exClazz == this.$clazz$)
3029- * { // there are polynormical methods.
3056+ * for (attr in p) { o = p[attr]; if (typeof o == "function" &&
3057+ * o.exName && !o.__CLASS_NAME__ && o != this.$clazz$[attr] &&
3058+ * o.exClazz == this.$clazz$) { // there are polynormical methods.
30303059 */
30313060
30323061 Method m = new Method (this , attr , NO_PARAMETERS , Void .class , NO_PARAMETERS , Modifier .PUBLIC );
@@ -3277,7 +3306,10 @@ private static boolean arrayContentsEq(Object[] a1, Object[] a2) {
32773306//
32783307// private native Constructor[] getDeclaredConstructors0(boolean publicOnly);
32793308//
3280- // private native Class[] getDeclaredClasses0();
3309+ private //native
3310+ Class [] getDeclaredClasses0 () {
3311+ return AnnotationParser .JSAnnotationObject .getDeclaredClasses (this .$clazz$ );
3312+ }
32813313//
32823314// private static String argumentTypesToString(Class[] argTypes) {
32833315// StringBuilder buf = new StringBuilder();
@@ -3705,10 +3737,12 @@ public boolean equals(Object o) {
37053737 /**
37063738 * @j2sNative
37073739 *
3708- * return o.__CLASS_NAME__ == "java.lang.Class" && o.$clazz$ == this.$clazz$;
3740+ * return o && o .__CLASS_NAME__ == "java.lang.Class" && o.$clazz$ == this.$clazz$;
37093741 *
37103742 */
3743+ {
37113744 return false ;
3745+ }
37123746 }
37133747
37143748 /**
0 commit comments