static boolean booleanUnaryOperation(Boolean B, int kind) throws UtilEvalError { boolean operand = B.booleanValue(); switch(kind) { case BANG: return !operand; } throw new UtilEvalError("Operator inappropriate for boolean"); }
public boolean booleanValue() throws UtilEvalError { if(value instanceof Boolean) return((Boolean)value).booleanValue(); throw new UtilEvalError("Primitive not a boolean"); }
public static boolean booleanUnaryOperation(Boolean B, int kind) throws UtilEvalError { boolean operand = B.booleanValue(); switch(kind) { case BANG: return !operand; default: throw new UtilEvalError("Operator inappropriate for boolean"); } }
public int intValue() throws UtilEvalError { if(value instanceof Number) return((Number)value).intValue(); else throw new UtilEvalError("Primitive not a number"); }
public boolean booleanValue() throws UtilEvalError { if(value instanceof Boolean) return((Boolean)value).booleanValue(); else throw new UtilEvalError("Primitive not a boolean"); }
public int intValue() throws UtilEvalError { if(value instanceof Number) return((Number)value).intValue(); throw new UtilEvalError("Primitive not a number"); }
public Number numberValue() throws UtilEvalError { Object value = this.value; // Promote character to Number type for these purposes if (value instanceof Character) value = new Integer(((Character)value).charValue()); if (value instanceof Number) return (Number)value; else throw new UtilEvalError("Primitive not a number"); }
private Object unaryOperation( Object op, int kind ) throws UtilEvalError { if ( op instanceof Boolean ) op = (Boolean) op ? Primitive.TRUE : Primitive.FALSE; if ( !(op instanceof Primitive) ) throw new UtilEvalError( "Unary operation " + tokenImage[kind] + " inappropriate for object" ); return Operators.unaryOperation((Primitive) op, kind); }
static UtilEvalError castError( String lhs, String rhs, int operation ) { if ( operation == ASSIGNMENT ) return new UtilEvalError ( "Can't assign " + rhs + " to "+ lhs ); Exception cce = new ClassCastException( "Cannot cast " + rhs + " to " + lhs ); return new UtilTargetError( cce ); }
public static UtilEvalError castError( String lhs, String rhs, int operation ) { if ( operation == ASSIGNMENT ) return new UtilEvalError ( "Can't assign " + rhs + " to "+ lhs ); Exception cce = new ClassCastException( "Cannot cast " + rhs + " to " + lhs ); return new UtilTargetError( cce ); }
Object getClassInstance() throws UtilEvalError { if ( classInstance != null ) return classInstance; if ( classStatic != null //|| ( getParent()!=null && getParent().classStatic != null ) ) throw new UtilEvalError( "Can't refer to class instance from static context."); else throw new InterpreterError( "Can't resolve class instance 'this' in: "+this); }
/** Gets the class instance. * @return the class instance * @throws UtilEvalError the util eval error */ Object getClassInstance() throws UtilEvalError { if (this.classInstance != null) return this.classInstance; if (this.classStatic != null // || (getParent()!=null && getParent().classStatic != null) ) throw new UtilEvalError( "Can't refer to class instance from static context."); else throw new InterpreterError( "Can't resolve class instance 'this' in: " + this); } // End instance data
private static void checkFoundStaticMethod(Method method, boolean staticOnly, Class clas) throws UtilEvalError { // We're looking for a static method but found an instance method if (method != null && staticOnly && !isStatic(method)) { throw new UtilEvalError("Cannot reach instance method: " + StringUtil.methodString(method.getName(), method.getParameterTypes()) + " from static context: " + clas.getName()); } }
private Object operation( Object lhs, Object rhs, int kind ) throws UtilEvalError { if ( lhs instanceof String || lhs.getClass().isArray() ) return Operators.arbitraryObjectsBinaryOperation(lhs, rhs, kind); if ( rhs == Primitive.NULL ) throw new UtilEvalError( "Illegal use of null object or 'null' literal" ); if ( (lhs instanceof Boolean || lhs instanceof Character || lhs instanceof Number || lhs instanceof Primitive) && (rhs instanceof Boolean || rhs instanceof Character || rhs instanceof Number || rhs instanceof Primitive) ) { return Operators.binaryOperation(lhs, rhs, kind); } throw new UtilEvalError("Non primitive value in operator: " + lhs.getClass() + " " + tokenImage[kind] + " " + rhs.getClass() ); } }
public Object unaryOperation( Object op, int kind ) throws UtilEvalError { if (op instanceof Boolean || op instanceof Character || op instanceof Number) return primitiveWrapperUnaryOperation( op, kind ); if ( !(op instanceof Primitive) ) throw new UtilEvalError( "Unary operation " + tokenImage[kind] + " inappropriate for object" ); return Primitive.unaryOperation((Primitive)op, kind); }
public static void setObjectProperty(Object obj, String propName, Object value) throws ReflectError, UtilEvalError { String accessorName = accessorName("set", propName); Object[] args = new Object[]{value}; Interpreter.debug("property access: "); try { Method method = resolveExpectedJavaMethod(null/*bcm*/, obj.getClass(), obj, accessorName, args, false); invokeMethod(method, obj, args); } catch (InvocationTargetException e) { throw new UtilEvalError("Property accessor threw exception: " + e.getTargetException()); } }
private static void checkFoundStaticMethod( Invocable method, boolean staticOnly, Class<?> clas ) throws UtilEvalError { // We're looking for a static method but found an instance method if ( method != null && staticOnly && !method.isStatic() ) throw new UtilEvalError( "Cannot reach instance method: " + StringUtil.methodString( method.getName(), method.getParameterTypes() ) + " from static context: "+ clas.getName() ); }
/** Concatenate two arrays. * @param lhs 1st array * @param rhs 2nd array * @return a new array instance of concatenated contents. * @throws UtilEvalError for inconsistent dimensions. */ public static Object concat(Object lhs, Object rhs) throws UtilEvalError { Class<?> lhsType = lhs.getClass(); Class<?> rhsType = rhs.getClass(); if ( Types.arrayDimensions(lhsType) != Types.arrayDimensions(rhsType) ) throw new UtilEvalError("Cannot concat arrays with inconsistent dimensions." + " Attempting to concat array of type " + StringUtil.typeString(lhs) + " with array of type " + StringUtil.typeString(rhs) + "."); Class<?> toType = Types.getCommonType( Types.arrayElementType(lhsType), Types.arrayElementType(rhsType)); int[] dims = dimensions(lhs); dims[0] = Array.getLength(lhs) + Array.getLength(rhs); Object toArray = Array.newInstance(toType, dims); copy(toType, toArray, lhs, rhs); return toArray; }
public static Object binaryOperationImpl( Object lhs, Object rhs, int kind ) throws UtilEvalError { if(lhs instanceof Boolean) return booleanBinaryOperation((Boolean)lhs, (Boolean)rhs, kind); else if(lhs instanceof Integer) return intBinaryOperation( (Integer)lhs, (Integer)rhs, kind ); else if(lhs instanceof Long) return longBinaryOperation((Long)lhs, (Long)rhs, kind); else if(lhs instanceof Float) return floatBinaryOperation((Float)lhs, (Float)rhs, kind); else if(lhs instanceof Double) return doubleBinaryOperation( (Double)lhs, (Double)rhs, kind); else throw new UtilEvalError("Invalid types in binary operator" ); }
@SuppressWarnings("unchecked") static <T> Object binaryOperationImpl( T lhs, T rhs, int kind ) throws UtilEvalError { if (lhs instanceof Boolean) return booleanBinaryOperation( (Boolean) lhs, (Boolean) rhs, kind ); if (COMPARABLE_OPS.contains(kind)) return comparableBinaryBooleanOperations((Comparable<T>) lhs, rhs, kind); if (lhs instanceof BigInteger) return bigIntegerBinaryOperation( (BigInteger) lhs, (BigInteger) rhs, kind ); if (lhs instanceof BigDecimal) return bigDecimalBinaryOperation( (BigDecimal) lhs, (BigDecimal) rhs, kind ); if (Types.isFloatingpoint(lhs)) return doubleBinaryOperation( (Double) lhs, (Double) rhs, kind ); if (lhs instanceof Number) return longBinaryOperation( (Long) lhs, (Long) rhs, kind ); throw new UtilEvalError("Invalid types in binary operator" ); }