]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/validation/ReportCollisions.java
Small improvements to statement collision reporting.
[simantics/platform.git] / bundles / org.simantics.graph.compiler / src / org / simantics / graph / compiler / internal / validation / ReportCollisions.java
1 package org.simantics.graph.compiler.internal.validation;\r
2 \r
3 import java.util.Collection;\r
4 \r
5 import org.simantics.graph.compiler.GraphCompilerPreferences;\r
6 import org.simantics.graph.compiler.internal.store.LocationStore;\r
7 import org.simantics.graph.compiler.internal.templates.TemplateDefinitionStore;\r
8 import org.simantics.graph.query.Res;\r
9 import org.simantics.graph.store.GraphStore;\r
10 import org.simantics.graph.store.StatementCollision;\r
11 import org.simantics.ltk.Problem;\r
12 \r
13 public class ReportCollisions implements Runnable {\r
14     GraphCompilerPreferences preferences;\r
15         Collection<Problem> problems;\r
16         GraphStore store;\r
17 \r
18         public ReportCollisions(\r
19                         GraphCompilerPreferences preferences, Collection<Problem> problems,\r
20                         GraphStore store) {\r
21             this.preferences = preferences;\r
22                 this.problems = problems;\r
23                 this.store = store;\r
24         }\r
25         \r
26         private static String abbreviateURI(Res res) {\r
27             if(res == null)\r
28                 return "null";\r
29             String uri = res.toString();\r
30             return uri.replace("http://www.simantics.org/", "");\r
31         }\r
32         \r
33         @Override\r
34         public void run() {\r
35                 LocationStore locations = store.getStore(LocationStore.class);\r
36                 for(int c : store.values.getCollisions().toArray())\r
37                         problems.add(new Problem(\r
38                                         locations.getLocation(c), \r
39                                         "Two literal values are given for the same resource."));\r
40                 for(int c : store.identities.getCollisions().toArray())\r
41                         problems.add(new Problem(\r
42                                         locations.getLocation(c), \r
43                                         "Two different identities are given for the same resource."));\r
44                 for(int c : store.getStore(TemplateDefinitionStore.class).getCollisions().toArray())\r
45                         problems.add(new Problem(\r
46                                         locations.getLocation(c), \r
47                                         "Two template definitions are given for the same resource."));\r
48                 if(preferences.validate)\r
49                     for(StatementCollision collision : store.statements.getCollisions()) {\r
50                         problems.add(new Problem(\r
51                                 locations.getLocation(collision.subject), \r
52                                 "The same statement is defined " + collision.count + " times: " +\r
53                                         abbreviateURI(store.idToRes(collision.subject)) + ", " +\r
54                                         abbreviateURI(store.idToRes(collision.predicate)) + ", " +\r
55                                         abbreviateURI(store.idToRes(collision.object))));\r
56                     }\r
57         }\r
58         \r
59 }\r