use of pcgen.base.formula.parse.ASTQuotString in project pcgen by PCGen.
the class DropIntoContext method evaluate.
@Override
public Object evaluate(EvaluateVisitor visitor, Node[] args, EvaluationManager manager) {
ASTQuotString qs = (ASTQuotString) args[0];
String legalScopeName = qs.getText();
Object result = args[1].jjtAccept(visitor, manager);
VarScoped vs;
if (result instanceof String) {
Class<? extends Loadable> objClass = StringPClassUtil.getClassFor(legalScopeName);
vs = (VarScoped) manager.get(ManagerKey.CONTEXT).getReferenceContext().silentlyGetConstructedCDOMObject(objClass, (String) result);
} else if (result instanceof VarScoped) {
vs = (VarScoped) result;
} else {
throw new IllegalStateException("result must be String or VarScoped");
}
return evaluateFromObject(visitor, legalScopeName, vs, args[2], manager);
}
use of pcgen.base.formula.parse.ASTQuotString in project pcgen by PCGen.
the class DropIntoContext method allowThreeArguments.
private FormatManager<?> allowThreeArguments(SemanticsVisitor visitor, FormulaSemantics semantics, Node[] args) {
Node scopeNode = args[0];
if (!(scopeNode instanceof ASTQuotString)) {
semantics.setInvalid("Parse Error: Invalid Scope Node: " + scopeNode.getClass().getName() + " found in location requiring a" + " Static String (first arg cannot be evaluated)");
return null;
}
ASTQuotString qs = (ASTQuotString) scopeNode;
String legalScopeName = qs.getText();
if (args[1] instanceof ASTQuotString) {
//Direct, no dependencies
return allowFromScopeName(visitor, semantics, legalScopeName, args[2]);
} else if (args[1] instanceof ASTPCGenSingleWord) {
//Variable
semantics = semantics.getWith(FormulaSemantics.ASSERTED, null);
FormatManager<?> objClass = (FormatManager<?>) args[1].jjtAccept(visitor, semantics);
if (!semantics.isValid()) {
return null;
}
Class<?> managedClass = objClass.getManagedClass();
if (String.class.isAssignableFrom(managedClass) || VarScoped.class.isAssignableFrom(objClass.getManagedClass())) {
return allowFromScopeName(visitor, semantics, legalScopeName, args[2]);
} else {
semantics.setInvalid("Parse Error: Invalid Object Format: " + objClass + " is not capable of holding variables and is not a key (String)");
return null;
}
} else {
//Error
semantics.setInvalid("Parse Error: Invalid second argument: " + " must be a String or single variable");
return null;
}
}
use of pcgen.base.formula.parse.ASTQuotString in project pcgen by PCGen.
the class DropIntoContext method getDependencies.
@Override
public void getDependencies(DependencyVisitor visitor, DependencyManager fdm, Node[] args) {
String legalScopeName = ((ASTQuotString) args[0]).getText();
TrainingStrategy ts = new TrainingStrategy();
DependencyManager trainer = fdm.getWith(DependencyManager.VARSTRATEGY, ts);
if (args[1] instanceof ASTQuotString) {
//Direct, no dependencies
} else if (args[1] instanceof ASTPCGenSingleWord) {
//Variable
args[1].jjtAccept(visitor, trainer);
} else {
//Error
}
DynamicDependency dd = new DynamicDependency(ts.getControlVar(), legalScopeName);
fdm.get(DependencyManager.DYNAMIC).addDependency(dd);
DependencyManager dynamic = fdm.getWith(DependencyManager.VARSTRATEGY, dd);
//Rest of Equation
args[2].jjtAccept(visitor, dynamic);
}
use of pcgen.base.formula.parse.ASTQuotString in project pcgen by PCGen.
the class InputFunction method getDependencies.
@Override
public void getDependencies(DependencyVisitor visitor, DependencyManager fdm, Node[] args) {
ASTQuotString inputName = (ASTQuotString) args[0];
String varName = inputName.getText();
visitor.visitVariable(ChannelUtilities.createVarName(varName), fdm);
}
Aggregations