]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java
7fec8f83ce0e3abe13b2b0fadbec83290cf5a8ba
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / header / ModuleHeader.java
1 package org.simantics.scl.compiler.internal.header;
2
3 import org.simantics.scl.compiler.elaboration.expressions.annotations.AnnotationUtils;
4 import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment;
5 import org.simantics.scl.compiler.errors.ErrorLog;
6 import org.simantics.scl.compiler.internal.parsing.declarations.DModuleHeader;
7
8 public class ModuleHeader {
9     public String classLoader;
10     public long classLoaderLocation;
11     public String defaultLocalName;
12     
13     private void read(ErrorLog errorLog, DModuleHeader header) {
14         for(FieldAssignment assignment : header.fields)
15             switch(assignment.name) {
16             case "bundle":
17                 if(assignment.value == null)
18                     errorLog.log(assignment.location, "Property classLoader needs to be given a string value.");
19                 else {
20                     classLoader = AnnotationUtils.extractString(assignment.value);
21                     if(classLoader == null)
22                         errorLog.log(assignment.value.location, "Expected bundle name here.");
23                     else 
24                         classLoaderLocation = assignment.location;
25                 }
26                 break;
27             case "defaultLocalName":
28                 if(assignment.value == null)
29                     errorLog.log(assignment.location, "Property defaultLocalName needs to be given a string value.");
30                 else {
31                         defaultLocalName = AnnotationUtils.extractString(assignment.value);
32                         if(defaultLocalName == null)
33                                 errorLog.log(assignment.value.location, "Expected string here.");
34                 }
35                 break;
36             default:
37                 errorLog.logWarning(assignment.location, "Unknown module header field was skipped.");
38             }
39     }
40     
41     public static ModuleHeader process(ErrorLog errorLog, DModuleHeader header) {
42         if(header == null)
43             return null;
44         ModuleHeader result = new ModuleHeader();
45         result.read(errorLog, header);
46         return result;
47     }
48 }