@Override @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (ReflectionUtils.isEqualsMethod(method)) { return (isProxyForSameBshObject(args[0])); } else if (ReflectionUtils.isHashCodeMethod(method)) { return this.xt.hashCode(); } else if (ReflectionUtils.isToStringMethod(method)) { return "BeanShell object [" + this.xt + "]"; } try { Object result = this.xt.invokeMethod(method.getName(), args); if (result == Primitive.NULL || result == Primitive.VOID) { return null; } if (result instanceof Primitive) { return ((Primitive) result).getValue(); } return result; } catch (EvalError ex) { throw new BshExecutionException(ex); } }
@Override @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (ReflectionUtils.isEqualsMethod(method)) { return (isProxyForSameBshObject(args[0])); } else if (ReflectionUtils.isHashCodeMethod(method)) { return this.xt.hashCode(); } else if (ReflectionUtils.isToStringMethod(method)) { return "BeanShell object [" + this.xt + "]"; } try { Object result = this.xt.invokeMethod(method.getName(), args); if (result == Primitive.NULL || result == Primitive.VOID) { return null; } if (result instanceof Primitive) { return ((Primitive) result).getValue(); } return result; } catch (EvalError ex) { throw new BshExecutionException(ex); } }
/** Unwrap primitive values and map voids to nulls. Non Primitive types remain unchanged. @param obj object type which may be bsh.Primitive @return corresponding "normal" Java type, "unwrapping" any bsh.Primitive types to their wrapper types. */ public static Object unwrap( Object obj ) { // map voids to nulls for the outside world if (obj == Primitive.VOID) return null; // unwrap primitives if (obj instanceof Primitive) return((Primitive)obj).getValue(); return obj; }
/** Unwrap primitive values and map voids to nulls. Non Primitive types remain unchanged. @param obj object type which may be bsh.Primitive @return corresponding "normal" Java type, "unwrapping" any bsh.Primitive types to their wrapper types. */ public static Object unwrap( Object obj ) { // map voids to nulls for the outside world if (obj == Primitive.VOID) return null; // unwrap primitives if (obj instanceof Primitive) return((Primitive)obj).getValue(); else return obj; }
@Override @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (ReflectionUtils.isEqualsMethod(method)) { return (isProxyForSameBshObject(args[0])); } else if (ReflectionUtils.isHashCodeMethod(method)) { return this.xt.hashCode(); } else if (ReflectionUtils.isToStringMethod(method)) { return "BeanShell object [" + this.xt + "]"; } try { Object result = this.xt.invokeMethod(method.getName(), args); if (result == Primitive.NULL || result == Primitive.VOID) { return null; } if (result instanceof Primitive) { return ((Primitive) result).getValue(); } return result; } catch (EvalError ex) { throw new BshExecutionException(ex); } }
public static boolean evaluateCondition( SimpleNode condExp, BshEvaluatingVisitor visitor) throws EvalError { CallStack callstack = visitor.getCallstack(); Interpreter interpreter = visitor.getInterpreter(); Object obj = condExp.accept(visitor); if(obj instanceof Primitive) { if ( obj == Primitive.VOID ) throw new EvalError("Condition evaluates to void type", condExp, callstack ); obj = ((Primitive)obj).getValue(); } if(obj instanceof Boolean) return ((Boolean)obj).booleanValue(); else throw new EvalError( "Condition must evaluate to a Boolean or boolean.", condExp, callstack ); }
return Primitive.shrinkWrap( result ); return Primitive.shrinkWrap( result ).getValue();
public Object invoke(final Map<String, ?> context) throws EvalError { final NameSpace nameSpace = new NameSpace(_interpreter.getClassManager(), "BeanshellExecutable"); nameSpace.setParent(_interpreter.getNameSpace()); final BshMethod method = new BshMethod(_method.getName(), _method.getReturnType(), _method.getParameterNames(), _method.getParameterTypes(), _method.methodBody, nameSpace, _method.getModifiers()); for (final Map.Entry<String, ?> entry : context.entrySet()) { try { nameSpace.setVariable(entry.getKey(), entry.getValue(), false); } catch (final UtilEvalError e) { throw new EvalError("cannot set variable '" + entry.getKey() + '\'', null, null, e); } } final Object result = method.invoke(new Object[0], new BshEvaluatingVisitor(null, _interpreter)); if (result instanceof Primitive) { if (( (Primitive) result).getType() == Void.TYPE) { return null; } return ( (Primitive) result).getValue(); } return result; }
((Primitive)val).getValue() : val;
/** 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));
Object obj = lhs; if ( node.isPrimitiveValue(lhs) ) obj = ((Primitive)lhs).getValue(); if ( obj instanceof Boolean && ( ((Boolean)obj).booleanValue() == false ) ) Object obj = lhs; if ( node.isPrimitiveValue(lhs) ) obj = ((Primitive)lhs).getValue(); if ( obj instanceof Boolean && ( ((Boolean)obj).booleanValue() == true ) )
value = fromValue.getValue();
new Primitive( castWrapper(toType, fromValue.getValue()) );
.castToType(Types.Suffix.getIntegralType(ch), 0); else jjtn000.value = Primitive.shrinkWrap(parseIntegral(literal).getValue()); } catch ( NumberFormatException e ) { throw createParseException( e.getMessage(), e );
Object operand = promoteToInteger(val.getValue());