[Acceleo] Problem when generating code with GMF [message #631425] |
Thu, 07 October 2010 10:11  |
Eclipse User |
|
|
|
Hello,
I'm trying to integrate Acceleo in a GMF editor to be able to generate code from the active editor.
For this, I created a new action this way:
public class Model2CodeAction extends Action {
private final IWorkbenchWindow window;
public Model2CodeAction(IWorkbenchWindow window) {
this.window = window;
setText("Generate code");
setId("Model2CodeAction");
}
@Override
public void run() {
IEditorPart activeEditor = window.getActivePage().getActiveEditor();
if (activeEditor == null) {
return;
}
if (!(activeEditor instanceof PLCOpenEditorDiagramEditor)) {
return;
}
PLCOpenEditorDiagramEditor diagramEditor = (PLCOpenEditorDiagramEditor) activeEditor;
EObject modelElement = diagramEditor.getDiagram().getElement();
try {
Generate generator = new Generate(modelElement,
new File("c:\\temp"), new LinkedList());
generator.doGenerate(null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
The action is registered in the GMF editor and appears properly. The problem occurs when I execute the action: an exception is thrown which says "Cannot modify resource set without a write transaction".
Here is the full stack trace:
java.lang.IllegalStateException: Cannot modify resource set without a write transaction
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting(TransactionChangeRecorder.java:348)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.appendNotification(TransactionChangeRecorder.java:302)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.processObjectNotification(TransactionChangeRecorder.java:284)
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.notifyChanged(TransactionChangeRecorder.java:240)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:380)
at org.eclipse.emf.common.notify.impl.NotificationImpl.dispatch(NotificationImpl.java:1033)
at org.eclipse.emf.ecore.impl.EPackageImpl.setEFactoryInstance(EPackageImpl.java:385)
at org.eclipse.acceleo.engine.internal.environment.AcceleoEnvironment.restoreBrokenEnvironmentPackages(AcceleoEnvironment.java:102)
at org.eclipse.acceleo.engine.internal.environment.AcceleoEnvironmentFactory.createEnvironment(AcceleoEnvironmentFactory.java:93)
at org.eclipse.ocl.OCL.<init>(OCL.java:101)
at org.eclipse.ocl.ecore.OCL.<init>(OCL.java:89)
at org.eclipse.ocl.ecore.OCL.newInstance(OCL.java:144)
at org.eclipse.acceleo.engine.generation.AcceleoEngine.evaluate(AcceleoEngine.java:127)
at org.eclipse.acceleo.engine.service.AcceleoService.doGenerateTemplate(AcceleoService.java:544)
at org.eclipse.acceleo.engine.service.AcceleoService.doGenerate(AcceleoService.java:380)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.generate(AbstractAcceleoGenerator.java:120)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.doGenerate(AbstractAcceleoGenerator.java:99)
at be.fmtc.savarch.PLCOpenEditor.Model2Code.files.Generate.doGenerate(Generate.java:148)
at PLCOpenEditor.diagram.custom.Model2CodeAction.run(Model2CodeAction.java:41)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at PLCOpenEditor.diagram.application.PLCOpenEditorApplication.start(PLCOpenEditorApplication.java:23)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
Does Acceleo try to modify the model for which it should generate the code ?
I don't know how to fix this problem.
|
|
|
Re: [Acceleo] Problem when generating code with GMF [message #631432 is a reply to message #631425] |
Thu, 07 October 2010 10:21   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------080602000608010301070204
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Hi Cedric,
Acceleo doesn't alter the model it generates code for, yet it does try
and find back the EPackageFactories it needs to use when deserializing
module files.
In your use case, this step might not be necessary. As I don't have any
environment with GMF at hand, would you have any way to retrieve the
Acceleo code source and try a little patch (so that I know whether this
is the only problem :p)?
Namely, I believe that changing
org.eclipse.acceleo.engine.internal.environment.AcceleoEnvir onment#restoreBrokenEnvironmentPackages()
(line 97) from
if (factory != null) {
to
if (factory != null && ((EPackage)element).getEFactoryInstance() !=
factory) {
would be enough to stop us from wrecking havock in that use case :).
Whether you can try it yourself or not, could you raise a bugzilla entry
for this issue?
Laurent Goubet
Obeo
Cedric wrote:
> Hello,
>
> I'm trying to integrate Acceleo in a GMF editor to be able to generate
> code from the active editor.
> For this, I created a new action this way:
>
> public class Model2CodeAction extends Action {
>
> private final IWorkbenchWindow window;
>
> public Model2CodeAction(IWorkbenchWindow window) {
> this.window = window;
> setText("Generate code");
> setId("Model2CodeAction");
> }
>
> @Override
> public void run() {
> IEditorPart activeEditor =
> window.getActivePage().getActiveEditor();
> if (activeEditor == null) {
> return;
> }
> if (!(activeEditor instanceof PLCOpenEditorDiagramEditor)) {
> return;
> }
>
> PLCOpenEditorDiagramEditor diagramEditor =
> (PLCOpenEditorDiagramEditor) activeEditor;
> EObject modelElement = diagramEditor.getDiagram().getElement();
> try {
> Generate generator = new Generate(modelElement,
> new File("c:\\temp"), new LinkedList());
> generator.doGenerate(null);
> } catch (Exception e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> }
>
> The action is registered in the GMF editor and appears properly. The
> problem occurs when I execute the action: an exception is thrown which
> says "Cannot modify resource set without a write transaction".
>
> Here is the full stack trace:
> java.lang.IllegalStateException: Cannot modify resource set without a
> write transaction
> at
> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ssertWriting(TransactionChangeRecorder.java:348)
>
> at
> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ppendNotification(TransactionChangeRecorder.java:302)
>
> at
> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.p rocessObjectNotification(TransactionChangeRecorder.java:284)
>
> at
> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.n otifyChanged(TransactionChangeRecorder.java:240)
>
> at
> org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify (BasicNotifierImpl.java:380)
>
> at
> org.eclipse.emf.common.notify.impl.NotificationImpl.dispatch (NotificationImpl.java:1033)
>
> at
> org.eclipse.emf.ecore.impl.EPackageImpl.setEFactoryInstance( EPackageImpl.java:385)
>
> at
> org.eclipse.acceleo.engine.internal.environment.AcceleoEnvir onment.restoreBrokenEnvironmentPackages(AcceleoEnvironment.j ava:102)
>
> at
> org.eclipse.acceleo.engine.internal.environment.AcceleoEnvir onmentFactory.createEnvironment(AcceleoEnvironmentFactory.ja va:93)
>
> at org.eclipse.ocl.OCL.<init>(OCL.java:101)
> at org.eclipse.ocl.ecore.OCL.<init>(OCL.java:89)
> at org.eclipse.ocl.ecore.OCL.newInstance(OCL.java:144)
> at
> org.eclipse.acceleo.engine.generation.AcceleoEngine.evaluate (AcceleoEngine.java:127)
>
> at
> org.eclipse.acceleo.engine.service.AcceleoService.doGenerate Template(AcceleoService.java:544)
>
> at
> org.eclipse.acceleo.engine.service.AcceleoService.doGenerate (AcceleoService.java:380)
>
> at
> org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator. generate(AbstractAcceleoGenerator.java:120)
>
> at
> org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator. doGenerate(AbstractAcceleoGenerator.java:99)
>
> at
> be.fmtc.savarch.PLCOpenEditor.Model2Code.files.Generate.doGe nerate(Generate.java:148)
>
> at
> PLCOpenEditor.diagram.custom.Model2CodeAction.run(Model2Code Action.java:41)
> at org.eclipse.jface.action.Action.runWithEvent(Action.java:498 )
> at
> org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(ActionContributionItem.java:584)
>
> at
> org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributionItem.java:501)
>
> at
> org.eclipse.jface.action.ActionContributionItem$5.handleEven t(ActionContributionItem.java:411)
>
> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
> at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:4066)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3657)
> at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2629)
> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
> at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:24 27)
> at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
>
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:663)
> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
> at
> PLCOpenEditor.diagram.application.PLCOpenEditorApplication.s tart(PLCOpenEditorApplication.java:23)
>
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:369)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>
> at java.lang.reflect.Method.invoke(Method.java:597)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 619)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
>
>
> Does Acceleo try to modify the model for which it should generate the
> code ? I don't know how to fix this problem.
--------------080602000608010301070204
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"
YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------080602000608010301070204--
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05349 seconds