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",
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
\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
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
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,
--- /dev/null
+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
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
\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
}\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