]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/commands/CommandSession.java
Fixed SCLConsoleView.setCurrentImports to be performed in a Job
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / commands / CommandSession.java
index d0e44a9c7b263a36c0a75b60cc5f678432081165..06853c898a7fe30895cfce8d4e3f0ff5abfb0f21 100644 (file)
@@ -17,6 +17,7 @@ import java.util.Set;
 
 import org.simantics.scl.compiler.common.names.Names;
 import org.simantics.scl.compiler.constants.StringConstant;
+import org.simantics.scl.compiler.dynamic.SafeDynamic;
 import org.simantics.scl.compiler.elaboration.expressions.EApply;
 import org.simantics.scl.compiler.elaboration.expressions.EBlock;
 import org.simantics.scl.compiler.elaboration.expressions.EConstant;
@@ -57,6 +58,8 @@ import org.simantics.scl.runtime.reporting.DelegatingSCLReportingHandler;
 import org.simantics.scl.runtime.reporting.SCLReporting;
 import org.simantics.scl.runtime.reporting.SCLReportingHandler;
 import org.simantics.scl.runtime.tuple.Tuple0;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import gnu.trove.map.hash.THashMap;
 import gnu.trove.procedure.TObjectProcedure;
@@ -65,6 +68,8 @@ import gnu.trove.set.hash.THashSet;
 
 public class CommandSession {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(CommandSession.class);
+
     ModuleRepository moduleRepository;
     SCLReportingHandler defaultHandler;
     
@@ -84,6 +89,10 @@ public class CommandSession {
      */
     private boolean validateOnly; 
     
+    public CommandSession(ModuleRepository moduleRepository) {
+        this(moduleRepository, SCLReporting.getCurrentReportingHandler());
+    }
+
     public CommandSession(ModuleRepository moduleRepository, SCLReportingHandler handler) {
         this.moduleRepository = moduleRepository;
         this.defaultHandler = new PrintDecorator(
@@ -142,7 +151,7 @@ public class CommandSession {
                 }
             }
         } catch(RuntimeException e) {
-            e.printStackTrace();
+            LOGGER.error("updateRuntimeEnvironment(clearErrorsFlags={}) failed", clearErrorsFlags, e);
             throw e;
         }
         valueToStringConverter = new ValueToStringConverter(runtimeEnvironment);
@@ -615,6 +624,11 @@ public class CommandSession {
         variableTypes.put(name, type);
     }
 
+    public void setVariable(String name, SafeDynamic typeAndValue) {
+        variableValues.put(name, typeAndValue.value);
+        variableTypes.put(name, typeAndValue.type_);
+    }
+
     public Object getVariableValue(String name) {
         return variableValues.get(name);
     }
@@ -623,6 +637,14 @@ public class CommandSession {
         return variableTypes.get(name);
     }
     
+    public SafeDynamic getVariableValueAndType(String name) {
+        Type type = variableTypes.get(name);
+        if(type == null)
+            return null;
+        Object value = variableValues.get(name);
+        return new SafeDynamic(type, value);
+    }
+    
     public void removeVariable(String name) {
        variableValues.remove(name);
        variableTypes.remove(name);