felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From db...@apache.org
Subject svn commit: r950110 - /felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java
Date Tue, 01 Jun 2010 15:17:49 GMT
Author: dbaum
Date: Tue Jun  1 15:17:48 2010
New Revision: 950110

URL: http://svn.apache.org/viewvc?rev=950110&view=rev
Log:
better message/exception when arguments can't be coerced (FELIX-2375)

Modified:
    felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java?rev=950110&r1=950109&r2=950110&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java (original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/Reflective.java Tue
Jun  1 15:17:48 2010
@@ -99,19 +99,16 @@ public final class Reflective
                 }
 
                 // Check if the command takes a session
-                if ((types.length > 0) && CommandSession.class.isAssignableFrom(types[0]))
+                if ((types.length > 0) && types[0].isInterface()
+                    && types[0].isAssignableFrom(session.getClass()))
                 {
                     xargs.add(0, session);
                 }
 
                 Object[] parms = new Object[types.length];
-                // if (types.length >= args.size() ) {
                 int local = coerce(session, target, m, types, parms, xargs);
                 if ((local >= xargs.size()) && (local >= types.length))
-                { // derek
-                    // -
-                    // stop
-                    // no-args
+                {
                     boolean exact = ((local == xargs.size()) && (local == types.length));
                     if (exact || (local > match))
                     {
@@ -128,21 +125,12 @@ public final class Reflective
                 {
                     possibleTypes.add(types);
                 }
-                // }
-                // if (match == -1 && types.length == 1
-                // && types[0] == Object[].class) {
-                // bestMethod = m;
-                // Object value = args.toArray();
-                // bestArgs = new Object[] { value };
-                // }
             }
         }
 
         if (bestMethod != null)
         {
             bestMethod.setAccessible(true);
-            // derek: BUGFIX catch InvocationTargetException
-            // return bestMethod.invoke(target, bestArgs);
             try
             {
                 return bestMethod.invoke(target, bestArgs);
@@ -159,9 +147,6 @@ public final class Reflective
         }
         else
         {
-            // throw new IllegalArgumentException("Cannot find command:" + name
-            // + " with args:" + args);
-            // { derek
             ArrayList<String> list = new ArrayList<String>();
             for (Class<?>[] types : possibleTypes)
             {
@@ -179,9 +164,18 @@ public final class Reflective
                 list.add(buf.toString());
             }
 
+            StringBuilder params = new StringBuilder();
+            for (Object arg : args)
+            {
+                if (params.length() > 1)
+                {
+                    params.append(", ");
+                }
+                params.append(arg.getClass().getSimpleName());
+            }
+
             throw new IllegalArgumentException(String.format(
-                "Cannot coerce %s%s to any of %s", name, args, list));
-            // } derek
+                "Cannot coerce %s(%s) to any of %s", name, params, list));
         }
     }
 
@@ -215,7 +209,8 @@ public final class Reflective
                 if (as[a] instanceof Parameter)
                 {
                     Parameter o = (Parameter) as[a];
-                    out[argIndex] = coerce(session, target, types[argIndex], o.absentValue());
+                    out[argIndex] = coerce(session, target, types[argIndex],
+                        o.absentValue());
                     start = argIndex + 1;
                 }
             }
@@ -273,8 +268,6 @@ public final class Reflective
             try
             {
                 // Try to convert one argument
-                // derek: add empty array as extra argument
-                // out[i] = coerce(session, target, types[i], in.get(i));
                 if (in.size() == 0)
                 {
                     out[i] = NO_MATCH;



Mime
View raw message