Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnsgar Radermacher2013-11-14 10:07:11 +0000
committerAnsgar Radermacher2013-11-14 10:08:28 +0000
commit624cf83edf265bc911d5daf1e6ec938e4a8bf350 (patch)
tree00b10fac453a51bd1e68e5745f2578734c027c1f /extraplugins
parent76440ecf0e5c5feb38a5d7aa945407093d04cb0a (diff)
downloadorg.eclipse.papyrus-624cf83edf265bc911d5daf1e6ec938e4a8bf350.tar.gz
org.eclipse.papyrus-624cf83edf265bc911d5daf1e6ec938e4a8bf350.tar.xz
org.eclipse.papyrus-624cf83edf265bc911d5daf1e6ec938e4a8bf350.zip
- bug 420372 - Cannot generate C++ code from new Papyrus model: amended: allow CDT editor opening when C++ nature is not applied
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handler/GenerateCodeHandler.java39
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppOperations.emtl210
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppOperations.mtl4
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/LocateCppProject.java60
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.test/model/TestCDTintegration.notation16
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.test/model/TestCDTintegration.uml16
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/editor/PapyrusCDTEditor.java5
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/handler/PapyrusCDTEditorHandler.java21
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/ObtainICElement.java36
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/SyncModelToCDT.java76
10 files changed, 258 insertions, 225 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handler/GenerateCodeHandler.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handler/GenerateCodeHandler.java
index 4e9e00e941d..d1bbfb174c8 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handler/GenerateCodeHandler.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handler/GenerateCodeHandler.java
@@ -12,7 +12,6 @@
package org.eclipse.papyrus.cpp.codegen.ui.handler;
-import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IContainer;
@@ -27,6 +26,7 @@ import org.eclipse.papyrus.acceleo.AcceleoDriver;
import org.eclipse.papyrus.acceleo.ui.handlers.CmdHandler;
import org.eclipse.papyrus.cpp.codegen.transformation.CppModelElementsCreator;
import org.eclipse.papyrus.cpp.codegen.ui.Activator;
+import org.eclipse.papyrus.cpp.codegen.utils.LocateCppProject;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.uml2.uml.PackageableElement;
@@ -63,7 +63,7 @@ public class GenerateCodeHandler extends CmdHandler {
if(selectedEObject instanceof PackageableElement) {
PackageableElement pe = (PackageableElement)selectedEObject;
- IProject modelProject = getTargetProject(pe);
+ IProject modelProject = LocateCppProject.getTargetProject(pe);
if(modelProject == null) {
return null;
}
@@ -96,39 +96,4 @@ public class GenerateCodeHandler extends CmdHandler {
}
return null;
}
-
- /**
- * Locate and return the target project for the given packagable element. Return null if
- * no target project can be found.
- *
- * Ensures that the target project is correctly setup to contain generated C/C++ code. Does
- * not create a new project, but may modify existing ones.
- */
- private static IProject getTargetProject(PackageableElement pe) {
- URI uri = pe.eResource().getURI();
-
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- if(uri.segmentCount() < 2)
- return null;
-
- IProject modelProject = root.getProject(uri.segment(1));
- if(!modelProject.exists())
- return null;
-
- // Make sure the target project has the C and C++ build natures.
- try {
- if(!modelProject.hasNature(CCProjectNature.CC_NATURE_ID)) {
- boolean apply = MessageDialog.openQuestion(new Shell(),
- "Need to apply C++ nature", "Code generation requires that the underlying project has a C++ nature. Do you want to apply this nature?");
- if (!apply) {
- return null;
- }
- CCProjectNature.addCCNature(modelProject, null);
- }
- }
- catch(CoreException e) {
- Activator.log.error(e);
- }
- return modelProject;
- }
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppOperations.emtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppOperations.emtl
index be27a66b917..40169465bf1 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppOperations.emtl
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppOperations.emtl
@@ -276,45 +276,45 @@
<referredProperty xsi:type="ecore:EReference" href="http://www.eclipse.org/uml2/4.0.0/UML#//Operation/type"/>
</argument>
</body>
+ <body xsi:type="ocl.ecore:IteratorExp" name="collect" eType="/3/Bag(String)">
+ <source xsi:type="ocl.ecore:OperationCallExp" eType="/3/Set(Parameter)">
+ <source xsi:type="ocl.ecore:VariableExp" name="self" referredVariable="/31">
+ <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Operation"/>
+ </source>
+ <referredOperation xsi:type="ecore:EOperation" href="http://www.eclipse.org/uml2/4.0.0/UML#//Operation/returnResult"/>
+ </source>
+ <body xsi:type="mtl:QueryInvocation">
+ <eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
+ <definition href="platform:/plugin/utils/Modifier.emtl#/0/modPtr"/>
+ <argument xsi:type="ocl.ecore:VariableExp" name="temp1" referredVariable="/0/CppReturnSpec/%/%.2/collect.1/temp2">
+ <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Parameter"/>
+ </argument>
+ </body>
+ <iterator xsi:type="ocl.ecore:Variable" name="temp2">
+ <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Parameter"/>
+ </iterator>
+ </body>
+ <body xsi:type="ocl.ecore:IteratorExp" name="collect" eType="/3/Bag(String)">
+ <source xsi:type="ocl.ecore:OperationCallExp" eType="/3/Set(Parameter)">
+ <source xsi:type="ocl.ecore:VariableExp" name="self" referredVariable="/32">
+ <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Operation"/>
+ </source>
+ <referredOperation xsi:type="ecore:EOperation" href="http://www.eclipse.org/uml2/4.0.0/UML#//Operation/returnResult"/>
+ </source>
+ <body xsi:type="mtl:QueryInvocation">
+ <eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
+ <definition href="platform:/plugin/utils/Modifier.emtl#/0/modRef"/>
+ <argument xsi:type="ocl.ecore:VariableExp" name="temp1" referredVariable="/0/CppReturnSpec/%/%.2/collect.2/temp3">
+ <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Parameter"/>
+ </argument>
+ </body>
+ <iterator xsi:type="ocl.ecore:Variable" name="temp3">
+ <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Parameter"/>
+ </iterator>
+ </body>
<body xsi:type="ocl.ecore:StringLiteralExp" stringSymbol=" "/>
</else>
</body>
- <body xsi:type="ocl.ecore:IteratorExp" name="collect" eType="/3/Bag(String)">
- <source xsi:type="ocl.ecore:OperationCallExp" eType="/3/Set(Parameter)">
- <source xsi:type="ocl.ecore:VariableExp" name="self" referredVariable="/31">
- <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Operation"/>
- </source>
- <referredOperation xsi:type="ecore:EOperation" href="http://www.eclipse.org/uml2/4.0.0/UML#//Operation/returnResult"/>
- </source>
- <body xsi:type="mtl:QueryInvocation">
- <eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
- <definition href="platform:/plugin/utils/Modifier.emtl#/0/modPtr"/>
- <argument xsi:type="ocl.ecore:VariableExp" name="temp1" referredVariable="/0/CppReturnSpec/collect/temp2">
- <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Parameter"/>
- </argument>
- </body>
- <iterator xsi:type="ocl.ecore:Variable" name="temp2">
- <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Parameter"/>
- </iterator>
- </body>
- <body xsi:type="ocl.ecore:IteratorExp" name="collect" eType="/3/Bag(String)">
- <source xsi:type="ocl.ecore:OperationCallExp" eType="/3/Set(Parameter)">
- <source xsi:type="ocl.ecore:VariableExp" name="self" referredVariable="/32">
- <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Operation"/>
- </source>
- <referredOperation xsi:type="ecore:EOperation" href="http://www.eclipse.org/uml2/4.0.0/UML#//Operation/returnResult"/>
- </source>
- <body xsi:type="mtl:QueryInvocation">
- <eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
- <definition href="platform:/plugin/utils/Modifier.emtl#/0/modRef"/>
- <argument xsi:type="ocl.ecore:VariableExp" name="temp1" referredVariable="/0/CppReturnSpec/collect.1/temp3">
- <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Parameter"/>
- </argument>
- </body>
- <iterator xsi:type="ocl.ecore:Variable" name="temp3">
- <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Parameter"/>
- </iterator>
- </body>
<parameter name="operation">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Operation"/>
</parameter>
@@ -364,31 +364,31 @@
<referredProperty xsi:type="ecore:EReference" href="http://www.eclipse.org/uml2/4.0.0/UML#//TypedElement/type"/>
</argument>
</body>
+ <body xsi:type="mtl:QueryInvocation">
+ <eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
+ <definition href="platform:/plugin/utils/Modifier.emtl#/0/modPtr"/>
+ <argument xsi:type="mtl:QueryInvocation">
+ <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Parameter"/>
+ <definition href="platform:/plugin/org.eclipse.papyrus.acceleo/org/eclipse/papyrus/acceleo/GenUtils.emtl#/0/returnResult"/>
+ <argument xsi:type="ocl.ecore:VariableExp" name="self" referredVariable="/40">
+ <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Behavior"/>
+ </argument>
+ </argument>
+ </body>
+ <body xsi:type="mtl:QueryInvocation">
+ <eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
+ <definition href="platform:/plugin/utils/Modifier.emtl#/0/modRef"/>
+ <argument xsi:type="mtl:QueryInvocation">
+ <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Parameter"/>
+ <definition href="platform:/plugin/org.eclipse.papyrus.acceleo/org/eclipse/papyrus/acceleo/GenUtils.emtl#/0/returnResult"/>
+ <argument xsi:type="ocl.ecore:VariableExp" name="self" referredVariable="/41">
+ <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Behavior"/>
+ </argument>
+ </argument>
+ </body>
<body xsi:type="ocl.ecore:StringLiteralExp" stringSymbol=" "/>
</else>
</body>
- <body xsi:type="mtl:QueryInvocation">
- <eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
- <definition href="platform:/plugin/utils/Modifier.emtl#/0/modPtr"/>
- <argument xsi:type="mtl:QueryInvocation">
- <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Parameter"/>
- <definition href="platform:/plugin/org.eclipse.papyrus.acceleo/org/eclipse/papyrus/acceleo/GenUtils.emtl#/0/returnResult"/>
- <argument xsi:type="ocl.ecore:VariableExp" name="self" referredVariable="/40">
- <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Behavior"/>
- </argument>
- </argument>
- </body>
- <body xsi:type="mtl:QueryInvocation">
- <eType xsi:type="ocl.ecore:PrimitiveType" href="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore#/0/String"/>
- <definition href="platform:/plugin/utils/Modifier.emtl#/0/modRef"/>
- <argument xsi:type="mtl:QueryInvocation">
- <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Parameter"/>
- <definition href="platform:/plugin/org.eclipse.papyrus.acceleo/org/eclipse/papyrus/acceleo/GenUtils.emtl#/0/returnResult"/>
- <argument xsi:type="ocl.ecore:VariableExp" name="self" referredVariable="/41">
- <eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Behavior"/>
- </argument>
- </argument>
- </body>
<parameter name="behavior">
<eType xsi:type="ecore:EClass" href="http://www.eclipse.org/uml2/4.0.0/UML#//Behavior"/>
</parameter>
@@ -2145,7 +2145,7 @@
</eAnnotations>
<eAnnotations source="positions.67" references="/0/CppReturnSpec/%">
<details key="start" value="1588"/>
- <details key="end" value="1698"/>
+ <details key="end" value="1750"/>
<details key="line" value="50"/>
</eAnnotations>
<eAnnotations source="positions.68" references="/0/CppReturnSpec/%/%">
@@ -2180,7 +2180,7 @@
</eAnnotations>
<eAnnotations source="positions.74" references="/0/CppReturnSpec/%/%.2">
<details key="start" value="1631"/>
- <details key="end" value="1693"/>
+ <details key="end" value="1745"/>
<details key="line" value="50"/>
</eAnnotations>
<eAnnotations source="positions.75" references="/0/CppReturnSpec/%/%.2/collect">
@@ -2233,71 +2233,71 @@
<details key="end" value="-1"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.85" references="/0/CppReturnSpec/%/%.2/%.2">
- <details key="start" value="1692"/>
- <details key="end" value="1693"/>
- <details key="line" value="50"/>
- </eAnnotations>
- <eAnnotations source="positions.86" references="/0/CppReturnSpec/collect">
- <details key="start" value="1699"/>
- <details key="end" value="1722"/>
+ <eAnnotations source="positions.85" references="/0/CppReturnSpec/%/%.2/collect.1">
+ <details key="start" value="1693"/>
+ <details key="end" value="1716"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.87" references="/0/CppReturnSpec/collect/%">
- <details key="start" value="1699"/>
- <details key="end" value="1713"/>
+ <eAnnotations source="positions.86" references="/0/CppReturnSpec/%/%.2/collect.1/%">
+ <details key="start" value="1693"/>
+ <details key="end" value="1707"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.88" references="/0/CppReturnSpec/collect/%/self">
+ <eAnnotations source="positions.87" references="/0/CppReturnSpec/%/%.2/collect.1/%/self">
<details key="start" value="-1"/>
<details key="end" value="-1"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.89" references="/0/CppReturnSpec/collect/%.1">
+ <eAnnotations source="positions.88" references="/0/CppReturnSpec/%/%.2/collect.1/%.1">
<details key="start" value="-1"/>
<details key="end" value="-1"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.90" references="/0/CppReturnSpec/collect/%.1/temp1">
+ <eAnnotations source="positions.89" references="/0/CppReturnSpec/%/%.2/collect.1/%.1/temp1">
<details key="start" value="-1"/>
<details key="end" value="-1"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.91" references="/0/CppReturnSpec/collect/temp2">
+ <eAnnotations source="positions.90" references="/0/CppReturnSpec/%/%.2/collect.1/temp2">
<details key="start" value="-1"/>
<details key="end" value="-1"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.92" references="/0/CppReturnSpec/collect.1">
- <details key="start" value="1725"/>
- <details key="end" value="1748"/>
+ <eAnnotations source="positions.91" references="/0/CppReturnSpec/%/%.2/collect.2">
+ <details key="start" value="1719"/>
+ <details key="end" value="1742"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.93" references="/0/CppReturnSpec/collect.1/%">
- <details key="start" value="1725"/>
- <details key="end" value="1739"/>
+ <eAnnotations source="positions.92" references="/0/CppReturnSpec/%/%.2/collect.2/%">
+ <details key="start" value="1719"/>
+ <details key="end" value="1733"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.94" references="/0/CppReturnSpec/collect.1/%/self">
+ <eAnnotations source="positions.93" references="/0/CppReturnSpec/%/%.2/collect.2/%/self">
<details key="start" value="-1"/>
<details key="end" value="-1"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.95" references="/0/CppReturnSpec/collect.1/%.1">
+ <eAnnotations source="positions.94" references="/0/CppReturnSpec/%/%.2/collect.2/%.1">
<details key="start" value="-1"/>
<details key="end" value="-1"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.96" references="/0/CppReturnSpec/collect.1/%.1/temp1">
+ <eAnnotations source="positions.95" references="/0/CppReturnSpec/%/%.2/collect.2/%.1/temp1">
<details key="start" value="-1"/>
<details key="end" value="-1"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.97" references="/0/CppReturnSpec/collect.1/temp3">
+ <eAnnotations source="positions.96" references="/0/CppReturnSpec/%/%.2/collect.2/temp3">
<details key="start" value="-1"/>
<details key="end" value="-1"/>
<details key="line" value="0"/>
</eAnnotations>
+ <eAnnotations source="positions.97" references="/0/CppReturnSpec/%/%.2/%.2">
+ <details key="start" value="1744"/>
+ <details key="end" value="1745"/>
+ <details key="line" value="50"/>
+ </eAnnotations>
<eAnnotations source="positions.98" references="/0/CppReturnSpec/operation">
<details key="start" value="1564"/>
<details key="end" value="1585"/>
@@ -2310,7 +2310,7 @@
</eAnnotations>
<eAnnotations source="positions.100" references="/0/CppReturnSpec.1/%">
<details key="start" value="1818"/>
- <details key="end" value="1933"/>
+ <details key="end" value="1985"/>
<details key="line" value="55"/>
</eAnnotations>
<eAnnotations source="positions.101" references="/0/CppReturnSpec.1/%/%">
@@ -2340,7 +2340,7 @@
</eAnnotations>
<eAnnotations source="positions.106" references="/0/CppReturnSpec.1/%/%.2">
<details key="start" value="1851"/>
- <details key="end" value="1928"/>
+ <details key="end" value="1980"/>
<details key="line" value="55"/>
</eAnnotations>
<eAnnotations source="positions.107" references="/0/CppReturnSpec.1/%/%.2/%">
@@ -2384,40 +2384,40 @@
<details key="line" value="0"/>
</eAnnotations>
<eAnnotations source="positions.115" references="/0/CppReturnSpec.1/%/%.2/%.3">
- <details key="start" value="1927"/>
- <details key="end" value="1928"/>
- <details key="line" value="55"/>
- </eAnnotations>
- <eAnnotations source="positions.116" references="/0/CppReturnSpec.1/%.1">
- <details key="start" value="1934"/>
- <details key="end" value="1957"/>
+ <details key="start" value="1928"/>
+ <details key="end" value="1951"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.117" references="/0/CppReturnSpec.1/%.1/%">
- <details key="start" value="1934"/>
- <details key="end" value="1948"/>
+ <eAnnotations source="positions.116" references="/0/CppReturnSpec.1/%/%.2/%.3/%">
+ <details key="start" value="1928"/>
+ <details key="end" value="1942"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.118" references="/0/CppReturnSpec.1/%.1/%/self">
+ <eAnnotations source="positions.117" references="/0/CppReturnSpec.1/%/%.2/%.3/%/self">
<details key="start" value="-1"/>
<details key="end" value="-1"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.119" references="/0/CppReturnSpec.1/%.2">
- <details key="start" value="1960"/>
- <details key="end" value="1983"/>
+ <eAnnotations source="positions.118" references="/0/CppReturnSpec.1/%/%.2/%.4">
+ <details key="start" value="1954"/>
+ <details key="end" value="1977"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.120" references="/0/CppReturnSpec.1/%.2/%">
- <details key="start" value="1960"/>
- <details key="end" value="1974"/>
+ <eAnnotations source="positions.119" references="/0/CppReturnSpec.1/%/%.2/%.4/%">
+ <details key="start" value="1954"/>
+ <details key="end" value="1968"/>
<details key="line" value="0"/>
</eAnnotations>
- <eAnnotations source="positions.121" references="/0/CppReturnSpec.1/%.2/%/self">
+ <eAnnotations source="positions.120" references="/0/CppReturnSpec.1/%/%.2/%.4/%/self">
<details key="start" value="-1"/>
<details key="end" value="-1"/>
<details key="line" value="0"/>
</eAnnotations>
+ <eAnnotations source="positions.121" references="/0/CppReturnSpec.1/%/%.2/%.5">
+ <details key="start" value="1979"/>
+ <details key="end" value="1980"/>
+ <details key="line" value="55"/>
+ </eAnnotations>
<eAnnotations source="positions.122" references="/0/CppReturnSpec.1/behavior">
<details key="start" value="1796"/>
<details key="end" value="1815"/>
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppOperations.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppOperations.mtl
index 7769d46e84d..a21d28529ef 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppOperations.mtl
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/util/operation/CppOperations.mtl
@@ -47,12 +47,12 @@ else
endif/]
[template public CppReturnSpec(operation : Operation)]
-[if (type = null)][ConsDestructorOrVoid()/][else][returnResult().modConst()/] [type.cppQualifiedName()/] [/if][returnResult().modPtr()/][returnResult().modRef()/]
+[if (type = null)][ConsDestructorOrVoid()/][else][returnResult().modConst()/] [type.cppQualifiedName()/][returnResult().modPtr()/][returnResult().modRef()/] [/if]
[/template]
[template public CppReturnSpec(behavior : Behavior)]
-[if (returnResult() = null)]void [else][returnResult().modConst()/] [returnResult().type.cppQualifiedName()/] [/if][returnResult().modPtr()/][returnResult().modRef()/]
+[if (returnResult() = null)]void [else][returnResult().modConst()/] [returnResult().type.cppQualifiedName()/][returnResult().modPtr()/][returnResult().modRef()/] [/if]
[/template]
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/LocateCppProject.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/LocateCppProject.java
new file mode 100644
index 00000000000..2fe7fceff1a
--- /dev/null
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/utils/LocateCppProject.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2013 CEA LIST.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.papyrus.cpp.codegen.utils;
+
+import org.eclipse.cdt.core.CCProjectNature;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.papyrus.cpp.codegen.Activator;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.uml2.uml.PackageableElement;
+
+public class LocateCppProject {
+ /**
+ * Locate and return the target project for the given packagable element. Return null if
+ * no target project can be found.
+ *
+ * Ensures that the target project is correctly setup to contain generated C/C++ code. Does
+ * not create a new project, but may modify existing ones.
+ */
+ public static IProject getTargetProject(PackageableElement pe) {
+ URI uri = pe.eResource().getURI();
+
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ if(uri.segmentCount() < 2)
+ return null;
+
+ IProject modelProject = root.getProject(uri.segment(1));
+ if(!modelProject.exists())
+ return null;
+
+ // Make sure the target project has the C and C++ build natures.
+ try {
+ if(!modelProject.hasNature(CCProjectNature.CC_NATURE_ID)) {
+ boolean apply = MessageDialog.openQuestion(new Shell(),
+ "Need to apply C++ nature", "Code generation requires that the underlying project has a C++ nature. Do you want to apply this nature?");
+ if (!apply) {
+ return null;
+ }
+ CCProjectNature.addCCNature(modelProject, null);
+ }
+ }
+ catch(CoreException e) {
+ Activator.log.error(e);
+ }
+ return modelProject;
+ }
+}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.test/model/TestCDTintegration.notation b/extraplugins/codegen/org.eclipse.papyrus.cpp.test/model/TestCDTintegration.notation
index 5aefa72c8b9..1843e346db6 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.test/model/TestCDTintegration.notation
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.test/model/TestCDTintegration.notation
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:texteditormodel="http://www.eclipse.org/Papyrus/Example/0.10.0/texteditormodel" xmlns:texteditormodel_1="http://www.eclipse.org/Papyrus/TextEditor/0.10.0/texteditormodel" xmlns:uml="http://www.eclipse.org/uml2/4.0.0/UML">
+<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:texteditormodel="http://www.eclipse.org/Papyrus/TextEditor/0.10.0/texteditormodel" xmlns:uml="http://www.eclipse.org/uml2/4.0.0/UML">
<notation:Diagram xmi:id="_8vp88DcVEeO6UdbIk03c9Q" type="PapyrusUMLClassDiagram" name="NewDiagram" measurementUnit="Pixel">
<children xmi:type="notation:Shape" xmi:id="__McvgDcVEeO6UdbIk03c9Q" type="2008" fontName="Sans Serif" lineColor="0">
<eAnnotations xmi:type="ecore:EAnnotation" xmi:id="__Md9oDcVEeO6UdbIk03c9Q" source="ShadowFigure">
@@ -23,6 +23,10 @@
<element xmi:type="uml:Operation" href="TestCDTintegration.uml#_TY18YB0LEeKlYLZOWTi6uw"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_A3SgsTcWEeO6UdbIk03c9Q"/>
</children>
+ <children xmi:type="notation:Shape" xmi:id="_FDs_YExiEeOmZKwrWJYDKQ" type="3013" fontName="Sans Serif" lineColor="0">
+ <element xmi:type="uml:Operation" href="TestCDTintegration.uml#_jnWMADcmEeO6UdbIk03c9Q"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_FDs_YUxiEeOmZKwrWJYDKQ" x="65" y="25"/>
+ </children>
<styles xmi:type="notation:TitleStyle" xmi:id="__MfLwTcVEeO6UdbIk03c9Q"/>
<styles xmi:type="notation:SortingStyle" xmi:id="__MfLwjcVEeO6UdbIk03c9Q"/>
<styles xmi:type="notation:FilteringStyle" xmi:id="__MfLwzcVEeO6UdbIk03c9Q"/>
@@ -39,7 +43,7 @@
<layoutConstraint xmi:type="notation:Bounds" xmi:id="__MmggjcVEeO6UdbIk03c9Q"/>
</children>
<element xmi:type="uml:Class" href="TestCDTintegration.uml#_K8FLcB0LEeKlYLZOWTi6uw"/>
- <layoutConstraint xmi:type="notation:Bounds" xmi:id="__McvgTcVEeO6UdbIk03c9Q" x="110" y="70" width="233"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="__McvgTcVEeO6UdbIk03c9Q" x="110" y="70" width="242" height="129"/>
</children>
<children xmi:type="notation:Shape" xmi:id="__kHooDcVEeO6UdbIk03c9Q" type="2007" fontName="Sans Serif" lineColor="0">
<eAnnotations xmi:type="ecore:EAnnotation" xmi:id="__kIPsDcVEeO6UdbIk03c9Q" source="ShadowFigure">
@@ -103,10 +107,8 @@
<styles xmi:type="notation:DiagramStyle" xmi:id="_8vp88TcVEeO6UdbIk03c9Q"/>
<element xmi:type="uml:Model" href="TestCDTintegration.uml#_Ae6MwPccEd-KM6l7lmIPkw"/>
</notation:Diagram>
- <texteditormodel:TextEditorModel xmi:id="_JY8YsDcWEeO6UdbIk03c9Q" type="CDTEditorInPapyrus" name="CDT Class3">
- <editedObject xmi:type="uml:Class" href="TestCDTintegration.uml#_K8FLcB0LEeKlYLZOWTi6uw"/></texteditormodel:TextEditorModel>
- <texteditormodel_1:TextEditorModel xmi:id="_EItkYEG6EeOMv8cdTsw5Zg" type="CDTEditorInPapyrus" name="CDT Class3">
+ <texteditormodel:TextEditorModel xmi:id="_EItkYEG6EeOMv8cdTsw5Zg" type="CDTEditorInPapyrus" name="CDT Class3">
<editedObject xmi:type="uml:Class" href="TestCDTintegration.uml#_K8FLcB0LEeKlYLZOWTi6uw"/>
- <selectedObject xmi:type="uml:Operation" href="TestCDTintegration.uml#_jnWMADcmEeO6UdbIk03c9Q"/>
- </texteditormodel_1:TextEditorModel>
+ <selectedObject xmi:type="uml:Class" href="TestCDTintegration.uml#_K8FLcB0LEeKlYLZOWTi6uw"/>
+ </texteditormodel:TextEditorModel>
</xmi:XMI>
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.test/model/TestCDTintegration.uml b/extraplugins/codegen/org.eclipse.papyrus.cpp.test/model/TestCDTintegration.uml
index e40977792b5..c93b1c60c02 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.test/model/TestCDTintegration.uml
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.test/model/TestCDTintegration.uml
@@ -49,7 +49,7 @@
<packagedElement xmi:type="uml:Class" xmi:id="_419y0A7hEeKpbseGaEy1LA" name="Class2"/>
<packagedElement xmi:type="uml:Class" xmi:id="_K8FLcB0LEeKlYLZOWTi6uw" name="Class3">
<ownedBehavior xmi:type="uml:OpaqueBehavior" xmi:id="_kTVuwP6QEeKlg5tzGV3QVQ" name="Operation1" isReentrant="false" specification="_TY18YB0LEeKlYLZOWTi6uw">
- <ownedParameter xmi:type="uml:Parameter" xmi:id="_JPzkEEL5EeO1TdFz52di_Q" name="arg">
+ <ownedParameter xmi:type="uml:Parameter" xmi:id="_SoTM0ExiEeOmZKwrWJYDKQ" name="arg">
<type xmi:type="uml:PrimitiveType" href="pathmap://PapyrusC_Cpp_LIBRARIES/AnsiCLibrary.uml#_7wRIABydEduyofBvg4RL2w"/>
</ownedParameter>
<language>C/C++</language>
@@ -57,7 +57,7 @@
cout &lt;&lt; &quot;value: &quot; &lt;&lt; arg;</body>
</ownedBehavior>
<ownedBehavior xmi:type="uml:OpaqueBehavior" xmi:id="_pX7DgDcmEeO6UdbIk03c9Q" name="Operation2" isReentrant="false" specification="_jnWMADcmEeO6UdbIk03c9Q">
- <ownedParameter xmi:type="uml:Parameter" xmi:id="_JPgCEEL5EeO1TdFz52di_Q" name="args">
+ <ownedParameter xmi:type="uml:Parameter" xmi:id="_SoUa8UxiEeOmZKwrWJYDKQ" name="args">
<type xmi:type="uml:PrimitiveType" href="pathmap://PapyrusC_Cpp_LIBRARIES/AnsiCLibrary.uml#_5lVhgBydEduyofBvg4RL2w"/>
</ownedParameter>
<language>C/C++</language>
@@ -68,15 +68,15 @@ args[0] = 2;</body>
<ownedComment xmi:type="uml:Comment" xmi:id="_II4ccP6WEeKlg5tzGV3QVQ" annotatedElement="_II4ccP6WEeKlg5tzGV3QVQ">
<body></body>
</ownedComment>
- <ownedParameter xmi:type="uml:Parameter" xmi:id="_JPy9AEL5EeO1TdFz52di_Q" name="arg">
+ <ownedParameter xmi:type="uml:Parameter" xmi:id="_SoSlwExiEeOmZKwrWJYDKQ" name="arg">
<type xmi:type="uml:PrimitiveType" href="pathmap://PapyrusC_Cpp_LIBRARIES/AnsiCLibrary.uml#_7wRIABydEduyofBvg4RL2w"/>
</ownedParameter>
</ownedOperation>
<ownedOperation xmi:type="uml:Operation" xmi:id="_jnWMADcmEeO6UdbIk03c9Q" name="Operation2" method="_pX7DgDcmEeO6UdbIk03c9Q">
<ownedComment xmi:type="uml:Comment" xmi:id="_rH4lQDcmEeO6UdbIk03c9Q" annotatedElement="_rH4lQDcmEeO6UdbIk03c9Q">
- <body></body>
+ <body>This is a test comment for operation 2</body>
</ownedComment>
- <ownedParameter xmi:type="uml:Parameter" xmi:id="_JPbwoEL5EeO1TdFz52di_Q" name="args">
+ <ownedParameter xmi:type="uml:Parameter" xmi:id="_SoUa8ExiEeOmZKwrWJYDKQ" name="args">
<type xmi:type="uml:PrimitiveType" href="pathmap://PapyrusC_Cpp_LIBRARIES/AnsiCLibrary.uml#_5lVhgBydEduyofBvg4RL2w"/>
</ownedParameter>
</ownedOperation>
@@ -116,7 +116,7 @@ args[0] = 2;</body>
</profileApplication>
</uml:Model>
<C_Cpp:Typedef xmi:id="_D6FjUDcWEeO6UdbIk03c9Q" definition="int" base_primitivetype="_DHJ24C-JEeObJ6ARx67E0g"/>
- <C_Cpp:Const xmi:id="_JPmvwEL5EeO1TdFz52di_Q" base_parameter="_JPbwoEL5EeO1TdFz52di_Q"/>
- <C_Cpp:Ptr xmi:id="_JProQEL5EeO1TdFz52di_Q" base_parameter="_JPbwoEL5EeO1TdFz52di_Q"/>
- <C_Cpp:Array xmi:id="_JPxH0EL5EeO1TdFz52di_Q" base_parameter="_JPbwoEL5EeO1TdFz52di_Q" definition="[5]"/>
+ <C_Cpp:Const xmi:id="_SoYFUExiEeOmZKwrWJYDKQ" base_parameter="_SoUa8ExiEeOmZKwrWJYDKQ"/>
+ <C_Cpp:Ptr xmi:id="_SobvsExiEeOmZKwrWJYDKQ" base_parameter="_SoUa8ExiEeOmZKwrWJYDKQ"/>
+ <C_Cpp:Array xmi:id="_SofaEExiEeOmZKwrWJYDKQ" base_parameter="_SoUa8ExiEeOmZKwrWJYDKQ" definition="[5]"/>
</xmi:XMI>
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/editor/PapyrusCDTEditor.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/editor/PapyrusCDTEditor.java
index c7ffe414fae..84acc507632 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/editor/PapyrusCDTEditor.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/editor/PapyrusCDTEditor.java
@@ -154,8 +154,9 @@ public class PapyrusCDTEditor extends CEditor {
// assure that gotoElement is called, if the element in the model gets updated
public void notifyChanged(Notification notification) {
if (notification.getEventType() == Notification.SET) {
- if (notification.getNewValue() instanceof NamedElement) {
- gotoElement((NamedElement) notification.getNewValue());
+ Object newValue = notification.getNewValue();
+ if (newValue instanceof NamedElement) {
+ gotoElement((NamedElement) newValue);
}
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/handler/PapyrusCDTEditorHandler.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/handler/PapyrusCDTEditorHandler.java
index a6991ddac9c..f7f9cb4600b 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/handler/PapyrusCDTEditorHandler.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/handler/PapyrusCDTEditorHandler.java
@@ -14,14 +14,11 @@
*****************************************************************************/
package org.eclipse.papyrus.texteditor.cdt.handler;
-import org.eclipse.cdt.core.CCProjectNature;
-import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -32,6 +29,7 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.workspace.AbstractEMFOperation;
import org.eclipse.papyrus.acceleo.ui.handlers.CmdHandler;
import org.eclipse.papyrus.commands.CheckedOperationHistory;
+import org.eclipse.papyrus.cpp.codegen.utils.LocateCppProject;
import org.eclipse.papyrus.infra.core.resource.NotFoundException;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
@@ -87,19 +85,7 @@ public class PapyrusCDTEditorHandler extends CmdHandler {
return false;
}
IProject modelProject = root.getProject(uri.segment(1));
- if(modelProject.exists()) {
- try {
- // check whether the project is a C or C++ project
- if(modelProject.hasNature(CProjectNature.C_NATURE_ID) ||
- modelProject.hasNature(CCProjectNature.CC_NATURE_ID)) {
- return true;
- }
- }
- catch (CoreException e) {
- Activator.getDefault().getLog().log(
- new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not verify, if CDT project", e));
- }
- }
+ return modelProject.exists();
}
return false;
}
@@ -157,6 +143,9 @@ public class PapyrusCDTEditorHandler extends CmdHandler {
IPageManager pageMngr = ServiceUtils.getInstance().getIPageManager(serviceRegistry);
Classifier classifierToEdit = getClassifierToEdit();
+ if (LocateCppProject.getTargetProject(classifierToEdit) == null) {
+ return;
+ }
TextEditorModel editorModel = getEditorModel(serviceRegistry, classifierToEdit);
if (editorModel == null) {
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/ObtainICElement.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/ObtainICElement.java
index 654c54d454d..411b2ee08b8 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/ObtainICElement.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/ObtainICElement.java
@@ -16,9 +16,13 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IFunctionDeclaration;
import org.eclipse.cdt.core.model.IParent;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Namespace;
import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Parameter;
+import org.eclipse.uml2.uml.ParameterDirectionKind;
+import org.eclipse.uml2.uml.Transition;
public class ObtainICElement {
/**
@@ -34,11 +38,22 @@ public class ObtainICElement {
return getICElement((IParent)child, element);
}
if(child instanceof IFunctionDeclaration) {
- // IFunctionDeclaration function = (IFunctionDeclaration) child;
+ IFunctionDeclaration function = (IFunctionDeclaration) child;
- if (element instanceof Operation) {
+ if (element instanceof Operation) {
if (child.getElementName().endsWith(Namespace.SEPARATOR + element.getName())) {
- return child;
+ // check, if number of parameter matches. TODO: this only handles a part of possible overloading cases
+ if (function.getNumberOfParameters() == countParameters(((Operation) element).getOwnedParameters())) {
+ return child;
+ }
+ }
+ }
+ else if (element instanceof Transition) {
+ Transition transition = (Transition) element;
+ if (child.getElementName().endsWith(Namespace.SEPARATOR + transition.getEffect().getName())) {
+ if (function.getNumberOfParameters() == countParameters(transition.getEffect().getOwnedParameters())) {
+ return child;
+ }
}
}
}
@@ -49,4 +64,19 @@ public class ObtainICElement {
return null;
}
+ /**
+ * Count the number of parameters without taking the return parameter into account
+ *
+ * @param list
+ * @return
+ */
+ public static int countParameters(EList<Parameter> list) {
+ int params = 0;
+ for (Parameter par : list) {
+ if (par.getDirection() != ParameterDirectionKind.RETURN_LITERAL) {
+ params++;
+ }
+ }
+ return params;
+ }
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/SyncModelToCDT.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/SyncModelToCDT.java
index ecc0e5dc911..427b314b1dd 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/SyncModelToCDT.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/sync/SyncModelToCDT.java
@@ -12,18 +12,15 @@
package org.eclipse.papyrus.texteditor.cdt.sync;
-import org.eclipse.cdt.core.CCProjectNature;
-import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
-import org.eclipse.emf.common.util.URI;
import org.eclipse.papyrus.acceleo.ModelElementsCreator;
import org.eclipse.papyrus.cpp.codegen.transformation.CppModelElementsCreator;
+import org.eclipse.papyrus.cpp.codegen.utils.LocateCppProject;
import org.eclipse.papyrus.infra.core.Activator;
import org.eclipse.uml2.uml.Classifier;
@@ -45,51 +42,40 @@ public class SyncModelToCDT {
return null;
}
- URI uri = classifier.eResource().getURI();
-
- // URIConverter uriConverter = resource.getResourceSet().getURIConverter();
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- if(uri.segmentCount() < 2) {
+ IProject modelProject = LocateCppProject.getTargetProject(classifier);
+ if(modelProject == null) {
return null;
}
- IProject modelProject = root.getProject(uri.segment(1));
- if(modelProject.exists()) {
- try {
- // check whether the project is a C or C++ project
- if(modelProject.hasNature(CProjectNature.C_NATURE_ID) ||
- modelProject.hasNature(CCProjectNature.CC_NATURE_ID))
- {
- String name = classifier.getName();
- // System.err.println("regen: " + name);
- // get the container for the current element
- ModelElementsCreator mec = new CppModelElementsCreator(modelProject);
- IContainer srcPkg = mec.getContainer(classifier);
- try {
- mec.createPackageableElement(srcPkg, null, classifier); // need listener for sync in both directions!
- } catch (CoreException coreException) {
- Activator.getDefault().getLog().log(coreException.getStatus());
- return null;
- }
- IFile cppFile = srcPkg.getFile(new Path(name + ".cpp")); // TODO: extension is configurable! //$NON-NLS-1$
- IFile hFile = srcPkg.getFile(new Path(name + ".h")); //$NON-NLS-1$
- if(!cppFile.exists()) {
- return null;
- }
- if(cppFile != null) {
- cppFile.refreshLocal(0, null);
- }
- if(hFile != null) {
- hFile.refreshLocal(0, null);
- }
+ IContainer srcPkg = null;
+ IFile cppFile = null;
+ try {
+ String name = classifier.getName();
+ // System.err.println("regen: " + name);
- return cppFile;
- // IStorage storage = new TextStorage(string);
+ // get the container for the current element
+ ModelElementsCreator mec = new CppModelElementsCreator(modelProject);
+ srcPkg = mec.getContainer(classifier);
+ mec.createPackageableElement(srcPkg, null, classifier); // need listener for sync in both directions!
+
+ cppFile = srcPkg.getFile(new Path(name + ".cpp")); // TODO: extension is configurable! //$NON-NLS-1$
+
+ // IStorage storage = new TextStorage(string);
+ }
+ catch (CoreException e) {
+ Activator.log.error(e);
+ }
+ finally {
+ // Refresh the container for the newly created files. This needs to be done even
+ // during error because of the possibility for partial results.
+ try {
+ if (srcPkg != null) {
+ srcPkg.refreshLocal(IResource.DEPTH_INFINITE, null);
}
- } catch (CoreException e) {
- }
+ } catch(CoreException e) {
+ Activator.log.error(e);
+ }
}
-
- return null;
+ return cppFile;
}
}

Back to the top