blob: 2d4585208ecda65423efdf6024c714f2912a569e [file] [log] [blame]
/*********************************************************************
* Copyright (c) 2008 The University of York.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.epsilon.eol.dom;
import org.eclipse.epsilon.eol.exceptions.EolRuntimeException;
import org.eclipse.epsilon.eol.execute.context.IEolContext;
public class OrOperatorExpression extends OperatorExpression {
public OrOperatorExpression() {}
public OrOperatorExpression(Expression firstOperand, Expression secondOperand) {
super(firstOperand, secondOperand);
}
@Override
public Object execute(IEolContext context) throws EolRuntimeException {
Object o1 = context.getExecutorFactory().execute(firstOperand,context);
if (o1 instanceof Boolean) {
Boolean b1 = (Boolean) o1;
if (b1.booleanValue() == true) {
return true;
}
else {
Object o2 = context.getExecutorFactory().execute(secondOperand,context);
if (o2 instanceof Boolean){
return (Boolean) o2;
}
else {
throw new EolRuntimeException("Operator 'or' applies only to operands of type Boolean", this);
}
}
}
else {
throw new EolRuntimeException("Operator 'or' applies only to operands of type Boolean", this);
}
}
}