Search in sources :

Example 21 with DataKinds

use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.

the class MathInterpreterVisitor method visit.

@Override
public void visit(Or entity) {
    boolean value = false;
    for (int i = 0, size = entity.size(); i < size; i++) {
        IEntity result = evaluate(entity.get(i));
        DataKinds dataKinds = DataTypeUtils.getUnboxedDataKind(result);
        if (dataKinds.isNotAData())
            throw new WholeIllegalArgumentException(WholeMessages.no_data).withSourceEntity(entity).withBindings(getBindings());
        else if (!dataKinds.isBoolean())
            throw new WholeIllegalArgumentException(WholeMessages.illegal_data_conversion).withSourceEntity(entity).withBindings(getBindings());
        else if (value |= result.wBooleanValue())
            break;
    }
    setResult(createBooleanLiteral(value));
}
Also used : IEntity(org.whole.lang.model.IEntity) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) DataKinds(org.whole.lang.reflect.DataKinds)

Example 22 with DataKinds

use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.

the class MathInterpreterVisitor method visit.

@Override
public void visit(And entity) {
    boolean value = true;
    for (int i = 0, size = entity.size(); i < size; i++) {
        IEntity result = evaluate(entity.get(i));
        DataKinds dataKinds = DataTypeUtils.getUnboxedDataKind(result);
        if (dataKinds.isNotAData())
            throw new WholeIllegalArgumentException(WholeMessages.no_data).withSourceEntity(entity).withBindings(getBindings());
        else if (!dataKinds.isBoolean())
            throw new WholeIllegalArgumentException(WholeMessages.illegal_data_conversion).withSourceEntity(entity).withBindings(getBindings());
        else if (!(value &= result.wBooleanValue()))
            break;
    }
    setResult(createBooleanLiteral(value));
}
Also used : IEntity(org.whole.lang.model.IEntity) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) DataKinds(org.whole.lang.reflect.DataKinds)

Aggregations

DataKinds (org.whole.lang.reflect.DataKinds)22 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)17 IEntity (org.whole.lang.model.IEntity)12 IDataTypeParser (org.whole.lang.parsers.IDataTypeParser)3 ArrayList (java.util.ArrayList)1 EnumValue (org.whole.lang.model.EnumValue)1