Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Are static JET templates useable?
Are static JET templates useable? [message #1801689] Thu, 24 January 2019 18:07 Go to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6425
Registered: July 2009
Senior Member
Hi

(DynamicTemplaes, GenModel.dynamicTemplates = true, cause the GenModel.templateDirectory to be compiled to the .JETEmitters project and used from there during genmodel *.java synthesis. Good. Unfortunately dynamic templates do not work standalone since Eclipse bundle functionality is used to run the JET compiler.)

Static templates, GenModel.dynamicTemplates = false, should, according to https://bugs.eclipse.org/bugs/show_bug.cgi?id=147318, allow the GenModel.templateDirectory to specify already compiled templates bypassing the need for and problems of running the JET compiler. Comment #2 helpfully observes that ALL templates in a package must be defined to ensure that the user package displaces the EMF package. But for me, my 'better' package is last on the classpath, so even though my templates are passed first to JETEmitter, the class loader loads the standard EMF templates regardless. When launching standalone, I could contrive a biased class loader that favours my package, but I would like the genmodel to work just the same interactively. Does EMF need to use a biased class loader?

Can static templates be used?

Workaround. I currently use a different package name for which a GenModelGeneratorAdapterFactory can provide distinctive JET_DESCRIPTORS. Works fine when my standalone code registers the replacing GenModelGeneratorAdapterFactory locally. Also works fine if a complementing GenModelGeneratorAdapterFactory registers complementary templates globally.

But how to register replacement templates globally? The only way I can see is to use a distinctive GenModel nsURI for which the replacements can then be globally registered. But this doesn't exploit static templates.

Am I missing something?

Regards

Ed Willink
Re: Are static JET templates useable? [message #1801709 is a reply to message #1801689] Fri, 25 January 2019 03:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30312
Registered: July 2009
Senior Member
I'm really not sure exactly what you tried. Certainly I don't expect that dynamicTemplates=false implies "dynamically load statically compiled templates from somewhere else". I believe that if you specify dynamicTemplates=true and specify platform:/plugin/<id> as your template path then it will try to find already complied templates in that bundle using that bundle's class loader.
Re: Are static JET templates useable? [message #1801711 is a reply to message #1801709] Fri, 25 January 2019 06:05 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6425
Registered: July 2009
Senior Member
Hi

I'm trying to use dynamicTemplates=false since when running standalone, dynamicTemplates=true is unuseable because the JET compiler requires bundles.

When dynamicTemplates=false and replacing a standard template, the replacement package must have all the same class names as the replaced package, so it is necessary to ensure that the replacement package wins the loader ambiguity. I am unclear how this can be achieved in for instance a JUnit or MWE2 launch without a custom class loader.

Regards

Ed Willink
Re: Are static JET templates useable? [message #1801712 is a reply to message #1801711] Fri, 25 January 2019 06:59 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30312
Registered: July 2009
Senior Member
Yes, overall the dynamic templates design requires bundles. Unfrotuantely, I don't understand the dynamicTemplates=false scenario; that just does nothing (is intended to do nothing). I.e., there isn't intended to be a replacement package in this case. But you seemed to imply up front that you found some way to hack a stand alone scenario that somehow does something you want even in this case, though I'm explaining to you that the intent is that dynamicTemplates=false does nothing and that dynamicTemplate=true does something: It will compile the templates on the path (platform:/resource/...) ; that only works with a workspace and JDT doing the compilation. Alternatively, it can load existing compiled templates from a bundle (platform:/plugin/...); that only works if we have bundles. None of this is designed to work without bundles, and none of it is designed , and intend, to do anything dynamic when dynamicTemplates is false.

Perhaps you can use your workaround approach to make this also work for standalone. So perhaps it's good to try it first for the non-standalone case, and then see how you might use a similar approach to also work standalone.
Re: Are static JET templates useable? [message #1801729 is a reply to message #1801712] Fri, 25 January 2019 11:33 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6425
Registered: July 2009
Senior Member
Hi

I certainly seem to be breaking new ground in using GenModel standalone; a couple of bugs wrt ASTFacade and JavaCore startup have been fixed (thank you again). Currently my use case of variant EMF JET templates is supported as part of a much larger model auto-generation MWE2 launch that registers the 'wrong' GenModelGeneratorAdapterFactory. This is easy standalone, impossible within Eclipse. I am trying to make my *.genmodel more honest so that the using Generate Model interactively works just the same.

Potentially the combination of dynamicTemplates={true,false} and templateDirectory={null,not-null} gives four use cases. However it appears that in practice only dynamicTemplates={false}+templateDirectory={null} and dynamicTemplates={true}+templateDirectory={not-null} are useful.

dynamicTemplates={true} successfully enables a user's org.eclipse.emf.codegen.ecore.templates.model.Class.java to displace EMF's org.eclipse.emf.codegen.ecore.templates.model.Class.java since synthesis of the user's org.eclipse.emf.codegen.ecore.templates.model.Class.java is followed by a local Java compilation that returns the Class which is then used without troubling the ClassLoader.

I am looking at dynamicTemplates={false}+templateDirectory={not-null} and discovering that the functionality is almost there. The problem is that since the user's template was not compiled by JETEmitter.initialize to create the required unambiguous Class whose generate Method is set directly by JETEmitter.setMethod. Instead AbstractGeneratorAdapter.setStaticTemplateClass loads the user's org.eclipse.emf.codegen.ecore.templates.model.Class from the classPath without regard to the templatePath. This seems to strongly favour loading EMF's rather than the user's class. If AbstractGeneratorAdapter.setStaticTemplateClass iterated along the templatePath the correct class might be loaded.

Conclusion: static templates are not useful to replace standard EMF templates; they can be useful for novel templates. A relatively simple local enhancement to AbstractGeneratorAdapter.setStaticTemplateClass could fix this. Do you want an enhancement Bugzilla/Gerrit?

Regards

Ed Willink
Re: Are static JET templates useable? [message #1801755 is a reply to message #1801729] Fri, 25 January 2019 16:32 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30312
Registered: July 2009
Senior Member
I'm really not sure where this is all going... I'm not sure what needs to be "fixed".. The intent is that when dynamic templates is false, the template path isn't used, but rather the built-in defaults are used, but I get a feeling you want to "fix" that...
Previous Topic:Common Navigator Framework viewer with EMF
Next Topic:How to extend EcoreUtil.Copier to copy EOpposite references
Goto Forum:
  


Current Time: Sat Jul 20 21:53:16 GMT 2019

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

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

Back to the top