]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
SCL Function registry for emulating listeners 63/3263/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 17 Sep 2019 13:34:48 +0000 (16:34 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 17 Sep 2019 13:34:48 +0000 (16:34 +0300)
gitlab #13

Change-Id: I1c370495412d47cbd27a1cfe06d508a5fa645256

org.simantics.interop.scl/.classpath [new file with mode: 0644]
org.simantics.interop.scl/.project [new file with mode: 0644]
org.simantics.interop.scl/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
org.simantics.interop.scl/META-INF/MANIFEST.MF [new file with mode: 0644]
org.simantics.interop.scl/build.properties [new file with mode: 0644]
org.simantics.interop.scl/pom.xml [new file with mode: 0644]
org.simantics.interop.scl/scl/Interop/FunctionRegistry.scl [new file with mode: 0644]
org.simantics.interop.scl/src/org/simantics/interop/scl/FunctionRegistry.java [new file with mode: 0644]

diff --git a/org.simantics.interop.scl/.classpath b/org.simantics.interop.scl/.classpath
new file mode 100644 (file)
index 0000000..eca7bdb
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.simantics.interop.scl/.project b/org.simantics.interop.scl/.project
new file mode 100644 (file)
index 0000000..1d339d0
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>org.simantics.interop.scl</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.ManifestBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.SchemaBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/org.simantics.interop.scl/.settings/org.eclipse.jdt.core.prefs b/org.simantics.interop.scl/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..0c68a61
--- /dev/null
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/org.simantics.interop.scl/META-INF/MANIFEST.MF b/org.simantics.interop.scl/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..008487b
--- /dev/null
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Scl
+Bundle-SymbolicName: org.simantics.interop.scl
+Bundle-Version: 1.0.0.qualifier
+Automatic-Module-Name: org.simantics.interop.scl
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Require-Bundle: org.simantics.scl.data;bundle-version="1.0.0",
+ org.simantics.scl.db;bundle-version="0.1.3",
+ org.simantics.scl.expressions;bundle-version="1.0.0",
+ org.simantics.scl.osgi;bundle-version="1.0.4",
+ org.simantics.scl.reflection;bundle-version="1.0.0",
+ org.simantics.scl.runtime;bundle-version="0.4.0",
+ org.simantics.utils.datastructures;bundle-version="1.1.0"
diff --git a/org.simantics.interop.scl/build.properties b/org.simantics.interop.scl/build.properties
new file mode 100644 (file)
index 0000000..a4fd10d
--- /dev/null
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .,\
+               scl/
diff --git a/org.simantics.interop.scl/pom.xml b/org.simantics.interop.scl/pom.xml
new file mode 100644 (file)
index 0000000..c331b6c
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+       xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+       <modelVersion>4.0.0</modelVersion>
+
+       <parent>
+               <groupId>org.simantics.interop</groupId>
+               <artifactId>org.simantics.interop.root</artifactId>
+               <version>1.0.0-SNAPSHOT</version>
+       </parent>
+
+       <artifactId>org.simantics.interop.scl</artifactId>
+       <packaging>eclipse-plugin</packaging>
+       <version>1.0.0-SNAPSHOT</version>
+
+</project>
diff --git a/org.simantics.interop.scl/scl/Interop/FunctionRegistry.scl b/org.simantics.interop.scl/scl/Interop/FunctionRegistry.scl
new file mode 100644 (file)
index 0000000..9d707cf
--- /dev/null
@@ -0,0 +1,22 @@
+importJava "org.simantics.interop.scl.FunctionRegistry" where
+  
+  register :: a -> String -> (f -> <Proc>()) -> <Proc> ()
+  @JavaName register
+  register1 :: a -> String -> (f -> b -> <Proc>()) -> <Proc> ()
+  @JavaName register
+  register2 :: a -> String -> (f -> b -> c -> <Proc>()) -> <Proc> ()
+  @JavaName register
+  register3 :: a -> String -> (f -> b -> c -> d -> <Proc>()) -> <Proc> ()
+  @JavaName register
+  register4 :: a -> String -> (f -> b -> c -> d -> e -> <Proc>()) -> <Proc> ()
+  call0 :: a -> String -> <Proc> ()
+  call1 :: a -> String -> b -> <Proc> ()
+  call2 :: a -> String -> b -> c -> <Proc> ()
+  call3 :: a -> String -> b -> c -> d -> <Proc> ()
+  call4 :: a -> String -> b -> c -> d -> e -> <Proc> ()
+  
+  @JavaName clear
+  clear :: a -> <Proc> ()
+  
+  @JavaName clear
+  clearName :: a -> String -> <Proc> ()
\ No newline at end of file
diff --git a/org.simantics.interop.scl/src/org/simantics/interop/scl/FunctionRegistry.java b/org.simantics.interop.scl/src/org/simantics/interop/scl/FunctionRegistry.java
new file mode 100644 (file)
index 0000000..003a50a
--- /dev/null
@@ -0,0 +1,82 @@
+package org.simantics.interop.scl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.simantics.scl.runtime.function.Function;
+import org.simantics.utils.datastructures.MapList;
+
+@SuppressWarnings({"rawtypes","unchecked"})
+public class FunctionRegistry {
+    
+    
+    static Map<Object, MapList<String, Function>> map = new HashMap<Object, MapList<String,Function>>();
+    
+    public static void register(Object key, String name, Function f) {
+        MapList<String, Function> fmap = map.get(key);
+        if (fmap == null) {
+            fmap = new MapList<>();
+            map.put(key, fmap);
+        }
+        fmap.add(name, f);
+    }
+    
+    public static void call0 (Object key, String name) {
+        MapList<String, Function> fmap = map.get(key);
+        if (fmap == null)
+            return;
+        for (Function f : fmap.getValues(name)) {
+            f.apply(null);
+        }
+    }
+    
+    
+    public static void call1 (Object key, String name, Object o1) {
+        MapList<String, Function> fmap = map.get(key);
+        if (fmap == null)
+            return;
+        for (Function f : fmap.getValues(name)) {
+            f.apply(o1);
+        }
+    }
+    
+    public static void call2 (Object key, String name, Object o1, Object o2) {
+        MapList<String, Function> fmap = map.get(key);
+        if (fmap == null)
+            return;
+        for (Function f : fmap.getValues(name)) {
+            f.apply(o1,o2);
+        }
+    }
+    
+    public static void call3 (Object key, String name, Object o1, Object o2, Object o3) {
+        MapList<String, Function> fmap = map.get(key);
+        if (fmap == null)
+            return;
+        for (Function f : fmap.getValues(name)) {
+            f.apply(o1,o2,o3);
+        }
+    }
+    
+    public static void call4 (Object key, String name, Object o1, Object o2, Object o3, Object o4) {
+        MapList<String, Function> fmap = map.get(key);
+        if (fmap == null)
+            return;
+        for (Function f : fmap.getValues(name)) {
+            f.apply(o1,o2,o3,o4);
+        }
+    }
+    
+    public static void clear(Object key) {
+        map.remove(key);
+    }
+    
+    public static void clear(Object key, String name) {
+        MapList<String, Function> fmap = map.get(key);
+        if (fmap == null)
+            return;
+        fmap.remove(name);
+    }
+    
+
+}