예제 #1
0
  protected void evaluateNode(OOEEEvaluationContext context) throws EvaluationException {
    try {
      getValueClass();
    } catch (ParsingException e) {
      throw new EvaluationException(ExceptionConstants.EBOS_000, e);
    }

    ExpressionNode expr = getChild(1);

    expr.evaluate(context);

    Object valueObject = context.stackPop();

    if (ExpressionUtil.isNumeric(valueClass)) {
      try {
        valueObject = ExpressionUtil.getNumericReturnObject(valueObject, valueClass);
      } catch (ParsingException e) {
        throw new EvaluationException(ExceptionConstants.EBOS_000, e);
      }
    } else if (ExpressionUtil.isReferenceType(valueClass)) {
      if (valueObject != null && !valueClass.isAssignableFrom(valueObject.getClass())) {
        throw new EvaluationException(
            ExceptionConstants.EBOS_OOEE_006, new Object[] {valueObject.getClass(), valueClass});
      }
    }

    context.stackPush(valueObject);
  }
예제 #2
0
  public Class checkType(OOEEParsingContext context) throws ParsingException {
    ExpressionNode type = getChild(0);

    setValueClass(type.checkType(context));

    ExpressionNode expr = getChild(1);

    Class fromClass = expr.checkType(context);

    if (!ExpressionUtil.isCastableFrom(valueClass, fromClass)) {
      throw new ParsingException(
          ExceptionConstants.EBOS_OOEE_070, new Object[] {fromClass, valueClass});
      //  throw new ParsingException("inconvertable cast from class " + fromClass + " to " +
      // valueClass);
    }

    // optimization code
    if (valueClass.isPrimitive() && expr.isConstant()) {
      super.isConstant = true;

      Object constantValue = expr.getConstantValue();

      if (ExpressionUtil.isNumeric(valueClass)) {
        constantValue = ExpressionUtil.getNumericReturnObject(constantValue, valueClass);
      }

      super.setConstantValue(constantValue);
    } else {
      super.isConstant = false;
    }

    // fix bug
    if (expr instanceof FieldExpression && parent instanceof FieldExpression) {
      boolean isClass = ((FieldExpression) expr).isClass();
      ((FieldExpression) parent).setIsClass(isClass);
    }

    return valueClass;
  }