1 package org.simantics.graph.compiler.internal.validation;
3 import java.util.Collection;
5 import org.simantics.graph.compiler.GraphCompilerPreferences;
6 import org.simantics.graph.compiler.internal.store.LocationStore;
7 import org.simantics.graph.compiler.internal.templates.TemplateDefinitionStore;
8 import org.simantics.graph.query.Res;
9 import org.simantics.graph.store.GraphStore;
10 import org.simantics.graph.store.StatementCollision;
11 import org.simantics.ltk.Problem;
13 public class ReportCollisions implements Runnable {
14 GraphCompilerPreferences preferences;
15 Collection<Problem> problems;
18 public ReportCollisions(
19 GraphCompilerPreferences preferences, Collection<Problem> problems,
21 this.preferences = preferences;
22 this.problems = problems;
26 private static String abbreviateURI(Res res) {
29 String uri = res.toString();
30 return uri.replace("http://www.simantics.org/", "");
35 LocationStore locations = store.getStore(LocationStore.class);
36 for(int c : store.values.getCollisions().toArray())
37 problems.add(new Problem(
38 locations.getLocation(c),
39 "Two literal values are given for the same resource."));
40 for(int c : store.identities.getCollisions().toArray())
41 problems.add(new Problem(
42 locations.getLocation(c),
43 "Two different identities are given for the same resource."));
44 for(int c : store.getStore(TemplateDefinitionStore.class).getCollisions().toArray())
45 problems.add(new Problem(
46 locations.getLocation(c),
47 "Two template definitions are given for the same resource."));
48 if(preferences.validate)
49 for(StatementCollision collision : store.statements.getCollisions()) {
50 problems.add(new Problem(
51 locations.getLocation(collision.subject),
52 "The same statement is defined " + collision.count + " times: " +
53 abbreviateURI(store.idToRes(collision.subject)) + ", " +
54 abbreviateURI(store.idToRes(collision.predicate)) + ", " +
55 abbreviateURI(store.idToRes(collision.object))));