Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnsgar Radermacher2013-11-12 12:58:54 +0000
committerAnsgar Radermacher2013-11-12 15:14:46 +0000
commit1dea78518bd66a5a53487dbb881b5653c8752197 (patch)
treec4e6c8726112eb82571f6b089803fa2078cbe1fe /extraplugins
parentdf5da14c366b7629438398d638df97c9df0f028f (diff)
downloadorg.eclipse.papyrus-1dea78518bd66a5a53487dbb881b5653c8752197.tar.gz
org.eclipse.papyrus-1dea78518bd66a5a53487dbb881b5653c8752197.tar.xz
org.eclipse.papyrus-1dea78518bd66a5a53487dbb881b5653c8752197.zip
- fix for bug 420372 - Cannot generate C++ code from new Papyrus model
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/Activator.java5
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handler/GenerateCodeHandler.java105
2 files changed, 63 insertions, 47 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/Activator.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/Activator.java
index bf99d5aeea7..30975f1ab1a 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/Activator.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/Activator.java
@@ -32,14 +32,15 @@ public class Activator extends AbstractUIPlugin {
plugin = this;
// register the login helper
- log = new LogHelper(plugin);
+ log = new LogHelper(plugin);
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
- public void stop(BundleContext context) throws Exception {
+ @Override
+ public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
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 6430bba1980..4e9e00e941d 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
@@ -13,7 +13,6 @@
package org.eclipse.papyrus.cpp.codegen.ui.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.IContainer;
@@ -22,8 +21,6 @@ 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.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.papyrus.acceleo.AcceleoDriver;
@@ -55,19 +52,7 @@ public class GenerateCodeHandler 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, e.getMessage(), e));
- }
- }
+ return modelProject.exists();
}
return false;
@@ -78,42 +63,72 @@ public class GenerateCodeHandler extends CmdHandler {
if(selectedEObject instanceof PackageableElement) {
PackageableElement pe = (PackageableElement)selectedEObject;
- URI uri = pe.eResource().getURI();
-
- // URIConverter uriConverter = resource.getResourceSet().getURIConverter();
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- if(uri.segmentCount() < 2) {
+ IProject modelProject = getTargetProject(pe);
+ if(modelProject == null) {
return null;
}
- IProject modelProject = root.getProject(uri.segment(1));
- if(modelProject.exists()) {
- // get the container for the current element
- AcceleoDriver.clearErrors();
- CppModelElementsCreator mec = new CppModelElementsCreator(modelProject);
- IContainer srcPkg = mec.getContainer(pe);
+
+ // 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 {
- mec.createPackageableElement(srcPkg, null, pe);
+ srcPkg.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch(CoreException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+ 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();
- 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);
+ 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;
}
- 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);
- }
- }
+ CCProjectNature.addCCNature(modelProject, null);
}
}
- return null;
+ catch(CoreException e) {
+ Activator.log.error(e);
+ }
+ return modelProject;
}
}

Back to the top