Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Disable invokation of the generator when a generated file change
Disable invokation of the generator when a generated file change [message #1748108] Fri, 18 November 2016 14:24 Go to next message
Michael Fraefel is currently offline Michael FraefelFriend
Messages: 11
Registered: November 2016
Junior Member
When I modify a generated file manually, always the generator is invoked again and override my changes. Is there a possibility to only invoke the generator when the model changes?

The reason why I need this is, I have written a post processor wich let me have a protected region on the generated files. The post processor works fine, when I use a external text editor to change the generated files. But when I change it in the IDE (Intellij), always the generator is invoked.

Re: Disable invokation of the generator when a generated file change [message #1748127 is a reply to message #1748108] Fri, 18 November 2016 17:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
hmmmm maybe you need to hook e.g. https://github.com/danieldietrich/xtext-protected-regions somehow to be used in intellij

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Disable invokation of the generator when a generated file change [message #1748128 is a reply to message #1748108] Fri, 18 November 2016 17:40 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Protected regions are considered as anti-pattern for code generators. Please consider to design your generator in a way to avoid this. The most common way is use of the generation gap pattern.

Sorry, I can't say so much about the topic itself, since I don't use IDEA.
Re: Disable invokation of the generator when a generated file change [message #1748132 is a reply to message #1748128] Fri, 18 November 2016 19:06 Go to previous messageGo to next message
Michael Fraefel is currently offline Michael FraefelFriend
Messages: 11
Registered: November 2016
Junior Member
I used xtext-protected-regions before, but it's not compatible with xtext 2.9.0.

I know that it's an anti-pattern. But before the protected regions, we worked with with abstract and impl classes. But this approach wasn't cool and we like the way with the protected regions.
Re: Disable invokation of the generator when a generated file change [message #1748133 is a reply to message #1748128] Fri, 18 November 2016 19:06 Go to previous messageGo to next message
Michael Fraefel is currently offline Michael FraefelFriend
Messages: 11
Registered: November 2016
Junior Member
I used xtext-protected-regions before, but it's not compatible with xtext 2.9.0.

I know that it's an anti-pattern. But before the protected regions, we worked with with abstract and impl classes. But this approach wasn't cool and we like the way with the protected regions.
Re: Disable invokation of the generator when a generated file change [message #1748134 is a reply to message #1748128] Fri, 18 November 2016 19:06 Go to previous messageGo to next message
Michael Fraefel is currently offline Michael FraefelFriend
Messages: 11
Registered: November 2016
Junior Member
I used xtext-protected-regions before, but it's not compatible with xtext 2.9.0.

I know that it's an anti-pattern. But before the protected regions, we worked with with abstract and impl classes. But this approach wasn't cool and we like the way with the protected regions.
Re: Disable invokation of the generator when a generated file change [message #1748135 is a reply to message #1748134] Fri, 18 November 2016 19:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
it should be possible to port the protected regions to 2.10 i dont see anything why that should not work.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Disable invokation of the generator when a generated file change [message #1748335 is a reply to message #1748135] Tue, 22 November 2016 10:44 Go to previous messageGo to next message
Michael Fraefel is currently offline Michael FraefelFriend
Messages: 11
Registered: November 2016
Junior Member
I took the source of xtext-protected-region and added the configuration as described here: https://github.com/danieldietrich/xtext-protected-regions
But here is the fist problem. There is no configuration for IntelliJ. For IntelliJ xtext use the URIBasedFileSystemAccess. I copied the ProtectedRegionJavaIoFileSystemAccess and modified it for URIBasedFileSystemAccess. But the modified class is never loaded. It seems that URIBasedFileSystemAccess is instantiated without Guice.
Re: Disable invokation of the generator when a generated file change [message #1748338 is a reply to message #1748335] Tue, 22 November 2016 11:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hmm did you do a findrefs on the class? How does your binding look like

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Disable invokation of the generator when a generated file change [message #1748342 is a reply to message #1748338] Tue, 22 November 2016 11:24 Go to previous messageGo to next message
Akos Kitta is currently offline Akos KittaFriend
Messages: 25
Registered: November 2015
Junior Member
We have a manual instantiation in the org.eclipse.xtext.build.IncrementalBuilder, if this is what you guys are talking about. Just stumbled upon yesterday. Please reference org.eclipse.xtext.build.IncrementalBuilder.InternalStatefulIncrementalBuilder.createFileSystemAccess(IResourceServiceProvider, Resource) method. But the file post-processor and output configuration provider and others are from the resource service provider, hence injection should be fine.
Re: Disable invokation of the generator when a generated file change [message #1750434 is a reply to message #1748342] Wed, 21 December 2016 06:16 Go to previous messageGo to next message
Michael Fraefel is currently offline Michael FraefelFriend
Messages: 11
Registered: November 2016
Junior Member
@Akos Kitta How I manual instantiate the org.eclipse.xtext.build.IncrementalBuilder? I tried it with this in the Module class:
    
override void configure(Binder binder) {
        super.configure(binder);
        binder.bind(new IncrementalBuilderCustom.class);
    }


But my IncrementalBuilderCustom isn't invoked. Thank you for your help.
Re: Disable invokation of the generator when a generated file change [message #1750439 is a reply to message #1750434] Wed, 21 December 2016 07:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
This makes no sense. Should be

binder.bind(IncrementalBuilder).to(YourIncrementalBuilder)

Or something like that


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Disable invokation of the generator when a generated file change [message #1750451 is a reply to message #1750434] Wed, 21 December 2016 08:34 Go to previous messageGo to next message
Akos Kitta is currently offline Akos KittaFriend
Messages: 25
Registered: November 2015
Junior Member
Michael,

Could you please clarify, in the first place, why do you need to have a custom builder? I just would like to understand your use-case. Thanks!
Re: Disable invokation of the generator when a generated file change [message #1750631 is a reply to message #1748342] Fri, 23 December 2016 13:24 Go to previous messageGo to next message
Michael Fraefel is currently offline Michael FraefelFriend
Messages: 11
Registered: November 2016
Junior Member
@Akos KittaFriend
I have buid a IFilePostProcessorwhich prevent the generator to overwrite protected regions in my generated files. The post processor works, but when i edit a generated file with Intellij, the generator starts generating immediately. So it's not possible to edit the protected region with Intellij. If I use an external Editor, I can edit it.

To change this, I would like to modify the IncrementalBuilder.

[Updated on: Fri, 23 December 2016 13:49]

Report message to a moderator

Re: Disable invokation of the generator when a generated file change [message #1750634 is a reply to message #1750439] Fri, 23 December 2016 14:01 Go to previous messageGo to next message
Michael Fraefel is currently offline Michael FraefelFriend
Messages: 11
Registered: November 2016
Junior Member
Hi Christian
binder.bind(IncrementalBuilder).to(YourIncrementalBuilder);

Don't work. Sad
Re: Disable invokation of the generator when a generated file change [message #1750648 is a reply to message #1750634] Fri, 23 December 2016 19:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
can you please elaborate what you are actually doing? how do you call the IncrementalBuilder and where do you bind it?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Disable invokation of the generator when a generated file change [message #1750768 is a reply to message #1750648] Wed, 28 December 2016 11:40 Go to previous messageGo to next message
Michael Fraefel is currently offline Michael FraefelFriend
Messages: 11
Registered: November 2016
Junior Member
The IncrementalBuilder is called by the XtextAutoBuilderComponent, but didn't change here something. I just implemented my own IFilePostProcesser. I configured the IFilePostProcessor and the custom IncrementalBuilder in the MyDSLModelRuntimeModule.xtend

I was doing the following steps:

  1. I created a new Plugin project as here described https://blogs.itemis.com/en/get-started-with-xtext-and-intellij-idea-in-5-minutes.
  2. I took our existing DSL from the xtext version 2.8 into the new created project.
  3. I tried to configure xtext-protected-regions, but I didn't find out how to configure FileSystemAccess provider for IntelliJ. On the website are only examples for Java standalone and Eclipse. With debugging I found out, that for IntelliJ the URIBasedFileSystemAccess is used.
  4. Then I created my own post processor (IFilePostProcessor), which works. But, the problem is, that the generator always starts generating code, when I change a generated file.
  5. Now I search for a solution, to prevent running the generator by changing a generated file.

Re: Disable invokation of the generator when a generated file change [message #1750782 is a reply to message #1750768] Wed, 28 December 2016 17:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
well it looks like idea is not customizable regarding this at all.
IdeaSharedInjectorProvider is created to create the builder so you can do whatever you want.
feel free to file a ticket https://github.com/eclipse/xtext-idea, but dont expect it to be fixed soon. currently there is no maintainer for xtext idea.

but i have another idea: what about moving the detection right to i generator and do a read/merge/generate there?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Disable invokation of the generator when a generated file change [message #1751168 is a reply to message #1750782] Thu, 05 January 2017 09:32 Go to previous message
Michael Fraefel is currently offline Michael FraefelFriend
Messages: 11
Registered: November 2016
Junior Member
Thank you for your idea! By thinking again about my problem, I found the solution.
I implemented already the merging of the generated content and the current content of the target file. By editing the target file, I never could read it with the latest modifications. Because of this, I want to prevent the generator of generating when I edit the target file with the protected regions. My fault was, that I was reading the file with "new File(...)". Now I read it with the IFileSystemAccess2 instance and I get now the latest changes. I can now everything solve within my custom IFilePostProcessor.

Best regards,
Michael Fraefel
Previous Topic:Load Model
Next Topic:[Highlighting] override text style
Goto Forum:
  


Current Time: Thu Mar 28 20:28:12 GMT 2024

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

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

Back to the top