]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/procedures/DefaultValueTyping.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.graph.compiler / src / org / simantics / graph / compiler / internal / procedures / DefaultValueTyping.java
diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/procedures/DefaultValueTyping.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/procedures/DefaultValueTyping.java
new file mode 100644 (file)
index 0000000..a6b54b4
--- /dev/null
@@ -0,0 +1,44 @@
+package org.simantics.graph.compiler.internal.procedures;\r
+\r
+import gnu.trove.procedure.TIntObjectProcedure;\r
+import gnu.trove.set.hash.TIntHashSet;\r
+\r
+import org.simantics.graph.compiler.internal.store.IPreValue;\r
+import org.simantics.graph.compiler.internal.store.PreValueStore;\r
+import org.simantics.graph.query.Path;\r
+import org.simantics.graph.query.Paths;\r
+import org.simantics.graph.store.GraphStore;\r
+\r
+public class DefaultValueTyping implements Runnable {\r
+\r
+       GraphStore store;\r
+       Paths paths;\r
+       \r
+       public DefaultValueTyping(Paths paths, GraphStore store) {\r
+           this.paths = paths;\r
+               this.store = store;\r
+       }\r
+\r
+       @Override\r
+       public void run() {\r
+               final int instanceOfId = store.identities.createPathToId(paths.InstanceOf);\r
+               final TIntHashSet \r
+                       instanceOfDomain = store.statements.getRelationDomain(instanceOfId);\r
+               PreValueStore preValues = store.getStore(PreValueStore.class);\r
+               preValues.forEachPreValue(new TIntObjectProcedure<IPreValue>() {                \r
+                       @Override\r
+                       public boolean execute(int a, IPreValue b) {\r
+                               if(!instanceOfDomain.contains(a)) {\r
+                                       Path defaultType = b.getDefaultType(paths);\r
+                                       if(defaultType != null)\r
+                                               store.statements.add(a, \r
+                                                               instanceOfId,\r
+                                                               store.identities.createPathToId(defaultType)\r
+                                                       );\r
+                               }\r
+                               return true;\r
+                       }\r
+               });\r
+       }       \r
+\r
+}\r