From 248798f4fad0a235508902877cffd1b4298921f7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Fri, 16 Sep 2016 17:28:01 +0300 Subject: [PATCH] Small improvements to statement collision reporting. Change-Id: I18469fcc69d11f1fcd652ad7f8ffd52496064d30 --- .../internal/validation/ReportCollisions.java | 15 ++++++++++++--- .../graph/store/StatementCollision.java | 4 +++- .../simantics/graph/store/StatementStore.java | 18 ++++++++++++++---- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/validation/ReportCollisions.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/validation/ReportCollisions.java index 28a53381e..277ddc7b1 100644 --- a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/validation/ReportCollisions.java +++ b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/validation/ReportCollisions.java @@ -5,6 +5,7 @@ import java.util.Collection; import org.simantics.graph.compiler.GraphCompilerPreferences; import org.simantics.graph.compiler.internal.store.LocationStore; import org.simantics.graph.compiler.internal.templates.TemplateDefinitionStore; +import org.simantics.graph.query.Res; import org.simantics.graph.store.GraphStore; import org.simantics.graph.store.StatementCollision; import org.simantics.ltk.Problem; @@ -22,6 +23,13 @@ public class ReportCollisions implements Runnable { this.store = store; } + private static String abbreviateURI(Res res) { + if(res == null) + return "null"; + String uri = res.toString(); + return uri.replace("http://www.simantics.org/", ""); + } + @Override public void run() { LocationStore locations = store.getStore(LocationStore.class); @@ -41,9 +49,10 @@ public class ReportCollisions implements Runnable { for(StatementCollision collision : store.statements.getCollisions()) { problems.add(new Problem( locations.getLocation(collision.subject), - "The same statement is defined twice: " + - store.idToRes(collision.predicate) + ", " + - store.idToRes(collision.object))); + "The same statement is defined " + collision.count + " times: " + + abbreviateURI(store.idToRes(collision.subject)) + ", " + + abbreviateURI(store.idToRes(collision.predicate)) + ", " + + abbreviateURI(store.idToRes(collision.object)))); } } 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 index 8c24b882d..3bcd4f0bf 100644 --- a/bundles/org.simantics.graph/src/org/simantics/graph/store/StatementCollision.java +++ b/bundles/org.simantics.graph/src/org/simantics/graph/store/StatementCollision.java @@ -4,11 +4,13 @@ public class StatementCollision { public final int subject; public final int predicate; public final int object; + public final int count; - public StatementCollision(int subject, int predicate, int object) { + public StatementCollision(int subject, int predicate, int object, int count) { this.subject = subject; this.predicate = predicate; this.object = object; + this.count = count; } } diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/store/StatementStore.java b/bundles/org.simantics.graph/src/org/simantics/graph/store/StatementStore.java index cc82975c8..02dfddde8 100644 --- a/bundles/org.simantics.graph/src/org/simantics/graph/store/StatementStore.java +++ b/bundles/org.simantics.graph/src/org/simantics/graph/store/StatementStore.java @@ -319,13 +319,23 @@ public class StatementStore implements IStore { public boolean execute(int predicate, TIntArrayList objects) { if(objects.size() > 1) { objects.sort(); - int oldObject = objects.get(0); + int oldObject = objects.get(0); + int collisionCount = 1; for(int i=1;i 1) { + collisions.add(new StatementCollision(subject, predicate, oldObject, collisionCount)); + collisionCount = 1; + } + oldObject = curObject; + } } + if(collisionCount > 1) + collisions.add(new StatementCollision(subject, predicate, oldObject, collisionCount)); } return true; } -- 2.47.1