From a788fd18ebfc517f48aa0730e4e72e86875a2159 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Tue, 17 Sep 2019 16:34:48 +0300 Subject: [PATCH] SCL Function registry for emulating listeners gitlab #13 Change-Id: I1c370495412d47cbd27a1cfe06d508a5fa645256 (cherry picked from commit 14d4d6b020af5777afe37ec990c8fb8661f0bd14) --- org.simantics.interop.scl/.classpath | 7 ++ org.simantics.interop.scl/.project | 28 +++++++ .../.settings/org.eclipse.jdt.core.prefs | 7 ++ .../META-INF/MANIFEST.MF | 14 ++++ org.simantics.interop.scl/build.properties | 5 ++ org.simantics.interop.scl/pom.xml | 17 ++++ .../scl/Interop/FunctionRegistry.scl | 22 +++++ .../interop/scl/FunctionRegistry.java | 82 +++++++++++++++++++ 8 files changed, 182 insertions(+) create mode 100644 org.simantics.interop.scl/.classpath create mode 100644 org.simantics.interop.scl/.project create mode 100644 org.simantics.interop.scl/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.simantics.interop.scl/META-INF/MANIFEST.MF create mode 100644 org.simantics.interop.scl/build.properties create mode 100644 org.simantics.interop.scl/pom.xml create mode 100644 org.simantics.interop.scl/scl/Interop/FunctionRegistry.scl create mode 100644 org.simantics.interop.scl/src/org/simantics/interop/scl/FunctionRegistry.java diff --git a/org.simantics.interop.scl/.classpath b/org.simantics.interop.scl/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/org.simantics.interop.scl/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.simantics.interop.scl/.project b/org.simantics.interop.scl/.project new file mode 100644 index 0000000..1d339d0 --- /dev/null +++ b/org.simantics.interop.scl/.project @@ -0,0 +1,28 @@ + + + org.simantics.interop.scl + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + 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 index 0000000..0c68a61 --- /dev/null +++ b/org.simantics.interop.scl/.settings/org.eclipse.jdt.core.prefs @@ -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 index 0000000..008487b --- /dev/null +++ b/org.simantics.interop.scl/META-INF/MANIFEST.MF @@ -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 index 0000000..a4fd10d --- /dev/null +++ b/org.simantics.interop.scl/build.properties @@ -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 index 0000000..c331b6c --- /dev/null +++ b/org.simantics.interop.scl/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + + org.simantics.interop + org.simantics.interop.root + 1.0.0-SNAPSHOT + + + org.simantics.interop.scl + eclipse-plugin + 1.0.0-SNAPSHOT + + diff --git a/org.simantics.interop.scl/scl/Interop/FunctionRegistry.scl b/org.simantics.interop.scl/scl/Interop/FunctionRegistry.scl new file mode 100644 index 0000000..9d707cf --- /dev/null +++ b/org.simantics.interop.scl/scl/Interop/FunctionRegistry.scl @@ -0,0 +1,22 @@ +importJava "org.simantics.interop.scl.FunctionRegistry" where + + register :: a -> String -> (f -> ()) -> () + @JavaName register + register1 :: a -> String -> (f -> b -> ()) -> () + @JavaName register + register2 :: a -> String -> (f -> b -> c -> ()) -> () + @JavaName register + register3 :: a -> String -> (f -> b -> c -> d -> ()) -> () + @JavaName register + register4 :: a -> String -> (f -> b -> c -> d -> e -> ()) -> () + call0 :: a -> String -> () + call1 :: a -> String -> b -> () + call2 :: a -> String -> b -> c -> () + call3 :: a -> String -> b -> c -> d -> () + call4 :: a -> String -> b -> c -> d -> e -> () + + @JavaName clear + clear :: a -> () + + @JavaName clear + clearName :: a -> String -> () \ 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 index 0000000..003a50a --- /dev/null +++ b/org.simantics.interop.scl/src/org/simantics/interop/scl/FunctionRegistry.java @@ -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> map = new HashMap>(); + + public static void register(Object key, String name, Function f) { + MapList 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 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 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 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 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 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 fmap = map.get(key); + if (fmap == null) + return; + fmap.remove(name); + } + + +} -- 2.45.1