use of pcgen.base.formula.base.FormulaSemantics in project pcgen by PCGen.
the class AbstractFormulaTestCase method isValid.
public void isValid(String formula, SimpleNode node, FormatManager<?> formatManager, Class<?> assertedFormat) {
SemanticsVisitor semanticsVisitor = new SemanticsVisitor();
FormulaSemantics semantics = managerFactory.generateFormulaSemantics(localSetup.getFormulaManager(), getGlobalScope(), assertedFormat);
semanticsVisitor.visit(node, semantics);
if (!semantics.isValid()) {
TestCase.fail("Expected Valid Formula: " + formula + " but was told: " + semantics.getReport());
}
}
use of pcgen.base.formula.base.FormulaSemantics in project pcgen by PCGen.
the class AbstractFormulaTestCase method isNotValid.
protected void isNotValid(String formula, SimpleNode node, FormatManager<?> formatManager, Class<?> assertedFormat) {
SemanticsVisitor semanticsVisitor = new SemanticsVisitor();
FormulaSemantics semantics = managerFactory.generateFormulaSemantics(localSetup.getFormulaManager(), getGlobalScope(), assertedFormat);
semanticsVisitor.visit(node, semantics);
if (semantics.isValid()) {
TestCase.fail("Expected Invalid Formula: " + formula + " but was valid");
}
}
use of pcgen.base.formula.base.FormulaSemantics in project pcgen by PCGen.
the class DropIntoContextFunctionTest method testInvalidWrongFormat3.
@Test
public void testInvalidWrongFormat3() {
String formula = "dropIntoContext(\"EQUIPMENT\", \"EquipKey\",\"Stuff\")";
SimpleNode node = TestUtilities.doParse(formula);
SemanticsVisitor semanticsVisitor = new SemanticsVisitor();
FormulaSemantics semantics = generateFormulaSemantics(getFormulaManager(), getGlobalScope(), null);
Object result = semanticsVisitor.visit(node, semantics);
if (semantics.isValid() && (result instanceof Number)) {
TestCase.fail("Expected Invalid Formula: " + formula + " but was valid");
}
}
use of pcgen.base.formula.base.FormulaSemantics in project pcgen by PCGen.
the class FormulaFactory method getValidFormula.
/**
* Returns a "valid" NEPFormula for the given expression.
*
* If the given expression does not represent a valid formula, then this
* will throw an IllegalArgumentException.
*
* If the given expression does not return an object of the type in the
* given FormatManager, then this will throw an IllegalArgumentException.
*
* @param expression
* The String representation of the formula to be converted to a
* NEPFormula
* @param managerFactory
* The ManagerFactory to be used for building the FormulaSemantics
* @param formulaManager
* The FormulaManager to be used for validating the NEPExpression
* @param varScope
* The LegalScope in which the NEPFormula is established and
* checked
* @param formatManager
* The FormatManager in which the NEPFormula is established and
* checked
* @return a "valid" NEPFormula for the given expression
*/
public static <T> NEPFormula<T> getValidFormula(String expression, ManagerFactory managerFactory, FormulaManager formulaManager, LegalScope varScope, FormatManager<T> formatManager) {
NEPFormula<T> formula = getNEPFormulaFor(formatManager, expression);
FormulaSemantics semantics = managerFactory.generateFormulaSemantics(formulaManager, varScope, formatManager.getManagedClass());
formula.isValid(formatManager, semantics);
if (!semantics.isValid()) {
throw new IllegalArgumentException("Cannot create a Formula from: " + expression + ", due to: " + semantics.getReport() + " with format " + formatManager.getIdentifierType());
}
return formula;
}
Aggregations