]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/procedures/DefaultValueTyping.java
a6b54b4a57062977bbaf5c84473b68ecde1b6236
[simantics/platform.git] / bundles / org.simantics.graph.compiler / src / org / simantics / graph / compiler / internal / procedures / DefaultValueTyping.java
1 package org.simantics.graph.compiler.internal.procedures;\r
2 \r
3 import gnu.trove.procedure.TIntObjectProcedure;\r
4 import gnu.trove.set.hash.TIntHashSet;\r
5 \r
6 import org.simantics.graph.compiler.internal.store.IPreValue;\r
7 import org.simantics.graph.compiler.internal.store.PreValueStore;\r
8 import org.simantics.graph.query.Path;\r
9 import org.simantics.graph.query.Paths;\r
10 import org.simantics.graph.store.GraphStore;\r
11 \r
12 public class DefaultValueTyping implements Runnable {\r
13 \r
14         GraphStore store;\r
15         Paths paths;\r
16         \r
17         public DefaultValueTyping(Paths paths, GraphStore store) {\r
18             this.paths = paths;\r
19                 this.store = store;\r
20         }\r
21 \r
22         @Override\r
23         public void run() {\r
24                 final int instanceOfId = store.identities.createPathToId(paths.InstanceOf);\r
25                 final TIntHashSet \r
26                         instanceOfDomain = store.statements.getRelationDomain(instanceOfId);\r
27                 PreValueStore preValues = store.getStore(PreValueStore.class);\r
28                 preValues.forEachPreValue(new TIntObjectProcedure<IPreValue>() {                \r
29                         @Override\r
30                         public boolean execute(int a, IPreValue b) {\r
31                                 if(!instanceOfDomain.contains(a)) {\r
32                                         Path defaultType = b.getDefaultType(paths);\r
33                                         if(defaultType != null)\r
34                                                 store.statements.add(a, \r
35                                                                 instanceOfId,\r
36                                                                 store.identities.createPathToId(defaultType)\r
37                                                         );\r
38                                 }\r
39                                 return true;\r
40                         }\r
41                 });\r
42         }       \r
43 \r
44 }\r