package rapanui.dsl;

import org.eclipse.emf.ecore.util.EcoreUtil;

public abstract class Builder {
	public static Formula reverse(Formula input) {
		return createFormula(input.getRight(), input.getFormulaType(), input.getLeft());
	}

	/**
	* NOTE: this method copies the input terms!
	*/
	public static Formula createEquation(Term left, Term right) {
		return createFormula(left, BINARY_RELATION.EQUATION, right);
	}

	/**
	* NOTE: this method copies the input terms!
	*/
	public static Formula createInclusion(Term left, Term right) {
		return createFormula(left, BINARY_RELATION.INCLUSION, right);
	}

	/**
	* NOTE: this method copies the input terms!
	*/
	public static Formula createFormula(Term left, BINARY_RELATION type, Term right) {
		assert left != null;
		assert right != null;

		Formula output = DslFactory.eINSTANCE.createFormula();
		output.setLeft(EcoreUtil.copy(left));
		output.setRight(EcoreUtil.copy(right));
		output.setFormulaType(type);
		return output;
	}

	/**
	* NOTE: this method copies the input term!
	*/
	public static DefinitionReference createDefinitionReference(Term target, Definition definition) {
		assert target != null;
		assert definition != null;

		DefinitionReference reference = DslFactory.eINSTANCE.createDefinitionReference();
		reference.setTarget(EcoreUtil.copy(target));
		reference.setDefinition(definition);
		return reference;
	}

	/**
	* NOTE: this method copies the input terms!
	*/
	public static BinaryOperation createBinaryOperation(Term left, BINARY_OPERATOR operator, Term right) {
		assert left != null;
		assert operator != null;
		assert right != null;

		BinaryOperation output = DslFactory.eINSTANCE.createBinaryOperation();
		output.setLeft(EcoreUtil.copy(left));
		output.setOperator(operator);
		output.setRight(EcoreUtil.copy(right));
		return output;
	}

	/**
	* NOTE: this method copies the input term!
	*/
	public static UnaryOperation createUnaryOperation(Term operand, POSTFIX_UNARY_OPERATOR operator) {
		assert operand != null;
		assert operator != null;

		UnaryOperation output = DslFactory.eINSTANCE.createUnaryOperation();
		output.setOperand(EcoreUtil.copy(operand));
		output.setOperator(operator);
		return output;
	}
}

@@ -740,56 +740,8 @@
 ) %7B%0A
-%09%09assert left != null;%0A%09%09assert right != null;%0A%0A
 %09%09Fo
@@ -1490,83 +1490,8 @@
 ) %7B%0A
-%09%09assert left != null;%0A%09%09assert operator != null;%0A%09%09assert right != null;%0A%0A
 %09%09Bi
@@ -1851,62 +1851,8 @@
 ) %7B%0A
-%09%09assert operand != null;%0A%09%09assert operator != null;%0A%0A
 %09%09Un

allow creation of Formula and Term with null values