Undo removal
diff --git a/modelgen/org.eclipse.stem.model.codegen/xtend-gen/org/eclipse/stem/model/codegen/xtext/ExpressionsClassGenerator.java b/modelgen/org.eclipse.stem.model.codegen/xtend-gen/org/eclipse/stem/model/codegen/xtext/ExpressionsClassGenerator.java
new file mode 100644
index 0000000..82697d3
--- /dev/null
+++ b/modelgen/org.eclipse.stem.model.codegen/xtend-gen/org/eclipse/stem/model/codegen/xtext/ExpressionsClassGenerator.java
@@ -0,0 +1,804 @@
+package org.eclipse.stem.model.codegen.xtext;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Iterables;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import org.eclipse.emf.codegen.ecore.genmodel.GenFeature;
+import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.stem.model.codegen.xtext.ModelExpressionGenerator;
+import org.eclipse.stem.model.ctdl.ContextSensitiveResourceWrapper;
+import org.eclipse.stem.model.ctdl.ctdl.AbsoluteCompartmentValueReference;
+import org.eclipse.stem.model.ctdl.ctdl.Block;
+import org.eclipse.stem.model.ctdl.ctdl.BooleanLiteral;
+import org.eclipse.stem.model.ctdl.ctdl.CompartmentTransitionDefinitions;
+import org.eclipse.stem.model.ctdl.ctdl.DefStatement;
+import org.eclipse.stem.model.ctdl.ctdl.Div;
+import org.eclipse.stem.model.ctdl.ctdl.Evaluation;
+import org.eclipse.stem.model.ctdl.ctdl.Expression;
+import org.eclipse.stem.model.ctdl.ctdl.ExternalFunctionReference;
+import org.eclipse.stem.model.ctdl.ctdl.FunctionCall;
+import org.eclipse.stem.model.ctdl.ctdl.FunctionReference;
+import org.eclipse.stem.model.ctdl.ctdl.GlobalVariableReference;
+import org.eclipse.stem.model.ctdl.ctdl.LocalVariableReference;
+import org.eclipse.stem.model.ctdl.ctdl.MetamodelResource;
+import org.eclipse.stem.model.ctdl.ctdl.Minus;
+import org.eclipse.stem.model.ctdl.ctdl.ModelParamReference;
+import org.eclipse.stem.model.ctdl.ctdl.Multi;
+import org.eclipse.stem.model.ctdl.ctdl.NumberLiteral;
+import org.eclipse.stem.model.ctdl.ctdl.Plus;
+import org.eclipse.stem.model.ctdl.ctdl.PrimaryExpression;
+import org.eclipse.stem.model.ctdl.ctdl.RelativeCompartmentValueReference;
+import org.eclipse.stem.model.ctdl.ctdl.ReturnStatement;
+import org.eclipse.stem.model.ctdl.ctdl.ScopedVariableReference;
+import org.eclipse.stem.model.ctdl.ctdl.StringLiteral;
+import org.eclipse.stem.model.ctdl.ctdl.TransitionBlock;
+import org.eclipse.stem.model.ctdl.ctdl.VariableReference;
+import org.eclipse.stem.model.ctdl.functions.ExternalFunctionDefinition;
+import org.eclipse.stem.model.ctdl.functions.FunctionArgumentReference;
+import org.eclipse.stem.model.ctdl.functions.JavaMethodArgument;
+import org.eclipse.stem.model.ctdl.functions.SystemArgumentReference;
+import org.eclipse.stem.model.ctdl.serializer.ITypeSerializer;
+import org.eclipse.stem.model.ctdl.serializer.TypeSerializerFactory;
+import org.eclipse.stem.model.metamodel.Compartment;
+import org.eclipse.stem.model.metamodel.ModelParam;
+import org.eclipse.stem.model.metamodel.Transition;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.generator.IFileSystemAccess;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.IteratorExtensions;
+import org.eclipse.xtext.xbase.lib.StringExtensions;
+
+@SuppressWarnings("all")
+public class ExpressionsClassGenerator extends ModelExpressionGenerator {
+  public void doGenerate(final List<XtextResource> resources, final IFileSystemAccess fsa) {
+    String _name = this.modelGenClass.getName();
+    String fileName = (_name + "Expressions.java");
+    CharSequence _build = this.build(resources);
+    fsa.generateFile(fileName, _build);
+  }
+  
+  public void doGenerate(final Resource resource, final IFileSystemAccess fsa) {
+    TreeIterator<EObject> _allContents = resource.getAllContents();
+    Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(_allContents);
+    Iterable<CompartmentTransitionDefinitions> _filter = Iterables.<CompartmentTransitionDefinitions>filter(_iterable, CompartmentTransitionDefinitions.class);
+    CompartmentTransitionDefinitions ctd = IterableExtensions.<CompartmentTransitionDefinitions>head(_filter);
+    MetamodelResource mm = ctd.getMetamodel();
+    Transition trans = mm.getTransition();
+    Compartment _source = trans.getSource();
+    String _name = _source.getName();
+    String _plus = (_name + "_");
+    Compartment _target = trans.getTarget();
+    String _name_1 = _target.getName();
+    String fname = (_plus + _name_1);
+    CharSequence _compile = this.compile(resource);
+    fsa.generateFile(fname, _compile);
+  }
+  
+  public CharSequence build(final List<XtextResource> r) {
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("package ");
+    GenPackage _genPackage = this.modelGenClass.getGenPackage();
+    String _classPackageName = _genPackage.getClassPackageName();
+    _builder.append(_classPackageName, "");
+    _builder.append(";");
+    CharSequence pkg = _builder;
+    StringConcatenation _builder_1 = new StringConcatenation();
+    _builder_1.append("\t\t");
+    _builder_1.append("/**");
+    _builder_1.newLine();
+    _builder_1.append("\t\t ");
+    _builder_1.append("* Generated expressions class for  ");
+    String _name = this.modelGenClass.getName();
+    _builder_1.append(_name, "		 ");
+    _builder_1.append(".");
+    _builder_1.newLineIfNotEmpty();
+    _builder_1.append("\t\t ");
+    _builder_1.append("* DO NOT EDIT DIRECTLY.  Use extended class and override methods for transitions as desired.");
+    _builder_1.newLine();
+    _builder_1.append("\t\t ");
+    _builder_1.append("* @generated");
+    _builder_1.newLine();
+    _builder_1.append("\t\t ");
+    _builder_1.append("*/");
+    _builder_1.newLine();
+    _builder_1.append("\t\t");
+    _builder_1.append("public class ");
+    String _name_1 = this.modelGenClass.getName();
+    _builder_1.append(_name_1, "		");
+    _builder_1.append("Expressions {");
+    _builder_1.newLineIfNotEmpty();
+    _builder_1.append("\t");
+    _builder_1.append("public void calculate(double t, long timeDelta, ");
+    String _importedName = this.getImportedName("org.eclipse.stem.core.model.STEMTime");
+    _builder_1.append(_importedName, "	");
+    _builder_1.append(" time, ");
+    String _importGenClassInterface = this.importGenClassInterface(this.modelGenClass);
+    _builder_1.append(_importGenClassInterface, "	");
+    _builder_1.append(" model, ");
+    String _importGenClassInterface_1 = this.importGenClassInterface(this.labelGenClass);
+    _builder_1.append(_importGenClassInterface_1, "	");
+    _builder_1.append(" label, ");
+    String _importGenClassInterface_2 = this.importGenClassInterface(this.labelValueGenClass);
+    _builder_1.append(_importGenClassInterface_2, "	");
+    _builder_1.append(" labelValue, ");
+    String _importedName_1 = this.getImportedName("org.eclipse.stem.core.graph.Node");
+    _builder_1.append(_importedName_1, "	");
+    _builder_1.append(" node, ");
+    String _importGenClassInterface_3 = this.importGenClassInterface(this.labelValueGenClass);
+    _builder_1.append(_importGenClassInterface_3, "	");
+    _builder_1.append(" deltaValue) {");
+    _builder_1.newLineIfNotEmpty();
+    {
+      Set<Compartment> _affectedCompartments = this.getAffectedCompartments(r);
+      for(final Compartment s : _affectedCompartments) {
+        _builder_1.append("\t\t");
+        _builder_1.append("double delta");
+        String _accessorName = this.getAccessorName(s);
+        _builder_1.append(_accessorName, "		");
+        _builder_1.append(" = 0.0;");
+        _builder_1.newLineIfNotEmpty();
+      }
+    }
+    _builder_1.append("\t\t");
+    _builder_1.newLine();
+    {
+      Iterable<ContextSensitiveResourceWrapper> _filter = Iterables.<ContextSensitiveResourceWrapper>filter(r, ContextSensitiveResourceWrapper.class);
+      for(final ContextSensitiveResourceWrapper s_1 : _filter) {
+        _builder_1.append("\t\t");
+        _builder_1.append("// Calculate delta for transition ");
+        Transition _transition = s_1.getTransition();
+        String _formattedName = this.getFormattedName(_transition);
+        _builder_1.append(_formattedName, "		");
+        _builder_1.newLineIfNotEmpty();
+        _builder_1.append("\t\t");
+        _builder_1.append("double generated_");
+        Transition _transition_1 = s_1.getTransition();
+        String _methodName = this.getMethodName(_transition_1);
+        _builder_1.append(_methodName, "		");
+        _builder_1.append(" = ");
+        Transition _transition_2 = s_1.getTransition();
+        String _methodName_1 = this.getMethodName(_transition_2);
+        _builder_1.append(_methodName_1, "		");
+        _builder_1.append("(t,timeDelta,time,model,label,labelValue,label.getNode());");
+        _builder_1.newLineIfNotEmpty();
+        _builder_1.append("\t\t");
+        _builder_1.append("delta");
+        Transition _transition_3 = s_1.getTransition();
+        Compartment _source = _transition_3.getSource();
+        String _accessorName_1 = this.getAccessorName(_source);
+        _builder_1.append(_accessorName_1, "		");
+        _builder_1.append(" -= generated_");
+        Transition _transition_4 = s_1.getTransition();
+        String _methodName_2 = this.getMethodName(_transition_4);
+        _builder_1.append(_methodName_2, "		");
+        _builder_1.append(";");
+        _builder_1.newLineIfNotEmpty();
+        _builder_1.append("\t\t");
+        _builder_1.append("delta");
+        Transition _transition_5 = s_1.getTransition();
+        Compartment _target = _transition_5.getTarget();
+        String _accessorName_2 = this.getAccessorName(_target);
+        _builder_1.append(_accessorName_2, "		");
+        _builder_1.append(" += generated_");
+        Transition _transition_6 = s_1.getTransition();
+        String _methodName_3 = this.getMethodName(_transition_6);
+        _builder_1.append(_methodName_3, "		");
+        _builder_1.append(";");
+        _builder_1.newLineIfNotEmpty();
+        {
+          Transition _transition_7 = s_1.getTransition();
+          EList<Compartment> _forIncidence = _transition_7.getForIncidence();
+          for(final Compartment c : _forIncidence) {
+            _builder_1.append("\t\t");
+            _builder_1.append("\t");
+            _builder_1.append("delta");
+            String _accessorName_3 = this.getAccessorName(c);
+            _builder_1.append(_accessorName_3, "			");
+            _builder_1.append(" += generated_");
+            Transition _transition_8 = s_1.getTransition();
+            String _methodName_4 = this.getMethodName(_transition_8);
+            _builder_1.append(_methodName_4, "			");
+            _builder_1.append(";");
+            _builder_1.newLineIfNotEmpty();
+          }
+        }
+        _builder_1.append("\t\t");
+        _builder_1.newLine();
+        _builder_1.append("\t\t");
+        _builder_1.append("\t");
+        _builder_1.append("// Stochastic exchange for ");
+        Transition _transition_9 = s_1.getTransition();
+        String _formattedName_1 = this.getFormattedName(_transition_9);
+        _builder_1.append(_formattedName_1, "			");
+        _builder_1.newLineIfNotEmpty();
+        _builder_1.append("\t\t");
+        _builder_1.append("\t");
+        String _importedName_2 = this.getImportedName("org.eclipse.stem.core.graph.Exchange");
+        _builder_1.append(_importedName_2, "			");
+        _builder_1.append(" exchange_");
+        Transition _transition_10 = s_1.getTransition();
+        String _methodName_5 = this.getMethodName(_transition_10);
+        _builder_1.append(_methodName_5, "			");
+        _builder_1.append(" = (");
+        String _importedName_3 = this.getImportedName("org.eclipse.stem.core.graph.Exchange");
+        _builder_1.append(_importedName_3, "			");
+        _builder_1.append(")");
+        String _importedName_4 = this.getImportedName("org.eclipse.stem.core.graph.ExchangePool");
+        _builder_1.append(_importedName_4, "			");
+        _builder_1.append(".POOL.get();");
+        _builder_1.newLineIfNotEmpty();
+        _builder_1.append("\t\t");
+        _builder_1.append("\t");
+        _builder_1.append("//deltaValue.getDepartures().add(exchange_");
+        Transition _transition_11 = s_1.getTransition();
+        String _methodName_6 = this.getMethodName(_transition_11);
+        _builder_1.append(_methodName_6, "			");
+        _builder_1.append(");");
+        _builder_1.newLineIfNotEmpty();
+        _builder_1.append("\t\t");
+        _builder_1.append("\t");
+        _builder_1.append("exchange_");
+        Transition _transition_12 = s_1.getTransition();
+        String _methodName_7 = this.getMethodName(_transition_12);
+        _builder_1.append(_methodName_7, "			");
+        _builder_1.append(".setType(");
+        String _importedName_5 = this.getImportedName("org.eclipse.stem.core.graph.ExchangeType");
+        _builder_1.append(_importedName_5, "			");
+        _builder_1.append(".COMPARTMENT_TRANSITION);");
+        _builder_1.newLineIfNotEmpty();
+        _builder_1.append("\t\t");
+        _builder_1.append("\t");
+        _builder_1.append("exchange_");
+        Transition _transition_13 = s_1.getTransition();
+        String _methodName_8 = this.getMethodName(_transition_13);
+        _builder_1.append(_methodName_8, "			");
+        _builder_1.append(".setSource(");
+        Transition _transition_14 = s_1.getTransition();
+        Compartment _source_1 = _transition_14.getSource();
+        GenFeature _genFeature = this.getGenFeature(_source_1);
+        String _packageAccessorName = this.getPackageAccessorName(_genFeature);
+        _builder_1.append(_packageAccessorName, "			");
+        _builder_1.append(");");
+        _builder_1.newLineIfNotEmpty();
+        _builder_1.append("\t\t");
+        _builder_1.append("\t");
+        _builder_1.append("exchange_");
+        Transition _transition_15 = s_1.getTransition();
+        String _methodName_9 = this.getMethodName(_transition_15);
+        _builder_1.append(_methodName_9, "			");
+        _builder_1.append(".setTarget(");
+        Transition _transition_16 = s_1.getTransition();
+        Compartment _target_1 = _transition_16.getTarget();
+        GenFeature _genFeature_1 = this.getGenFeature(_target_1);
+        String _packageAccessorName_1 = this.getPackageAccessorName(_genFeature_1);
+        _builder_1.append(_packageAccessorName_1, "			");
+        _builder_1.append(");");
+        _builder_1.newLineIfNotEmpty();
+        _builder_1.append("\t\t");
+        _builder_1.append("\t");
+        _builder_1.append("exchange_");
+        Transition _transition_17 = s_1.getTransition();
+        String _methodName_10 = this.getMethodName(_transition_17);
+        _builder_1.append(_methodName_10, "			");
+        _builder_1.append(".setCount(generated_");
+        Transition _transition_18 = s_1.getTransition();
+        String _methodName_11 = this.getMethodName(_transition_18);
+        _builder_1.append(_methodName_11, "			");
+        _builder_1.append(");");
+        _builder_1.newLineIfNotEmpty();
+        {
+          Transition _transition_19 = s_1.getTransition();
+          EList<Compartment> _forIncidence_1 = _transition_19.getForIncidence();
+          for(final Compartment c_1 : _forIncidence_1) {
+            _builder_1.append("\t\t");
+            _builder_1.append("\t");
+            _builder_1.append("exchange_");
+            Transition _transition_20 = s_1.getTransition();
+            String _methodName_12 = this.getMethodName(_transition_20);
+            _builder_1.append(_methodName_12, "			");
+            _builder_1.append(".getForIncidence().add(");
+            GenFeature _genFeature_2 = this.getGenFeature(c_1);
+            String _packageAccessorName_2 = this.getPackageAccessorName(_genFeature_2);
+            _builder_1.append(_packageAccessorName_2, "			");
+            _builder_1.append(");");
+            _builder_1.newLineIfNotEmpty();
+          }
+        }
+      }
+    }
+    _builder_1.append("\t\t");
+    _builder_1.newLine();
+    {
+      Set<Compartment> _affectedCompartments_1 = this.getAffectedCompartments(r);
+      for(final Compartment s_2 : _affectedCompartments_1) {
+        _builder_1.append("\t\t");
+        _builder_1.append("deltaValue.set");
+        String _accessorName_4 = this.getAccessorName(s_2);
+        _builder_1.append(_accessorName_4, "		");
+        _builder_1.append("(delta");
+        String _accessorName_5 = this.getAccessorName(s_2);
+        _builder_1.append(_accessorName_5, "		");
+        _builder_1.append(");");
+        _builder_1.newLineIfNotEmpty();
+      }
+    }
+    _builder_1.append("\t");
+    _builder_1.append("}");
+    _builder_1.newLine();
+    _builder_1.append("\t\t\t");
+    _builder_1.newLine();
+    {
+      for(final XtextResource e : r) {
+        CharSequence _compile = this.compile(e);
+        _builder_1.append(_compile, "");
+        _builder_1.newLineIfNotEmpty();
+      }
+    }
+    _builder_1.append("} //");
+    CharSequence body = _builder_1;
+    String imports = this.getSortedImports();
+    StringConcatenation _builder_2 = new StringConcatenation();
+    _builder_2.append(pkg, "");
+    _builder_2.newLineIfNotEmpty();
+    _builder_2.newLine();
+    _builder_2.append(imports, "");
+    _builder_2.newLineIfNotEmpty();
+    _builder_2.newLine();
+    _builder_2.append(body, "");
+    return ((CharSequence) _builder_2);
+  }
+  
+  protected CharSequence _compile(final Resource r) {
+    StringConcatenation _builder = new StringConcatenation();
+    TreeIterator<EObject> _allContents = r.getAllContents();
+    Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(_allContents);
+    Iterable<TransitionBlock> _filter = Iterables.<TransitionBlock>filter(_iterable, TransitionBlock.class);
+    TransitionBlock _head = IterableExtensions.<TransitionBlock>head(_filter);
+    CharSequence _compile = this.compile(_head);
+    _builder.append(_compile, "");
+    return _builder;
+  }
+  
+  protected CharSequence _compile(final TransitionBlock t) {
+    EObject _eContainer = t.eContainer();
+    CompartmentTransitionDefinitions ctd = ((CompartmentTransitionDefinitions) _eContainer);
+    MetamodelResource _metamodel = ctd.getMetamodel();
+    Transition transition = _metamodel.getTransition();
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("/**");
+    _builder.newLine();
+    _builder.append(" ");
+    _builder.append("* Computes delta for transition ");
+    Compartment _source = transition.getSource();
+    String _name = _source.getName();
+    _builder.append(_name, " ");
+    _builder.append(" -> ");
+    Compartment _target = transition.getTarget();
+    String _name_1 = _target.getName();
+    _builder.append(_name_1, " ");
+    _builder.newLineIfNotEmpty();
+    _builder.append(" ");
+    _builder.append("* @generated");
+    _builder.newLine();
+    _builder.append(" ");
+    _builder.append("*/");
+    _builder.newLine();
+    _builder.append("protected double ");
+    Compartment _source_1 = transition.getSource();
+    String _name_2 = _source_1.getName();
+    _builder.append(_name_2, "");
+    _builder.append("_");
+    Compartment _target_1 = transition.getTarget();
+    String _name_3 = _target_1.getName();
+    _builder.append(_name_3, "");
+    _builder.append(" (double t, long timeDelta, ");
+    String _importedName = this.getImportedName("org.eclipse.stem.core.model.STEMTime");
+    _builder.append(_importedName, "");
+    _builder.append(" time, ");
+    String _importGenClassInterface = this.importGenClassInterface(this.modelGenClass);
+    _builder.append(_importGenClassInterface, "");
+    _builder.append(" model, ");
+    String _importGenClassInterface_1 = this.importGenClassInterface(this.labelGenClass);
+    _builder.append(_importGenClassInterface_1, "");
+    _builder.append(" label, ");
+    String _importGenClassInterface_2 = this.importGenClassInterface(this.labelValueGenClass);
+    _builder.append(_importGenClassInterface_2, "");
+    _builder.append(" labelValue, ");
+    String _importedName_1 = this.getImportedName("org.eclipse.stem.core.graph.Node");
+    _builder.append(_importedName_1, "");
+    _builder.append(" node) {");
+    _builder.newLineIfNotEmpty();
+    {
+      Block _block = t.getBlock();
+      EList<DefStatement> _statements = _block.getStatements();
+      for(final DefStatement s : _statements) {
+        CharSequence _compile = this.compile(s);
+        _builder.append(_compile, "");
+      }
+    }
+    _builder.newLineIfNotEmpty();
+    _builder.append("return ");
+    Block _block_1 = t.getBlock();
+    ReturnStatement _ret = _block_1.getRet();
+    CharSequence _compile_1 = this.compile(_ret);
+    _builder.append(_compile_1, "");
+    _builder.append(";");
+    _builder.newLineIfNotEmpty();
+    _builder.append("}");
+    _builder.newLine();
+    return ((CharSequence) _builder);
+  }
+  
+  protected CharSequence _compile(final DefStatement d) {
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("double ");
+    String _varname = d.getVarname();
+    _builder.append(_varname, "");
+    _builder.append("=");
+    Evaluation _expr = d.getExpr();
+    CharSequence _compile = this.compile(_expr);
+    _builder.append(_compile, "");
+    _builder.append(";");
+    return _builder;
+  }
+  
+  protected CharSequence _compile(final Evaluation e) {
+    StringConcatenation _builder = new StringConcatenation();
+    Expression _expression = e.getExpression();
+    CharSequence _compile = this.compile(_expression, Double.TYPE);
+    _builder.append(_compile, "");
+    return _builder;
+  }
+  
+  protected CharSequence _compile(final PrimaryExpression pe, final Class<? extends Object> expectedType) {
+    String neg = "";
+    boolean _isNegate = pe.isNegate();
+    if (_isNegate) {
+      neg = "-";
+    }
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("(");
+    _builder.append(neg, "");
+    Expression _exp = pe.getExp();
+    CharSequence _compile = this.compile(_exp, expectedType);
+    _builder.append(_compile, "");
+    _builder.append(")");
+    _builder.newLineIfNotEmpty();
+    return ((CharSequence) _builder);
+  }
+  
+  protected CharSequence _compile(final Plus p, final Class<? extends Object> expectedType) {
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("(");
+    Expression _left = p.getLeft();
+    CharSequence _compile = this.compile(_left, Double.TYPE);
+    _builder.append(_compile, "");
+    _builder.append("+");
+    Expression _right = p.getRight();
+    CharSequence _compile_1 = this.compile(_right, Double.TYPE);
+    _builder.append(_compile_1, "");
+    _builder.append(")");
+    return _builder;
+  }
+  
+  protected CharSequence _compile(final Minus m, final Class<? extends Object> expectedType) {
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("(");
+    Expression _left = m.getLeft();
+    CharSequence _compile = this.compile(_left, Double.TYPE);
+    _builder.append(_compile, "");
+    _builder.append("-");
+    Expression _right = m.getRight();
+    CharSequence _compile_1 = this.compile(_right, Double.TYPE);
+    _builder.append(_compile_1, "");
+    _builder.append(")");
+    return _builder;
+  }
+  
+  protected CharSequence _compile(final Multi m, final Class<? extends Object> expectedType) {
+    StringConcatenation _builder = new StringConcatenation();
+    Expression _left = m.getLeft();
+    CharSequence _compile = this.compile(_left, Double.TYPE);
+    _builder.append(_compile, "");
+    _builder.append("*");
+    Expression _right = m.getRight();
+    CharSequence _compile_1 = this.compile(_right, Double.TYPE);
+    _builder.append(_compile_1, "");
+    return _builder;
+  }
+  
+  protected CharSequence _compile(final Div d, final Class<? extends Object> expectedType) {
+    StringConcatenation _builder = new StringConcatenation();
+    Expression _left = d.getLeft();
+    CharSequence _compile = this.compile(_left, Double.TYPE);
+    _builder.append(_compile, "");
+    _builder.append("/");
+    Expression _right = d.getRight();
+    CharSequence _compile_1 = this.compile(_right, Double.TYPE);
+    _builder.append(_compile_1, "");
+    return _builder;
+  }
+  
+  protected CharSequence _compileReference(final GlobalVariableReference rf, final Class<? extends Object> expectedType) {
+    StringConcatenation _builder = new StringConcatenation();
+    String _name = rf.getName();
+    _builder.append(_name, "");
+    return _builder;
+  }
+  
+  protected CharSequence _compileReference(final LocalVariableReference rf, final Class<? extends Object> expectedType) {
+    StringConcatenation _builder = new StringConcatenation();
+    String _name = rf.getName();
+    _builder.append(_name, "");
+    return _builder;
+  }
+  
+  protected CharSequence _compileReference(final AbsoluteCompartmentValueReference rf, final Class<? extends Object> expectedType) {
+    ITypeSerializer serializer = TypeSerializerFactory.getSerializer(rf, expectedType, this.labelValueGenClass);
+    boolean _notEquals = (!Objects.equal(serializer, null));
+    if (_notEquals) {
+      return serializer.serialize();
+    }
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("labelValue.get");
+    Compartment _obj = rf.getObj();
+    String _name = _obj.getName();
+    String _firstUpper = StringExtensions.toFirstUpper(_name);
+    _builder.append(_firstUpper, "");
+    _builder.append("()");
+    return ((CharSequence) _builder);
+  }
+  
+  protected CharSequence _compileReference(final RelativeCompartmentValueReference rf, final Class<? extends Object> expectedType) {
+    ITypeSerializer serializer = TypeSerializerFactory.getSerializer(rf, expectedType, this.labelValueGenClass);
+    boolean _notEquals = (!Objects.equal(serializer, null));
+    if (_notEquals) {
+      return serializer.serialize();
+    }
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("labelValue.get");
+    Compartment _obj = rf.getObj();
+    String _name = _obj.getName();
+    String _firstUpper = StringExtensions.toFirstUpper(_name);
+    _builder.append(_firstUpper, "");
+    _builder.append("()/labelValue.getPopulationCount()");
+    return ((CharSequence) _builder);
+  }
+  
+  protected CharSequence _compileReference(final ModelParamReference rf, final Class<? extends Object> expectedType) {
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("model.get");
+    ModelParam _obj = rf.getObj();
+    String _name = _obj.getName();
+    String _firstUpper = StringExtensions.toFirstUpper(_name);
+    _builder.append(_firstUpper, "");
+    _builder.append("()");
+    return _builder;
+  }
+  
+  protected CharSequence _compile(final VariableReference rf, final Class<? extends Object> expectedType) {
+    StringConcatenation _builder = new StringConcatenation();
+    ScopedVariableReference _ref = rf.getRef();
+    CharSequence _compileReference = this.compileReference(_ref, expectedType);
+    _builder.append(_compileReference, "");
+    return _builder;
+  }
+  
+  protected CharSequence _compile(final NumberLiteral nl, final Class<? extends Object> expectedType) {
+    StringConcatenation _builder = new StringConcatenation();
+    double _value = nl.getValue();
+    _builder.append(_value, "");
+    return _builder;
+  }
+  
+  protected CharSequence _compile(final StringLiteral sl, final Class<? extends Object> expectedType) {
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("\"");
+    String _value = sl.getValue();
+    _builder.append(_value, "");
+    _builder.append("\"");
+    return _builder;
+  }
+  
+  protected CharSequence _compile(final BooleanLiteral bl, final Class<? extends Object> expectedType) {
+    StringConcatenation _builder = new StringConcatenation();
+    boolean _isValue = bl.isValue();
+    _builder.append(_isValue, "");
+    return _builder;
+  }
+  
+  protected CharSequence _compile(final Expression exp, final Class<? extends Object> expectedType) {
+    StringConcatenation _builder = new StringConcatenation();
+    Expression _exp = exp.getExp();
+    CharSequence _compile = this.compile(_exp, expectedType);
+    _builder.append(_compile, "");
+    return _builder;
+  }
+  
+  protected CharSequence _compileArgument(final SystemArgumentReference arg, final FunctionCall fc) {
+    StringConcatenation _builder = new StringConcatenation();
+    String _mapsFrom = arg.getMapsFrom();
+    _builder.append(_mapsFrom, "");
+    return _builder;
+  }
+  
+  protected CharSequence _compileArgument(final FunctionArgumentReference arg, final FunctionCall fc) {
+    StringConcatenation _builder = new StringConcatenation();
+    EList<Expression> _args = fc.getArgs();
+    int _argIndex = arg.getArgIndex();
+    Expression _get = _args.get(_argIndex);
+    Class<? extends Object> _javaType = arg.getJavaType();
+    CharSequence _compile = this.compile(_get, _javaType);
+    _builder.append(_compile, "");
+    return _builder;
+  }
+  
+  protected CharSequence _compileFunction(final ExternalFunctionReference fcr, final FunctionCall fc) {
+    StringConcatenation _builder = new StringConcatenation();
+    ExternalFunctionDefinition _func = fcr.getFunc();
+    String _className = _func.getClassName();
+    String _importedName = this.getImportedName(_className);
+    _builder.append(_importedName, "");
+    _builder.append(".");
+    ExternalFunctionDefinition _func_1 = fcr.getFunc();
+    String _methodName = _func_1.getMethodName();
+    _builder.append(_methodName, "");
+    _builder.append("(");
+    _builder.newLineIfNotEmpty();
+    {
+      ExternalFunctionDefinition _func_2 = fcr.getFunc();
+      EList<JavaMethodArgument> _javaMethodArguments = _func_2.getJavaMethodArguments();
+      for(final JavaMethodArgument arg : _javaMethodArguments) {
+        _builder.append("\t\t");
+        {
+          ExternalFunctionDefinition _func_3 = fcr.getFunc();
+          EList<JavaMethodArgument> _javaMethodArguments_1 = _func_3.getJavaMethodArguments();
+          JavaMethodArgument _head = IterableExtensions.<JavaMethodArgument>head(_javaMethodArguments_1);
+          boolean _notEquals = (!Objects.equal(arg, _head));
+          if (_notEquals) {
+            _builder.append(",");
+          }
+        }
+        _builder.newLineIfNotEmpty();
+        _builder.append("\t\t");
+        CharSequence _compileArgument = this.compileArgument(arg, fc);
+        _builder.append(_compileArgument, "		");
+        _builder.newLineIfNotEmpty();
+        _builder.append("\t\t");
+      }
+    }
+    _builder.append(")");
+    return _builder;
+  }
+  
+  protected CharSequence _compileFunction(final FunctionReference fcr, final FunctionCall fc) {
+    StringConcatenation _builder = new StringConcatenation();
+    String _name = fcr.getName();
+    _builder.append(_name, "");
+    _builder.append("(");
+    {
+      EList<Expression> _args = fc.getArgs();
+      for(final Expression e : _args) {
+        _builder.append(" ");
+        _builder.newLineIfNotEmpty();
+        {
+          EList<Expression> _args_1 = fc.getArgs();
+          Expression _head = IterableExtensions.<Expression>head(_args_1);
+          boolean _equals = Objects.equal(e, _head);
+          if (_equals) {
+            CharSequence _compile = this.compile(e);
+            _builder.append(_compile, "");
+            _builder.newLineIfNotEmpty();
+          } else {
+            _builder.append(",");
+            CharSequence _compile_1 = this.compile(e);
+            _builder.append(_compile_1, "");
+            _builder.newLineIfNotEmpty();
+          }
+        }
+        _builder.append("\t\t\t");
+      }
+    }
+    _builder.append(")");
+    return _builder;
+  }
+  
+  protected CharSequence _compile(final FunctionCall fc, final Class<? extends Object> expectedType) {
+    StringConcatenation _builder = new StringConcatenation();
+    FunctionReference _ref = fc.getRef();
+    CharSequence _compileFunction = this.compileFunction(_ref, fc);
+    _builder.append(_compileFunction, "");
+    return _builder;
+  }
+  
+  public CharSequence compile(final Notifier e) {
+    if (e instanceof Evaluation) {
+      return _compile((Evaluation)e);
+    } else if (e instanceof DefStatement) {
+      return _compile((DefStatement)e);
+    } else if (e instanceof TransitionBlock) {
+      return _compile((TransitionBlock)e);
+    } else if (e instanceof Resource) {
+      return _compile((Resource)e);
+    } else {
+      throw new IllegalArgumentException("Unhandled parameter types: " +
+        Arrays.<Object>asList(e).toString());
+    }
+  }
+  
+  public CharSequence compile(final Expression bl, final Class<? extends Object> expectedType) {
+    if (bl instanceof BooleanLiteral) {
+      return _compile((BooleanLiteral)bl, expectedType);
+    } else if (bl instanceof Div) {
+      return _compile((Div)bl, expectedType);
+    } else if (bl instanceof FunctionCall) {
+      return _compile((FunctionCall)bl, expectedType);
+    } else if (bl instanceof Minus) {
+      return _compile((Minus)bl, expectedType);
+    } else if (bl instanceof Multi) {
+      return _compile((Multi)bl, expectedType);
+    } else if (bl instanceof NumberLiteral) {
+      return _compile((NumberLiteral)bl, expectedType);
+    } else if (bl instanceof Plus) {
+      return _compile((Plus)bl, expectedType);
+    } else if (bl instanceof PrimaryExpression) {
+      return _compile((PrimaryExpression)bl, expectedType);
+    } else if (bl instanceof StringLiteral) {
+      return _compile((StringLiteral)bl, expectedType);
+    } else if (bl instanceof VariableReference) {
+      return _compile((VariableReference)bl, expectedType);
+    } else if (bl != null) {
+      return _compile(bl, expectedType);
+    } else {
+      throw new IllegalArgumentException("Unhandled parameter types: " +
+        Arrays.<Object>asList(bl, expectedType).toString());
+    }
+  }
+  
+  public CharSequence compileReference(final ScopedVariableReference rf, final Class<? extends Object> expectedType) {
+    if (rf instanceof AbsoluteCompartmentValueReference) {
+      return _compileReference((AbsoluteCompartmentValueReference)rf, expectedType);
+    } else if (rf instanceof RelativeCompartmentValueReference) {
+      return _compileReference((RelativeCompartmentValueReference)rf, expectedType);
+    } else if (rf instanceof GlobalVariableReference) {
+      return _compileReference((GlobalVariableReference)rf, expectedType);
+    } else if (rf instanceof LocalVariableReference) {
+      return _compileReference((LocalVariableReference)rf, expectedType);
+    } else if (rf instanceof ModelParamReference) {
+      return _compileReference((ModelParamReference)rf, expectedType);
+    } else {
+      throw new IllegalArgumentException("Unhandled parameter types: " +
+        Arrays.<Object>asList(rf, expectedType).toString());
+    }
+  }
+  
+  public CharSequence compileArgument(final JavaMethodArgument arg, final FunctionCall fc) {
+    if (arg instanceof FunctionArgumentReference) {
+      return _compileArgument((FunctionArgumentReference)arg, fc);
+    } else if (arg instanceof SystemArgumentReference) {
+      return _compileArgument((SystemArgumentReference)arg, fc);
+    } else {
+      throw new IllegalArgumentException("Unhandled parameter types: " +
+        Arrays.<Object>asList(arg, fc).toString());
+    }
+  }
+  
+  public CharSequence compileFunction(final FunctionReference fcr, final FunctionCall fc) {
+    if (fcr instanceof ExternalFunctionReference) {
+      return _compileFunction((ExternalFunctionReference)fcr, fc);
+    } else if (fcr != null) {
+      return _compileFunction(fcr, fc);
+    } else {
+      throw new IllegalArgumentException("Unhandled parameter types: " +
+        Arrays.<Object>asList(fcr, fc).toString());
+    }
+  }
+}