diff options
Diffstat (limited to 'extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org')
45 files changed, 4811 insertions, 0 deletions
diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppBindBody.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppBindBody.java new file mode 100644 index 00000000000..016a7d87da1 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppBindBody.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet; + +import org.eclipse.papyrus.cpp.codegen.Constants; +import org.eclipse.papyrus.cpp.codegen.utils.*; +import Cpp.CppInclude; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.*; +import org.eclipse.emf.common.util.EList; +import org.eclipse.papyrus.cpp.codegen.jet.util.*; +import java.util.*; +import org.eclipse.papyrus.cpp.codegen.Activator; + +public class CppBindBody +{ + protected static String nl; + public static synchronized CppBindBody create(String lineSeparator) + { + nl = lineSeparator; + CppBindBody result = new CppBindBody(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#define "; + protected final String TEXT_2 = "_BODY" + NL + "" + NL + "/************************************************************"; + protected final String TEXT_3 = NL + " "; + protected final String TEXT_4 = " template binding body" + NL + " ************************************************************/" + NL; + protected final String TEXT_5 = NL; + protected final String TEXT_6 = NL; + protected final String TEXT_7 = NL; + protected final String TEXT_8 = NL; + protected final String TEXT_9 = NL; + protected final String TEXT_10 = NL + "#include <"; + protected final String TEXT_11 = "."; + protected final String TEXT_12 = ">" + NL; + protected final String TEXT_13 = NL; + protected final String TEXT_14 = NL; + protected final String TEXT_15 = NL; + protected final String TEXT_16 = NL; + protected final String TEXT_17 = NL; + protected final String TEXT_18 = NL; + protected final String TEXT_19 = NL; + protected final String TEXT_20 = NL; + protected final String TEXT_21 = NL + NL + "/************************************************************/" + NL + "template class "; + protected final String TEXT_22 = " <"; + protected final String TEXT_23 = ">;" + NL; + protected final String TEXT_24 = NL; + protected final String TEXT_25 = NL + NL + "/************************************************************" + NL + " End of "; + protected final String TEXT_26 = " template binding body" + NL + " ************************************************************/"; + protected final String TEXT_27 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Class currentClass = (Class) argument; + + // Get the package name + String className = currentClass.getName(); + String classFullName = GenUtils.getFullName (currentClass); + String classFULLNAME = classFullName.toUpperCase(); + String parentClass = ""; + String namespace = GenUtils.getNamespace (currentClass); + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + // Retrieve owner Package + Package owner = currentClass.getPackage(); + String fullPath = ""; + + if (owner != null) { + fullPath = GenUtils.getFullPath(owner) + "/"; + } // else fullPath == "" + + TemplateBinding tb = GenUtils.getTemplateBindings(currentClass);; + + // prepare parent class declaration + EList<org.eclipse.uml2.uml.Element> templates = tb.getTargets(); + Class templateClass = (Class) ((TemplateSignature) templates.get(0)).getOwner(); + parentClass = GenUtils.qualifiedName (templateClass); + + // Prepare bindings parameter declaration + + String tParamDecl = ""; + Iterator<TemplateParameterSubstitution> tps = tb.getParameterSubstitutions().iterator(); + while(tps.hasNext()) { + TemplateParameterSubstitution paramSub = tps.next(); + + CppTemplateBindingParameter jetTParam = new CppTemplateBindingParameter(); + tParamDecl = tParamDecl+jetTParam.generate (paramSub); + + if (tps.hasNext()) { + tParamDecl = tParamDecl + ", "; + } + } + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_2); + stringBuffer.append(TEXT_3); + stringBuffer.append( className ); + stringBuffer.append(TEXT_4); + stringBuffer.append(TEXT_5); + stringBuffer.append( Constants.cppIncPreBodyStart ); + stringBuffer.append(TEXT_6); + stringBuffer.append( ClassUtils.getCppIncludePreBody(currentClass) ); + stringBuffer.append(TEXT_7); + stringBuffer.append( Constants.cppIncPreBodyEnd ); + stringBuffer.append(TEXT_8); + stringBuffer.append(TEXT_9); + stringBuffer.append( Constants.includeHFile ); + stringBuffer.append(TEXT_10); + stringBuffer.append( fullPath ); + stringBuffer.append( className ); + stringBuffer.append(TEXT_11); + stringBuffer.append( headerFileSuffix ); + stringBuffer.append(TEXT_12); + stringBuffer.append(TEXT_13); + stringBuffer.append( Constants.cppIncBodyStart ); + stringBuffer.append(TEXT_14); + stringBuffer.append( ClassUtils.getCppIncludeBody(currentClass) ); + stringBuffer.append(TEXT_15); + stringBuffer.append( Constants.cppIncBodyEnd ); + stringBuffer.append(TEXT_16); + stringBuffer.append(TEXT_17); + stringBuffer.append( GenUtils.openNS(currentClass) ); + stringBuffer.append(TEXT_18); + stringBuffer.append(TEXT_19); + stringBuffer.append( Constants.derivedIncludes ); + stringBuffer.append(TEXT_20); + stringBuffer.append( ClassUtils.createIncludeDecl(currentClass) ); + stringBuffer.append(TEXT_21); + stringBuffer.append( parentClass ); + stringBuffer.append(TEXT_22); + stringBuffer.append( tParamDecl ); + stringBuffer.append(TEXT_23); + stringBuffer.append(TEXT_24); + stringBuffer.append( GenUtils.closeNS(currentClass) ); + stringBuffer.append(TEXT_25); + stringBuffer.append( className ); + stringBuffer.append(TEXT_26); + stringBuffer.append(TEXT_27); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppBindHeader.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppBindHeader.java new file mode 100644 index 00000000000..cd28f8d1210 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppBindHeader.java @@ -0,0 +1,186 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet; + +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.CppInclude; +import org.eclipse.uml2.uml.Class; +import org.eclipse.emf.common.util.EList; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.TemplateSignature; +import org.eclipse.uml2.uml.TemplateParameterSubstitution; +import org.eclipse.papyrus.cpp.codegen.jet.util.*; +import java.util.*; +import org.eclipse.papyrus.cpp.codegen.Activator; + +public class CppBindHeader +{ + protected static String nl; + public static synchronized CppBindHeader create(String lineSeparator) + { + nl = lineSeparator; + CppBindHeader result = new CppBindHeader(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#ifndef "; + protected final String TEXT_2 = "_H" + NL + "#define "; + protected final String TEXT_3 = "_H" + NL + "" + NL + "/************************************************************"; + protected final String TEXT_4 = NL + " "; + protected final String TEXT_5 = " template binding header" + NL + " ************************************************************/" + NL; + protected final String TEXT_6 = NL; + protected final String TEXT_7 = NL; + protected final String TEXT_8 = NL; + protected final String TEXT_9 = NL; + protected final String TEXT_10 = NL; + protected final String TEXT_11 = NL + NL + "#include <"; + protected final String TEXT_12 = "."; + protected final String TEXT_13 = ">" + NL; + protected final String TEXT_14 = NL; + protected final String TEXT_15 = " " + NL + "/************************************************************/" + NL + "typedef "; + protected final String TEXT_16 = " <"; + protected final String TEXT_17 = "> "; + protected final String TEXT_18 = ";" + NL; + protected final String TEXT_19 = NL; + protected final String TEXT_20 = NL + NL + "/************************************************************" + NL + " End of "; + protected final String TEXT_21 = " template binding header" + NL + " ************************************************************/" + NL + "" + NL + "#endif"; + protected final String TEXT_22 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Class currentClass = (Class) argument; + + // Get the package name + String className = currentClass.getName(); + String classFullName = GenUtils.getFullName (currentClass); + String classFULLNAME = classFullName.toUpperCase(); + String classparent = ""; + String openNS = GenUtils.openNS (currentClass); + String closeNS = GenUtils.closeNS (currentClass); + + // Include declaration "CppInclude" + String headerDecl = ""; + CppInclude cppInclude = GenUtils.getApplication(currentClass, CppInclude.class); + if (cppInclude != null) { + headerDecl = "// Include from CppInclude declaration" + NL + cppInclude.getHeader() + NL; + } + + // Prepare owner package header include + Package ownerPackage = currentClass.getPackage(); + String ownerInclude = ""; + if (ownerPackage != null) { + // Create an util template to prepare the declaration + CppOwnerPackageIncludeDeclaration jetOwnerInclude + = new CppOwnerPackageIncludeDeclaration(); + // Execute the util template + ownerInclude = jetOwnerInclude.generate(ownerPackage); + } + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + //find path for the package owning current class + String fullPath = ""; + String separ = ""; + + if (ownerPackage != null) { + fullPath = GenUtils.getFullPath (ownerPackage); + separ = "/"; + } // else fullPath == "" + + org.eclipse.uml2.uml.TemplateBinding tb = GenUtils.getTemplateBindings(currentClass); + + // prepare parent class declaration + EList<org.eclipse.uml2.uml.Element> templates = tb.getTargets(); + Class templateClass = (Class) ((TemplateSignature)templates.get(0)).getOwner(); + classparent = templateClass.getName(); + + // Prepare bindings parameter declaration + + String tParamDecl=""; + TemplateParameterSubstitution paramsub; + Iterator<TemplateParameterSubstitution> tps = tb.getParameterSubstitutions().iterator(); + while(tps.hasNext()) { + paramsub = (TemplateParameterSubstitution)tps.next(); + + CppTemplateBindingParameter jetTParam + = new CppTemplateBindingParameter(); + tParamDecl = tParamDecl+jetTParam.generate(paramsub); + + if (tps.hasNext()) { + tParamDecl = tParamDecl+", "; + } + } + + + // Prepare dependency includes + CppClassAllIncludesDeclaration jetClassIncludes + = new CppClassAllIncludesDeclaration(); + String classIncludes = jetClassIncludes.generate(argument); + if (!classIncludes.equals("")) { + classIncludes = "/* Structural includes (inheritance, dependencies... */"+NL+classIncludes; + } + + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_2); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_3); + stringBuffer.append(TEXT_4); + stringBuffer.append( className ); + stringBuffer.append(TEXT_5); + stringBuffer.append(TEXT_6); + stringBuffer.append( ownerInclude ); + stringBuffer.append(TEXT_7); + stringBuffer.append(TEXT_8); + stringBuffer.append( classIncludes ); + stringBuffer.append(TEXT_9); + stringBuffer.append(TEXT_10); + stringBuffer.append( headerDecl ); + stringBuffer.append(TEXT_11); + stringBuffer.append( fullPath ); + stringBuffer.append( separ ); + stringBuffer.append( classparent ); + stringBuffer.append(TEXT_12); + stringBuffer.append( headerFileSuffix ); + stringBuffer.append(TEXT_13); + stringBuffer.append(TEXT_14); + stringBuffer.append( openNS ); + stringBuffer.append(TEXT_15); + stringBuffer.append( classparent ); + stringBuffer.append(TEXT_16); + stringBuffer.append( tParamDecl ); + stringBuffer.append(TEXT_17); + stringBuffer.append( className ); + stringBuffer.append(TEXT_18); + stringBuffer.append(TEXT_19); + stringBuffer.append( closeNS ); + stringBuffer.append(TEXT_20); + stringBuffer.append( className ); + stringBuffer.append(TEXT_21); + stringBuffer.append(TEXT_22); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppClassBody.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppClassBody.java new file mode 100644 index 00000000000..6d61bd37fe2 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppClassBody.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet; + +import org.eclipse.papyrus.cpp.codegen.Constants; +import org.eclipse.papyrus.cpp.codegen.utils.*; +import org.eclipse.emf.common.util.EList; +import Cpp.CppInclude; +import org.eclipse.uml2.uml.Classifier; +import org.eclipse.uml2.uml.Package; +import org.eclipse.papyrus.cpp.codegen.jet.util.*; +import org.eclipse.papyrus.cpp.codegen.Activator; + +public class CppClassBody +{ + protected static String nl; + public static synchronized CppClassBody create(String lineSeparator) + { + nl = lineSeparator; + CppClassBody result = new CppClassBody(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#define "; + protected final String TEXT_2 = "_BODY" + NL + "" + NL + "/************************************************************"; + protected final String TEXT_3 = NL + " "; + protected final String TEXT_4 = " class body" + NL + " ************************************************************/" + NL; + protected final String TEXT_5 = NL; + protected final String TEXT_6 = NL; + protected final String TEXT_7 = NL; + protected final String TEXT_8 = NL; + protected final String TEXT_9 = NL + "#include <"; + protected final String TEXT_10 = "."; + protected final String TEXT_11 = ">" + NL; + protected final String TEXT_12 = NL; + protected final String TEXT_13 = NL; + protected final String TEXT_14 = NL; + protected final String TEXT_15 = NL; + protected final String TEXT_16 = NL; + protected final String TEXT_17 = NL; + protected final String TEXT_18 = NL; + protected final String TEXT_19 = NL; + protected final String TEXT_20 = NL; + protected final String TEXT_21 = NL; + protected final String TEXT_22 = NL + NL + "/************************************************************" + NL + " End of "; + protected final String TEXT_23 = " class body" + NL + " ************************************************************/"; + protected final String TEXT_24 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + + // Get the package name + String className = currentClass.getName(); + String classFullName= GenUtils.getFullName (currentClass); + String classFULLNAME= classFullName.toUpperCase(); + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + // TODO - Prepare static attribute + String staticAttributes = ""; + + // Retrieve owner Package + Package owner = currentClass.getPackage(); + String fullPath = ""; + + if (owner != null) { + fullPath = GenUtils.getFullPath(owner) + "/"; + } // else fullPath == "" + + // Prepare attributes and Methods declarations + String allOperations = ""; + + // Methods + CppClassOperationsImplementation jetClassOp + = new CppClassOperationsImplementation(); + allOperations = jetClassOp.generate(currentClass); + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_2); + stringBuffer.append(TEXT_3); + stringBuffer.append( className ); + stringBuffer.append(TEXT_4); + stringBuffer.append(TEXT_5); + stringBuffer.append( Constants.cppIncPreBodyStart ); + stringBuffer.append(TEXT_6); + stringBuffer.append( ClassUtils.getCppIncludePreBody(currentClass) +); + stringBuffer.append( Constants.cppIncPreBodyEnd ); + stringBuffer.append(TEXT_7); + stringBuffer.append(TEXT_8); + stringBuffer.append( Constants.includeHFile ); + stringBuffer.append(TEXT_9); + stringBuffer.append( fullPath ); + stringBuffer.append( className ); + stringBuffer.append(TEXT_10); + stringBuffer.append( headerFileSuffix ); + stringBuffer.append(TEXT_11); + stringBuffer.append(TEXT_12); + stringBuffer.append( Constants.cppIncBodyStart ); + stringBuffer.append(TEXT_13); + stringBuffer.append( ClassUtils.getCppIncludeBody(currentClass) +); + stringBuffer.append( Constants.cppIncBodyEnd ); + stringBuffer.append(TEXT_14); + stringBuffer.append(TEXT_15); + stringBuffer.append( Constants.derivedIncludes ); + stringBuffer.append(TEXT_16); + stringBuffer.append( ClassUtils.createIncludeDecl(currentClass) ); + stringBuffer.append(TEXT_17); + stringBuffer.append(TEXT_18); + stringBuffer.append( GenUtils.openNS(currentClass) ); + stringBuffer.append(TEXT_19); + stringBuffer.append( ClassUtils.getStaticAttributes(currentClass) ); + stringBuffer.append(TEXT_20); + stringBuffer.append( allOperations ); + stringBuffer.append(TEXT_21); + stringBuffer.append( GenUtils.closeNS(currentClass) ); + stringBuffer.append(TEXT_22); + stringBuffer.append( className ); + stringBuffer.append(TEXT_23); + stringBuffer.append(TEXT_24); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppClassHeader.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppClassHeader.java new file mode 100644 index 00000000000..4497c4d9346 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppClassHeader.java @@ -0,0 +1,276 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet; + +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.CppInclude; +import org.eclipse.papyrus.cpp.codegen.StdStereo; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.*; +import org.eclipse.papyrus.cpp.codegen.jet.util.*; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; + +public class CppClassHeader +{ + protected static String nl; + public static synchronized CppClassHeader create(String lineSeparator) + { + nl = lineSeparator; + CppClassHeader result = new CppClassHeader(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#ifndef "; + protected final String TEXT_2 = "_H" + NL + "#define "; + protected final String TEXT_3 = "_H" + NL + "" + NL + "/************************************************************"; + protected final String TEXT_4 = NL + " "; + protected final String TEXT_5 = " class header" + NL + " ************************************************************/" + NL; + protected final String TEXT_6 = NL; + protected final String TEXT_7 = NL; + protected final String TEXT_8 = NL; + protected final String TEXT_9 = NL; + protected final String TEXT_10 = NL; + protected final String TEXT_11 = NL; + protected final String TEXT_12 = " "; + protected final String TEXT_13 = NL; + protected final String TEXT_14 = NL + "/************************************************************/"; + protected final String TEXT_15 = NL; + protected final String TEXT_16 = NL; + protected final String TEXT_17 = " "; + protected final String TEXT_18 = " {"; + protected final String TEXT_19 = NL; + protected final String TEXT_20 = NL + NL + " public:"; + protected final String TEXT_21 = NL; + protected final String TEXT_22 = NL + NL + " protected:"; + protected final String TEXT_23 = NL; + protected final String TEXT_24 = NL + NL + " private:"; + protected final String TEXT_25 = NL; + protected final String TEXT_26 = NL + NL + "};" + NL + "/************************************************************/" + NL + "/* External declarations (package visibility) */"; + protected final String TEXT_27 = NL; + protected final String TEXT_28 = NL; + protected final String TEXT_29 = NL + "/************************************************************/" + NL + "/* Inline functions */"; + protected final String TEXT_30 = NL; + protected final String TEXT_31 = NL; + protected final String TEXT_32 = NL + NL + "/************************************************************" + NL + " End of "; + protected final String TEXT_33 = " class header" + NL + " ************************************************************/" + NL + "" + NL + "#endif"; + protected final String TEXT_34 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + + // Get the package name + String className = currentClass.getName(); + String classFULLNAME = GenUtils.getFullName (currentClass).toUpperCase(); + String openNS = GenUtils.openNS (currentClass); + String closeNS = GenUtils.closeNS (currentClass); + String classDoc = ""; + String classOrStruct = (currentClass instanceof DataType) ? "struct" : "class"; + + // Doc for the class + CppElementDoc jDoc = new CppElementDoc(); + classDoc = jDoc.generate(currentClass); + + String includeProtection; + + // Include declaration "CppInclude" + String headerDecl = ""; + CppInclude cppInclude = GenUtils.getApplication(currentClass, CppInclude.class); + if (cppInclude != null) { + headerDecl = GenUtils.maskNull(cppInclude.getHeader()); + if (headerDecl.length() > 0) { + headerDecl = "// Include from CppInclude declaration" + NL + headerDecl.replace("HFILENAME", classFULLNAME) + NL; + } + } + + // Prepare owner package header include + Package ownerPackage = currentClass.getPackage(); + String ownerInclude = ""; + if (ownerPackage != null) { + // Create an util template to prepare the declaration + CppOwnerPackageIncludeDeclaration jetOwnerInclude + = new CppOwnerPackageIncludeDeclaration(); + // Execute the util template + ownerInclude = jetOwnerInclude.generate(ownerPackage); + } + + + // Prepare owned type and enum declaration + String typeEnumDefPackage = ""; + String typeEnumDef = ""; + + CppClassTypeAndEnum jetTE = new CppClassTypeAndEnum(); + typeEnumDef = jetTE.generate(currentClass); + + CppClassTypeAndEnumPackage jetTEp + = new CppClassTypeAndEnumPackage(); + typeEnumDefPackage = jetTEp.generate(currentClass); + + + // Prepare dependency includes + CppClassAllIncludesDeclaration jetClassIncludes + = new CppClassAllIncludesDeclaration(); + String classIncludes = jetClassIncludes.generate(argument); + if (!classIncludes.equals("")) { + classIncludes = "/* Structural includes (inheritance, dependencies... */"+NL+classIncludes; + } + + // Prepare friend dependency includes + CppClassIncludeFriendDeclaration jetClassFIncludes + = new CppClassIncludeFriendDeclaration(); + String friendIncludes = jetClassFIncludes.generate(argument); + if (!friendIncludes.equals("")) { + friendIncludes = "/* Friend class declaration */"+NL+friendIncludes; + } + + // Prepare attributes and Methods declarations + String publicAttributes = ""; + String publicOperations = ""; + String protectedAttributes = ""; + String protectedOperations = ""; + String privateAttributes = ""; + String privateOperations = ""; + String packageAttributes = ""; + String packageOperations = ""; + + // Attributes + CppClassAttributesDeclaration jetClassPAttr = new CppClassAttributesDeclaration(); + publicAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PUBLIC_LITERAL); + protectedAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PROTECTED_LITERAL); + privateAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PRIVATE_LITERAL); + packageAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PACKAGE_LITERAL); + + // Methods + CppClassOperationsDeclaration jetClassPOp = new CppClassOperationsDeclaration(); + publicOperations = jetClassPOp.generate(currentClass, VisibilityKind.PUBLIC_LITERAL); + protectedOperations = jetClassPOp.generate(currentClass, VisibilityKind.PROTECTED_LITERAL); + privateOperations = jetClassPOp.generate(currentClass, VisibilityKind.PRIVATE_LITERAL); + packageOperations = jetClassPOp.generate(currentClass, VisibilityKind.PACKAGE_LITERAL); + + boolean hasConstructor = false; + for (Operation operation : currentClass.getOperations ()) { + if (GenUtils.hasStereotype(operation, StdStereo.create)) { + hasConstructor = true; + break; + } + } + String defaultInitializer = ""; + for (Property attribute : currentClass.getAttributes ()) { + if (attribute.isStatic()) { + // static attributes are initialized differently + continue; + } + ValueSpecification vs = attribute.getDefaultValue (); + if ((vs != null) && (vs.stringValue() != null)) { + if (!defaultInitializer.equals("")) { + // not first attribute + defaultInitializer += ", "; + } + defaultInitializer += attribute.getName () + "(" + vs.stringValue() + ")"; + } + } + // no constructor, add it, if some properties have default values + if ((!hasConstructor) && (!defaultInitializer.equals (""))) { + defaultInitializer = className + "() : " + defaultInitializer + " {}"; + } + else { + defaultInitializer = ""; + } + + // Inline functions implementations + String inlineFunctionsImplementation = ""; + CppClassInlineOperationsImplementation jetInlineClassPOp + = new CppClassInlineOperationsImplementation(); + inlineFunctionsImplementation = jetInlineClassPOp.generate(currentClass); + + // Prepare inherited classes or implemented interfaces + String inheritedDeclarations = ""; + CppClassInheritedDeclarations jetInherited + = new CppClassInheritedDeclarations(); + inheritedDeclarations = jetInherited.generate(currentClass); + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_2); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_3); + stringBuffer.append(TEXT_4); + stringBuffer.append( className ); + stringBuffer.append(TEXT_5); + stringBuffer.append(TEXT_6); + stringBuffer.append( ownerInclude ); + stringBuffer.append(TEXT_7); + stringBuffer.append(TEXT_8); + stringBuffer.append( classIncludes ); + stringBuffer.append(TEXT_9); + stringBuffer.append(TEXT_10); + stringBuffer.append( headerDecl ); + stringBuffer.append(TEXT_11); + stringBuffer.append( openNS ); + stringBuffer.append(TEXT_12); + stringBuffer.append(TEXT_13); + stringBuffer.append( typeEnumDefPackage ); + stringBuffer.append(TEXT_14); + stringBuffer.append(TEXT_15); + stringBuffer.append( classDoc ); + stringBuffer.append(TEXT_16); + stringBuffer.append( classOrStruct ); + stringBuffer.append(TEXT_17); + stringBuffer.append( className ); + stringBuffer.append( inheritedDeclarations ); + stringBuffer.append(TEXT_18); + stringBuffer.append(TEXT_19); + stringBuffer.append( friendIncludes ); + stringBuffer.append( typeEnumDef ); + stringBuffer.append(TEXT_20); + stringBuffer.append(TEXT_21); + stringBuffer.append( defaultInitializer ); + stringBuffer.append( publicAttributes ); + stringBuffer.append( publicOperations ); + stringBuffer.append(TEXT_22); + stringBuffer.append(TEXT_23); + stringBuffer.append( protectedAttributes ); + stringBuffer.append( protectedOperations ); + stringBuffer.append(TEXT_24); + stringBuffer.append(TEXT_25); + stringBuffer.append( privateAttributes ); + stringBuffer.append( privateOperations ); + stringBuffer.append(TEXT_26); + stringBuffer.append(TEXT_27); + stringBuffer.append( packageAttributes ); + stringBuffer.append(TEXT_28); + stringBuffer.append( packageOperations ); + stringBuffer.append(TEXT_29); + stringBuffer.append(TEXT_30); + stringBuffer.append( inlineFunctionsImplementation ); + stringBuffer.append(TEXT_31); + stringBuffer.append( closeNS ); + stringBuffer.append(TEXT_32); + stringBuffer.append( className ); + stringBuffer.append(TEXT_33); + stringBuffer.append(TEXT_34); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppInterfaceHeader.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppInterfaceHeader.java new file mode 100644 index 00000000000..933b4a00407 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppInterfaceHeader.java @@ -0,0 +1,160 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet; + +import org.eclipse.uml2.uml.Interface; +import org.eclipse.uml2.uml.Package; +import Cpp.CppInclude; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import org.eclipse.papyrus.cpp.codegen.jet.util.*; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; + +public class CppInterfaceHeader +{ + protected static String nl; + public static synchronized CppInterfaceHeader create(String lineSeparator) + { + nl = lineSeparator; + CppInterfaceHeader result = new CppInterfaceHeader(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#ifndef "; + protected final String TEXT_2 = "_H" + NL + "#define "; + protected final String TEXT_3 = "_H" + NL + "" + NL + "/************************************************************"; + protected final String TEXT_4 = NL + " "; + protected final String TEXT_5 = " interface header" + NL + " ************************************************************/" + NL; + protected final String TEXT_6 = NL; + protected final String TEXT_7 = NL; + protected final String TEXT_8 = NL; + protected final String TEXT_9 = NL; + protected final String TEXT_10 = NL; + protected final String TEXT_11 = NL; + protected final String TEXT_12 = NL + "/************************************************************/"; + protected final String TEXT_13 = NL; + protected final String TEXT_14 = NL + "class "; + protected final String TEXT_15 = " "; + protected final String TEXT_16 = "{" + NL + "" + NL + "/* Public declarations */" + NL + "public:"; + protected final String TEXT_17 = NL; + protected final String TEXT_18 = NL + NL + "};" + NL + "" + NL + "/************************************************************" + NL + " End of "; + protected final String TEXT_19 = " interface header" + NL + " ************************************************************/"; + protected final String TEXT_20 = NL; + protected final String TEXT_21 = NL + NL + "#endif"; + protected final String TEXT_22 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Interface currentInterface = (Interface) argument; + + // Get the package name + String interfaceName = currentInterface.getName(); + String interfaceFULLNAME = GenUtils.getFullNameUC (currentInterface); + + // For interface documentation + String iDoc = ""; + + // Retrieve enum doc + CppElementDoc jDoc = new CppElementDoc(); + iDoc = jDoc.generate(currentInterface); + + // Include declaration "CppInclude" + String headerDecl = ""; + CppInclude cppInclude = GenUtils.getApplication(currentInterface, CppInclude.class); + if (cppInclude != null) { + headerDecl = "// Include from CppInclude declaration" + NL + cppInclude.getHeader() + NL; + } + + // Prepare owner package header include + Package ownerPackage = currentInterface.getPackage(); + String ownerInclude = ""; + if (ownerPackage != null) { + // Create an util template to prepare the declaration + CppOwnerPackageIncludeDeclaration jetOwnerInclude + = new CppOwnerPackageIncludeDeclaration(); + // Execute the util template + ownerInclude = jetOwnerInclude.generate(ownerPackage); + } + + + // Prepare dependency includes + CppInterfaceAllIncludesDeclaration jetInterfaceIncludes + = new CppInterfaceAllIncludesDeclaration(); + String interfaceIncludes = jetInterfaceIncludes.generate(argument); + if (!interfaceIncludes.equals("")) { + interfaceIncludes = "/* Structural includes (inheritance, dependencies, ... */"+NL+interfaceIncludes; + } + + // Prepare Methods declarations + String publicOperations = ""; + + // Methods + CppInterfacePublicOperationsDeclaration jetPublicInterfacePOp + = new CppInterfacePublicOperationsDeclaration(); + publicOperations = jetPublicInterfacePOp.generate(currentInterface); + + + // Prepare inherited interfaces + String inheritedDeclarations = ""; + CppInterfaceInheritedDeclarations jetInherited + = new CppInterfaceInheritedDeclarations(); + inheritedDeclarations = jetInherited.generate(currentInterface); + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( interfaceFULLNAME ); + stringBuffer.append(TEXT_2); + stringBuffer.append( interfaceFULLNAME ); + stringBuffer.append(TEXT_3); + stringBuffer.append(TEXT_4); + stringBuffer.append( interfaceName ); + stringBuffer.append(TEXT_5); + stringBuffer.append(TEXT_6); + stringBuffer.append( ownerInclude ); + stringBuffer.append(TEXT_7); + stringBuffer.append(TEXT_8); + stringBuffer.append( interfaceIncludes ); + stringBuffer.append(TEXT_9); + stringBuffer.append(TEXT_10); + stringBuffer.append( headerDecl ); + stringBuffer.append(TEXT_11); + stringBuffer.append( GenUtils.openNS(currentInterface) ); + stringBuffer.append(TEXT_12); + stringBuffer.append(TEXT_13); + stringBuffer.append( iDoc ); + stringBuffer.append(TEXT_14); + stringBuffer.append( interfaceName ); + stringBuffer.append(TEXT_15); + stringBuffer.append( inheritedDeclarations ); + stringBuffer.append(TEXT_16); + stringBuffer.append(TEXT_17); + stringBuffer.append( publicOperations ); + stringBuffer.append(TEXT_18); + stringBuffer.append( interfaceName ); + stringBuffer.append(TEXT_19); + stringBuffer.append(TEXT_20); + stringBuffer.append( GenUtils.closeNS(currentInterface) ); + stringBuffer.append(TEXT_21); + stringBuffer.append(TEXT_22); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppPackageHeader.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppPackageHeader.java new file mode 100644 index 00000000000..58865c8b294 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppPackageHeader.java @@ -0,0 +1,203 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet; + +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.CppInclude; +import Cpp.CppNoCodeGen; +import org.eclipse.uml2.uml.*; +import org.eclipse.uml2.uml.Package; +import org.eclipse.emf.common.util.EList; +import org.eclipse.papyrus.cpp.codegen.jet.util.*; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import java.util.Iterator; +import java.util.Set; +import java.util.HashSet; +import org.eclipse.papyrus.cpp.codegen.Activator; + +public class CppPackageHeader +{ + protected static String nl; + public static synchronized CppPackageHeader create(String lineSeparator) + { + nl = lineSeparator; + CppPackageHeader result = new CppPackageHeader(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#ifndef PKG_"; + protected final String TEXT_2 = NL + "#define PKG_"; + protected final String TEXT_3 = NL + NL + "/************************************************************" + NL + " Pkg_"; + protected final String TEXT_4 = " package header" + NL + " ************************************************************/" + NL; + protected final String TEXT_5 = NL; + protected final String TEXT_6 = NL + "\t" + NL + "/* Package dependency header include */"; + protected final String TEXT_7 = NL + "#include <"; + protected final String TEXT_8 = "."; + protected final String TEXT_9 = ">"; + protected final String TEXT_10 = NL + NL + "/* CppInclude header declarations insert */"; + protected final String TEXT_11 = NL; + protected final String TEXT_12 = NL; + protected final String TEXT_13 = NL; + protected final String TEXT_14 = NL + "/* Types Defined in the package */"; + protected final String TEXT_15 = NL; + protected final String TEXT_16 = NL; + protected final String TEXT_17 = NL; + protected final String TEXT_18 = NL + NL + "/************************************************************" + NL + " End of Pkg_"; + protected final String TEXT_19 = " package header" + NL + " ************************************************************/" + NL + "" + NL + "#endif"; + protected final String TEXT_20 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the package + Package currentPackage = (Package) argument; + Package fatherPackage = currentPackage.getNestingPackage(); // return owner package + + // Get the package name + String packageName = currentPackage.getName(); + String packageFULLNAME = GenUtils.getFullName (currentPackage).toUpperCase(); + String openNS = GenUtils.openNS (currentPackage) + "namespace " + currentPackage.getName () + " {\n"; + String closeNS = "} // of namespace" + currentPackage.getName () + "\n" + GenUtils.closeNS (currentPackage); + + // Prepare the header declarations for this package + String headerDecl = ""; + CppInclude cppInclude = GenUtils.getApplication(currentPackage, CppInclude.class); + if (cppInclude != null) { + headerDecl = "// Include from CppInclude declaration" + NL + cppInclude.getHeader() + NL; + } + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + + // Prepare Father include declaration + String fatherPkgInclude = ""; + if (fatherPackage != null) { + // Create an util template to prepare the declaration + CppOwnerPackageIncludeDeclaration jetPkgInclude + = new CppOwnerPackageIncludeDeclaration(); + // Execute the util template + fatherPkgInclude = jetPkgInclude.generate(fatherPackage); + } + + + // Prepare Dependency includes declarations ... + // Retrieve package used by current package (dependencies) + + String cFullName = ""; // used in java to contruct and in template to read list + + // Get packages linked by dependencies + EList<Package> usedPackages = GenUtils.getUsedPackages (currentPackage); + Set<String> usedPackagesNames = new HashSet<String>(); + // Add imported packages + usedPackages.addAll(currentPackage.getImportedPackages()); + + Iterator<Package> usedPackagesIt = usedPackages.iterator(); + Iterator<String> usedPackagesNamesIt; + + // Refactor as a new Set containing names to be declared for packages (with path) + while(usedPackagesIt.hasNext()) { + Package currentUsedPackage = usedPackagesIt.next(); + String cPackageName = currentUsedPackage.getName(); + String cPackagePath = GenUtils.getFullPath (currentUsedPackage); + + cFullName = cPackagePath+"/Pkg_"+cPackageName; + + // Add this name to the set if codegen stereotype is not applied + PackageImport packImport = currentPackage.getPackageImport(currentUsedPackage); + if(!GenUtils.hasStereotype(packImport, CppNoCodeGen.class)) { + if (!GenUtils.hasStereotype(currentUsedPackage, CppNoCodeGen.class)) { + usedPackagesNames.add(cFullName); + } + } + } + + // and prepare the Iterator for the template... + usedPackagesNamesIt = usedPackagesNames.iterator(); + + + + // Prepare owned type and enum declaration + String typeDef = ""; + String enumDef = ""; + + Iterator<Type> typeIt = currentPackage.getOwnedTypes().iterator(); + while (typeIt.hasNext()) { + Type currentElt = typeIt.next(); + if (!GenUtils.hasStereotype(currentElt, CppNoCodeGen.class)) { + if (currentElt instanceof org.eclipse.uml2.uml.PrimitiveType) { + + PrimitiveType currentType = (PrimitiveType) currentElt; + CppPrimitiveTypeDefinition jetPrimitiveType = new CppPrimitiveTypeDefinition(); + // Execute the util template + typeDef = typeDef+jetPrimitiveType.generate(currentType); + + } else if (currentElt instanceof org.eclipse.uml2.uml.Enumeration) { + + Enumeration currentEnum = (Enumeration) currentElt; + CppEnumerationDefinition jetEnum = new CppEnumerationDefinition(); + // Execute the util template + enumDef = enumDef+jetEnum.generate(currentEnum); + + } + } + } + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( packageFULLNAME ); + stringBuffer.append(TEXT_2); + stringBuffer.append( packageFULLNAME ); + stringBuffer.append(TEXT_3); + stringBuffer.append( packageName ); + stringBuffer.append(TEXT_4); + stringBuffer.append(TEXT_5); + stringBuffer.append( fatherPkgInclude ); + stringBuffer.append(TEXT_6); + // For every depency linked package + while(usedPackagesNamesIt.hasNext()) { + cFullName = (String) usedPackagesNamesIt.next(); + stringBuffer.append(TEXT_7); + stringBuffer.append( cFullName ); + stringBuffer.append(TEXT_8); + stringBuffer.append( headerFileSuffix ); + stringBuffer.append(TEXT_9); + } + stringBuffer.append(TEXT_10); + stringBuffer.append(TEXT_11); + stringBuffer.append( headerDecl ); + stringBuffer.append(TEXT_12); + stringBuffer.append(TEXT_13); + stringBuffer.append( openNS ); + stringBuffer.append(TEXT_14); + stringBuffer.append(TEXT_15); + stringBuffer.append( typeDef ); + stringBuffer.append(TEXT_16); + stringBuffer.append( enumDef ); + stringBuffer.append(TEXT_17); + stringBuffer.append( closeNS ); + stringBuffer.append(TEXT_18); + stringBuffer.append( packageName ); + stringBuffer.append(TEXT_19); + stringBuffer.append(TEXT_20); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppTemplateHeader.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppTemplateHeader.java new file mode 100644 index 00000000000..4aad3809ba8 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/CppTemplateHeader.java @@ -0,0 +1,288 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet; + +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.*; +import org.eclipse.papyrus.cpp.codegen.jet.util.*; +import Cpp.CppInclude; +import Cpp.CppNoCodeGen; +import Cpp.CppInline; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import java.util.*; + +public class CppTemplateHeader +{ + protected static String nl; + public static synchronized CppTemplateHeader create(String lineSeparator) + { + nl = lineSeparator; + CppTemplateHeader result = new CppTemplateHeader(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#ifndef "; + protected final String TEXT_2 = "_H" + NL + "#define "; + protected final String TEXT_3 = "_H" + NL + "" + NL + "/************************************************************"; + protected final String TEXT_4 = NL + " "; + protected final String TEXT_5 = " template class header" + NL + " ************************************************************/" + NL; + protected final String TEXT_6 = NL; + protected final String TEXT_7 = NL; + protected final String TEXT_8 = NL; + protected final String TEXT_9 = NL; + protected final String TEXT_10 = NL; + protected final String TEXT_11 = NL; + protected final String TEXT_12 = NL; + protected final String TEXT_13 = NL + "/************************************************************/" + NL + "template <"; + protected final String TEXT_14 = "> class "; + protected final String TEXT_15 = " "; + protected final String TEXT_16 = "{"; + protected final String TEXT_17 = NL; + protected final String TEXT_18 = NL + "/* Public declarations */" + NL + "public:"; + protected final String TEXT_19 = NL; + protected final String TEXT_20 = NL; + protected final String TEXT_21 = NL + NL + "/* Protected declarations */" + NL + "protected:"; + protected final String TEXT_22 = NL; + protected final String TEXT_23 = NL; + protected final String TEXT_24 = NL + NL + "/* Private declarations */" + NL + "private:"; + protected final String TEXT_25 = NL; + protected final String TEXT_26 = NL; + protected final String TEXT_27 = NL + NL + "};" + NL + "" + NL + "/************************************************************/" + NL + "/* Template functions */"; + protected final String TEXT_28 = NL; + protected final String TEXT_29 = NL; + protected final String TEXT_30 = NL; + protected final String TEXT_31 = NL + "/* Inline functions */"; + protected final String TEXT_32 = NL; + protected final String TEXT_33 = NL; + protected final String TEXT_34 = NL; + protected final String TEXT_35 = NL + NL + "/************************************************************" + NL + " End of "; + protected final String TEXT_36 = " template class header" + NL + " ************************************************************/" + NL + "" + NL + "#endif"; + protected final String TEXT_37 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + + // Get the package name + String className = currentClass.getName(); + String classFullName = GenUtils.getFullName(currentClass); + String classFULLNAME = classFullName.toUpperCase(); + String openNS = GenUtils.openNS (currentClass); + String closeNS = GenUtils.closeNS (currentClass); + + // Include declaration "CppInclude" + String headerDecl = ""; + CppInclude cppInclude = GenUtils.getApplication(currentClass, CppInclude.class); + if (cppInclude != null) { + headerDecl = "// Include from CppInclude declaration" + NL + cppInclude.getHeader() + NL; + } + + // Prepare owner package header include + Package ownerPackage = currentClass.getPackage(); + String ownerInclude = ""; + if (ownerPackage != null) { + // Create an util template to prepare the declaration + CppOwnerPackageIncludeDeclaration jetOwnerInclude = new CppOwnerPackageIncludeDeclaration(); + // Execute the util template + ownerInclude = jetOwnerInclude.generate(ownerPackage); + } + + // Prepare owned type and enum declaration + String typeEnumDefPackage = ""; + String typeEnumDef = ""; + + CppClassTypeAndEnum jetTE = new CppClassTypeAndEnum(); + typeEnumDef = jetTE.generate(currentClass); + + CppClassTypeAndEnumPackage jetTEp = new CppClassTypeAndEnumPackage(); + typeEnumDefPackage = jetTEp.generate(currentClass); + + // Prepare template parameter declaration + Iterator<org.eclipse.uml2.uml.TemplateParameter> tparam = + GenUtils.getTemplateParameters(currentClass).iterator(); + + String tParamDecl = ""; + String tDecl = ""; + + while (tparam.hasNext()) { + CppTemplateParameter jetTParam = new CppTemplateParameter(); + tParamDecl = tParamDecl + jetTParam.generate(tparam.next()); + + if (tparam.hasNext()) { + tParamDecl = tParamDecl + ", "; + } + } + + tDecl = "template <" + tParamDecl + ">" + NL; + + // Prepare dependency includes + CppClassAllIncludesDeclaration jetClassIncludes = new CppClassAllIncludesDeclaration(); + String classIncludes = jetClassIncludes.generate(argument); + if (!classIncludes.equals("")) { + classIncludes = "/* Structural includes (inheritance, dependencies... */" + + NL + classIncludes; + } + + // Prepare attributes and Methods declarations + String publicAttributes = ""; + String protectedAttributes = ""; + String privateAttributes = ""; + String publicOperations = "", publicOperationsImpl = ""; + String protectedOperations = "", protectedOperationsImpl = ""; + String privateOperations = "", privateOperationsImpl = ""; + + // Attributes + CppClassAttributesDeclaration jetClassPAttr = new CppClassAttributesDeclaration(); + publicAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PUBLIC_LITERAL); + protectedAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PROTECTED_LITERAL); + privateAttributes = jetClassPAttr.generate(currentClass, VisibilityKind.PRIVATE_LITERAL); + + // Methods implementation + String inlineFuncImpl = ""; + // String inlineFuncDecl = ""; + + // Implementation + CppOperationTemplateImplementation jetOpImpl = new CppOperationTemplateImplementation(); + // Declaration + CppOperationDeclaration jetOpDecl = new CppOperationDeclaration(); + + // Retrieve operations + Iterator<Operation> operations = currentClass.getOperations().iterator(); + while (operations.hasNext()) { + Operation currentOperation = operations.next(); + + if (GenUtils.hasStereotype(currentOperation, CppNoCodeGen.class) || + currentOperation.isAbstract()) { + continue; + } + if (GenUtils.hasStereotype(currentOperation, CppInline.class)) { + String opDoc = ""; + // Doc for the template + CppOperationDoc jDoc = new CppOperationDoc(); + opDoc = jDoc.generate(currentOperation); + // Inline declaration + if (currentOperation.getVisibility() == VisibilityKind.PUBLIC_LITERAL) { + publicOperations = publicOperations + + jetOpDecl.generate(currentOperation) + ";"; + } else if (currentOperation.getVisibility() == VisibilityKind.PRIVATE_LITERAL) { + privateOperations = privateOperations + + jetOpDecl.generate(currentOperation) + ";"; + } else if (currentOperation.getVisibility() == VisibilityKind.PROTECTED_LITERAL) { + protectedOperations = protectedOperations + + jetOpDecl.generate(currentOperation) + ";"; + } // else nothing + // Inline implementation + inlineFuncImpl = inlineFuncImpl + opDoc + NL + tDecl + + jetOpImpl.generate(currentOperation) + NL; + } else { + if (currentOperation.getVisibility() == VisibilityKind.PUBLIC_LITERAL) { + publicOperationsImpl = publicOperationsImpl + tDecl + + jetOpImpl.generate(currentOperation); + publicOperations = publicOperations + + jetOpDecl.generate(currentOperation) + ";"; + } else if (currentOperation.getVisibility() == VisibilityKind.PRIVATE_LITERAL) { + privateOperationsImpl = privateOperationsImpl + tDecl + + jetOpImpl.generate(currentOperation); + privateOperations = privateOperations + + jetOpDecl.generate(currentOperation) + ";"; + } else if (currentOperation.getVisibility() == VisibilityKind.PROTECTED_LITERAL) { + protectedOperationsImpl = protectedOperationsImpl + tDecl + + jetOpImpl.generate(currentOperation); + protectedOperations = protectedOperations + + jetOpDecl.generate(currentOperation) + ";"; + } // else nothing + } + } + + // Prepare inherited classes or implemented interfaces + String inheritedDeclarations = ""; + CppClassInheritedDeclarations jetInherited = new CppClassInheritedDeclarations(); + inheritedDeclarations = jetInherited.generate(currentClass); + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_2); + stringBuffer.append( classFULLNAME ); + stringBuffer.append(TEXT_3); + stringBuffer.append(TEXT_4); + stringBuffer.append( className ); + stringBuffer.append(TEXT_5); + stringBuffer.append(TEXT_6); + stringBuffer.append( ownerInclude ); + stringBuffer.append(TEXT_7); + stringBuffer.append(TEXT_8); + stringBuffer.append( classIncludes ); + stringBuffer.append(TEXT_9); + stringBuffer.append(TEXT_10); + stringBuffer.append( headerDecl ); + stringBuffer.append(TEXT_11); + stringBuffer.append( openNS ); + stringBuffer.append(TEXT_12); + stringBuffer.append( typeEnumDefPackage ); + stringBuffer.append(TEXT_13); + stringBuffer.append( tParamDecl ); + stringBuffer.append(TEXT_14); + stringBuffer.append( className ); + stringBuffer.append(TEXT_15); + stringBuffer.append( inheritedDeclarations ); + stringBuffer.append(TEXT_16); + stringBuffer.append(TEXT_17); + stringBuffer.append( typeEnumDef ); + stringBuffer.append(TEXT_18); + stringBuffer.append(TEXT_19); + stringBuffer.append( publicAttributes ); + stringBuffer.append(TEXT_20); + stringBuffer.append( publicOperations ); + stringBuffer.append(TEXT_21); + stringBuffer.append(TEXT_22); + stringBuffer.append( protectedAttributes ); + stringBuffer.append(TEXT_23); + stringBuffer.append( protectedOperations ); + stringBuffer.append(TEXT_24); + stringBuffer.append(TEXT_25); + stringBuffer.append( privateAttributes ); + stringBuffer.append(TEXT_26); + stringBuffer.append( privateOperations ); + stringBuffer.append(TEXT_27); + stringBuffer.append(TEXT_28); + stringBuffer.append( publicOperationsImpl ); + stringBuffer.append(TEXT_29); + stringBuffer.append( protectedOperationsImpl ); + stringBuffer.append(TEXT_30); + stringBuffer.append( privateOperationsImpl ); + stringBuffer.append(TEXT_31); + stringBuffer.append(TEXT_32); + stringBuffer.append( inlineFuncImpl ); + stringBuffer.append(TEXT_33); + stringBuffer.append(TEXT_34); + stringBuffer.append( closeNS ); + stringBuffer.append(TEXT_35); + stringBuffer.append( className ); + stringBuffer.append(TEXT_36); + stringBuffer.append(TEXT_37); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppElementDoc.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppElementDoc.java new file mode 100644 index 00000000000..3b6157ccdb9 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppElementDoc.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.doc; + +import org.eclipse.uml2.uml.Element; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppElementDoc +{ + protected static String nl; + public static synchronized CppElementDoc create(String lineSeparator) + { + nl = lineSeparator; + CppElementDoc result = new CppElementDoc(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "/**" + NL + " * "; + protected final String TEXT_2 = NL + " */"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the element + Element currentElt = (Element) argument; + String eltDoc = ""; + + + // Doc for the element + eltDoc = GenUtils.getComments(currentElt); + eltDoc = eltDoc.replaceAll(NL, NL+" * "); + + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( eltDoc ); + stringBuffer.append(TEXT_2); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppOperationDoc.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppOperationDoc.java new file mode 100644 index 00000000000..b8fdbb83fb3 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppOperationDoc.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.doc; + +import org.eclipse.uml2.uml.Operation; +import org.eclipse.uml2.uml.Parameter; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import java.util.Iterator; + +public class CppOperationDoc +{ + protected static String nl; + public static synchronized CppOperationDoc create(String lineSeparator) + { + nl = lineSeparator; + CppOperationDoc result = new CppOperationDoc(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "/**" + NL + " * "; + protected final String TEXT_2 = NL + " * "; + protected final String TEXT_3 = NL + " */"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the element + Operation currentOperation = (Operation) argument; + Parameter currentParameter; + + String opDoc = ""; + String opParams = ""; +// String opReturn = ""; +// TODO: return not handled? (or treated as any other parameter?) + + // Doc for the element + opDoc = GenUtils.getComments(currentOperation); + opDoc = opDoc.replaceAll(NL, NL+" * "); + + // Treat params + Iterator<Parameter> parameters = currentOperation.getOwnedParameters().iterator(); + while(parameters.hasNext()) { + currentParameter = (Parameter) parameters.next(); + + // Prepare parameters + CppParamDoc jetParam = new CppParamDoc(); + opParams = opParams+jetParam.generate(currentParameter); + + if (parameters.hasNext()){ + opParams = opParams+NL+" * "; + } + } + + // Treat return + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( opDoc ); + stringBuffer.append(TEXT_2); + stringBuffer.append( opParams ); + stringBuffer.append(TEXT_3); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppParamDoc.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppParamDoc.java new file mode 100644 index 00000000000..398b823a7bb --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/doc/CppParamDoc.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.doc; + +import org.eclipse.uml2.uml.Parameter; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppParamDoc +{ + protected static String nl; + public static synchronized CppParamDoc create(String lineSeparator) + { + nl = lineSeparator; + CppParamDoc result = new CppParamDoc(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "@param "; + protected final String TEXT_2 = " "; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the element + Parameter currentElt = (Parameter) argument; + + String paramName = currentElt.getName(); + String paramDoc = GenUtils.getComments(currentElt); + + paramDoc = paramDoc.replaceAll(NL, NL+" * "); + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( paramName ); + stringBuffer.append(TEXT_2); + stringBuffer.append( paramDoc ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeDeclaration.java new file mode 100644 index 00000000000..faad5c04422 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeDeclaration.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Property; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.*; + +public class CppAttributeDeclaration +{ + protected static String nl; + public static synchronized CppAttributeDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppAttributeDeclaration result = new CppAttributeDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = NL + "\t"; + protected final String TEXT_2 = NL + "\t"; + protected final String TEXT_3 = " "; + protected final String TEXT_4 = ";"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the property + Property currentAttribute = (Property) argument; + + String attributeName = currentAttribute.getName(); + String typeName = ""; + String prefix = ""; + String suffix = ""; + String multiple = ""; + + // For property documentation + String propDoc = ""; + + // Retrieve enum doc + CppElementDoc jDoc = new CppElementDoc(); + propDoc = jDoc.generate(currentAttribute); + propDoc = propDoc.replaceAll(NL, NL+" "); + + if (currentAttribute.getType() == null) { + typeName = "undefined"; + } else { + typeName = GenUtils.qualifiedName (currentAttribute.getType()); + } + + // Static attribute + if (currentAttribute.isStatic()) { + prefix = "static"+" "; + } + + Modifier modifier = new Modifier(currentAttribute); + + // Treat multiplicity for association attributes + int multiplicity = currentAttribute.getUpper(); + if (multiplicity == 1) { + multiple = ""; + } else if (multiplicity == -1) { + multiple = "*"; + } else { + multiple = ""; + modifier.array = "[" + multiplicity + "]"; + } + + // If attribute is aggregation + if (GenUtils.isAggregation(currentAttribute)) { + // attributeName = "(*"+attributeName+")"; // this produce a pointer on a tab + attributeName = "*"+attributeName; // this produce a tab of pointers + } + + + if (GenUtils.hasStereotype(currentAttribute, CppConst.class) && currentAttribute.isStatic()) { + // const & static attributes may be initialized within class declaration + // check if initial value UML or profile + if (currentAttribute.getDefaultValue() != null) { + suffix = " = " + currentAttribute.getDefaultValue().stringValue(); + } + else { + CppDefault cppDefault = GenUtils.getApplication(currentAttribute, CppDefault.class); + if (cppDefault != null) { + suffix = " = " + cppDefault.getValue(); + } + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( propDoc ); + stringBuffer.append(TEXT_2); + stringBuffer.append( prefix ); + stringBuffer.append( modifier.isConst ); + stringBuffer.append( typeName ); + stringBuffer.append( multiple ); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( modifier.ref ); + stringBuffer.append(TEXT_3); + stringBuffer.append( attributeName ); + stringBuffer.append( modifier.array ); + stringBuffer.append( suffix ); + stringBuffer.append(TEXT_4); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeImplementation.java new file mode 100644 index 00000000000..ab85473afbc --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppAttributeImplementation.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.*; + +public class CppAttributeImplementation +{ + protected static String nl; + public static synchronized CppAttributeImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppAttributeImplementation result = new CppAttributeImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "\t"; + protected final String TEXT_2 = NL + "\t"; + protected final String TEXT_3 = " "; + protected final String TEXT_4 = ";"; + protected final String TEXT_5 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the property + Property currentAttribute = (Property) argument; + + String attributeName = currentAttribute.getName(); +// String className = currentAttribute.getOwner().getName(); + String typeName = ""; + String scopeName = ""; +// String prefix = ""; + String suffix = ""; + String multiple = ""; + + // For property documentation + String propDoc = ""; + + // Retrieve enum doc + CppElementDoc jDoc = new CppElementDoc(); + propDoc = jDoc.generate(currentAttribute); + propDoc = propDoc.replaceAll(NL, NL+" "); + + if (currentAttribute.getType() == null) { + typeName = "undefined"; + } + else { + Type type = currentAttribute.getType(); + typeName = GenUtils.qualifiedName (type); + /* + // If type is owned by a class add the scope + if (type.getOwner() instanceof Class) { + scopeName = ((Class) type.getOwner()).getName(); + typeName = scopeName+"::"+typeName; + } + */ + } + + // Multiple + // TODO? need to evaluate limitMultiplicity stereotype? + int upper = currentAttribute.getUpper(); + if ((upper == -1) || (upper > 1)) { + multiple = "*"; + } + + Modifier modifier = new Modifier(currentAttribute); + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( propDoc ); + stringBuffer.append(TEXT_2); + stringBuffer.append( typeName ); + stringBuffer.append( multiple ); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( modifier.ref ); + stringBuffer.append(TEXT_3); + stringBuffer.append( attributeName ); + stringBuffer.append( modifier.array ); + stringBuffer.append( suffix ); + stringBuffer.append(TEXT_4); + stringBuffer.append(TEXT_5); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAllIncludesDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAllIncludesDeclaration.java new file mode 100644 index 00000000000..acc9eb087fa --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAllIncludesDeclaration.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.*; +import org.eclipse.uml2.uml.Class; +import org.eclipse.emf.common.util.EList; +import org.eclipse.uml2.uml.Package; +import org.eclipse.emf.common.util.UniqueEList; +import java.util.*; +import org.eclipse.uml2.uml.PrimitiveType; +import org.eclipse.uml2.uml.Enumeration; +import org.eclipse.uml2.uml.Classifier; + +public class CppClassAllIncludesDeclaration +{ + protected static String nl; + public static synchronized CppClassAllIncludesDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppClassAllIncludesDeclaration result = new CppClassAllIncludesDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + protected final String TEXT_3 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + + // Get the package name + // String className = currentClass.getName(); + + // Prepare Dependency includes declarations ... + // Retrieve package used by current package (dependencies) + // use a unique list to avoid duplicates + EList<Classifier> usedClasses = new UniqueEList<Classifier> (); + + String newInclude = ""; + + // class attributes dependencies + usedClasses.addAll (GenUtils.getOwnedAttributeTypes(currentClass)); + // operation parameters dependencies + usedClasses.addAll (GenUtils.getIncludesFromOperations(currentClass)); + // realized interface dependencies + if (currentClass instanceof Class) { + usedClasses.addAll (GenUtils.getImplementedInterfaces((Class) currentClass)); + } + // dependencies and associations + usedClasses.addAll (GenUtils.getRelationshipsNoDeps(currentClass)); + + // template parameters are declared locally (if owned) and do not correspond to a file + // that can be included + usedClasses.removeAll (GenUtils.getTemplateParameteredElements(currentClass)); + + Iterator<Classifier> usedClassesIt = usedClasses.iterator(); + // Parsing all as NamedElement + String includes = ClassUtils.createIncludeDecl (usedClasses, currentClass); + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( includes ); + stringBuffer.append(TEXT_2); + stringBuffer.append(TEXT_3); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesDeclaration.java new file mode 100644 index 00000000000..a0de92709c3 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesDeclaration.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.Iterator; + +public class CppClassAttributesDeclaration +{ + protected static String nl; + public static synchronized CppClassAttributesDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppClassAttributesDeclaration result = new CppClassAttributesDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument1, Object argument2) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument1; + String attrDecl = ""; + + // Retrieve public attributes + Iterator<Property> attributes = currentClass.getAttributes().iterator(); + while (attributes.hasNext()) { + Property attribute = attributes.next(); + if (attribute.getVisibility() == argument2) { + CppAttributeDeclaration jetAttDecl = new CppAttributeDeclaration(); + attrDecl = attrDecl+jetAttDecl.generate(attribute); + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( attrDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesImplementation.java new file mode 100644 index 00000000000..4c30ed0bedd --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassAttributesImplementation.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.Iterator; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppClassAttributesImplementation +{ + protected static String nl; + public static synchronized CppClassAttributesImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppClassAttributesImplementation result = new CppClassAttributesImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + String attrDecl = ""; + String attrSDecl = ""; + + CppAttributeImplementation jetAttDecl = new CppAttributeImplementation(); + CppStaticAttributeImplementation jetSAttDecl = new CppStaticAttributeImplementation(); + + Iterator<Property> attributesIt = currentClass.getAttributes().iterator(); + while (attributesIt.hasNext()) { + Property attribute = (Property) attributesIt.next(); + + // just check that this property is not a static const + // in that case it declared and defined in the header file + + // Static + if (attribute.isStatic()) { + attrSDecl = attrSDecl+jetSAttDecl.generate(attribute); + } else { + attrDecl = attrDecl+jetAttDecl.generate(attribute); + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( attrSDecl ); + stringBuffer.append( attrDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassFriendDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassFriendDeclaration.java new file mode 100644 index 00000000000..030fae595ff --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassFriendDeclaration.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.NamedElement; + +public class CppClassFriendDeclaration +{ + protected static String nl; + public static synchronized CppClassFriendDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppClassFriendDeclaration result = new CppClassFriendDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "friend class "; + protected final String TEXT_2 = ";"; + protected final String TEXT_3 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + NamedElement currentNE = (NamedElement) argument; + String cClassName = currentNE.getName(); + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( cClassName ); + stringBuffer.append(TEXT_2); + stringBuffer.append(TEXT_3); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeClassDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeClassDeclaration.java new file mode 100644 index 00000000000..e7fc0246e6e --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeClassDeclaration.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppClassIncludeClassDeclaration +{ + protected static String nl; + public static synchronized CppClassIncludeClassDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppClassIncludeClassDeclaration result = new CppClassIncludeClassDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + protected final String TEXT_3 = NL; + protected final String TEXT_4 = "class "; + protected final String TEXT_5 = ";"; + protected final String TEXT_6 = NL; + protected final String TEXT_7 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + NamedElement currentNE = (NamedElement) argument; + String cClassName = currentNE.getName(); + String isTemplate = ""; + String openNS = GenUtils.openNS (currentNE); + String closeNS = GenUtils.closeNS (currentNE); + + if (GenUtils.hasStereotype(currentNE, CppTemplate.class)) { + isTemplate = "template "; + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append(TEXT_2); + stringBuffer.append( openNS ); + stringBuffer.append(TEXT_3); + stringBuffer.append( isTemplate ); + stringBuffer.append(TEXT_4); + stringBuffer.append( cClassName ); + stringBuffer.append(TEXT_5); + stringBuffer.append(TEXT_6); + stringBuffer.append( closeNS ); + stringBuffer.append(TEXT_7); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeDeclaration.java new file mode 100644 index 00000000000..a10b49edd59 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeDeclaration.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Package; +import org.eclipse.papyrus.cpp.codegen.Activator; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppClassIncludeDeclaration +{ + protected static String nl; + public static synchronized CppClassIncludeDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppClassIncludeDeclaration result = new CppClassIncludeDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#include <"; + protected final String TEXT_2 = ">"; + protected final String TEXT_3 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + + // Retrieve the class + NamedElement currentNE = (NamedElement) argument; + String cClassPath = ""; + Package nearestPkg = currentNE.getNearestPackage(); + String cClassName = currentNE.getName(); + + if ( //!(nearestPkg.getUml2Package() instanceof org.eclipse.uml2.uml.Model) + /*&& */!(GenUtils.hasStereotype(nearestPkg, CppRoot.class))) { + cClassPath = GenUtils.getFullPath(nearestPkg)+"/"; + } + + + // If an external class is referred + CppExternClass extClass = GenUtils.getApplication(currentNE, CppExternClass.class); + CppTemplate template = GenUtils.getApplication(currentNE, CppTemplate.class); + if (extClass != null) { + cClassPath = ""; + cClassName = extClass.getName(); + if ((cClassName == null) || cClassName.equals ("")) { + // default value + cClassName = currentNE.getQualifiedName ().replace ("::", "/") + "." + headerFileSuffix; + // strip model name + cClassName = cClassName.substring (currentNE.getModel ().getName ().length () + 1); + } + } else if (template != null) { + cClassPath = ""; + cClassName = template.getDeclaration(); + } + else cClassName=cClassName+"."+headerFileSuffix; + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( cClassPath ); + stringBuffer.append( cClassName ); + stringBuffer.append(TEXT_2); + stringBuffer.append(TEXT_3); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeFriendDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeFriendDeclaration.java new file mode 100644 index 00000000000..1b37bcb57aa --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassIncludeFriendDeclaration.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppClassIncludeFriendDeclaration +{ + protected static String nl; + public static synchronized CppClassIncludeFriendDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppClassIncludeFriendDeclaration result = new CppClassIncludeFriendDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; +// NamedElement currentElt = (NamedElement) argument; + + // Prepare Dependency includes declarations ... + // Retrieve package used by current package (dependencies) + Iterator<Classifier> friendClassesIt = GenUtils.getUsedClassifiers(currentClass).iterator(); + + // Parsing all as NamedElement + String friendClass = ""; + + while (friendClassesIt.hasNext()) { + Classifier cClass = friendClassesIt.next(); + + if (GenUtils.hasStereotype(cClass, CppFriend.class) && + (!GenUtils.hasStereotype(cClass, CppNoCodeGen.class))) { + + CppClassFriendDeclaration jetIDecl + = new CppClassFriendDeclaration(); + + friendClass = friendClass+jetIDecl.generate(cClass); + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( friendClass ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInheritedDeclarations.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInheritedDeclarations.java new file mode 100644 index 00000000000..9081b1f7aaa --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInheritedDeclarations.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppClassInheritedDeclarations +{ + protected static String nl; + public static synchronized CppClassInheritedDeclarations create(String lineSeparator) + { + nl = lineSeparator; + CppClassInheritedDeclarations result = new CppClassInheritedDeclarations(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + String targetName = ""; + String visibility = ""; + String decl = ""; + + // Get generalization and implementation relationships + Iterator<DirectedRelationship> relationshipIt = + currentClass.getSourceDirectedRelationships().iterator(); + // Iterator impIt = currentClass.getImplementations().iterator(); + + while (relationshipIt.hasNext()) { + + DirectedRelationship relationship = relationshipIt.next(); + + if ((relationship instanceof Generalization) || + (relationship instanceof InterfaceRealization)) + { + org.eclipse.uml2.uml.Classifier target = null; + if (relationship.getTargets ().size() > 0) { + // there should always be at least one element in the target + // list and it should be a classifier, but better check. + org.eclipse.uml2.uml.Element element = + relationship.getTargets().get(0); + if (element instanceof org.eclipse.uml2.uml.Classifier) { + target = (org.eclipse.uml2.uml.Classifier) element; + } + } + if (target != null) { + // If not <NoCodeGen> + if (!GenUtils.hasStereotype(target, CppNoCodeGen.class)) + { + CppVisibility cppVisibility = GenUtils.getApplication(relationship, CppVisibility.class); + if (cppVisibility != null) { + visibility = cppVisibility.getValue(); + } else { + visibility = "public"; + } + + targetName = GenUtils.qualifiedName (target); + if (!decl.equals("")) { + decl = decl + ", "; + } + decl = decl+visibility+" "+targetName; + } + } + } + } + + // Parse implementations + // RS: removed code: Implementation does not exist in UML2 v2. + // TODO: replace Implementation with new UML2 constructions? +// Implementation currentImp; +// +// while (impIt.hasNext()) { +// +// currentImp = (Implementation) impIt.next(); +// currentNE = (NamedElement) currentImp; +// +// // get visibility and target name +// visibility = currentNE.getVisibilityAsString(); +// +// // If not <NoCodeGen> +// if (!GenUtils.hasStereotype(currentImp.getTarget(), CppNoCodeGen.class)) { +// +// targetName = currentImp.getTarget().getName(); +// +// if (!decl.equals("")) { +// decl = decl + ", "; +// } +// decl = decl+visibility+" "+targetName; +// +// } +// } + + + // ":" if decl non empty + String prefix = ""; + if (!decl.equals("")) { + prefix = " : "; + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( prefix ); + stringBuffer.append( decl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInlineOperationsImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInlineOperationsImplementation.java new file mode 100644 index 00000000000..4ff043d4116 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassInlineOperationsImplementation.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.Iterator; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppClassInlineOperationsImplementation +{ + protected static String nl; + public static synchronized CppClassInlineOperationsImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppClassInlineOperationsImplementation result = new CppClassInlineOperationsImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + String opDecl = ""; + + // Retrieve operations + Iterator<Operation> operations = currentClass.getOperations().iterator(); + while (operations.hasNext()) { + Operation currentOp = operations.next(); + if (GenUtils.hasStereotype (currentOp, CppInline.class) && + !GenUtils.hasStereotype (currentOp, CppNoCodeGen.class)) { + + CppOperationImplementation jetOpImpl = new CppOperationImplementation(); + opDecl = opDecl+jetOpImpl.generate(currentOp); + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( opDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsDeclaration.java new file mode 100644 index 00000000000..1ba52bc71f5 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsDeclaration.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.Iterator; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppClassOperationsDeclaration +{ + protected static String nl; + public static synchronized CppClassOperationsDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppClassOperationsDeclaration result = new CppClassOperationsDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument1, Object argument2) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument1; + String opDecl = ""; + + // Retrieve attributes + Iterator<Operation> operations = currentClass.getOperations().iterator(); + while (operations.hasNext()) { + Operation operation = operations.next(); + if (!GenUtils.hasStereotype (operation, CppNoCodeGen.class)) { + if (operation.getVisibility() == argument2) { + CppOperationDeclaration jetOpDecl = new CppOperationDeclaration(); + String cOpDecl = jetOpDecl.generate(operation); + + // if main cOpDecl = ""; + if (!cOpDecl.equals("")) { + opDecl = opDecl+NL+cOpDecl+";"; + } + } + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( opDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsImplementation.java new file mode 100644 index 00000000000..377e7f579bf --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassOperationsImplementation.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.Iterator; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppClassOperationsImplementation +{ + protected static String nl; + public static synchronized CppClassOperationsImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppClassOperationsImplementation result = new CppClassOperationsImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + String opDecl = ""; + + // Retrieve operations + Iterator<Operation> operations = currentClass.getOperations().iterator(); + while (operations.hasNext()) { + Operation currentOp = operations.next(); + if (!GenUtils.hasStereotype (currentOp, CppInline.class) && + !GenUtils.hasStereotype (currentOp, CppNoCodeGen.class) && + !currentOp.isAbstract()) { + CppOperationImplementation jetOpImpl = new CppOperationImplementation(); + opDecl = opDecl+jetOpImpl.generate(currentOp); + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( opDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnum.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnum.java new file mode 100644 index 00000000000..db433ffb881 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnum.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import org.eclipse.uml2.uml.*; + +public class CppClassTypeAndEnum +{ + protected static String nl; + public static synchronized CppClassTypeAndEnum create(String lineSeparator) + { + nl = lineSeparator; + CppClassTypeAndEnum result = new CppClassTypeAndEnum(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + + // Prepare owned type and enum declaration + String publicTypeDef = ""; + String privateTypeDef = ""; + String protectedTypeDef = ""; + String publicEnumDef = ""; + String privateEnumDef = ""; + String protectedEnumDef = ""; + String publicKeyword = "public:"; + String protectedKeyword = "protected:"; + String privateKeyword = "private:"; + + for (Element currentElt : currentClass.getOwnedElements()) { + if (!GenUtils.hasStereotype(currentElt, Cpp.CppNoCodeGen.class)) { + if (currentElt instanceof PrimitiveType) { + + org.eclipse.uml2.uml.PrimitiveType currentType = (org.eclipse.uml2.uml.PrimitiveType) currentElt; + CppPrimitiveTypeDefinition jetPrimitiveType = new CppPrimitiveTypeDefinition(); + // Execute the util template + if (currentType.getVisibility() == VisibilityKind.PUBLIC_LITERAL) { + publicTypeDef = publicTypeDef+jetPrimitiveType.generate(currentType); + } else if (currentType.getVisibility() == VisibilityKind.PROTECTED_LITERAL) { + protectedTypeDef = protectedTypeDef+jetPrimitiveType.generate(currentType); + } else if (currentType.getVisibility() == VisibilityKind.PRIVATE_LITERAL) { + privateTypeDef = privateTypeDef+jetPrimitiveType.generate(currentType); + } + } + else if (currentElt instanceof Enumeration) { + + Enumeration currentEnum = (Enumeration) currentElt; + CppEnumerationDefinition jetEnum = new CppEnumerationDefinition(); + // Execute the util template + if (currentEnum.getVisibility() == VisibilityKind.PUBLIC_LITERAL) { + publicEnumDef = publicEnumDef+jetEnum.generate(currentEnum); + } else if (currentEnum.getVisibility() == VisibilityKind.PROTECTED_LITERAL) { + protectedEnumDef = protectedEnumDef+jetEnum.generate(currentEnum); + } else if (currentEnum.getVisibility() == VisibilityKind.PRIVATE_LITERAL) { + privateEnumDef = privateEnumDef+jetEnum.generate(currentEnum); + } + } + } + } + + // If not "" add a comment before declarations + if (publicTypeDef.equals("") && publicEnumDef.equals("")) { + publicKeyword = ""; + } else { + if (!publicTypeDef.equals("")) { + publicTypeDef = "/* Public type definitions */"+NL+publicTypeDef+NL; + } + if (!publicEnumDef.equals("")) { + publicEnumDef = "/* Public enumeration definitions */"+NL+publicEnumDef+NL; + } + } + + if (protectedTypeDef.equals("") && protectedEnumDef.equals("")) { + protectedKeyword = ""; + } else { + if (!protectedTypeDef.equals("")) { + protectedTypeDef = "/* Protected type definitions */"+NL+protectedTypeDef+NL; + } + if (!protectedEnumDef.equals("")) { + protectedEnumDef = "/* Protected enumeration definitions */"+NL+protectedEnumDef+NL; + } + } + + if (privateTypeDef.equals("") && privateEnumDef.equals("")) { + privateKeyword = ""; + } else { + if (!privateTypeDef.equals("")) { + privateTypeDef = "/* Private type definitions */"+NL+privateTypeDef+NL; + } + if (!privateEnumDef.equals("")) { + privateEnumDef = "/* Private enumeration definitions */"+NL+privateEnumDef+NL; + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( publicKeyword ); + stringBuffer.append( publicTypeDef ); + stringBuffer.append( publicEnumDef ); + stringBuffer.append( protectedKeyword ); + stringBuffer.append( protectedTypeDef ); + stringBuffer.append( protectedEnumDef ); + stringBuffer.append( privateKeyword ); + stringBuffer.append( privateTypeDef ); + stringBuffer.append( privateEnumDef ); + stringBuffer.append(TEXT_2); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnumPackage.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnumPackage.java new file mode 100644 index 00000000000..4818c9dd823 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppClassTypeAndEnumPackage.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import java.util.Iterator; +import Cpp.*; + +public class CppClassTypeAndEnumPackage +{ + protected static String nl; + public static synchronized CppClassTypeAndEnumPackage create(String lineSeparator) + { + nl = lineSeparator; + CppClassTypeAndEnumPackage result = new CppClassTypeAndEnumPackage(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + protected final String TEXT_3 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Classifier currentClass = (Classifier) argument; + + + // Prepare owned type and enum declaration + String packageTypeDef = ""; + String packageEnumDef = ""; + + Iterator<Element> typeIt = currentClass.getOwnedElements().iterator(); + while (typeIt.hasNext()) { + Element currentElt = typeIt.next(); + if (!GenUtils.hasStereotype(currentElt, CppNoCodeGen.class)) { + if (currentElt instanceof PrimitiveType) { + + PrimitiveType currentType = (PrimitiveType) currentElt; + CppPrimitiveTypeDefinition jetPrimitiveType = new CppPrimitiveTypeDefinition(); + // Execute the util template + if (currentType.getVisibility() == VisibilityKind.PACKAGE_LITERAL) { + packageTypeDef = packageTypeDef+jetPrimitiveType.generate(currentType); + } + + + } else if (currentElt instanceof Enumeration) { + + Enumeration currentEnum = (Enumeration) currentElt; + CppEnumerationDefinition jetEnum = new CppEnumerationDefinition(); + // Execute the util template + if (currentEnum.getVisibility() == VisibilityKind.PACKAGE_LITERAL) { + packageEnumDef = packageEnumDef+jetEnum.generate(currentEnum); + } + + } + } + } + + // If not "" add a comment before declarations + if (!packageEnumDef.equals("")) { + packageEnumDef = "/* Package enumeration definitions */"+NL+packageEnumDef; + } + if (!packageTypeDef.equals("")) { + packageTypeDef = "/* Package type definitions */"+NL+packageTypeDef; + } + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( packageTypeDef ); + stringBuffer.append(TEXT_2); + stringBuffer.append( packageEnumDef ); + stringBuffer.append(TEXT_3); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppEnumerationDefinition.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppEnumerationDefinition.java new file mode 100644 index 00000000000..b3589b1a5fe --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppEnumerationDefinition.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Enumeration; +import org.eclipse.uml2.uml.EnumerationLiteral; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import java.util.Iterator; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import Cpp.*; + +public class CppEnumerationDefinition +{ + protected static String nl; + public static synchronized CppEnumerationDefinition create(String lineSeparator) + { + nl = lineSeparator; + CppEnumerationDefinition result = new CppEnumerationDefinition(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL + "enum "; + protected final String TEXT_3 = " {" + NL + "\t"; + protected final String TEXT_4 = NL + "};" + NL; + protected final String TEXT_5 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // This is an util template to prepare Enumeration definition + ///////////////////////////////////////////////////////////// + + + // Retrieve the enumeration + Enumeration currentEnumeration = (Enumeration) argument; + + // Get the package name + String enumName = currentEnumeration.getName(); + + // Doc + String enumDoc = ""; + String enumLitDoc = ""; + + // Retrieve enum doc + CppElementDoc jDoc = new CppElementDoc(); + enumDoc = jDoc.generate(currentEnumeration); + + // Retrieve literals + String enumLiterals = ""; + + Iterator<EnumerationLiteral> literalsIt = currentEnumeration.getOwnedLiterals().iterator(); + + while (literalsIt.hasNext()) { + + // retrieve current + EnumerationLiteral currentLiteral = literalsIt.next(); + + enumLiterals = enumLiterals+currentLiteral.getName(); + + // if current literal is initialised + CppInit cppInit = GenUtils.getApplication(currentLiteral, CppInit.class); + if (cppInit != null) { + // Add the initialisation value + int initValue = cppInit.getValue(); + enumLiterals = enumLiterals + " = " + initValue; + } + + // Retrieve doc + if (!GenUtils.getComments(currentLiteral).equals("")) { + enumLitDoc = " //< "+GenUtils.getComments(currentLiteral); + } else { + enumLitDoc = ""; + } + + // if more literal left prepare new line for next literal + if (literalsIt.hasNext()) { + enumLiterals = enumLiterals+" ,"+enumLitDoc+NL+"\t"; + } else { + enumLiterals = enumLiterals+enumLitDoc; + } + } + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( enumDoc ); + stringBuffer.append(TEXT_2); + stringBuffer.append( enumName ); + stringBuffer.append(TEXT_3); + stringBuffer.append( enumLiterals ); + stringBuffer.append(TEXT_4); + stringBuffer.append(TEXT_5); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceAllIncludesDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceAllIncludesDeclaration.java new file mode 100644 index 00000000000..ced6f6754b1 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceAllIncludesDeclaration.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import org.eclipse.uml2.uml.Interface; +import org.eclipse.emf.common.util.EList; +import org.eclipse.uml2.uml.Package; +import org.eclipse.emf.common.util.UniqueEList; +import java.util.*; +import org.eclipse.uml2.uml.PrimitiveType; +import org.eclipse.uml2.uml.Enumeration; +import org.eclipse.uml2.uml.Classifier; + +public class CppInterfaceAllIncludesDeclaration +{ + protected static String nl; + public static synchronized CppInterfaceAllIncludesDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppInterfaceAllIncludesDeclaration result = new CppInterfaceAllIncludesDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the interface + Interface currentInterface = (Interface) argument; + + // Prepare Dependency includes declarations ... + // Retrieve package used by current package (dependencies) + // use a unique list to avoid duplicates + EList<Classifier> usedClasses = new UniqueEList<Classifier> (); + + String newInclude = ""; + + // class attributes dependencies + usedClasses.addAll (GenUtils.getOwnedAttributeTypes(currentInterface)); + // operation parameters dependencies + usedClasses.addAll (GenUtils.getIncludesFromOperations(currentInterface)); + // dependencies and associations + usedClasses.addAll (GenUtils.getRelationships(currentInterface)); + + Iterator<Classifier> usedClassesIt = usedClasses.iterator(); + // Parsing all as NamedElement + String includes = ""; + + while (usedClassesIt.hasNext()) + { + Classifier cl = usedClassesIt.next (); + + // Only add include if this is not for the current class + if (!currentInterface.equals(cl)) { + // ... and if it does not have the stereotype "CppNoCodeGen", unless + // it has stereotype "CppExternalClass" + if ( (!GenUtils.hasStereotype(cl, CppNoCodeGen.class)) || + GenUtils.hasStereotype(cl, CppExternClass.class)) { + + if ((cl instanceof Enumeration) || (cl instanceof PrimitiveType)) + { + // Enumeration is not defined in a separate file, but in the + // package that owns it => include the owning package (might be a duplicate input, if owning + // package is also the owner of current interface) + CppOwnerPackageIncludeDeclaration jetIDecl + = new CppOwnerPackageIncludeDeclaration(); + if (cl.getOwner() instanceof Package) { + newInclude = jetIDecl.generate (cl.getOwner ()); + } + else { + newInclude = ""; + } + } + else { + // include the file associated with the classifier + CppClassIncludeDeclaration jetIDecl + = new CppClassIncludeDeclaration(); + newInclude = jetIDecl.generate (cl); + } + + includes = includes+newInclude; + } + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( includes ); + stringBuffer.append(TEXT_2); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceIncludeDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceIncludeDeclaration.java new file mode 100644 index 00000000000..63b3a5ebe72 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceIncludeDeclaration.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Package; +import org.eclipse.papyrus.cpp.codegen.Activator; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppInterfaceIncludeDeclaration +{ + protected static String nl; + public static synchronized CppInterfaceIncludeDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppInterfaceIncludeDeclaration result = new CppInterfaceIncludeDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "#include <"; + protected final String TEXT_2 = "."; + protected final String TEXT_3 = ">"; + protected final String TEXT_4 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + // Retrieve the interface + NamedElement currentNE = (NamedElement) argument; + String iInterfacePath = ""; + Package nearestPkg = currentNE.getNearestPackage(); + String iInterfaceName = currentNE.getName(); + + if ( //!(nearestPkg.getUml2Package() instanceof org.eclipse.uml2.uml.Model) + /*&&*/ !(GenUtils.hasStereotype(nearestPkg, CppRoot.class))) { + iInterfacePath = GenUtils.getFullPath (nearestPkg) + "/"; + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( iInterfacePath ); + stringBuffer.append( iInterfaceName ); + stringBuffer.append(TEXT_2); + stringBuffer.append( headerFileSuffix ); + stringBuffer.append(TEXT_3); + stringBuffer.append(TEXT_4); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceInheritedDeclarations.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceInheritedDeclarations.java new file mode 100644 index 00000000000..309f94f1d57 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfaceInheritedDeclarations.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Classifier; +import org.eclipse.uml2.uml.Generalization; +import java.util.Iterator; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppInterfaceInheritedDeclarations +{ + protected static String nl; + public static synchronized CppInterfaceInheritedDeclarations create(String lineSeparator) + { + nl = lineSeparator; + CppInterfaceInheritedDeclarations result = new CppInterfaceInheritedDeclarations(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the interface + Classifier currentClass = (Classifier) argument; + String decl = ""; + String visibility = ""; + + // Get generalization and implementation relationships + Iterator<Generalization> genIt = currentClass.getGeneralizations().iterator(); + + // Parse generalizations + while (genIt.hasNext()) { + + Generalization currentGen = genIt.next(); + + visibility = GenUtils.getVisibility(currentGen); + + // If not <NoCodeGen> + Classifier tmpClassifier = currentGen.getGeneral(); + if (!GenUtils.hasStereotype(tmpClassifier, CppNoCodeGen.class)) { + + String targetName = tmpClassifier.getName(); + + if (!decl.equals("")) { + decl = decl + ", "; + } + decl = decl+visibility+" "+targetName; + } + } + + // ":" only if decl not empty + String prefix = ""; + if (!decl.equals("")) { + prefix = ": "; + visibility = "public "; + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( prefix ); + stringBuffer.append( decl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfacePublicOperationsDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfacePublicOperationsDeclaration.java new file mode 100644 index 00000000000..84debe54ae5 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppInterfacePublicOperationsDeclaration.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Interface; +import org.eclipse.uml2.uml.Operation; +import org.eclipse.uml2.uml.VisibilityKind; +import java.util.*; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppInterfacePublicOperationsDeclaration +{ + protected static String nl; + public static synchronized CppInterfacePublicOperationsDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppInterfacePublicOperationsDeclaration result = new CppInterfacePublicOperationsDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Interface currentInterface = (Interface) argument; + String opDecl = ""; + + // Retrieve operations + Iterator<Operation> operations = currentInterface.getOwnedOperations().iterator(); + while (operations.hasNext()) { + Operation currentOperation = operations.next(); + if ((currentOperation.getVisibility() == VisibilityKind.PUBLIC_LITERAL) && + !GenUtils.hasStereotype (currentOperation, CppNoCodeGen.class)) { + CppOperationDeclaration jetOpDecl = new CppOperationDeclaration(); + String cOpDecl = jetOpDecl.generate(currentOperation); + + // if main cOpDecl = ""; + if (!cOpDecl.equals("")) { + opDecl = opDecl+"\t"+cOpDecl+";"; + } + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( opDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationDeclaration.java new file mode 100644 index 00000000000..28ff6878080 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationDeclaration.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.StdStereo; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppOperationDeclaration +{ + protected static String nl; + public static synchronized CppOperationDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppOperationDeclaration result = new CppOperationDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + protected final String TEXT_3 = NL + "\t"; + protected final String TEXT_4 = "("; + protected final String TEXT_5 = ")"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Operation + Operation currentOperation = (Operation) argument; + + String operationName = currentOperation.getName(); + + String opParameters = ""; + + String returnTypeName = "void"; + String pVirtualSuffix = ""; + String prefix = ""; + String constOp = ""; + + + String opDoc = ""; + + // Doc for the template + CppOperationDoc jDoc = new CppOperationDoc(); + opDoc = GenUtils.indent (jDoc.generate(currentOperation), "\t"); + + // Prepare return type + CppOperationReturnType jetRT = new CppOperationReturnType(); + returnTypeName = jetRT.generate(currentOperation); + if (!returnTypeName.equals ("")) { + returnTypeName += " "; + } + + boolean isInterface = currentOperation.getOwner () instanceof Interface; + + // Static attribute + if (currentOperation.isStatic()) { + prefix = prefix+"static"+" "; + } + + // Inline attribute + if (GenUtils.hasStereotype(currentOperation, CppInline.class)) { + prefix = prefix+"inline"+" "; + } + + // Creator / Destructor: use function within StdStereo + if (StdStereo.isApplied(currentOperation, StdStereo.create)) { + returnTypeName = ""; + } + if (StdStereo.isApplied(currentOperation, StdStereo.destroy)) { + returnTypeName = ""; + operationName = "~"+operationName; + } + + // Const attribute on operation + if (GenUtils.hasStereotype(currentOperation, CppConst.class)) { + constOp = " const"; + } + + // Virtual attribute on operation + if (GenUtils.hasStereotype(currentOperation, CppVirtual.class)) { + prefix = "virtual "+prefix; + } + + // Pure Virtual attribute on operation + if (isInterface || currentOperation.isAbstract ()) { + prefix = "virtual "+prefix; + pVirtualSuffix = " = 0"; + } + + // Friend attribute on operation + if (GenUtils.hasStereotype(currentOperation, CppFriend.class)) { + prefix = "friend "+prefix; + } + + // Prepare parameters + CppOperationParameters jetParams = new CppOperationParameters(); + opParameters = jetParams.generate(currentOperation); + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template only if current operation is not main +// else nothing is return... +////////////////////////////////////////////////////////////////////////////////////////// + +if (!operationName.equals("main")) { + +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append(TEXT_2); + stringBuffer.append( opDoc ); + stringBuffer.append(TEXT_3); + stringBuffer.append( prefix ); + stringBuffer.append( returnTypeName ); + stringBuffer.append( operationName ); + stringBuffer.append(TEXT_4); + stringBuffer.append( opParameters ); + stringBuffer.append(TEXT_5); + stringBuffer.append( constOp ); + stringBuffer.append( pVirtualSuffix ); + ////////////////////////////////////////////////////////////////////////////////////////// +} // else nothing done +////////////////////////////////////////////////////////////////////////////////////////// + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationImplementation.java new file mode 100644 index 00000000000..af6da84736b --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationImplementation.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.StdStereo; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppOperationImplementation +{ + protected static String nl; + public static synchronized CppOperationImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppOperationImplementation result = new CppOperationImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + protected final String TEXT_3 = NL; + protected final String TEXT_4 = " "; + protected final String TEXT_5 = " ("; + protected final String TEXT_6 = ") {"; + protected final String TEXT_7 = NL; + protected final String TEXT_8 = NL + "}" + NL; + protected final String TEXT_9 = "\t" + NL; + protected final String TEXT_10 = NL; + protected final String TEXT_11 = NL; + protected final String TEXT_12 = " "; + protected final String TEXT_13 = "::"; + protected final String TEXT_14 = "("; + protected final String TEXT_15 = ")"; + protected final String TEXT_16 = " {"; + protected final String TEXT_17 = NL; + protected final String TEXT_18 = NL + "}" + NL; + protected final String TEXT_19 = "\t"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Operation + Operation currentOperation = (Operation) argument; + + String body = ""; + String className = ""; + String operationName = currentOperation.getName(); + String opParameters = ""; + String returnTypeName = "void"; + String isInline = ""; + String isConst = ""; + String constInit = ""; + + String opDoc = ""; + + // Doc for the template + CppOperationDoc jDoc = new CppOperationDoc(); + opDoc = jDoc.generate(currentOperation); + + // Retrieve class name. Operation may belong to a class or datatype, thus use + // generic getOwner function + Element opOwner = currentOperation.getOwner(); + className = (opOwner instanceof NamedElement) ? ((NamedElement) opOwner).getName() : ""; + + // Retrieve body content + body = GenUtils.getBody (currentOperation, "C/C++"); + + // Prepare return type + CppOperationReturnType jetRT = new CppOperationReturnType(); + returnTypeName = jetRT.generate(currentOperation); + + // Creator / Destructor: use function within StdStereo + if (StdStereo.isApplied(currentOperation, StdStereo.create)) { + returnTypeName = ""; + } + if (StdStereo.isApplied(currentOperation, StdStereo.destroy)) { + returnTypeName = ""; + operationName = "~"+operationName; + } + + // If is inline operation + if (GenUtils.hasStereotype(currentOperation, CppInline.class)) { + isInline = "inline "; + } + + // Const op + if (GenUtils.hasStereotype(currentOperation, CppConst.class)) { + isConst = " const"; + } + + // Constructor init list + CppConstInit cppConstInit = GenUtils.getApplication(currentOperation, CppConstInit.class); + if ((cppConstInit != null) + && StdStereo.isApplied(currentOperation, StdStereo.create)) { + constInit = " : " + cppConstInit.getInitialisation(); + } + + // Prepare parameters + CppOperationParametersWithoutDefaultValue jetParams = new CppOperationParametersWithoutDefaultValue(); + opParameters = jetParams.generate(currentOperation); + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template two cases main operation or classical +////////////////////////////////////////////////////////////////////////////////////////// + +// main + if (operationName.equals("main")) { + +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append(TEXT_2); + stringBuffer.append( opDoc ); + stringBuffer.append(TEXT_3); + stringBuffer.append( returnTypeName ); + stringBuffer.append(TEXT_4); + stringBuffer.append( operationName ); + stringBuffer.append(TEXT_5); + stringBuffer.append( opParameters ); + stringBuffer.append(TEXT_6); + stringBuffer.append(TEXT_7); + stringBuffer.append( body ); + stringBuffer.append(TEXT_8); + ////////////////////////////////////////////////////////////////////////////////////////// + + } + else { + +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_9); + stringBuffer.append(TEXT_10); + stringBuffer.append( opDoc ); + stringBuffer.append(TEXT_11); + stringBuffer.append( isInline ); + stringBuffer.append( returnTypeName ); + stringBuffer.append(TEXT_12); + stringBuffer.append( className ); + stringBuffer.append(TEXT_13); + stringBuffer.append( operationName ); + stringBuffer.append(TEXT_14); + stringBuffer.append( opParameters ); + stringBuffer.append(TEXT_15); + stringBuffer.append( isConst ); + stringBuffer.append( constInit ); + stringBuffer.append(TEXT_16); + stringBuffer.append(TEXT_17); + stringBuffer.append( body ); + stringBuffer.append(TEXT_18); + ////////////////////////////////////////////////////////////////////////////////////////// + } +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_19); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParameters.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParameters.java new file mode 100644 index 00000000000..fc67d3ec185 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParameters.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.*; + +public class CppOperationParameters +{ + protected static String nl; + public static synchronized CppOperationParameters create(String lineSeparator) + { + nl = lineSeparator; + CppOperationParameters result = new CppOperationParameters(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Operation + Operation currentOperation = (Operation) argument; + Parameter currentParameter; + + String paramDecl = ""; + + Iterator<Parameter> parameters = currentOperation.getOwnedParameters().iterator(); + while(parameters.hasNext()) { + currentParameter = parameters.next(); + if (currentParameter.getDirection () != ParameterDirectionKind.RETURN_LITERAL) { + // Prepare parameters + CppParameter jetParam = new CppParameter(); + if (!paramDecl.equals("")) { + paramDecl += ", "; + } + paramDecl = paramDecl+jetParam.generate(currentParameter); + } + } + + paramDecl.replaceAll(NL, ""); + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( paramDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParametersWithoutDefaultValue.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParametersWithoutDefaultValue.java new file mode 100644 index 00000000000..d3e0dc8d710 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationParametersWithoutDefaultValue.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import java.util.*; + +public class CppOperationParametersWithoutDefaultValue +{ + protected static String nl; + public static synchronized CppOperationParametersWithoutDefaultValue create(String lineSeparator) + { + nl = lineSeparator; + CppOperationParametersWithoutDefaultValue result = new CppOperationParametersWithoutDefaultValue(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Operation + Operation currentOperation = (Operation) argument; + Parameter currentParameter; + + String paramDecl = ""; + + Iterator<Parameter> parameters = currentOperation.getOwnedParameters().iterator(); + while(parameters.hasNext()) { + currentParameter = parameters.next(); + if (currentParameter.getDirection () != ParameterDirectionKind.RETURN_LITERAL) { + // Prepare parameters + CppParameterWithoutDefaultValue jetParam = new CppParameterWithoutDefaultValue(); + if (!paramDecl.equals("")) { + paramDecl += ", "; + } + paramDecl = paramDecl+jetParam.generate(currentParameter); + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( paramDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationReturnType.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationReturnType.java new file mode 100644 index 00000000000..5a75d7009e8 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationReturnType.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import org.eclipse.uml2.uml.Class; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.*; + +public class CppOperationReturnType +{ + protected static String nl; + public static synchronized CppOperationReturnType create(String lineSeparator) + { + nl = lineSeparator; + CppOperationReturnType result = new CppOperationReturnType(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "::"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Operation + Operation currentOperation = (Operation) argument; + + String returnTypeName = "void"; + String ownerName = ""; + Modifier modifier = new Modifier(); + + // Return type + if (currentOperation.getType() == null) { + returnTypeName = "void"; + } else { + if (currentOperation.getType() == null) { + returnTypeName = "undefined"; + } else { + // Treat the type if it is not "package visibility" and owned by a class + Type currentType = currentOperation.getType(); + returnTypeName = GenUtils.qualifiedName (currentType); + + if (currentType.getVisibility() != VisibilityKind.PACKAGE_LITERAL) { + if (currentType.getOwner() instanceof Class) { + ownerName = ((Class) currentType.getOwner()).getName(); + } + } + } + + // Treat pointer or ref on return parameter (only one return parameter should exists) + // retrieve return parameter +// RS: changed test: now getReturnResult returns only one param +// if (currentOperation.getUml2Operation().getReturnResults().size() == 1) { +// org.eclipse.uml2.uml.Parameter uml2Param +// = (org.eclipse.uml2.uml.Parameter) currentOperation.getUml2Operation().getReturnResults().get(0); +// Parameter currentRParameter +// = new Parameter(uml2Param); +// // case Pointer +// if (currentRParameter.hasStereotype(xy, CppPtr.class)) { +// isPointer = " "+currentRParameter.getTaggedValue(CppPtr.class, "declaration"); +// } +// if (currentRParameter.hasStereotype(xy, CppRef.class)) { +// isRef = " "+currentRParameter.getTaggedValue(CppRef.class, "declaration"); +// } +// if (currentRParameter.hasStereotype(xy, CppConst.class_)) { +// isConst = "const "; +// } +// } + if (currentOperation.getReturnResult() instanceof Parameter) { + Parameter uml2Param = (Parameter) currentOperation.getReturnResult(); + modifier = new Modifier(uml2Param); + } + } + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template two cases : scope required or not +////////////////////////////////////////////////////////////////////////////////////////// + +// No scope details + if (ownerName.equals("")) { +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( modifier.isConst ); + stringBuffer.append( returnTypeName ); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( modifier.ref ); + ////////////////////////////////////////////////////////////////////////////////////////// +} else { +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( modifier.isConst ); + stringBuffer.append( ownerName ); + stringBuffer.append(TEXT_1); + stringBuffer.append( returnTypeName ); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( modifier.ref ); + ////////////////////////////////////////////////////////////////////////////////////////// +} +////////////////////////////////////////////////////////////////////////////////////////// + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationTemplateImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationTemplateImplementation.java new file mode 100644 index 00000000000..18487bed8a5 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOperationTemplateImplementation.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import org.eclipse.uml2.uml.Class; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.StdStereo; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppOperationTemplateImplementation +{ + protected static String nl; + public static synchronized CppOperationTemplateImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppOperationTemplateImplementation result = new CppOperationTemplateImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "("; + protected final String TEXT_2 = ")"; + protected final String TEXT_3 = " {"; + protected final String TEXT_4 = NL; + protected final String TEXT_5 = NL + "}"; + protected final String TEXT_6 = "<"; + protected final String TEXT_7 = ">::"; + protected final String TEXT_8 = "("; + protected final String TEXT_9 = ")"; + protected final String TEXT_10 = " {"; + protected final String TEXT_11 = NL; + protected final String TEXT_12 = NL + "}"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Operation + Operation currentOperation = (Operation) argument; + + String operationName = currentOperation.getName(); + String opParameters = ""; + String returnTypeName = "void"; + String isConst = ""; + String isInline = ""; + + // Retrieve class & class name + Class currentClass = currentOperation.getClass_ (); + String className = currentClass.getName(); + + // Retrieve body content + String body = GenUtils.getBody (currentOperation, "C/C++"); + + // Prepare return type + CppOperationReturnType jetRT = new CppOperationReturnType(); + returnTypeName = jetRT.generate(currentOperation); + if (! "".equals(returnTypeName)) { + returnTypeName = returnTypeName + " "; + } + + // Creator / Destructor: use function within StdStereo + if (StdStereo.isApplied(currentOperation, StdStereo.create)) { + returnTypeName = ""; + } + if (StdStereo.isApplied(currentOperation, StdStereo.destroy)) { + returnTypeName = ""; + operationName = "~"+operationName; + } + + // If inline operation + if (GenUtils.hasStereotype(currentOperation, CppInline.class)) { + isInline = "inline "; + } + + // Const op + if (GenUtils.hasStereotype(currentOperation, CppConst.class)) { + isConst = " const"; + } + + // Prepare parameters + CppOperationParametersWithoutDefaultValue jetParams + = new CppOperationParametersWithoutDefaultValue(); + opParameters = jetParams.generate(currentOperation); + + + // Prepare template parameter declaration without type + String tparamWoType = ""; + + if (currentClass != null) { + tparamWoType = GenUtils.getTemplateParametersWoType(currentClass); + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// +// Package visibility + if (currentOperation.getVisibility() == VisibilityKind.PACKAGE_LITERAL) { + +////////////////////////////////////////////////////////////////////////////////////////// + + + stringBuffer.append( isInline ); + stringBuffer.append( returnTypeName ); + stringBuffer.append( operationName ); + stringBuffer.append(TEXT_1); + stringBuffer.append( opParameters ); + stringBuffer.append(TEXT_2); + stringBuffer.append( isConst ); + stringBuffer.append(TEXT_3); + stringBuffer.append(TEXT_4); + stringBuffer.append( body ); + stringBuffer.append(TEXT_5); + + +////////////////////////////////////////////////////////////////////////////////////////// + + } else { // Default case + +////////////////////////////////////////////////////////////////////////////////////////// + + + stringBuffer.append( isInline ); + stringBuffer.append( returnTypeName ); + stringBuffer.append( className ); + stringBuffer.append(TEXT_6); + stringBuffer.append( tparamWoType ); + stringBuffer.append(TEXT_7); + stringBuffer.append( operationName ); + stringBuffer.append(TEXT_8); + stringBuffer.append( opParameters ); + stringBuffer.append(TEXT_9); + stringBuffer.append( isConst ); + stringBuffer.append(TEXT_10); + stringBuffer.append(TEXT_11); + stringBuffer.append( body ); + stringBuffer.append(TEXT_12); + + +////////////////////////////////////////////////////////////////////////////////////////// + } +////////////////////////////////////////////////////////////////////////////////////////// + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOwnerPackageIncludeDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOwnerPackageIncludeDeclaration.java new file mode 100644 index 00000000000..777e4798740 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppOwnerPackageIncludeDeclaration.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Package; +import org.eclipse.papyrus.cpp.codegen.Activator; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppOwnerPackageIncludeDeclaration +{ + protected static String nl; + public static synchronized CppOwnerPackageIncludeDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppOwnerPackageIncludeDeclaration result = new CppOwnerPackageIncludeDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = " \t" + NL + "/* Owner package header include */" + NL + "#include <"; + protected final String TEXT_2 = "/Pkg_"; + protected final String TEXT_3 = "."; + protected final String TEXT_4 = ">"; + protected final String TEXT_5 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the type passed as argument + Package currentPkg = (Package) argument; + String currentPkgName = currentPkg.getName(); + String currentPkgPath = GenUtils.getFullPath (currentPkg); + + // Retrieve header file suffix + String headerFileSuffix = Activator.getDefault().getPluginPreferences().getString("headSuffix"); + + // Prepare Father include declaration + boolean isRoot = false; + + // The currentElt has the CppRoot stereotype + if (GenUtils.hasStereotype(currentPkg, CppRoot.class)) { + isRoot = true; + } + // The currentPkg is the model root package + //if (currentPkg instanceof org.eclipse.uml2.uml.Model){ + // isRoot = true; + //} + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + // if currentPkg is not root it is referenced here + if (!isRoot) { + stringBuffer.append(TEXT_1); + stringBuffer.append( currentPkgPath ); + stringBuffer.append(TEXT_2); + stringBuffer.append( currentPkgName ); + stringBuffer.append(TEXT_3); + stringBuffer.append( headerFileSuffix ); + stringBuffer.append(TEXT_4); + // endif + } + stringBuffer.append(TEXT_5); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameter.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameter.java new file mode 100644 index 00000000000..87ac2c0bfac --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameter.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Parameter; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.Modifier; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppParameter +{ + protected static String nl; + public static synchronized CppParameter create(String lineSeparator) + { + nl = lineSeparator; + CppParameter result = new CppParameter(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = " "; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Parameter + Parameter currentParameter = (Parameter) argument; + + String parameterName = currentParameter.getName(); + + String typeName = ""; + String suffix = ""; + Modifier modifier = new Modifier(currentParameter); + + if (currentParameter.getType() == null) { + typeName = "undefined"; + } else { + typeName = GenUtils.qualifiedName (currentParameter.getType()); + } + + // Initial value + CppDefault cppDefault = GenUtils.getApplication(currentParameter, CppDefault.class); + if (cppDefault != null) { + suffix = " = " + cppDefault.getValue(); + } + + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( modifier.isConst ); + stringBuffer.append( typeName ); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( modifier.ref ); + stringBuffer.append(TEXT_1); + stringBuffer.append( parameterName ); + stringBuffer.append( modifier.array ); + stringBuffer.append( suffix ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameterWithoutDefaultValue.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameterWithoutDefaultValue.java new file mode 100644 index 00000000000..1bb92004f6d --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppParameterWithoutDefaultValue.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Parameter; +import org.eclipse.uml2.uml.Classifier; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.Modifier; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppParameterWithoutDefaultValue +{ + protected static String nl; + public static synchronized CppParameterWithoutDefaultValue create(String lineSeparator) + { + nl = lineSeparator; + CppParameterWithoutDefaultValue result = new CppParameterWithoutDefaultValue(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "<"; + protected final String TEXT_2 = ">"; + protected final String TEXT_3 = " "; + protected final String TEXT_4 = " "; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the Parameter + Parameter currentParameter = (Parameter) argument; + + String parameterName = currentParameter.getName(); + + String typeName = ""; + Modifier modifier = new Modifier(currentParameter); + + // Prepare template parameter declaration without type + String tparamWoType = ""; + + if (currentParameter.getType() == null) { + typeName = "undefined"; + } + else if (currentParameter.getType() instanceof Classifier) { + Classifier classifier = (Classifier) currentParameter.getType(); + tparamWoType = GenUtils.getTemplateParametersWoType(classifier); + + typeName = GenUtils.qualifiedName (currentParameter.getType()); + } + else { + typeName = GenUtils.qualifiedName (currentParameter.getType()); + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// +// Package visibility + if (!"".equals(tparamWoType)) { + +////////////////////////////////////////////////////////////////////////////////////////// + + + stringBuffer.append( modifier.isConst ); + stringBuffer.append( typeName ); + stringBuffer.append(TEXT_1); + stringBuffer.append( tparamWoType ); + stringBuffer.append(TEXT_2); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( modifier.ref ); + stringBuffer.append(TEXT_3); + stringBuffer.append( parameterName ); + stringBuffer.append( modifier.array ); + + +////////////////////////////////////////////////////////////////////////////////////////// + + } else { // Default case + +////////////////////////////////////////////////////////////////////////////////////////// + + + stringBuffer.append( modifier.isConst ); + stringBuffer.append( typeName ); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( modifier.ref ); + stringBuffer.append(TEXT_4); + stringBuffer.append( parameterName ); + stringBuffer.append( modifier.array ); + + + +////////////////////////////////////////////////////////////////////////////////////////// + } +////////////////////////////////////////////////////////////////////////////////////////// + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppPrimitiveTypeDefinition.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppPrimitiveTypeDefinition.java new file mode 100644 index 00000000000..c014caf01d6 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppPrimitiveTypeDefinition.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.PrimitiveType; +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppPrimitiveTypeDefinition +{ + protected static String nl; + public static synchronized CppPrimitiveTypeDefinition create(String lineSeparator) + { + nl = lineSeparator; + CppPrimitiveTypeDefinition result = new CppPrimitiveTypeDefinition(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + protected final String TEXT_3 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the type passed as argument + PrimitiveType currentPType = (PrimitiveType) argument; + String currentPTypeName = currentPType.getName(); + String definition = ""; + + // Doc + String typeDoc = ""; + + // Retrieve enum doc + CppElementDoc jDoc = new CppElementDoc(); + + /** + * Support two different kinds of primitive types + * (1) those that are native types of the programming language such as long + * For these, no additional definition has to be done and they should be referenced + * with their name only + * (2) those that correspond to a typedef (e.g. typedef long ErrorType). These require + * a typedef definition within the package and need to be referenced with their + * fully qualified name (e.g. MyPackage::ErrorType) + */ + // Retrieve type definition + CppType cppType = GenUtils.getApplication(currentPType, CppType.class); + if (cppType != null) { + typeDoc = jDoc.generate(currentPType); + definition = "typedef " + cppType.getDefinition(); + + // If definition string contains "typeName" it should be replaced with type name... + if (definition.indexOf("typeName") != -1) { + definition = definition.replaceAll("typeName", currentPTypeName); + } else { + definition = definition + " " + currentPTypeName; + } + definition = definition + ";"; + } + else { + definition = GenUtils.getStdtypes(currentPType); + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( typeDoc ); + stringBuffer.append(TEXT_2); + stringBuffer.append( definition ); + stringBuffer.append(TEXT_3); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppStaticAttributeImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppStaticAttributeImplementation.java new file mode 100644 index 00000000000..e24233da4ab --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppStaticAttributeImplementation.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.*; + +public class CppStaticAttributeImplementation +{ + protected static String nl; + public static synchronized CppStaticAttributeImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppStaticAttributeImplementation result = new CppStaticAttributeImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = "::"; + protected final String TEXT_3 = ";"; + protected final String TEXT_4 = NL; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the property + Property currentAttribute = (Property) argument; + + String attributeName = currentAttribute.getName(); + String className = GenUtils.qualifiedName (currentAttribute.getClass_()); + String typeName = ""; + String suffix = ""; + String multiple = ""; + String isAgg = ""; // attribute is an aggregation or association + + + if (currentAttribute.getType() == null) { + typeName = "undefined"+" "; + } else { + typeName = GenUtils.qualifiedName (currentAttribute.getType()) + " "; + } + + // Multiple + // if (currentAttribute.isMultiple()) { + // multiple = "*"; + // } + + // If attribute is aggregation then generate a pointer + if (GenUtils.isAggregation(currentAttribute)) { + // attributeName = "(*"+attributeName+")"; // this produce a pointer on a tab + isAgg = "*"; // this produce a tab of pointers + } + + Modifier modifier = new Modifier(currentAttribute); + + // Initial value + if (currentAttribute.getDefaultValue() != null) { + // via UML + suffix = " = " + currentAttribute.getDefaultValue().stringValue(); + } + else { + CppDefault cppDefault = GenUtils.getApplication(currentAttribute, CppDefault.class); + if (cppDefault != null) { + suffix = " = " + cppDefault.getValue(); + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + stringBuffer.append(TEXT_1); + stringBuffer.append( typeName ); + stringBuffer.append( multiple ); + stringBuffer.append( modifier.ptr ); + stringBuffer.append( isAgg ); + stringBuffer.append( modifier.ref ); + stringBuffer.append( className ); + stringBuffer.append(TEXT_2); + stringBuffer.append( attributeName ); + stringBuffer.append( modifier.array ); + stringBuffer.append( suffix ); + stringBuffer.append(TEXT_3); + stringBuffer.append(TEXT_4); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateBindingParameter.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateBindingParameter.java new file mode 100644 index 00000000000..09feb0868b5 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateBindingParameter.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.*; + +public class CppTemplateBindingParameter +{ + protected static String nl; + public static synchronized CppTemplateBindingParameter create(String lineSeparator) + { + nl = lineSeparator; + CppTemplateBindingParameter result = new CppTemplateBindingParameter(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + + // Retrieve the TemplateParameter + // Retrieve the TemplateParameter + TemplateParameterSubstitution currentTParam = (TemplateParameterSubstitution) argument; + + String typeName = ""; + + if (currentTParam.getActual() == null) { + typeName ="param undefined"; + } + else { + ParameterableElement actual = currentTParam.getActual(); + + if (actual instanceof LiteralInteger) { + typeName = "" + ((LiteralInteger) currentTParam.getActual()).getValue(); + } + else { + typeName = ((NamedElement) currentTParam.getActual()).getName(); + } // value = currentTParam.getFormal().getParameteredElement().getName(); + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( typeName ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateDeclaration.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateDeclaration.java new file mode 100644 index 00000000000..567a6ce365f --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateDeclaration.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.TemplateParameter; +import java.util.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppTemplateDeclaration +{ + protected static String nl; + public static synchronized CppTemplateDeclaration create(String lineSeparator) + { + nl = lineSeparator; + CppTemplateDeclaration result = new CppTemplateDeclaration(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = "template <"; + protected final String TEXT_2 = ">"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Class currentClass = (Class) argument; + + + // Prepare template parameter declaration + Iterator<TemplateParameter> tparam = GenUtils.getTemplateParameters(currentClass).iterator(); + String tParamDecl = ""; + + while(tparam.hasNext()) { + TemplateParameter currentTParam = tparam.next(); + + CppTemplateParameter jetTParam = new CppTemplateParameter(); + tParamDecl = tParamDecl+jetTParam.generate(currentTParam); + + if (tparam.hasNext()) { + tParamDecl = tParamDecl+", "; + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append(TEXT_1); + stringBuffer.append( tParamDecl ); + stringBuffer.append(TEXT_2); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateInlineOperationsImplementation.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateInlineOperationsImplementation.java new file mode 100644 index 00000000000..999e3789ce1 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateInlineOperationsImplementation.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import org.eclipse.papyrus.cpp.codegen.jet.doc.*; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.Operation; +import java.util.Iterator; +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; + +public class CppTemplateInlineOperationsImplementation +{ + protected static String nl; + public static synchronized CppTemplateInlineOperationsImplementation create(String lineSeparator) + { + nl = lineSeparator; + CppTemplateInlineOperationsImplementation result = new CppTemplateInlineOperationsImplementation(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + // Retrieve the class + Class currentClass = (Class) argument; + String opDecl = ""; + String tDecl = ""; + + // Retrieve template declaration + CppTemplateDeclaration jetTDecl = new CppTemplateDeclaration(); + // tDecl should contain something like "template <class x, class y>" + tDecl = jetTDecl.generate(currentClass) + " "; + + // Retrieve operations + Iterator<Operation> operations = currentClass.getOwnedOperations().iterator(); + while (operations.hasNext()) { + Operation currentOperation = operations.next(); + + if (GenUtils.hasStereotype (currentOperation, CppInline.class) && + !GenUtils.hasStereotype (currentOperation, CppNoCodeGen.class)) { + String opDoc = ""; + + // Doc for the template + CppOperationDoc jDoc = new CppOperationDoc(); + opDoc = jDoc.generate(currentOperation); + + CppOperationTemplateImplementation jetOpImpl = new CppOperationTemplateImplementation(); + opDecl = opDecl+opDoc+NL+tDecl+jetOpImpl.generate(currentOperation)+NL; + } + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( opDecl ); + return stringBuffer.toString(); + } +}
\ No newline at end of file diff --git a/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateParameter.java b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateParameter.java new file mode 100644 index 00000000000..30e4dc8da32 --- /dev/null +++ b/extraplugins/cpp-codegen/org.eclipse.papyrus.cpp.codegen/jetsrc/org/eclipse/papyrus/cpp/codegen/jet/util/CppTemplateParameter.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * All rights reserved. This program and the accompanying materials + * are property of the CEA, their use is subject to specific agreement + * with the CEA. + * + * Contributors: + * CEA List - initial API and implementation + *******************************************************************************/ + +package org.eclipse.papyrus.cpp.codegen.jet.util; + +import Cpp.*; +import org.eclipse.papyrus.cpp.codegen.utils.GenUtils; +import org.eclipse.uml2.uml.TemplateParameter; + +public class CppTemplateParameter +{ + protected static String nl; + public static synchronized CppTemplateParameter create(String lineSeparator) + { + nl = lineSeparator; + CppTemplateParameter result = new CppTemplateParameter(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = " "; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Java preparation +////////////////////////////////////////////////////////////////////////////////////////// + + + // Retrieve the TemplateParameter + TemplateParameter currentTParam = (TemplateParameter) argument; + + String parameterName = ""; + String typeName = ""; + + + if (GenUtils.getType(currentTParam) == "") { + typeName = "undefined"; + } else { + typeName = GenUtils.getType(currentTParam); //.getName(); + } + + // Retrieve name under stereotype CppTemplateParameter/name + Cpp.CppTemplateParameter ctp = GenUtils.getApplication(currentTParam, Cpp.CppTemplateParameter.class); + if (ctp != null) { + parameterName = ctp.getName(); + } + +////////////////////////////////////////////////////////////////////////////////////////// +// The following part contains the template +////////////////////////////////////////////////////////////////////////////////////////// + + stringBuffer.append( typeName ); + stringBuffer.append(TEXT_1); + stringBuffer.append( parameterName ); + return stringBuffer.toString(); + } +}
\ No newline at end of file |