]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Small improvements to statement collision reporting. 79/79/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Fri, 16 Sep 2016 14:28:01 +0000 (17:28 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Fri, 16 Sep 2016 14:28:01 +0000 (17:28 +0300)
Change-Id: I18469fcc69d11f1fcd652ad7f8ffd52496064d30

bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/validation/ReportCollisions.java
bundles/org.simantics.graph/src/org/simantics/graph/store/StatementCollision.java
bundles/org.simantics.graph/src/org/simantics/graph/store/StatementStore.java

index 28a53381e3ca5f2cdac83a5be2cc9181f79ccaf5..277ddc7b16cdb876d1bcef7760467a2e08519430 100644 (file)
@@ -5,6 +5,7 @@ import java.util.Collection;
 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.query.Res;\r
 import org.simantics.graph.store.GraphStore;\r
 import org.simantics.graph.store.StatementCollision;\r
 import org.simantics.ltk.Problem;\r
@@ -22,6 +23,13 @@ public class ReportCollisions implements Runnable {
                this.store = store;\r
        }\r
        \r
+       private static String abbreviateURI(Res res) {\r
+           if(res == null)\r
+               return "null";\r
+           String uri = res.toString();\r
+           return uri.replace("http://www.simantics.org/", "");\r
+       }\r
+       \r
        @Override\r
        public void run() {\r
                LocationStore locations = store.getStore(LocationStore.class);\r
@@ -41,9 +49,10 @@ public class ReportCollisions implements Runnable {
                    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
+                               "The same statement is defined " + collision.count + " times: " +\r
+                                       abbreviateURI(store.idToRes(collision.subject)) + ", " +\r
+                                       abbreviateURI(store.idToRes(collision.predicate)) + ", " +\r
+                                       abbreviateURI(store.idToRes(collision.object))));\r
                    }\r
        }\r
        \r
index 8c24b882dc85bd3310f95b93682a630054aa81c7..3bcd4f0bfedbdece8a60c55dd046ca8ef0ac8f28 100644 (file)
@@ -4,11 +4,13 @@ public class StatementCollision {
     public final int subject;\r
     public final int predicate;\r
     public final int object;\r
+    public final int count;\r
     \r
-    public StatementCollision(int subject, int predicate, int object) {\r
+    public StatementCollision(int subject, int predicate, int object, int count) {\r
         this.subject = subject;\r
         this.predicate = predicate;\r
         this.object = object;\r
+        this.count = count;\r
     }\r
 }\r
 \r
index cc82975c8191fe2cd980c9eaf3963fa47e49939c..02dfddde81085d06727089863185c4e10345d54f 100644 (file)
@@ -319,13 +319,23 @@ public class StatementStore implements IStore {
            public boolean execute(int predicate, TIntArrayList objects) {\r
                if(objects.size() > 1) {\r
                    objects.sort();\r
-                   int oldObject = objects.get(0); \r
+                   int oldObject = objects.get(0);\r
+                   int collisionCount = 1;\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
+                       if(curObject == oldObject) {\r
+                           ++collisionCount;\r
+                       }\r
+                       else {\r
+                           if(collisionCount > 1) {\r
+                               collisions.add(new StatementCollision(subject, predicate, oldObject, collisionCount));\r
+                               collisionCount = 1;\r
+                           }\r
+                           oldObject = curObject;\r
+                       }\r
                    }\r
+                if(collisionCount > 1)\r
+                    collisions.add(new StatementCollision(subject, predicate, oldObject, collisionCount));\r
                }\r
                return true;\r
            }\r