Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtend2] Where is ONFILECLOSE in Xtend2?
[Xtend2] Where is ONFILECLOSE in Xtend2? [message #682833] Sun, 12 June 2011 03:40 Go to next message
Jos Warmer is currently offline Jos Warmer
Messages: 104
Registered: October 2010
Senior Member
In Xpand the <<EXTEND>> call has a parameter ONFILECLOSE. This is useful for e.g. capturing imports and writing only after you process ed the complete file.

In Xtend2 the <<EXTEND>> co0ntruct has disappeared, you now use an Xtend2 function instead. However, I cannot find the replacement for the ONFILECLOSE feature. Is it really gone in Xtend2, or am I missing something ?

[Updated on: Sun, 12 June 2011 04:12]

Report message to a moderator

(no subject) [message #682913 is a reply to message #682833] Sun, 12 June 2011 08:31 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2788
Registered: July 2009
Senior Member
Hi Jos,

the rich strings implement the CharSequence interface. You can do any
post processing before you pass the sequence to the IFileSystemAccess.
There is actually no need for a dedicated ONFILECLOSE-callback.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 12.06.11 09:40, schrieb Jos Warmer:
> In Xpand the <<EXTEND>> call has a parameter ONFILECLOSE. This is useful
> for e.g. capturing imports and writing only after you process ed the
> complete file.
>
> In Xtend2 the <<EXTEND>> co0ntruct has disappeared, you now use an
> Xtend2 function instead. However, I cannot find the replacement for the
> ONFILECLOSE feature. Is it really gone in Xtend2, or am I missing
> something ?
Re: (no subject) [message #682919 is a reply to message #682913] Sun, 12 June 2011 09:33 Go to previous messageGo to next message
Jos Warmer is currently offline Jos Warmer
Messages: 104
Registered: October 2010
Senior Member
So the idea is that I just put a marker somewhere in the CharSequence and then use the "replace(...)' method to do the post processing. That is the workaround that I already use. Glad to know this is the intended way of doing this.
Re: (no subject) [message #683193 is a reply to message #682919] Mon, 13 June 2011 03:41 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander Nittka
Messages: 1073
Registered: July 2009
Senior Member
Hi,

no this is not the idea, but you are free to compose the result as you wish before passing it to the IFileSystemAccess. Have a look at the DomainModelGenerator.xtend in the domainmodel example. At least in the version, I look at currently there is an ImportManager. I guess the "problem" is not thinking in terms of the old Xpand. It is not necessary to create the file from top to bottom (when *calculating* the contents).

Alex
Re: (no subject) [message #683360 is a reply to message #683193] Mon, 13 June 2011 11:28 Go to previous messageGo to next message
Jos Warmer is currently offline Jos Warmer
Messages: 104
Registered: October 2010
Senior Member
Alexander,

You are right in not thinking like old Xpand, but in this case I find the way it was done in old Xpand actually shorter and easier. On the other hand, the new way is more flexible and has more possibilities.

Jos
Re: (no subject) [message #683375 is a reply to message #683193] Mon, 13 June 2011 12:02 Go to previous messageGo to next message
Jos Warmer is currently offline Jos Warmer
Messages: 104
Registered: October 2010
Senior Member
Alexander,

I have taken a look at the ImportManager, but that works on JvmTypeReference, which is part of Xbase. When trying to understand how that is being used, I lack information of how to use Xbase in my own grammar. Without more documentation /examples/tutorial I don't know how this can be used.

jos
Re: (no subject) [message #683380 is a reply to message #683375] Mon, 13 June 2011 12:22 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 4412
Registered: July 2009
Senior Member
Hi,

this import manager just gives you an idea how to solve the problem

(1) Create a Stateful Thing (Import Manager) that collects the Import Stuff
(2) do the body calculation, fill the thing, assign body to a var/val
(3) print out the imports
(4) print out the body

from the domain model example

	def compile(Entity e) ''' 
		«val importManager = new ImportManager(true)»
		«/* first evaluate the body in order to collect the used types for the import section */
		val body = body(e, importManager)»
		«IF !(e.packageName.isNullOrEmpty)»
			package «e.packageName»;
			
		«ENDIF»
		«FOR i:importManager.imports»
			import «i»;
		«ENDFOR»
		
		«body»
	'''


In the easiest case this Import Manager is a simple List/Set

~Christian

[Updated on: Mon, 13 June 2011 12:30]

Report message to a moderator

Re: (no subject) [message #683807 is a reply to message #683380] Tue, 14 June 2011 09:08 Go to previous messageGo to next message
Jos Warmer is currently offline Jos Warmer
Messages: 104
Registered: October 2010
Senior Member
Christian,

I can see that this works when you have only one insertion point at the beginning of the template. But if you have multiple insertion points scattered through the file, this won't work. You would need to generate the body in many parts and then insert all the pieces in between.

The only solution I see is to put markers in the generated string and replace them afterwards. This is, however, not very efficient.

With the ONFILECOSE (or something similar) inside the template we can make this very efficient. We just need a specialized CharSequence that can also insert efficiently at defined positions. As CharSequence is implemented as a List<String> all you need to do is to ensure that an insertion point is exactly between two Strings in the list. Then, using closures this should be easy to define and implement.

E.g.
    def methodToBeEvaluatedLater(){
        ...
    }
    def methodToBeEvaluatedLater2(){
        ...
    }
 
    def templateWithInsertionpoints() '''
        Generated text
        ...  randon number of lines ...
        more text
        <<EVAL methodToBeEvaluatedLater()>>
        and more text
        ...
        <<EVAL methodToBeEvaluatedLater2()>>
        and more text
        ...
    '''

where <<EVAL methodName()>> means that the methodToBeEvaluetedLater() is evaluated at the end of executing the templateWithInsertionpoints() method.
This way, methodToBeEvaluatedLater() itself could also be a template and even use insertion points itself recursively.

SO I think we have lost valuable functionality by removing the ONFILECLOSE. I was one of the people originally requesting this kind of insertion point feature and I would like to request this again for Xtend2.

Jos
Re: (no subject) [message #683827 is a reply to message #683807] Tue, 14 June 2011 09:31 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 4412
Registered: July 2009
Senior Member
Hi,

feel free to file such an enhancement request for Xtend2 too Wink

~Christian
Re: (no subject) [message #684160 is a reply to message #683807] Wed, 15 June 2011 02:32 Go to previous message
Alexander Nittka is currently offline Alexander Nittka
Messages: 1073
Registered: July 2009
Senior Member
Hi,

but can't you do exactly that now as well? You insert a particular key-String into the text and before passing it to the file system access, you replace them...

Alex
Previous Topic:(no subject)
Next Topic:Xtext CDO integration.
Goto Forum:
  


Current Time: Tue May 21 13:52:36 EDT 2013

Powered by FUDForum. Page generated in 0.01934 seconds