use of cbit.vcell.parser.SymbolTableFunctionEntry in project vcell by virtualcell.
the class ParameterContext method getEntry.
/**
* getEntry method comment.
*/
public SymbolTableEntry getEntry(String identifierString) {
SymbolTableEntry localSTE = getLocalEntry(identifierString);
if (localSTE != null && !(localSTE instanceof UnresolvedParameter)) {
return localSTE;
}
// may be null.
UnresolvedParameter unresolvedParameter = (UnresolvedParameter) localSTE;
SymbolTableEntry externalSTE = getNameScope().getExternalEntry(identifierString, this);
if (externalSTE instanceof SymbolTableFunctionEntry) {
return externalSTE;
}
//
if (externalSTE != null) {
if (unresolvedParameter != null) {
removeUnresolvedParameters(this);
}
return addProxyParameter(externalSTE);
} else if (unresolvedParameter != null) {
return unresolvedParameter;
}
return null;
}
use of cbit.vcell.parser.SymbolTableFunctionEntry in project vcell by virtualcell.
the class EventPanel method populateVariableComboBoxModel.
public static void populateVariableComboBoxModel(DefaultComboBoxModel<String> defaultComboBoxModel, SimulationContext simContext) /*,boolean bExcludeFuncAndReserved*/
{
// fill comboboxmodel with possible variables from simContext (symboltable entries) list
defaultComboBoxModel.removeAllElements();
Map<String, SymbolTableEntry> entryMap = new HashMap<String, SymbolTableEntry>();
simContext.getEntries(entryMap);
ArrayList<String> varNameList = new ArrayList<String>();
for (String varName : entryMap.keySet()) {
SymbolTableEntry symbolTableEntry = entryMap.get(varName);
if (/*bExcludeFuncAndReserved && */
(symbolTableEntry instanceof SymbolTableFunctionEntry || symbolTableEntry instanceof Model.ReservedSymbol)) {
continue;
}
varNameList.add(varName);
}
Collections.sort(varNameList);
for (String varName : varNameList) {
defaultComboBoxModel.addElement(varName);
}
}
use of cbit.vcell.parser.SymbolTableFunctionEntry in project vcell by virtualcell.
the class TableCellEditorAutoCompletion method stopCellEditing.
@Override
public boolean stopCellEditing() {
if (thisTable.getCellEditor() == null) {
return true;
}
if (textFieldAutoCompletion.getSelectedIndex() >= 0) {
return false;
}
final int editingRow = thisTable.getEditingRow();
final int editingColumn = thisTable.getEditingColumn();
textFieldAutoCompletion.stopEditing();
boolean bExpressionValid = true;
if (thisTable.getColumnClass(editingColumn).equals(ScopedExpression.class)) {
if (textFieldAutoCompletion.getSymbolTable() != null) {
ScopedExpression scopedExpression = (ScopedExpression) thisTable.getValueAt(editingRow, editingColumn);
String text = textFieldAutoCompletion.getText();
if (text.trim().length() > 0) {
try {
Expression exp = new Expression(text);
exp.validateUnscopedSymbols();
if (scopedExpression == null || scopedExpression.isValidateFunctionBinding()) {
FunctionInvocation[] functionInvocations = exp.getFunctionInvocations(null);
for (FunctionInvocation functionInvocation : functionInvocations) {
String formalDefinition = functionInvocation.getFormalDefinition();
if (functionInvocation.getFunctionId() == FunctionType.USERDEFINED) {
SymbolTableFunctionEntry stfe = (SymbolTableFunctionEntry) textFieldAutoCompletion.getSymbolTable().getEntry(formalDefinition);
if (stfe == null) {
//
// check for wrong number of arguments
//
Map<String, SymbolTableEntry> entries = new HashMap<String, SymbolTableEntry>();
textFieldAutoCompletion.getSymbolTable().getEntries(entries);
System.out.println("available symbols");
for (String symbol : entries.keySet()) {
System.out.print(symbol + ",");
}
System.out.println("");
throw new ExpressionBindingException("unknown function " + formalDefinition, formalDefinition);
}
} else {
// built in function, check arguments
FunctionType functionType = functionInvocation.getFunctionId();
String formalDefinitionBuiltin = ASTFuncNode.getFormalDefinition(functionType.getName(), functionType.getArgTypes());
if (!formalDefinition.equals(formalDefinitionBuiltin)) {
throw new ExpressionBindingException("expecting " + formalDefinitionBuiltin, formalDefinition);
}
}
}
}
if (scopedExpression == null || scopedExpression.isValidateIdentifierBinding()) {
exp.bindExpression(textFieldAutoCompletion.getSymbolTable());
}
} catch (ExpressionBindingException ex) {
ex.printStackTrace(System.out);
DialogUtils.showErrorDialog(thisTable.getParent(), ex.getMessage() + "\n\nUse 'Ctrl-Space' to see a list of available names in your model or 'Esc' to revert to the original expression.");
bExpressionValid = false;
} catch (ExpressionException ex) {
ex.printStackTrace(System.out);
DialogUtils.showErrorDialog(thisTable.getParent(), ex.getMessage() + "\n\nUse 'Esc' to revert to the original expression.");
bExpressionValid = false;
}
}
}
}
if (!bExpressionValid) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
thisTable.requestFocus();
thisTable.setRowSelectionInterval(editingRow, editingRow);
((JComponent) getComponent()).setBorder(new LineBorder(Color.red));
textFieldAutoCompletion.requestFocus();
}
});
return false;
}
return super.stopCellEditing();
}
use of cbit.vcell.parser.SymbolTableFunctionEntry in project vcell by virtualcell.
the class ReactionStep method getEntry.
public SymbolTableEntry getEntry(String identifier) {
SymbolTableEntry localSTE = getLocalEntry(identifier);
if (localSTE != null && !(localSTE instanceof Kinetics.UnresolvedParameter)) {
return localSTE;
}
Kinetics.UnresolvedParameter unresolvedParameter = (Kinetics.UnresolvedParameter) localSTE;
SymbolTableEntry externalSTE = getNameScope().getExternalEntry(identifier, this);
if (externalSTE instanceof SymbolTableFunctionEntry) {
return externalSTE;
}
//
if (externalSTE != null) {
if (unresolvedParameter != null) {
getKinetics().removeUnresolvedParameter(unresolvedParameter);
}
return getKinetics().addProxyParameter(externalSTE);
} else if (unresolvedParameter != null) {
return unresolvedParameter;
}
//
if (getModel() != null) {
SymbolTableEntry reservedSTE = getModel().getReservedSymbolByName(identifier);
if (reservedSTE != null) {
if (reservedSTE.equals(getModel().getX()) || reservedSTE.equals(getModel().getY()) || reservedSTE.equals(getModel().getZ())) {
throw new RuntimeException("x, y or z can not be used in the Reaction Editor. " + "They are reserved as spatial variables and Physiological Models must be spatially independent.");
}
return getKinetics().addProxyParameter(reservedSTE);
}
}
return null;
}
Aggregations