blob: 1b112659ed086bef81e178ba9046efc6cb7d3489 [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;
import org.eclipse.epsilon.eol.types.NumberUtil;
public class DivOperatorExpression extends EagerOperatorExpression {
public DivOperatorExpression() {}
public DivOperatorExpression(Expression firstOperand, Expression secondOperand) {
super(firstOperand, secondOperand);
}
@Override
public Object execute(Object o1, Object o2, IEolContext context) throws EolRuntimeException {
if (o1 instanceof Number && o2 instanceof Number){
return NumberUtil.divide((Number) o1, (Number) o2);
}
throw new EolRuntimeException("Cannot divide " + context.getPrettyPrinterManager().toString(o1) + " by " + context.getPrettyPrinterManager().toString(o2));
}
}