]> gerrit.simantics Code Review - simantics/platform.git/blob
30efe78c4797b50a282214f06616c6de5cec908c
[simantics/platform.git] /
1 package org.simantics.graph.compiler.internal.validation;
2
3 import java.util.Collection;
4
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;
12
13 public class ReportCollisions implements Runnable {
14     GraphCompilerPreferences preferences;
15         Collection<Problem> problems;
16         GraphStore store;
17
18         public ReportCollisions(
19                         GraphCompilerPreferences preferences, Collection<Problem> problems,
20                         GraphStore store) {
21             this.preferences = preferences;
22                 this.problems = problems;
23                 this.store = store;
24         }
25         
26         private static String abbreviateURI(Res res) {
27             if(res == null)
28                 return "null";
29             String uri = res.toString();
30             return uri.replace("http://www.simantics.org/", "");
31         }
32         
33         @Override
34         public void run() {
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))));
56                     }
57         }
58         
59 }