]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7105) Added defaultLocalName property to SCL modules 58/458/4
authorHannu Niemistö <hannu.niemisto@iki.fi>
Mon, 24 Apr 2017 05:58:38 +0000 (08:58 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 24 Apr 2017 08:35:08 +0000 (11:35 +0300)
In textual modules defaultLocalName can be set in the module header. For
ontology modules, use Ontology.defaultLocalName property.

Change-Id: I2966c0b16e5d5f07c0e591a094f63908a7b492b3

bundles/org.simantics.layer0/graph.tg
bundles/org.simantics.layer0/graph/Layer0SCL.pgraph
bundles/org.simantics.layer0/src/org/simantics/layer0/Layer0.java
bundles/org.simantics.modeling/src/org/simantics/modeling/scl/OntologyModule.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java

index 053b27ddf0ce810a043ef0ef3a2a70e024891bc6..1d8b2756211657be5c47cbaa72849ed9a9ad63c1 100644 (file)
Binary files a/bundles/org.simantics.layer0/graph.tg and b/bundles/org.simantics.layer0/graph.tg differ
index 88e081701957e78fef70711179b413fdd67f1d1c..526139c0db35f983d4d9a968c6004ba08e556a83 100644 (file)
@@ -55,9 +55,11 @@ L0.Functions.clusterValidator : L0.Function
 
 L0.SCLModule <T L0.Entity
     >-- L0.SCLModule.definition --> L0.String <R L0.HasProperty : L0.TotalFunction
-    >-- L0.SCLModule.alias --> L0.String <R L0.HasProperty : L0.TotalFunction
     @L0.assert L0.SCLModule.definition ""
-    @L0.assert L0.SCLModule.alias ""
+
+L0.Ontology
+    >-- L0.Ontology.defaultLocalName --> L0.String <R L0.HasProperty : L0.TotalFunction
+    @L0.assert L0.Ontology.defaultLocalName ""
 
 L0.entityReplacer ==> "Resource -> Resource -> <WriteGraph> ()" <R L0.HasProperty : L0.FunctionalRelation
     L0.HasDescription """Used for defining an SCL function that knows how to copy the contents from one entity instance to another when both instances are known to be of the same type.
index 5467995bb7f600390cf61bb07ae603f7d22e296c..8c2b4ae1cb7a45047da124f3cc66f15f7c175620 100644 (file)
@@ -202,6 +202,8 @@ public class Layer0 {
     public final Resource NamespaceMigrationStep_Prefix_to;
     public final Resource NamespaceMigrationStep_Prefix_to_Inverse;
     public final Resource Ontology;
+    public final Resource Ontology_defaultLocalName;
+    public final Resource Ontology_defaultLocalName_Inverse;
     public final Resource Ontology_download;
     public final Resource Ontology_download_Inverse;
     public final Resource Ontology_global;
@@ -232,8 +234,6 @@ public class Layer0 {
     public final Resource SCLMigrationStep;
     public final Resource SCLMigrationStep_SCLMigrationStepAction;
     public final Resource SCLModule;
-    public final Resource SCLModule_alias;
-    public final Resource SCLModule_alias_Inverse;
     public final Resource SCLModule_definition;
     public final Resource SCLModule_definition_Inverse;
     public final Resource SCLValue;
@@ -506,6 +506,8 @@ public class Layer0 {
         public static final String NamespaceMigrationStep_Prefix_to = "http://www.simantics.org/Layer0-1.1/NamespaceMigrationStep/Prefix/to";
         public static final String NamespaceMigrationStep_Prefix_to_Inverse = "http://www.simantics.org/Layer0-1.1/NamespaceMigrationStep/Prefix/to/Inverse";
         public static final String Ontology = "http://www.simantics.org/Layer0-1.1/Ontology";
+        public static final String Ontology_defaultLocalName = "http://www.simantics.org/Layer0-1.1/Ontology/defaultLocalName";
+        public static final String Ontology_defaultLocalName_Inverse = "http://www.simantics.org/Layer0-1.1/Ontology/defaultLocalName/Inverse";
         public static final String Ontology_download = "http://www.simantics.org/Layer0-1.1/Ontology/download";
         public static final String Ontology_download_Inverse = "http://www.simantics.org/Layer0-1.1/Ontology/download/Inverse";
         public static final String Ontology_global = "http://www.simantics.org/Layer0-1.1/Ontology/global";
@@ -536,8 +538,6 @@ public class Layer0 {
         public static final String SCLMigrationStep = "http://www.simantics.org/Layer0-1.1/SCLMigrationStep";
         public static final String SCLMigrationStep_SCLMigrationStepAction = "http://www.simantics.org/Layer0-1.1/SCLMigrationStep/SCLMigrationStepAction";
         public static final String SCLModule = "http://www.simantics.org/Layer0-1.1/SCLModule";
-        public static final String SCLModule_alias = "http://www.simantics.org/Layer0-1.1/SCLModule/alias";
-        public static final String SCLModule_alias_Inverse = "http://www.simantics.org/Layer0-1.1/SCLModule/alias/Inverse";
         public static final String SCLModule_definition = "http://www.simantics.org/Layer0-1.1/SCLModule/definition";
         public static final String SCLModule_definition_Inverse = "http://www.simantics.org/Layer0-1.1/SCLModule/definition/Inverse";
         public static final String SCLValue = "http://www.simantics.org/Layer0-1.1/SCLValue";
@@ -820,6 +820,8 @@ public class Layer0 {
         NamespaceMigrationStep_Prefix_to = getResourceOrNull(graph, URIs.NamespaceMigrationStep_Prefix_to);
         NamespaceMigrationStep_Prefix_to_Inverse = getResourceOrNull(graph, URIs.NamespaceMigrationStep_Prefix_to_Inverse);
         Ontology = getResourceOrNull(graph, URIs.Ontology);
+        Ontology_defaultLocalName = getResourceOrNull(graph, URIs.Ontology_defaultLocalName);
+        Ontology_defaultLocalName_Inverse = getResourceOrNull(graph, URIs.Ontology_defaultLocalName_Inverse);
         Ontology_download = getResourceOrNull(graph, URIs.Ontology_download);
         Ontology_download_Inverse = getResourceOrNull(graph, URIs.Ontology_download_Inverse);
         Ontology_global = getResourceOrNull(graph, URIs.Ontology_global);
@@ -850,8 +852,6 @@ public class Layer0 {
         SCLMigrationStep = getResourceOrNull(graph, URIs.SCLMigrationStep);
         SCLMigrationStep_SCLMigrationStepAction = getResourceOrNull(graph, URIs.SCLMigrationStep_SCLMigrationStepAction);
         SCLModule = getResourceOrNull(graph, URIs.SCLModule);
-        SCLModule_alias = getResourceOrNull(graph, URIs.SCLModule_alias);
-        SCLModule_alias_Inverse = getResourceOrNull(graph, URIs.SCLModule_alias_Inverse);
         SCLModule_definition = getResourceOrNull(graph, URIs.SCLModule_definition);
         SCLModule_definition_Inverse = getResourceOrNull(graph, URIs.SCLModule_definition_Inverse);
         SCLValue = getResourceOrNull(graph, URIs.SCLValue);
index 1c8c91927fc9cc525f966555fbbe1515c6ae012d..39cf2f76555387e85091512c0f4844e6cdecb38f 100644 (file)
@@ -41,13 +41,27 @@ public class OntologyModule extends LazyModule {
     private static final TCon RESOURCE = Types.con(DB_MODULE, "Resource");
     
     Resource ontology;
+    String defaultLocalName;
     THashMap<Resource,Map<String,Resource>> childMaps = new THashMap<Resource,Map<String,Resource>>();
     
     public OntologyModule(ReadGraph graph, String moduleName) throws DatabaseException {
         super(moduleName);
         ontology = graph.getResource(moduleName);
+        readDefaultLocalName(graph);
         childMaps.put(ontology, createLocalMap(graph, ontology));
     }
+    
+    private void readDefaultLocalName(ReadGraph graph) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        defaultLocalName = graph.getPossibleRelatedValue(ontology, L0.Ontology_defaultLocalName);
+        if(defaultLocalName == null)
+            defaultLocalName = "";
+    }
+
+       @Override
+    public String getDefaultLocalName() {
+       return defaultLocalName;
+    }
 
     @Override
     public List<ImportDeclaration> getDependencies() {
index 898f6c0a5680c88bad669e56c5395a5fe65d0164..c36564eda59981fef0d800fc1d4492556f7817cd 100644 (file)
@@ -159,6 +159,8 @@ public class Elaboration {
 
         module = new ConcreteModule(moduleName);
         compilationContext.module = module;
+        if(moduleHeader != null && moduleHeader.defaultLocalName != null)
+               module.setDefaultLocalName(moduleHeader.defaultLocalName);
         try {
             if(timer != null)
                 timer.suspendTimer();
index 9ca588779866f7022b32957195b70ff0bc580580..7fec8f83ce0e3abe13b2b0fadbec83290cf5a8ba 100644 (file)
@@ -8,6 +8,7 @@ import org.simantics.scl.compiler.internal.parsing.declarations.DModuleHeader;
 public class ModuleHeader {
     public String classLoader;
     public long classLoaderLocation;
+    public String defaultLocalName;
     
     private void read(ErrorLog errorLog, DModuleHeader header) {
         for(FieldAssignment assignment : header.fields)
@@ -23,6 +24,15 @@ public class ModuleHeader {
                         classLoaderLocation = assignment.location;
                 }
                 break;
+            case "defaultLocalName":
+               if(assignment.value == null)
+                    errorLog.log(assignment.location, "Property defaultLocalName needs to be given a string value.");
+               else {
+                       defaultLocalName = AnnotationUtils.extractString(assignment.value);
+                       if(defaultLocalName == null)
+                               errorLog.log(assignment.value.location, "Expected string here.");
+               }
+               break;
             default:
                 errorLog.logWarning(assignment.location, "Unknown module header field was skipped.");
             }
index 697e64ef805e1eafc53300cb37c49c79c66b4e8e..55ee202f7d78d9b56f189bee8df90d96920f03b7 100644 (file)
@@ -31,6 +31,7 @@ import gnu.trove.procedure.TObjectProcedure;
 
 public class ConcreteModule implements Module {
     String moduleName;
+    String defaultLocalName;
     THashMap<String, TypeDescriptor> typeDescriptors = new THashMap<String, TypeDescriptor>();
     THashMap<String, EffectConstructor> effectConstructors = new THashMap<String, EffectConstructor>();
     THashMap<String, TypeClass> typeClasses = new THashMap<String, TypeClass>();
@@ -54,6 +55,15 @@ public class ConcreteModule implements Module {
         this.moduleName = moduleName;
     }
 
+    @Override
+    public String getDefaultLocalName() {
+       return defaultLocalName;
+    }
+    
+    public void setDefaultLocalName(String defaultLocalName) {
+               this.defaultLocalName = defaultLocalName;
+       }
+    
     public boolean addTypeDescriptor(String name, TypeDescriptor typeConstructor) {
         return typeDescriptors.put(name, typeConstructor) != null;
     }
index 6f13ed426940e11a2d59e949a670c1cedb7a7d6f..aff2e2d7f815e1ee5c7c3caa15a0fe43a5e47f40 100644 (file)
@@ -25,6 +25,7 @@ import gnu.trove.procedure.TObjectProcedure;
 
 public interface Module {
     String getName();
+    String getDefaultLocalName();
     
     SCLValue getValue(String name);
     SCLRelation getRelation(String name);