emul/src/main/java/java/lang/reflect/Method.java
branchlauncher
changeset 354 002b7c3d5157
parent 266 2e2e6f946208
child 355 eea0065bcc1a
     1.1 --- a/emul/src/main/java/java/lang/reflect/Method.java	Wed Dec 05 10:03:58 2012 +0100
     1.2 +++ b/emul/src/main/java/java/lang/reflect/Method.java	Wed Dec 19 16:43:37 2012 +0100
     1.3 @@ -137,7 +137,24 @@
     1.4       * @return the return type for the method this object represents
     1.5       */
     1.6      public Class<?> getReturnType() {
     1.7 -        throw new UnsupportedOperationException();
     1.8 +        switch (sig.charAt(0)) {
     1.9 +            case 'I': return Integer.TYPE;
    1.10 +            case 'J': return Long.TYPE;
    1.11 +            case 'D': return Double.TYPE;
    1.12 +            case 'F': return Float.TYPE;
    1.13 +            case 'B': return Byte.TYPE;
    1.14 +            case 'Z': return Boolean.TYPE;
    1.15 +            case 'S': return Short.TYPE;
    1.16 +//            case 'V': return Void.TYPE;
    1.17 +            case 'L': try {
    1.18 +                int up = sig.indexOf("_2");
    1.19 +                String type = sig.substring(1, up);
    1.20 +                return Class.forName(type);
    1.21 +            } catch (ClassNotFoundException ex) {
    1.22 +                // should not happen
    1.23 +            }
    1.24 +        }
    1.25 +        throw new UnsupportedOperationException(sig);
    1.26      }
    1.27  
    1.28      /**
    1.29 @@ -488,17 +505,33 @@
    1.30       * @exception ExceptionInInitializerError if the initialization
    1.31       * provoked by this method fails.
    1.32       */
    1.33 +    public Object invoke(Object obj, Object... args)
    1.34 +        throws IllegalAccessException, IllegalArgumentException,
    1.35 +           InvocationTargetException
    1.36 +    {
    1.37 +        Object res = invoke0(this, obj, args);
    1.38 +        if (getReturnType().isPrimitive()) {
    1.39 +            res = fromPrimitive(getReturnType(), res);
    1.40 +        }
    1.41 +        return res;
    1.42 +    }
    1.43 +    
    1.44      @JavaScriptBody(args = { "method", "self", "args" }, body =
    1.45            "if (args.length > 0) throw 'unsupported now';"
    1.46          + "return method.fld_data(self);"
    1.47      )
    1.48 -    public Object invoke(Object obj, Object... args)
    1.49 -        throws IllegalAccessException, IllegalArgumentException,
    1.50 -           InvocationTargetException
    1.51 -    {
    1.52 -        throw new UnsupportedOperationException();
    1.53 +    private static native Object invoke0(Method m, Object self, Object[] args);
    1.54 +
    1.55 +    private static Object fromPrimitive(Class<?> type, Object o) {
    1.56 +        if (type == Integer.TYPE) {
    1.57 +            return fromInteger(o);
    1.58 +        }
    1.59 +        return o;
    1.60      }
    1.61 -
    1.62 +    
    1.63 +    @JavaScriptBody(args = "o", body = "return vm.java_lang_Integer(false).valueOf__Ljava_lang_Integer_2I(o);")
    1.64 +    private static native Integer fromInteger(Object o);
    1.65 +    
    1.66      /**
    1.67       * Returns {@code true} if this method is a bridge
    1.68       * method; returns {@code false} otherwise.