Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Code generation is non-deterministic
Code generation is non-deterministic [message #516252] Tue, 23 February 2010 11:44 Go to next message
Dennis HendriksFriend
Messages: 74
Registered: January 2010
Location: The Netherlands
Member
Hello all,

I have an Ecore and corresponding GMF mappings etc. I've created diagram code from it. I need quite a bit of custom code, resulting in '@generated NOT' in the code). If I regenerate the diagram code, the output changes all over the place, like this diff shows:

Index: cifg2.1.0.diagram/src/cifg/diagram/edit/parts/UrgencyOperator2EditPart.java
===================================================================
--- cifg2.1.0.diagram/src/cifg/diagram/edit/parts/UrgencyOperator2EditPart.java (revision 220)
+++ cifg2.1.0.diagram/src/cifg/diagram/edit/parts/UrgencyOperator2EditPart.java (working copy)
@@ -128,18 +128,18 @@
                                                        .getFigureUrgencyOperatorAnnotationsAnnotationsLabel());
                        return true;
                }
+               if (childEditPart instanceof UrgencyOperatorAnnotationsHeaderLabel2EditPart) {
+                       ((UrgencyOperatorAnnotationsHeaderLabel2EditPart) childEditPart)
+                                       .setLabel(getPrimaryShape()
+                                                       .getFigureUrgencyOperatorAnnotationsHeaderLabel());
+                       return true;
+               }
                if (childEditPart instanceof UrgencyOperatorHeaderLabel2EditPart) {
                        ((UrgencyOperatorHeaderLabel2EditPart) childEditPart)
                                        .setLabel(getPrimaryShape()
                                                        .getFigureUrgencyOperatorHeaderLabel());
                        return true;
                }
-               if (childEditPart instanceof UrgencyOperatorAnnotationsHeaderLabel2EditPart) {
-                       ((UrgencyOperatorAnnotationsHeaderLabel2EditPart) childEditPart)
-                                       .setLabel(getPrimaryShape()
-                                                       .getFigureUrgencyOperatorAnnotationsHeaderLabel());
-                       return true;
-               }
                if (childEditPart instanceof UrgencyOperatorUrgencyOperatorBodiesCompartment2EditPart) {
                        IFigure pane = getPrimaryShape()
                                        .getFigureUrgencyOperatorBodiesShape();
@@ -162,10 +162,10 @@
                if (childEditPart instanceof UrgencyOperatorAnnotations2EditPart) {
                        return true;
                }
-               if (childEditPart instanceof UrgencyOperatorHeaderLabel2EditPart) {
+               if (childEditPart instanceof UrgencyOperatorAnnotationsHeaderLabel2EditPart) {
                        return true;
                }
-               if (childEditPart instanceof UrgencyOperatorAnnotationsHeaderLabel2EditPart) {
+               if (childEditPart instanceof UrgencyOperatorHeaderLabel2EditPart) {
                        return true;
                }
                if (childEditPart instanceof UrgencyOperatorUrgencyOperatorBodiesCompartment2EditPart) {


I have some scripts to create patches for all custom code. I can remove all diagram code and regenerate it and see if the patch still fits. This way I can regenerate the code and get all changes of the gmfmap/gmfgraph etc, with minimal effort to readd the custom code. However, as the above diff shows, the generated diagram code is not deterministic. A lot of code gets shuffled around.

Questions:
1. Is there any way to have the benefit of full regeneration of diagram code, while still having a way to easily readd all the custom code?

2. Are there any plans to make the diagram code generation deterministic (the cases of the if-statements could be sorted or something)?

Any help would be greatly appreciated.

Dennis
Re: Code generation is non-deterministic [message #516504 is a reply to message #516252] Wed, 24 February 2010 09:27 Go to previous messageGo to next message
Dennis HendriksFriend
Messages: 74
Registered: January 2010
Location: The Netherlands
Member
OK, so it turns out only the order of the generated if-statements of the addFixedChild and removeFixedChild methods of the *EditPart classes get shuffled around. I searched a bit, and found the following file:

./apps/eclipse/plugins/org.eclipse.gmf.templates.legacy_1.0. 0.v20090614-0839/codegen.lite.templates/xpt/diagram/parts/No deEditPart.xpt

it contains:

�DEFINE addFixedChild FOR gmfgen::GenNode-�
	�IF hasFixedChildren()-�
		�EXPAND xpt::Common::generatedMemberComment�
		protected boolean addFixedChild(org.eclipse.gef.EditPart childEditPart) {
			�FOREACH getInnerFixedLabels() AS label-�
				�LET (gmfgen::ParentAssignedViewmap) label.viewmap AS childViewmap-�
					if (childEditPart instanceof �label.getEditPartQualifiedClassName()�) {
						((�label.getEditPartQualifiedClassName()�) childEditPart).�EXPAND impl::diagram::editparts::TextAware::labelSetterName FOR childViewmap�(getPrimaryShape().�childViewmap.getterName�());
						return true;
					}
				�ENDLET-�
			�ENDFOREACH-�


I changed the line:

		protected boolean addFixedChild(org.eclipse.gef.EditPart childEditPart) {


to

		protected boolean addFixedChild(org.eclipse.gef.EditPart childEditPart) {TESTTEST


I removed the .gmfgen file and recreated it from the .gmfmap file. Then I used the .gmfgen file to regenerate the diagram code (after removing the diagram code first). I did not see the added 'TESTTEST' appear in the generated diagram code.

How can I modify the templates to actually have a result on the generated diagram code? Any help would be greatly appreciated.

Dennis
Re: Code generation is non-deterministic [message #516514 is a reply to message #516252] Wed, 24 February 2010 10:27 Go to previous messageGo to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

I think that you can take a look at this recent article:
http://www.bonitasoft.org/blog/?p=388

Smile

Regards,


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team

[Updated on: Wed, 24 February 2010 10:27]

Report message to a moderator

Re: Code generation is non-deterministic [message #516534 is a reply to message #516514] Wed, 24 February 2010 11:21 Go to previous messageGo to next message
Dennis HendriksFriend
Messages: 74
Registered: January 2010
Location: The Netherlands
Member
Aurelien Pupier wrote on Wed, 24 February 2010 11:27
I think that you can take a look at this recent article:
http://www.bonitasoft.org/blog/?p=388


Looks very interesting. I'll take a look at it. Thanks!

Dennis
Re: Code generation is non-deterministic [message #516567 is a reply to message #516534] Wed, 24 February 2010 12:25 Go to previous message
Dennis HendriksFriend
Messages: 74
Registered: January 2010
Location: The Netherlands
Member
OK, I tried the aspect thing and it works perfectly! Thanks again.

One more thing. In the .gmfgen, there is already code:

      <viewmap
          xsi:type="gmfgen:InnerClassViewmap"
          className="SynchronizationOperatorFigure"
          classBody="&#xA;/**&#xA; * @generated&#xA; */&#xA;public class SynchronizationOperatorFigure extends org.eclipse.draw2d.RectangleFigure {&#xA;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;private org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel fFigureSynchronizationOperatorHeaderLabel; &#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;private org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel fFigureSynchronizationOperatorActionsLabel; &#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;private 
.............


I found that the 'createContents' method (which I would like to customize) is generated by these Xpand templates:

[... plugins]$ grep -i -r "createconten" .
./org.eclipse.gmf.templates.legacy_1.0.0.v20090614-0839/graphdef.codegen.templates/top/Figure.xpt:              createContents();
./org.eclipse.gmf.templates.legacy_1.0.0.v20090614-0839/graphdef.codegen.templates/top/Figure.xpt:              createContents();
./org.eclipse.gmf.templates.legacy_1.0.0.v20090614-0839/graphdef.codegen.templates/top/Figure.xpt:      private void createContents(){
./org.eclipse.gmf.templates.legacy_1.0.0.v20090614-0839/graphdef.codegen.templates/Children.xpt:        private void createContents(){


as part of the creation of the .gmfgen file from the .gmfmap file.

Is there a way to customize these templates as well?

Dennis
Previous Topic:Custom Actions/ Custom Behaviour
Next Topic:xpand templates
Goto Forum:
  


Current Time: Fri Apr 19 01:06:04 GMT 2024

Powered by FUDForum. Page generated in 0.01654 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top