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));
}
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;
}
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);
}
Aggregations