| /******************************************************************************* |
| * Copyright (c) 2015 CEA LIST. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * CEA LIST - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.papyrus.designer.languages.c.codegen.lib |
| |
| import java.util.ArrayList |
| import org.eclipse.uml2.uml.Class |
| import org.eclipse.uml2.uml.Classifier |
| import org.eclipse.uml2.uml.DataType |
| import org.eclipse.uml2.uml.Element |
| import org.eclipse.uml2.uml.Interface |
| import org.eclipse.uml2.uml.NamedElement |
| import org.eclipse.uml2.uml.Namespace |
| import org.eclipse.uml2.uml.Package |
| import org.eclipse.uml2.uml.profile.standard.ModelLibrary |
| |
| import static extension org.eclipse.papyrus.designer.languages.c.codegen.lib.commonScript.* |
| import static extension org.eclipse.papyrus.designer.languages.c.codegen.lib.interfaceScript.* |
| import static extension org.eclipse.papyrus.designer.languages.c.codegen.services.UmlCommentServices.* |
| import static extension org.eclipse.papyrus.designer.languages.common.base.GenUtils.* |
| import org.eclipse.papyrus.designer.languages.cpp.profile.C_Cpp.Include |
| |
| class importScript { |
| def public static genImport(Classifier classifier) ''' |
| «classifier.partComment('Import')» |
| «classifier.genImportList()» «classifier.genDynamicInstanciationImport()» |
| // User imports |
| /* "startUserCode" to add imports */ |
| /* "endUserCode" to add imports */ |
| ''' |
| def public static genInclude(NamedElement namedElement) ''' |
| /* include other files*/ |
| «IF namedElement.hasStereotype(Include)» |
| «var include = namedElement.getApplicableStereotype("C_Cpp::Include")» |
| «namedElement.getValue(include, "body")» |
| «ENDIF» |
| ''' |
| |
| def public static genImportList(Classifier classifier) ''' |
| «FOR import_ : classifier.getImportList» |
| «import_.genRelativeNamedImport(classifier)» |
| «ENDFOR» |
| ''' |
| |
| |
| def public static getImportList(Classifier classifier) { |
| classifier.genNamespaceImports + classifier.genOwningPackageImports + classifier.genUsageImports |
| } |
| |
| |
| def public static genRelativeNamedImport(Element element) ''' |
| ''' |
| |
| |
| def public static genRelativeNamedImport(NamedElement namedElement1, NamedElement namedElement2) ''' |
| «IF (namedElement1.hasStereotypeTree(ModelLibrary))» |
| #include <«namedElement1.namespace.genName()».h> |
| «ELSE» |
| #include "«namedElement2.getRelativePath(namedElement1)»«namedElement1.genName()».h" |
| «ENDIF» |
| ''' |
| |
| def public static genRelativeNamedImport(Package pkg, NamedElement namedElement) ''' |
| «IF (pkg.hasStereotypeTree(ModelLibrary))» |
| #include <«pkg.genName()».h> |
| «ELSE» |
| #include "«pkg.getRelativePath(namedElement)»«pkg.genName».h" |
| «ENDIF» |
| ''' |
| |
| |
| def public static genOwningPackageImports(Classifier classifier) { |
| classifier.namespace.genNamespaceImports() |
| } |
| |
| |
| def public static genNamespaceImports(Namespace namespace) { |
| namespace.elementImports.map[it.importedElement] |
| } |
| |
| def public static genUsageImports(Classifier lassifier) { |
| return new ArrayList<Classifier>(); |
| } |
| |
| def public static genUsageImports(Class clazz) { |
| if (clazz.hasStereotypeTree(ModelLibrary)) { |
| clazz.getUsedInterfaces() |
| } |
| else { |
| clazz.getUsedInterfaces().map[getInterfaceRealizationClass] |
| } |
| } |
| |
| def public static getTypeListOfClassifier(Class clazz) { |
| val list = clazz.getAllAttributes.map[type] |
| list.addAll(clazz.getAllOperations.map[ownedParameters.map[type]]) |
| list.addAll(clazz.generals) |
| return list |
| } |
| |
| |
| def public static getTypeListOfClassifier(Interface intf) { |
| val list = intf.ownedAttributes.map[type] |
| list.addAll(intf.ownedOperations.map[ownedParameters.map[type]]) |
| list.addAll(intf.generals) |
| return list |
| } |
| |
| |
| def public static getTypeListOfClassifier(DataType dataType) { |
| val list = dataType.ownedAttributes.map[type] |
| list.addAll(dataType.ownedOperations.map[ownedParameters.map[type]]) |
| list.addAll(dataType.generals) |
| return list |
| } |
| |
| // TODO: why do need stdlib in this case? |
| def public static genDynamicInstanciationImport(Classifier classifier) ''' |
| #include <stdio.h> |
| #include <stdlib.h> |
| ''' |
| } |