Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnsgar Radermacher2014-05-07 07:49:32 +0000
committerAnsgar Radermacher2014-05-07 09:26:33 +0000
commit163e2c7030ea08bc3712f889ac38c8f667431f2f (patch)
tree115f8bf7eba2f98db2aea3f99d515d545951cb33 /extraplugins
parent337a85fe99dd84101590a2876f302124a5920785 (diff)
downloadorg.eclipse.papyrus-163e2c7030ea08bc3712f889ac38c8f667431f2f.tar.gz
org.eclipse.papyrus-163e2c7030ea08bc3712f889ac38c8f667431f2f.tar.xz
org.eclipse.papyrus-163e2c7030ea08bc3712f889ac38c8f667431f2f.zip
433338 - [C++ codegen] Required files are not generated
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handlers/GenerateCodeHandler.java81
1 files changed, 59 insertions, 22 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handlers/GenerateCodeHandler.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handlers/GenerateCodeHandler.java
index 5ae5b318c30..02f19132da9 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handlers/GenerateCodeHandler.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handlers/GenerateCodeHandler.java
@@ -20,12 +20,15 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.dialogs.MessageDialog;
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.ClassUtils;
import org.eclipse.papyrus.cpp.codegen.utils.LocateCppProject;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.uml2.uml.Classifier;
@@ -60,6 +63,56 @@ public class GenerateCodeHandler extends CmdHandler {
return false;
}
+ /**
+ * Generate code for a passed packageable element and the elements required by it (in the sense of #included statements)
+ *
+ * @param mec model elements creator
+ * @param pe the element that should be generated
+ * @param alreadyHandled list of packageable elements for which code has already been generated.
+ * @param recurse if the passed packageableElement is a package, generate code for its contents (recursively).
+ */
+ public void generate(CppModelElementsCreator mec, PackageableElement pe, EList<PackageableElement> alreadyHandled, boolean recurse) {
+ IContainer srcPkg = mec.getContainer(pe);
+ try {
+ alreadyHandled.add(pe);
+ mec.createPackageableElement(srcPkg, null, pe, false);
+ }
+ catch (CoreException coreException) {
+ Activator.log.error(coreException);
+ }
+ 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 {
+ srcPkg.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch(CoreException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ if (pe instanceof Classifier) {
+ EList<Classifier> requiredClassifiers = ClassUtils.includedClassifiers((Classifier) pe);
+ for (Classifier requiredClassifier : requiredClassifiers) {
+ if (!alreadyHandled.contains(requiredClassifier)) {
+ generate(mec, requiredClassifier, alreadyHandled, false);
+ }
+ }
+ }
+ // owning package is required by generated code.
+ Package owningPackage = pe.getNearestPackage();
+ if ((owningPackage != null) && (owningPackage != pe)) {
+ if (!alreadyHandled.contains(owningPackage)) {
+ generate(mec, owningPackage, alreadyHandled, false);
+ }
+ }
+ if ((pe instanceof Package) && recurse) {
+ // Continue generation parsing package contents
+ for(PackageableElement currentElement : ((Package) pe).getPackagedElements()) {
+ generate(mec, currentElement, alreadyHandled, recurse);
+ }
+ }
+ }
+
public Object execute(ExecutionEvent event) throws ExecutionException {
if(selectedEObject instanceof PackageableElement) {
@@ -73,28 +126,12 @@ public class GenerateCodeHandler extends CmdHandler {
// get the container for the current element
AcceleoDriver.clearErrors();
CppModelElementsCreator mec = new CppModelElementsCreator(modelProject);
- IContainer srcPkg = mec.getContainer(pe);
- try {
- mec.createPackageableElement(srcPkg, null, pe);
-
- if (AcceleoDriver.hasErrors()) {
- MessageDialog.openInformation(new Shell(), "Errors during code generation", //$NON-NLS-1$
- "Errors occured during code generation. Please check the error log"); //$NON-NLS-1$
- }
- }
- catch (CoreException coreException) {
- Activator.log.error(coreException);
- return null;
- }
- 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 {
- srcPkg.refreshLocal(IResource.DEPTH_INFINITE, null);
- } catch(CoreException e) {
- Activator.log.error(e);
- }
- }
+ generate(mec, pe, new BasicEList<PackageableElement>(), true);
+
+ if (AcceleoDriver.hasErrors()) {
+ MessageDialog.openInformation(new Shell(), "Errors during code generation", //$NON-NLS-1$
+ "Errors occured during code generation. Please check the error log"); //$NON-NLS-1$
+ }
}
return null;
}

Back to the top