]> gerrit.simantics Code Review - simantics/platform.git/blob
28a53381e3ca5f2cdac83a5be2cc9181f79ccaf5
[simantics/platform.git] /
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.store.GraphStore;\r
9 import org.simantics.graph.store.StatementCollision;\r
10 import org.simantics.ltk.Problem;\r
11 \r
12 public class ReportCollisions implements Runnable {\r
13     GraphCompilerPreferences preferences;\r
14         Collection<Problem> problems;\r
15         GraphStore store;\r
16 \r
17         public ReportCollisions(\r
18                         GraphCompilerPreferences preferences, Collection<Problem> problems,\r
19                         GraphStore store) {\r
20             this.preferences = preferences;\r
21                 this.problems = problems;\r
22                 this.store = store;\r
23         }\r
24         \r
25         @Override\r
26         public void run() {\r
27                 LocationStore locations = store.getStore(LocationStore.class);\r
28                 for(int c : store.values.getCollisions().toArray())\r
29                         problems.add(new Problem(\r
30                                         locations.getLocation(c), \r
31                                         "Two literal values are given for the same resource."));\r
32                 for(int c : store.identities.getCollisions().toArray())\r
33                         problems.add(new Problem(\r
34                                         locations.getLocation(c), \r
35                                         "Two different identities are given for the same resource."));\r
36                 for(int c : store.getStore(TemplateDefinitionStore.class).getCollisions().toArray())\r
37                         problems.add(new Problem(\r
38                                         locations.getLocation(c), \r
39                                         "Two template definitions are given for the same resource."));\r
40                 if(preferences.validate)\r
41                     for(StatementCollision collision : store.statements.getCollisions()) {\r
42                         problems.add(new Problem(\r
43                                 locations.getLocation(collision.subject), \r
44                                 "The same statement is defined twice: " +\r
45                                         store.idToRes(collision.predicate) + ", " +\r
46                                         store.idToRes(collision.object)));\r
47                     }\r
48         }\r
49         \r
50 }\r