|
3 | 3 | import java.io.IOException; |
4 | 4 | import java.io.StringWriter; |
5 | 5 | import java.util.HashSet; |
| 6 | +import java.util.List; |
6 | 7 | import java.util.Objects; |
7 | 8 | import java.util.Set; |
| 9 | +import java.util.stream.Collectors; |
8 | 10 | import java.util.stream.Stream; |
| 11 | + |
| 12 | +import org.eclipse.swt.SWT; |
| 13 | +import org.eclipse.swt.widgets.Display; |
| 14 | +import org.eclipse.swt.widgets.FileDialog; |
| 15 | +import org.modelio.metamodel.uml.infrastructure.ModelElement; |
| 16 | +import org.modelio.metamodel.uml.infrastructure.ModelTree; |
| 17 | +import org.modelio.metamodel.uml.infrastructure.Stereotype; |
| 18 | +import org.modelio.metamodel.uml.statik.Association; |
| 19 | +import org.modelio.metamodel.uml.statik.Class; |
| 20 | +import org.modelio.vcore.smkernel.mapi.MObject; |
| 21 | + |
9 | 22 | import com.github.jknack.handlebars.Handlebars; |
10 | 23 | import com.github.jknack.handlebars.Options; |
11 | 24 | import com.github.jknack.handlebars.Template; |
12 | 25 | import com.github.jknack.handlebars.helper.ConditionalHelpers; |
13 | 26 | import com.github.jknack.handlebars.io.ClassPathTemplateLoader; |
14 | 27 | import com.modeliosoft.modelio.javadesigner.annotations.objid; |
| 28 | + |
15 | 29 | import fr.softeam.toscadesigner.api.tosca.standard.association.TRelationshipTemplate; |
16 | 30 | import fr.softeam.toscadesigner.api.tosca.standard.class_.CapabilityStereotype; |
17 | 31 | import fr.softeam.toscadesigner.api.tosca.standard.class_.TCapabilityDefinition; |
|
21 | 35 | import fr.softeam.toscadesigner.api.tosca.standard.class_.TRelationshipType; |
22 | 36 | import fr.softeam.toscadesigner.api.tosca.standard.class_.TRequirement; |
23 | 37 | import fr.softeam.toscadesigner.api.tosca.standard.class_.TRequirementDefinition; |
24 | | -import org.eclipse.swt.SWT; |
25 | | -import org.eclipse.swt.widgets.Display; |
26 | | -import org.eclipse.swt.widgets.FileDialog; |
27 | | -import org.modelio.metamodel.uml.infrastructure.ModelElement; |
28 | | -import org.modelio.metamodel.uml.infrastructure.ModelTree; |
29 | | -import org.modelio.metamodel.uml.infrastructure.Stereotype; |
30 | | -import org.modelio.metamodel.uml.statik.Association; |
31 | | -import org.modelio.metamodel.uml.statik.Class; |
32 | | -import org.modelio.vcore.smkernel.mapi.MObject; |
| 38 | +import fr.softeam.toscadesigner.impl.ToscaDesignerModule; |
33 | 39 |
|
34 | 40 | @objid ("e7453252-f578-4da1-815c-d2ce0e765130") |
35 | 41 | public abstract class AbstractToscaFileGenerator { |
@@ -167,21 +173,19 @@ private Handlebars setupHandlebars() { |
167 | 173 | // } |
168 | 174 | } else if (new TopologyTemplateChecker().isTypeOf(context)) { |
169 | 175 | // 3. Check for non-tosca types in node templates |
170 | | - |
171 | | - // To develop when TNodeTemplate will have the «type» property |
172 | | - // List<ModelElement> nodeTemplates = context.getCompositionChildren().stream() |
173 | | - // .filter(object -> { |
174 | | - // Stereotype tNodeTemplateStereotype = ToscaDesignerModule.getInstance().getModuleContext().getModelingSession().getMetamodelExtensions() |
175 | | - // .getStereotype("TNodeTemplate", object.getMClass()); |
176 | | - // return tNodeTemplateStereotype != null && ((ModelElement) object).isStereotyped(tNodeTemplateStereotype); |
177 | | - // }) |
178 | | - // .map(ModelElement.class::cast) |
179 | | - // .collect(Collectors.toList()); |
180 | | - // for (ModelElement nodeTemplate : nodeTemplates) { |
181 | | - // if (nodeTemplate.getProperty(TNodeTemplate.STEREOTYPE_NAME, TNodeTemplate.TYPE_PROPERTY)) { |
182 | | - // imports.add(/* import statement */); |
183 | | - // } |
184 | | - // } |
| 176 | + List<TNodeTemplate> nodeTemplates = context.getCompositionChildren().stream().filter(object -> { |
| 177 | + Stereotype tNodeTemplateStereotype = ToscaDesignerModule.getInstance().getModuleContext() |
| 178 | + .getModelingSession().getMetamodelExtensions() |
| 179 | + .getStereotype("TNodeTemplate", object.getMClass()); |
| 180 | + return tNodeTemplateStereotype != null |
| 181 | + && ((ModelElement) object).isStereotyped(tNodeTemplateStereotype); |
| 182 | + }).map(Class.class::cast).map(c -> TNodeTemplate.safeInstantiate(c)).collect(Collectors.toList()); |
| 183 | + for (TNodeTemplate nodeTemplate : nodeTemplates) { |
| 184 | + |
| 185 | + String targetNamespace = ((Class) context).getOwner().getName(); |
| 186 | + imports.add(new Import(nodeTemplate.getElement().getName() + ".tosca", targetNamespace , "MYRTUS-")); |
| 187 | + |
| 188 | + } |
185 | 189 |
|
186 | 190 | } |
187 | 191 |
|
|
0 commit comments