X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2Fvalidation%2FReportCollisions.java;h=30efe78c4797b50a282214f06616c6de5cec908c;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=e7346e94570c92edd76c0e46e4df56b2b87935d0;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git 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 e7346e945..30efe78c4 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 @@ -1,38 +1,59 @@ -package org.simantics.graph.compiler.internal.validation; - -import java.util.Collection; - -import org.simantics.graph.compiler.internal.store.LocationStore; -import org.simantics.graph.compiler.internal.templates.TemplateDefinitionStore; -import org.simantics.graph.store.GraphStore; -import org.simantics.ltk.Problem; - -public class ReportCollisions implements Runnable { - Collection problems; - GraphStore store; - - public ReportCollisions( - Collection problems, - GraphStore store) { - this.problems = problems; - this.store = store; - } - - @Override - public void run() { - LocationStore locations = store.getStore(LocationStore.class); - for(int c : store.values.getCollisions().toArray()) - problems.add(new Problem( - locations.getLocation(c), - "Two literal values are given for the same resource.")); - for(int c : store.identities.getCollisions().toArray()) - problems.add(new Problem( - locations.getLocation(c), - "Two different identities are given for the same resource.")); - for(int c : store.getStore(TemplateDefinitionStore.class).getCollisions().toArray()) - problems.add(new Problem( - locations.getLocation(c), - "Two tempalate definitions are given for the same resource.")); - } - -} +package org.simantics.graph.compiler.internal.validation; + +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; + +public class ReportCollisions implements Runnable { + GraphCompilerPreferences preferences; + Collection problems; + GraphStore store; + + public ReportCollisions( + GraphCompilerPreferences preferences, Collection problems, + GraphStore store) { + this.preferences = preferences; + this.problems = problems; + 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); + for(int c : store.values.getCollisions().toArray()) + problems.add(new Problem( + locations.getLocation(c), + "Two literal values are given for the same resource.")); + for(int c : store.identities.getCollisions().toArray()) + problems.add(new Problem( + locations.getLocation(c), + "Two different identities are given for the same resource.")); + for(int c : store.getStore(TemplateDefinitionStore.class).getCollisions().toArray()) + problems.add(new Problem( + locations.getLocation(c), + "Two template definitions are given for the same resource.")); + if(preferences.validate) + for(StatementCollision collision : store.statements.getCollisions()) { + problems.add(new Problem( + locations.getLocation(collision.subject), + "The same statement is defined " + collision.count + " times: " + + abbreviateURI(store.idToRes(collision.subject)) + ", " + + abbreviateURI(store.idToRes(collision.predicate)) + ", " + + abbreviateURI(store.idToRes(collision.object)))); + } + } + +}