Search in sources :

Example 1 with FormulaManager

use of pcgen.base.formula.base.FormulaManager in project pcgen by PCGen.

the class DropIntoContext method evaluateFromObject.

private Object evaluateFromObject(EvaluateVisitor visitor, String legalScopeName, VarScoped vs, Node node, EvaluationManager manager) {
    FormulaManager fm = manager.get(EvaluationManager.FMANAGER);
    ScopeInstanceFactory siFactory = fm.getScopeInstanceFactory();
    ScopeInstance scopeInst = siFactory.get(legalScopeName, vs);
    //Rest of Equation
    return node.jjtAccept(visitor, manager.getWith(EvaluationManager.INSTANCE, scopeInst));
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) FormulaManager(pcgen.base.formula.base.FormulaManager) ScopeInstanceFactory(pcgen.base.formula.inst.ScopeInstanceFactory)

Example 2 with FormulaManager

use of pcgen.base.formula.base.FormulaManager in project pcgen by PCGen.

the class DropIntoContext method allowFromScopeName.

private FormatManager<?> allowFromScopeName(SemanticsVisitor visitor, FormulaSemantics semantics, String legalScopeName, Node node) {
    FormulaManager fm = semantics.get(FormulaSemantics.FMANAGER);
    ScopeInstanceFactory siFactory = fm.getScopeInstanceFactory();
    LegalScope legalScope = siFactory.getScope(legalScopeName);
    if (legalScope == null) {
        semantics.setInvalid("Parse Error: Invalid Scope Name: " + legalScopeName + " is not a valid scope name");
        return null;
    }
    //Rest of Equation
    semantics = semantics.getWith(FormulaSemantics.FMANAGER, fm);
    semantics = semantics.getWith(FormulaSemantics.SCOPE, legalScope);
    FormatManager<?> format = (FormatManager<?>) node.jjtAccept(visitor, semantics);
    return format;
}
Also used : FormulaManager(pcgen.base.formula.base.FormulaManager) LegalScope(pcgen.base.formula.base.LegalScope) FormatManager(pcgen.base.util.FormatManager) ScopeInstanceFactory(pcgen.base.formula.inst.ScopeInstanceFactory)

Example 3 with FormulaManager

use of pcgen.base.formula.base.FormulaManager in project pcgen by PCGen.

the class LookupFunction method evaluate.

@Override
public Object evaluate(EvaluateVisitor visitor, Node[] args, EvaluationManager manager) {
    //Table name node (must be a Table)
    DataTable dataTable = (DataTable) args[0].jjtAccept(visitor, manager.getWith(EvaluationManager.ASSERTED, DATATABLE_CLASS));
    FormatManager<?> lookupFormat = dataTable.getFormat(0);
    //Lookup value (format based on the table)
    @SuppressWarnings("PMD.PrematureDeclaration") Object lookupValue = args[1].jjtAccept(visitor, manager.getWith(EvaluationManager.ASSERTED, lookupFormat.getManagedClass()));
    //Result Column Name (must be a tableColumn)
    TableColumn column = (TableColumn) args[2].jjtAccept(visitor, manager.getWith(EvaluationManager.ASSERTED, COLUMN_CLASS));
    String columnName = column.getName();
    if (!dataTable.isColumn(columnName)) {
        FormatManager<?> fmt = column.getFormatManager();
        System.out.println("Lookup called on invalid column: '" + columnName + "' is not present on table '" + dataTable.getName() + "' assuming default for " + fmt.getIdentifierType());
        FormulaManager fm = manager.get(EvaluationManager.FMANAGER);
        return fm.getDefault(fmt.getManagedClass());
    }
    if (!dataTable.hasRow(lookupValue)) {
        FormatManager<?> fmt = column.getFormatManager();
        System.out.println("Lookup called on invalid item: '" + lookupValue + "' is not present in the first row of table '" + dataTable.getName() + "' assuming default for " + fmt.getIdentifierType());
        FormulaManager fm = manager.get(EvaluationManager.FMANAGER);
        return fm.getDefault(fmt.getManagedClass());
    }
    return dataTable.lookupExact(lookupValue, columnName);
}
Also used : DataTable(pcgen.cdom.format.table.DataTable) FormulaManager(pcgen.base.formula.base.FormulaManager) TableColumn(pcgen.cdom.format.table.TableColumn)

Aggregations

FormulaManager (pcgen.base.formula.base.FormulaManager)3 ScopeInstanceFactory (pcgen.base.formula.inst.ScopeInstanceFactory)2 LegalScope (pcgen.base.formula.base.LegalScope)1 ScopeInstance (pcgen.base.formula.base.ScopeInstance)1 FormatManager (pcgen.base.util.FormatManager)1 DataTable (pcgen.cdom.format.table.DataTable)1 TableColumn (pcgen.cdom.format.table.TableColumn)1