From c3945d04f5f0cff02b6d33d92d78325f53f121fa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Mon, 24 Apr 2017 08:58:38 +0300 Subject: [PATCH] (refs #7105) Added defaultLocalName property to SCL modules 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 | Bin 55689 -> 55700 bytes .../graph/Layer0SCL.pgraph | 6 ++++-- .../src/org/simantics/layer0/Layer0.java | 12 ++++++------ .../modeling/scl/OntologyModule.java | 14 ++++++++++++++ .../scl/compiler/compilation/Elaboration.java | 2 ++ .../internal/header/ModuleHeader.java | 10 ++++++++++ .../scl/compiler/module/ConcreteModule.java | 10 ++++++++++ .../simantics/scl/compiler/module/Module.java | 1 + 8 files changed, 47 insertions(+), 8 deletions(-) diff --git a/bundles/org.simantics.layer0/graph.tg b/bundles/org.simantics.layer0/graph.tg index 053b27ddf0ce810a043ef0ef3a2a70e024891bc6..1d8b2756211657be5c47cbaa72849ed9a9ad63c1 100644 GIT binary patch delta 586 zcmYk3%}*0i6vgLG(R3gdpFlBatPL?G6A}{w37uJhC<}oY!UE%>Xak-4Q6Pbqk1{QV zilm50xVkYUER0Ku@h;f8_fMc3!+*fSRTtD#5i^sV+t6#3mVIIP(lT=CTv{e~Zl(r=7n#-G+&kBz#-il6|BK7~4Fjtjf#h zRb6F)u6XdWWMBOZaBRn*qKvvd#QX10IN}EC$v>A!#nUflXJo{U60fg(p#pcf5n4qs zrc<5|^S3B>zNHuT<#KVHHNM9Xr!bY17ZjX7H4?;8k delta 638 zcmZ9HO)O(!6o&6_Zxw?9giP!)%r zu(F@zBrGhfCz;GnL?V${Sos-OtPqru`@G zkFg5yNcMi|Vfw_nWI33+SUe3)?>z77EH|o&DwdbKGTEI;i&$anVP*DSrt=>)*&@WK zLxY248otgF5k}P-943Q14tVFO#eGj1{`Od?(%TFo%9$cfZi#&3DV>?-_{=i{4cZf>MXfdn*n_ZKg{7nq7i&=U-l+# nfcJ@f><$>|^A-- L0.SCLModule.definition --> L0.String -- L0.SCLModule.alias --> L0.String -- L0.Ontology.defaultLocalName --> L0.String "Resource -> Resource -> ()" > childMaps = new THashMap>(); 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 getDependencies() { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java index 898f6c0a5..c36564eda 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java @@ -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(); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java index 9ca588779..7fec8f83c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/header/ModuleHeader.java @@ -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."); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java index 697e64ef8..55ee202f7 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java @@ -31,6 +31,7 @@ import gnu.trove.procedure.TObjectProcedure; public class ConcreteModule implements Module { String moduleName; + String defaultLocalName; THashMap typeDescriptors = new THashMap(); THashMap effectConstructors = new THashMap(); THashMap typeClasses = new THashMap(); @@ -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; } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java index 6f13ed426..aff2e2d7f 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java @@ -25,6 +25,7 @@ import gnu.trove.procedure.TObjectProcedure; public interface Module { String getName(); + String getDefaultLocalName(); SCLValue getValue(String name); SCLRelation getRelation(String name); -- 2.43.2