]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NameExistenceChecks.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / compilation / NameExistenceChecks.java
1 package org.simantics.scl.compiler.compilation;\r
2 \r
3 import org.simantics.scl.compiler.elaboration.modules.SCLValue;\r
4 import org.simantics.scl.compiler.elaboration.modules.TypeConstructor;\r
5 import org.simantics.scl.compiler.environment.AmbiguousNameException;\r
6 import org.simantics.scl.compiler.environment.Environment;\r
7 import org.simantics.scl.compiler.errors.ErrorLog;\r
8 \r
9 public class NameExistenceChecks {\r
10     public static void checkIfValueExists(ErrorLog errorLog, long location,\r
11             Environment environment, String name) {\r
12         try {\r
13             SCLValue value = environment.getLocalNamespace().getValue(name);\r
14             if(value != null)\r
15                 errorLog.log(location,\r
16                         "Value " + name + " is already defined in the module " + \r
17                                 value.getName().module + \r
18                         " that is imported to the default namespace.");\r
19         } catch(AmbiguousNameException e) {\r
20             errorLog.log(location,\r
21                     "Value " + name + " is already defined in the modules " + \r
22                             e.conflictingModules[0] + " and  " + e.conflictingModules[1] +  \r
23                     " that are imported to the default namespace.");\r
24         }\r
25     }\r
26     \r
27     public static void checkIfTypeExists(ErrorLog errorLog, long location,\r
28             Environment environment, String name) {\r
29         try {\r
30             TypeConstructor value = environment.getLocalNamespace().getTypeConstructor(name);\r
31             if(value != null)\r
32                 errorLog.log(location,\r
33                         "Type " + name + " is already defined in the module " + \r
34                                 value.name.module + \r
35                         " that is imported to the default namespace.");\r
36         } catch(AmbiguousNameException e) {\r
37             errorLog.log(location,\r
38                     "Type " + name + " is already defined in the modules " + \r
39                             e.conflictingModules[0] + " and  " + e.conflictingModules[1] +  \r
40                     " that are imported to the default namespace.");\r
41         }\r
42     }\r
43 }\r