Beispiel #1
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;
  }