public static Object [] wrap( Object[] args, Class<?> [] paramTypes ) { if ( args == null ) return null; Object [] oa = new Object[ args.length ]; for(int i=0; i<args.length; i++) oa[i] = wrap( args[i], paramTypes[i] ); return oa; }
public static Object [] wrap( Object[] args, Class [] paramTypes ) { if ( args == null ) return null; Object [] oa = new Object[ args.length ]; for(int i=0; i<args.length; i++) oa[i] = wrap( args[i], paramTypes[i] ); return oa; }
Object getValue() throws UtilEvalError { if ( lhs != null ) return type == null ? lhs.getValue() : Primitive.wrap( lhs.getValue(), type ); return value; }
private static Object getFieldValue(Class clas, Object object, String fieldName, boolean staticOnly) throws UtilEvalError, ReflectError { try { Field f = resolveExpectedJavaField(clas, fieldName, staticOnly); Object value = f.get(object); Class returnType = f.getType(); return Primitive.wrap(value, returnType); } catch (NullPointerException e) { // shouldn't happen throw new ReflectError("???" + fieldName + " is not a static field."); } catch (IllegalAccessException e) { throw new ReflectError("Can't access field: " + fieldName); } }
public static Object getIndex(Object array, int index) throws ReflectError, UtilTargetError { if (Interpreter.DEBUG) { Interpreter.debug("getIndex: " + array + ", index=" + index); } try { Object val = Array.get(array, index); return Primitive.wrap(val, array.getClass().getComponentType()); } catch (ArrayIndexOutOfBoundsException e1) { throw new UtilTargetError(e1); } catch (Exception e) { throw new ReflectError("Array access:" + e); } }
/** Abstraction to cleanly apply the primitive result wrapping. * @param base represents the base object instance. * @param pars parameter arguments * @return invocation result * @throws InvocationTargetException wrapped target exceptions */ public synchronized Object invoke(Object base, Object... pars) throws InvocationTargetException { if (null == pars) pars = Reflect.ZERO_ARGS; try { return Primitive.wrap( invokeTarget(base, pars), getReturnType()); } catch (Throwable ite) { throw new InvocationTargetException(ite); } }
/** Get object from array or list at index. * @param array to retrieve from * @param index of the element to retrieve * @return Array.get for array or List.get for list * @throws UtilTargetError wrapped Index out of bounds */ public static Object getIndex(Object array, int index) throws UtilTargetError { Interpreter.debug("getIndex: ", array, ", index=", index); try { if ( array instanceof List ) return ((List<?>) array).get(index); Object val = Array.get(array, index); return Primitive.wrap( val, Types.arrayElementType(array.getClass()) ); } catch( IndexOutOfBoundsException e1 ) { int len = array instanceof List ? ((List<?>) array).size() : Array.getLength(array); throw new UtilTargetError("Index " + index + " out-of-bounds for length " + len, e1); } }
invokeMethod( methodName, Primitive.wrap(args, paramTypes) ) );
invokeMethod( methodName, Primitive.wrap(args, paramTypes) ) );
return Primitive.wrap(returnValue, returnType); } catch (IllegalAccessException e) { throw new ReflectError("Cannot access method " + StringUtil.methodString(method.getName(), method.getParameterTypes()) + " in '" + method.getDeclaringClass() + "' :" + e, e);
return (Primitive) Primitive.wrap(result, result.getClass()); else return Primitive.shrinkWrap( result );
public Object getValue() throws UtilEvalError { if ( type == VARIABLE ) return nameSpace.getVariable( varName ); if (type == FIELD) try { Object o = field.get( object ); return Primitive.wrap( o, field.getType() ); } catch(IllegalAccessException e2) { throw new UtilEvalError("Can't read field: " + field); } if ( type == PROPERTY ) try { return Reflect.getObjectProperty(object, propName); } catch(ReflectError e) { Interpreter.debug(e.getMessage()); throw new UtilEvalError("No such property: " + propName); } if ( type == INDEX ) try { return Reflect.getIndex(object, index); } catch(Exception e) { throw new UtilEvalError("Array access: " + e); } throw new InterpreterError("LHS type"); }
/** Specialty invoke for field access invocable types. * Based on arguments supplied infer get or set operation. * {@inheritDoc} */ @Override public synchronized Object invoke(Object base, Object... pars) throws InvocationTargetException { try { if (0 == pars.length) { // getter if (isStatic()) return Primitive.wrap( getMethodHandle().invoke(), getReturnType()); return Primitive.wrap( getMethodHandle().invoke(base), getReturnType()); } else { // setter if (isStatic()) return getSetterHandle().invoke(super.coerceToType( pars[0], getParameterTypes()[0])); return getSetterHandle().invoke(base, super.coerceToType( pars[0], getParameterTypes()[0])); } } catch (Throwable ite) { throw new InvocationTargetException(ite.getCause()); } }
/** Helper class for type suffixes. */ public static class Suffix { private static final Map<String, Class<?>> m = Collections.unmodifiableMap(new HashMap<String, Class<?>>() { private static final long serialVersionUID = 1L; { put("O", Byte.TYPE); put("S", Short.TYPE); put("I", Integer.TYPE); put("L", Long.TYPE); put("W", BigInteger.class); put("w", BigDecimal.class); put("d", Double.TYPE); put("f", Float.TYPE); } }); private static String toUpperKey(Character key) { return key.toString().toUpperCase(); } private static String toLowerKey(Character key) { return key.toString().toLowerCase(); } public static boolean isIntegral(Character key) { return m.containsKey(toUpperKey(key)); } public static Class<?> getIntegralType(Character key) { return m.get(toUpperKey(key));
primFromValue = (Primitive)Primitive.wrap( fromValue, unboxedFromType );