fixed tibdoc
[sbp.git] / src / edu / berkeley / sbp / util / Reflection.java
index cf683f0..de614d0 100644 (file)
@@ -23,10 +23,16 @@ public final class Reflection {
             }
             if (c == String.class) {
                 boolean ok = true;
-                for(int i=0; i<a.length; i++) if (a[i]==null || !(a[i] instanceof Character)) ok = false;
+                for(int i=0; i<a.length; i++)
+                    if (a[i]==null || (!(a[i] instanceof Character) && !(a[i] instanceof String)))
+                        ok = false;
                 if (ok) {
                     StringBuffer s = new StringBuffer();
-                    for(int i=0; i<a.length; i++) s.append((((Character)a[i])).charValue());
+                    for(int i=0; i<a.length; i++)
+                        s.append(a[i] instanceof Character
+                                 ? (((Character)a[i]).charValue())+""
+                                 : (String)a[i]
+                                 );
                     return s.toString();
                 }
             }
@@ -44,10 +50,18 @@ public final class Reflection {
         return (Object[])Array.newInstance(c, i);
     }
 
+    public static Object lub(Object argo) {
+        if (argo instanceof Object[]) return lub((Object[])argo);
+        return argo;
+    }
     public static Object[] lub(Object[] argo) {
         if (argo==null) return null;
         Class c = null;
-        for(Object o : argo) if (o != null) c = Reflection.lub(c, o.getClass());
+        for(int i=0; i<argo.length; i++) {
+            if (argo[i]==null) continue;
+            argo[i] = lub(argo[i]);
+            c = Reflection.lub(c, argo[i].getClass());
+        }
         if (c==null) c = Object.class;
         Object[] ret = Reflection.newArray(c, argo.length);
         System.arraycopy(argo, 0, ret, 0, argo.length);
@@ -60,9 +74,15 @@ public final class Reflection {
         if (a==b) return a;
         if (a.isAssignableFrom(b)) return a;
         if (b.isAssignableFrom(a)) return b;
+        if (a.isArray() && b.isArray())
+            return arrayClass(lub(a.getComponentType(), b.getComponentType()));
         return lub(b, a.getSuperclass());
     }
 
+    public static Class arrayClass(Class c) {
+        return Reflection.newArray(c, 0).getClass();
+    }
+
     /** a version of <tt>Class.forName</tt> that returns <tt>null</tt> instead of throwing an exception */
     public static Class forNameOrNull(String s) {
         try {
@@ -72,6 +92,7 @@ public final class Reflection {
         }
     }
 
+    public static Object fuzzyInvoke(Object o, Member m) { return fuzzyInvoke(o, m, new Object[0]); }
     /** invoke method/constructor m on object o with arguments args, and perform reasonable coercions as needed */
     public static Object fuzzyInvoke(Object o, Member m, Object[] args) {
         try {