Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Dependency on a Reusable Base Generator not Working(Reuse code in a base generator project in several other generators)
[Acceleo] Dependency on a Reusable Base Generator not Working [message #1799566] Mon, 10 December 2018 11:45 Go to next message
Thomas Pusztai is currently offline Thomas PusztaiFriend
Messages: 27
Registered: September 2018
Junior Member
Hi,

I'm trying to write some code generators using Acceleo 3.7.5. for generating code from UML models. I started with one generator that generates Java code, which went very well. However, I now need to be able to support generators for multiple target languages.

My idea is to create a base generator, which contains the general procedure that iterates over the model and calls various Acceleo modules to generate code for the UML model elements. In the base generator these modules are empty, but in a generator for a specific language I would use dynamic template overriding to generate code for the respective target language.

I started by setting up the base generator project and moving the Java services and the associated Acceleo queries there. I then set up the code generator project for the Java language to use the base generator as a dependency and be able to override templates, as described on this Acceleo documentation page in the secion "Additional Concepts -> Dynamic Overriding".

When I try to run the Java generator now, I always get multiple exceptions like the following:
!ENTRY org.eclipse.acceleo.engine 2 2 2018-12-10 12:02:22.894
!MESSAGE Unresolved compilation error, expression was null.
!STACK 0
org.eclipse.acceleo.engine.AcceleoEvaluationException: Unresolved compilation error, expression was null.
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1895)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:1049)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoQueryInvocation(AcceleoEvaluationVisitor.java:880)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1951)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:1049)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoForBlock(AcceleoEvaluationVisitor.java:448)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1922)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:1049)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoTemplate(AcceleoEvaluationVisitor.java:922)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1906)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:1049)
	at org.eclipse.ocl.internal.evaluation.QueryImpl.evaluate(QueryImpl.java:146)
	at org.eclipse.ocl.ecore.QueryImpl.evaluate(QueryImpl.java:56)
	at org.eclipse.acceleo.engine.generation.AcceleoEngine.doEvaluate(AcceleoEngine.java:365)
	at org.eclipse.acceleo.engine.generation.AcceleoEngine.evaluate(AcceleoEngine.java:142)
	at org.eclipse.acceleo.engine.service.AcceleoService.doGenerateTemplate(AcceleoService.java:984)
	at org.eclipse.acceleo.engine.service.AcceleoService.doGenerate(AcceleoService.java:641)
	at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.generate(AbstractAcceleoGenerator.java:209)
	at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.generate(AbstractAcceleoGenerator.java:172)
	at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.doGenerate(AbstractAcceleoGenerator.java:159)
	at master.thesis.architecture.fog.uml.gen.java.main.FogUml2Java.doGenerate(FogUml2Java.java:202)
	at JavaCodeGenerator.ui.common.GenerateAll.doGenerate(GenerateAll.java:81)
	at JavaCodeGenerator.ui.popupMenus.AcceleoGenerateCodeGeneratorAction$1.run(AcceleoGenerateCodeGeneratorAction.java:78)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)

!ENTRY org.eclipse.acceleo.engine 2 2 2018-12-10 12:02:22.905
!MESSAGE Invalid loop iteration at line 54 in Module fogUml2Java for block for (unresolved query invocation : null()). Last recorded value of self was org.eclipse.uml2.uml.internal.impl.ModelImpl@5d31e0c6 (name: HealthCare, visibility: <unset>) (URI: null) (viewpoint: <unset>).
!STACK 0
org.eclipse.acceleo.engine.AcceleoEvaluationException: Invalid loop iteration at line 54 in Module fogUml2Java for block for (unresolved query invocation : null()). Last recorded value of self was org.eclipse.uml2.uml.internal.impl.ModelImpl@5d31e0c6 (name: HealthCare, visibility: <unset>) (URI: null) (viewpoint: <unset>).
	at fogUml2Java.main(Model)(fogUml2Java.mtl:54)
	at fogUml2Java.main(Model)(fogUml2Java.mtl:50)


Line 54 in the fogUml2Java module, which is mentioned in the stack trace, calls the getAllModelClasses() query that I have moved to the base generator project:
[for (modelClass : Class | fogModel.getAllModelClasses())]
	[modelClass.genModelClassJavaFile()/]
[/for]


I have updated the module import statement correctly after creating the base generator and I'm also able to navigate to the query by Ctrl+Clicking it. I've tried running the Java generator in three different ways, but the result was always basically the same:

  1. BaseGenerator and JavaGenerator in the Eclipse development instance and running the JavaGenerator using "Run As -> Launch Acceleo Application".
  2. BaseGenerator deployed in an Eclipse runtime instance, which has the JavaGenerator project open and running the JavaGenerator using "Run As -> Launch Acceleo Application".
  3. Base Generator, JavaGenerator, and an Acceleo UI Launcher for the JavaGenerator deployed in an Eclipse runtime instance and running the JavaGenerator using the UI launcher.


How can I fix this problem, such that the JavaGenerator will find the BaseGenerator dependency?

Best regards,
Thomas
Re: [Acceleo] Dependency on a Reusable Base Generator not Working [message #1799575 is a reply to message #1799566] Mon, 10 December 2018 12:40 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6437
Registered: July 2009
Senior Member
Hi

Sorry, it happens. I'm not sure anyone has really come up with a solution. I found that after multiple restarts, cleans, delete intermediate files, dummy edits, things seemed to work again for a bit. I think the basic problem is that a recompilation didn't happen. Only getting a problem after you refactored into multiple files seems vaguely familiar. Trying doing dummy edits in each of the template files to see which one provokes the required compilation.

Regards

Ed Willink
Re: [Acceleo] Dependency on a Reusable Base Generator not Working [message #1799581 is a reply to message #1799575] Mon, 10 December 2018 14:41 Go to previous messageGo to next message
Thomas Pusztai is currently offline Thomas PusztaiFriend
Messages: 27
Registered: September 2018
Junior Member
Hi,

Thanks, I will try that. Just one more question: which of the three ways of running the generator do I have to use? Do I really need to deploy both, the BaseGenerator and the JavaGenerator in a runtime instance or is it enough to deploy the BaseGenerator and run the JavaGenerator using "Run As -> Launch Acceleo Application"?

Best regards,
Thomas
Re: [Acceleo] Dependency on a Reusable Base Generator not Working [message #1799585 is a reply to message #1799581] Mon, 10 December 2018 15:01 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6437
Registered: July 2009
Senior Member
Hi

I'm not sure if I understand the question, but I would expect to launch once for each application I actually want to run.

Regards

Ed Willink
Re: [Acceleo] Dependency on a Reusable Base Generator not Working [message #1799586 is a reply to message #1799585] Mon, 10 December 2018 15:28 Go to previous messageGo to next message
Thomas Pusztai is currently offline Thomas PusztaiFriend
Messages: 27
Registered: September 2018
Junior Member
Hi,

Thanks for your fast reply. My question is the following: to launch an Acceleo generator I generally have two options: 1) right click my main .mtl file and select "Run/Debug As -> Launch Acceleo Application" or 2) create an Acceleo UI Launcher project and deploy this in an Eclipse runtime instance by opening the plugin.xml file and selecting "Launch an Eclipse application in Debug mode".

Before refactoring, when I only had a single generator, I always used the first method, because it is faster. Does this also work for my new scenario where the JavaGenerator depends on the BaseGenerator or do I have to launch an Eclipse runtime instance with the BaseGenerator (and possibly also the JavaGenerator) plugins deployed?

Best regards,
Thomas

Re: [Acceleo] Dependency on a Reusable Base Generator not Working [message #1799588 is a reply to message #1799586] Mon, 10 December 2018 16:43 Go to previous messageGo to next message
Thomas Pusztai is currently offline Thomas PusztaiFriend
Messages: 27
Registered: September 2018
Junior Member
I have now tried deleting the bin directory of all code generation projects, cleaning those projects in Eclipse, and adding a space to every .java and .mtl file in each of the projects. I launched the Acceleo UI Launcher plugin, which depends on the JavaGenerator, which in turn depends on the BaseGenerator, inside an Eclipse application in debug mode and the result is still the same.

I checked the list of loaded plugins in the runtime instance using "Help -> About Eclipse Platform -> Installation Details" and found both my generators and the UI launcher in there.

I also checked the .emtl file for my main Acceleo module in the JavaGenerator and found the following imports tag, which is the new path:
<imports href="platform:/resource/CodeGeneratorBase/bin/master/thesis/architecture/fog/uml/gen/base/services/fogUmlServices.emtl#/0"/>


Do you have any other ideas?

Best regards,
Thomas
Re: [Acceleo] Dependency on a Reusable Base Generator not Working [message #1799592 is a reply to message #1799588] Mon, 10 December 2018 17:28 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6437
Registered: July 2009
Senior Member
Hi

Sorry. It all seems very familiar. I can only bring the following to your attention.

I migrated all my Acceleo templates for Eclipse OCL tooling to Xtend about 5 years ago. I no longer use Acceleo. You may see some of the reasons in my Bugzillas and forum postings. Some of my problems were certainly exceptional in that my use of Acceleo based on Classic Eclipse OCL to support development of Pivot Eclipse OCL ran into difficulties with Acceleo's failure to correctly resolve URIs and so distinguish between two OCLs. Other problems were that I was foolishly attempting to abuse M2T. My Xtend equvalents have a substantial hand-coded Java M2M prior to the eventual M2T.

I am perhaps the only Eclipse committer who regularly responds to questions on this forum. I suspect that the last response from an Acceleo developer was March 2018.

https://projects.eclipse.org/projects/modeling.m2t.acceleo shows 20 commits in the last 12 months.

Regards

Ed Willink

Re: [Acceleo] Dependency on a Reusable Base Generator not Working [message #1799593 is a reply to message #1799592] Mon, 10 December 2018 17:52 Go to previous message
Thomas Pusztai is currently offline Thomas PusztaiFriend
Messages: 27
Registered: September 2018
Junior Member
Hi,

Thank you again for your response.

That doesn't look good with regards to modularity. I'm doing this as part of my computer science master thesis and the goal is conceptual research and not a polished product. Since I'm already into Acceleo now, I don't want to rewrite all the code generation by switching to Xtend. So my new plan is to accept the presence of some duplicate code and move the generators for both target languages into a single Acceleo generator.

Best regards,
Thomas
Previous Topic:Generate Output files in a different folder than the project
Next Topic:The problems occurs when I follow the Acceleo Getting Started guidance in the wiki to generate java
Goto Forum:
  


Current Time: Sun Aug 18 19:41:55 GMT 2019

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

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

Back to the top