]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Check statement collisions 73/73/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 15 Sep 2016 10:58:42 +0000 (13:58 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 15 Sep 2016 10:58:42 +0000 (13:58 +0300)
Added a new validation step that checks whether the result
of graph compilation contains the same statement more than once.

Change-Id: I3d1f5941048d62538e4f732f30cd55099a015513

bundles/org.simantics.graph.compiler/META-INF/MANIFEST.MF
bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/GraphCompiler.java
bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/validation/ReportCollisions.java
bundles/org.simantics.graph/META-INF/MANIFEST.MF
bundles/org.simantics.graph/src/org/simantics/graph/store/StatementCollision.java [new file with mode: 0644]
bundles/org.simantics.graph/src/org/simantics/graph/store/StatementStore.java

index 6d785149f1272476c6e306f69d0660f9c5734ced..d64d3d56432796808e56877e2677d28d244fd975 100644 (file)
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: Compiler
 Bundle-SymbolicName: org.simantics.graph.compiler;singleton:=true
-Bundle-Version: 1.1.11.qualifier
+Bundle-Version: 1.1.15.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Require-Bundle: org.simantics.graph;bundle-version="1.0.0";visibility:=reexport,
  org.simantics.ltk.antlr;bundle-version="1.0.0",
index 21761a3b156d2e404684a830745a33a5a9c043ad..5f30082a806a537d47a3c6a625a6311ebe2c450f 100644 (file)
@@ -124,7 +124,7 @@ public class GraphCompiler {
                        run(new CreateInverseRelations(graph, store));\r
                        run(new AddConsistsOf(paths, store));\r
                        run(new ConvertPreValues(graph, store, errors));\r
-                       run(new ReportCollisions(errors, store));\r
+                       run(new ReportCollisions(preferences, errors, store));\r
                        if(preferences.validate)\r
                                run(new ValidateGraph(graph, errors, store, preferences));\r
                        \r
index e7346e94570c92edd76c0e46e4df56b2b87935d0..28a53381e3ca5f2cdac83a5be2cc9181f79ccaf5 100644 (file)
@@ -2,18 +2,22 @@ package org.simantics.graph.compiler.internal.validation;
 \r
 import java.util.Collection;\r
 \r
+import org.simantics.graph.compiler.GraphCompilerPreferences;\r
 import org.simantics.graph.compiler.internal.store.LocationStore;\r
 import org.simantics.graph.compiler.internal.templates.TemplateDefinitionStore;\r
 import org.simantics.graph.store.GraphStore;\r
+import org.simantics.graph.store.StatementCollision;\r
 import org.simantics.ltk.Problem;\r
 \r
 public class ReportCollisions implements Runnable {\r
+    GraphCompilerPreferences preferences;\r
        Collection<Problem> problems;\r
        GraphStore store;\r
 \r
        public ReportCollisions(\r
-                       Collection<Problem> problems,\r
+                       GraphCompilerPreferences preferences, Collection<Problem> problems,\r
                        GraphStore store) {\r
+           this.preferences = preferences;\r
                this.problems = problems;\r
                this.store = store;\r
        }\r
@@ -32,7 +36,15 @@ public class ReportCollisions implements Runnable {
                for(int c : store.getStore(TemplateDefinitionStore.class).getCollisions().toArray())\r
                        problems.add(new Problem(\r
                                        locations.getLocation(c), \r
-                                       "Two tempalate definitions are given for the same resource."));\r
+                                       "Two template definitions are given for the same resource."));\r
+               if(preferences.validate)\r
+                   for(StatementCollision collision : store.statements.getCollisions()) {\r
+                       problems.add(new Problem(\r
+                               locations.getLocation(collision.subject), \r
+                               "The same statement is defined twice: " +\r
+                                       store.idToRes(collision.predicate) + ", " +\r
+                                       store.idToRes(collision.object)));\r
+                   }\r
        }\r
        \r
 }\r
index 448d8556ba68551fe90af862bff6a30fbaad0763..5f4404acc377654f15cb79c95be04028b3fc09a7 100644 (file)
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: Transferable Graph Runtime
 Bundle-SymbolicName: org.simantics.graph
-Bundle-Version: 1.1.11.qualifier
+Bundle-Version: 1.1.15.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Require-Bundle: org.simantics.databoard;bundle-version="0.5.1",
  gnu.trove3;bundle-version="3.0.0";visibility:=reexport,
diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/store/StatementCollision.java b/bundles/org.simantics.graph/src/org/simantics/graph/store/StatementCollision.java
new file mode 100644 (file)
index 0000000..8c24b88
--- /dev/null
@@ -0,0 +1,14 @@
+package org.simantics.graph.store;\r
+\r
+public class StatementCollision {\r
+    public final int subject;\r
+    public final int predicate;\r
+    public final int object;\r
+    \r
+    public StatementCollision(int subject, int predicate, int object) {\r
+        this.subject = subject;\r
+        this.predicate = predicate;\r
+        this.object = object;\r
+    }\r
+}\r
+\r
index 96b6b1c725ee61a073ac2b7cebf949ff94def4bc..cc82975c8191fe2cd980c9eaf3963fa47e49939c 100644 (file)
@@ -1,5 +1,7 @@
 package org.simantics.graph.store;\r
 \r
+import java.util.ArrayList;\r
+\r
 import gnu.trove.list.array.TIntArrayList;\r
 import gnu.trove.map.hash.TIntIntHashMap;\r
 import gnu.trove.map.hash.TIntObjectHashMap;\r
@@ -10,7 +12,7 @@ import gnu.trove.set.hash.TIntHashSet;
 \r
 /**\r
  * Statement store indexes a set of statements. \r
- * @author Hannu Niemistö\r
+ * @author Hannu Niemist\r
  */\r
 public class StatementStore implements IStore {\r
        \r
@@ -287,5 +289,54 @@ public class StatementStore implements IStore {
                        }\r
                });\r
                return statements.toArray();\r
+       }\r
+\r
+       private static class CollisionSubjectProcedure implements TIntObjectProcedure<TIntObjectHashMap<TIntArrayList>> {\r
+           CollisionPredicateProcedure predicateProcedure;\r
+\r
+           public CollisionSubjectProcedure(CollisionPredicateProcedure predicateProcedure) {\r
+               this.predicateProcedure = predicateProcedure;\r
+           }\r
+\r
+           @Override\r
+           public boolean execute(int subject, TIntObjectHashMap<TIntArrayList> predicateObjectMap) {\r
+               predicateProcedure.subject = subject;\r
+               predicateObjectMap.forEachEntry(predicateProcedure);\r
+               return true;\r
+           }\r
+\r
+       }\r
+\r
+       private static class CollisionPredicateProcedure implements TIntObjectProcedure<TIntArrayList> {\r
+        ArrayList<StatementCollision> collisions;\r
+           int subject;\r
+           \r
+           public CollisionPredicateProcedure(ArrayList<StatementCollision> collisions) {\r
+            this.collisions = collisions;\r
+        }\r
+           \r
+        @Override\r
+           public boolean execute(int predicate, TIntArrayList objects) {\r
+               if(objects.size() > 1) {\r
+                   objects.sort();\r
+                   int oldObject = objects.get(0); \r
+                   for(int i=1;i<objects.size();++i) {\r
+                       int curObject = objects.get(i);\r
+                       if(curObject == oldObject)\r
+                           collisions.add(new StatementCollision(subject, predicate, curObject));\r
+                       oldObject = curObject;\r
+                   }\r
+               }\r
+               return true;\r
+           }\r
+\r
+       }\r
+\r
+       public ArrayList<StatementCollision> getCollisions() {\r
+           ArrayList<StatementCollision> collisions = new ArrayList<StatementCollision>();\r
+           CollisionPredicateProcedure predicateProcedure = new CollisionPredicateProcedure(collisions);\r
+           CollisionSubjectProcedure subjectProcedure = new CollisionSubjectProcedure(predicateProcedure);\r
+           statements.forEachEntry(subjectProcedure);\r
+           return collisions;\r
        }       \r
 }\r