From: Hannu Niemistö Date: Thu, 15 Sep 2016 10:58:42 +0000 (+0300) Subject: Check statement collisions X-Git-Tag: v1.25.0~115^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=55f09d0198f1431c19ffa62e0cad361c1a2787e4 Check statement collisions Added a new validation step that checks whether the result of graph compilation contains the same statement more than once. Change-Id: I3d1f5941048d62538e4f732f30cd55099a015513 --- diff --git a/bundles/org.simantics.graph.compiler/META-INF/MANIFEST.MF b/bundles/org.simantics.graph.compiler/META-INF/MANIFEST.MF index 6d785149f..d64d3d564 100644 --- a/bundles/org.simantics.graph.compiler/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.graph.compiler/META-INF/MANIFEST.MF @@ -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", diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/GraphCompiler.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/GraphCompiler.java index 21761a3b1..5f30082a8 100644 --- a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/GraphCompiler.java +++ b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/GraphCompiler.java @@ -124,7 +124,7 @@ public class GraphCompiler { run(new CreateInverseRelations(graph, store)); run(new AddConsistsOf(paths, store)); run(new ConvertPreValues(graph, store, errors)); - run(new ReportCollisions(errors, store)); + run(new ReportCollisions(preferences, errors, store)); if(preferences.validate) run(new ValidateGraph(graph, errors, store, preferences)); 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..28a53381e 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 @@ -2,18 +2,22 @@ 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.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( - Collection problems, + GraphCompilerPreferences preferences, Collection problems, GraphStore store) { + this.preferences = preferences; this.problems = problems; this.store = store; } @@ -32,7 +36,15 @@ public class ReportCollisions implements Runnable { 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.")); + "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 twice: " + + store.idToRes(collision.predicate) + ", " + + store.idToRes(collision.object))); + } } } diff --git a/bundles/org.simantics.graph/META-INF/MANIFEST.MF b/bundles/org.simantics.graph/META-INF/MANIFEST.MF index 448d8556b..5f4404acc 100644 --- a/bundles/org.simantics.graph/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.graph/META-INF/MANIFEST.MF @@ -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 index 000000000..8c24b882d --- /dev/null +++ b/bundles/org.simantics.graph/src/org/simantics/graph/store/StatementCollision.java @@ -0,0 +1,14 @@ +package org.simantics.graph.store; + +public class StatementCollision { + public final int subject; + public final int predicate; + public final int object; + + public StatementCollision(int subject, int predicate, int object) { + this.subject = subject; + this.predicate = predicate; + this.object = object; + } +} + 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 96b6b1c72..cc82975c8 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 @@ -1,5 +1,7 @@ package org.simantics.graph.store; +import java.util.ArrayList; + import gnu.trove.list.array.TIntArrayList; import gnu.trove.map.hash.TIntIntHashMap; import gnu.trove.map.hash.TIntObjectHashMap; @@ -10,7 +12,7 @@ import gnu.trove.set.hash.TIntHashSet; /** * Statement store indexes a set of statements. - * @author Hannu Niemistö + * @author Hannu Niemist� */ public class StatementStore implements IStore { @@ -287,5 +289,54 @@ public class StatementStore implements IStore { } }); return statements.toArray(); + } + + private static class CollisionSubjectProcedure implements TIntObjectProcedure> { + CollisionPredicateProcedure predicateProcedure; + + public CollisionSubjectProcedure(CollisionPredicateProcedure predicateProcedure) { + this.predicateProcedure = predicateProcedure; + } + + @Override + public boolean execute(int subject, TIntObjectHashMap predicateObjectMap) { + predicateProcedure.subject = subject; + predicateObjectMap.forEachEntry(predicateProcedure); + return true; + } + + } + + private static class CollisionPredicateProcedure implements TIntObjectProcedure { + ArrayList collisions; + int subject; + + public CollisionPredicateProcedure(ArrayList collisions) { + this.collisions = collisions; + } + + @Override + public boolean execute(int predicate, TIntArrayList objects) { + if(objects.size() > 1) { + objects.sort(); + int oldObject = objects.get(0); + for(int i=1;i getCollisions() { + ArrayList collisions = new ArrayList(); + CollisionPredicateProcedure predicateProcedure = new CollisionPredicateProcedure(collisions); + CollisionSubjectProcedure subjectProcedure = new CollisionSubjectProcedure(predicateProcedure); + statements.forEachEntry(subjectProcedure); + return collisions; } }