Search in sources :

Example 6 with FormulaSemantics

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());
    }
}
Also used : FormulaSemantics(pcgen.base.formula.base.FormulaSemantics) SemanticsVisitor(pcgen.base.formula.visitor.SemanticsVisitor)

Example 7 with FormulaSemantics

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");
    }
}
Also used : FormulaSemantics(pcgen.base.formula.base.FormulaSemantics) SemanticsVisitor(pcgen.base.formula.visitor.SemanticsVisitor)

Example 8 with FormulaSemantics

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");
    }
}
Also used : FormulaSemantics(pcgen.base.formula.base.FormulaSemantics) SimpleNode(pcgen.base.formula.parse.SimpleNode) SemanticsVisitor(pcgen.base.formula.visitor.SemanticsVisitor) Test(org.junit.Test)

Example 9 with FormulaSemantics

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;
}
Also used : FormulaSemantics(pcgen.base.formula.base.FormulaSemantics)

Aggregations

FormulaSemantics (pcgen.base.formula.base.FormulaSemantics)9 SemanticsVisitor (pcgen.base.formula.visitor.SemanticsVisitor)8 Test (org.junit.Test)4 SimpleNode (pcgen.base.formula.parse.SimpleNode)4 VariableID (pcgen.base.formula.base.VariableID)3 VariableLibrary (pcgen.base.formula.base.VariableLibrary)3 LegalScope (pcgen.base.formula.base.LegalScope)2 ScopeInstance (pcgen.base.formula.base.ScopeInstance)2 ReconstructionVisitor (pcgen.base.formula.visitor.ReconstructionVisitor)2 Equipment (pcgen.core.Equipment)2 ConsolidatedListCommitStrategy (pcgen.rules.context.ConsolidatedListCommitStrategy)2 LoadContext (pcgen.rules.context.LoadContext)2 RuntimeLoadContext (pcgen.rules.context.RuntimeLoadContext)2 RuntimeReferenceContext (pcgen.rules.context.RuntimeReferenceContext)2 WriteableVariableStore (pcgen.base.formula.base.WriteableVariableStore)1 ColumnFormatFactory (pcgen.cdom.format.table.ColumnFormatFactory)1 DataTable (pcgen.cdom.format.table.DataTable)1 TableFormatFactory (pcgen.cdom.format.table.TableFormatFactory)1