/** Get the Java types of the arguments. * @param args object array of argument values. * @return class array of argument types. */ public static Class<?>[] getTypes( Object[] args ) { if ( args == null ) return Reflect.ZERO_TYPES; Class<?>[] types = new Class[ args.length ]; for( int i=0; i < args.length; i++ ) types[i] = getType(args[i]); return types; }
/** Find the type of an object. * @param arg the object to query. * @return null if arg null, getType if Primitive or getClass. */ public static Class<?> getType( Object arg ) { return getType(arg, false); }
public Class<?> getType() { if ( null != field ) return field.getReturnType(); if ( null != var ) return var.getType(); try { return Types.getType(getValue()); } catch ( UtilEvalError e ) { return null; } }
Class<?> fromType = getType(fromValue);
public Object invoke(final Map<String, ?> context) throws EvalError { final NameSpace nameSpace = new NameSpace("BeanshellExecutable", _interpreter.getClassManager()); nameSpace.setParent(_interpreter.getNameSpace()); final BshMethod method = new BshMethod(_method.getName(), _method.getReturnType(), _method.getParameterNames(), _method.getParameterTypes(), _method.getParameterModifiers(), _method.methodBody, nameSpace, _method.getModifiers()); for (final Map.Entry<String, ?> entry : context.entrySet()) { try { final Object value = entry.getValue(); nameSpace.setVariable(entry.getKey(), value != null ? value : Primitive.NULL, false); } catch (final UtilEvalError e) { throw new EvalError("cannot set variable '" + entry.getKey() + '\'', null, null, e); } } final Object result = method.invoke(Reflect.ZERO_ARGS, _interpreter); if ( Types.getType(result) == Void.TYPE ) return null; return Primitive.unwrap(result); }
/** Helper function to traverse array dimensions to find the common type. * Recursive calling for each element in an array initializer or finds the * common type relative to a value cell. * @param common the current common type * @param node the node to query * @param callstack the evaluation call stack * @param interpreter the evaluation interpreter * @return the common type for all cells * @throws EvalError thrown at node evaluation */ private Class<?> inferCommonType(Class<?> common, Node node, CallStack callstack, Interpreter interpreter ) throws EvalError { // Object is already the most common type and maps are typed LHS.MapEntry if ( Object.class == common || LHS.MapEntry.class == common ) return common; // inspect value elements for common type if ( !(node instanceof BSHArrayInitializer) ) { Object value = ((SimpleNode) node).eval(callstack, interpreter); Class<?> type = Types.getType(value, Primitive.isWrapperType(common)); return Types.getCommonType(common, Types.arrayElementType(type)); } // avoid traversing maps as arrays when nested in array if ( isMapInArray((BSHArrayInitializer) node) ) return Types.getCommonType(common, Map.class); // recurse through nested array initializer nodes int count = node.jjtGetNumChildren(); for ( int i = 0; i < count; i++ ) common = this.inferCommonType(common, node.jjtGetChild(i), callstack, interpreter); return common; }
dimensions += Types.arrayDimensions(Types.getType(ot));