Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » append instead of appendImmediate for "AFTER" in loops
append instead of appendImmediate for "AFTER" in loops [message #849568] Thu, 19 April 2012 05:03 Go to next message
Christoph Zwicker
Messages: 16
Registered: April 2010
Junior Member
Hi all,

It seems that in FOR loops, the "AFTER" instruction translates into a ".append" call. I would have expected it to be ".appendImmeditate" in order to have symmetrical behavior with "SEPARATOR"...

What I would like to do when declaring enum instances is:
«FOR field : fields SEPARATOR ", //$NON-NLS-1$" AFTER "; //$NON-NLS-1$"»
	«field.declaration»
«ENDFOR»

The only workaround I found to simulate the expected behavior is the following:
«FOR field : fields SEPARATOR ", //$NON-NLS-1$"»
	«field.declaration»«IF field.equals(fields.last)»; //$NON-NLS-1$«ENDIF»
«ENDFOR»


Am I missing something? If not: I guess you would not accept this as a bug as it would change the current behavior. Any chance you might introduce a new keyword, e.g. "LAST" resulting in a "appendImmediate"?

Thanks,
Chris
Re: append instead of appendImmediate for "AFTER" in loops [message #849728 is a reply to message #849568] Thu, 19 April 2012 07:56 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Hi Chris,

the expressions BEFORE and AFTER are inserted before or after the actual
FOR LOOP. They are not meant to appear immediatly after the expression
in the for loop itself.

You could experiment with something like this:

«FOR field : fields SEPARATOR ", //$NON-NLS-1$\n" AFTER ";
//$NON-NLS-1$"»«field.declaration»«ENDFOR»

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

Am 19.04.12 11:03, schrieb Christoph Zwicker:
> Hi all,
>
> It seems that in FOR loops, the "AFTER" instruction translates into a
> ".append" call. I would have expected it to be ".appendImmeditate" in
> order to have symmetrical behavior with "SEPARATOR"...
>
> What I would like to do when declaring enum instances is:
>
> «FOR field : fields SEPARATOR ", //$NON-NLS-1$" AFTER "; //$NON-NLS-1$"»
> «field.declaration»
> «ENDFOR»
>
> The only workaround I found to simulate the expected behavior is the
> following:
>
> «FOR field : fields SEPARATOR ", //$NON-NLS-1$"»
> «field.declaration»«IF field.equals(fields.last)»; //$NON-NLS-1$«ENDIF»
> «ENDFOR»
>
>
> Am I missing something? If not: I guess you would not accept this as a
> bug as it would change the current behavior. Any chance you might
> introduce a new keyword, e.g. "LAST" resulting in a "appendImmediate"?
>
> Thanks,
> Chris
Re: append instead of appendImmediate for "AFTER" in loops [message #851032 is a reply to message #849728] Fri, 20 April 2012 11:25 Go to previous message
Christoph Zwicker
Messages: 16
Registered: April 2010
Junior Member
Hi Sebastian

Thank you for your reply. I had tried the solution you suggest earlier, but it destroys the indentation. I'll live with my workaround, it works fine - it's just a little clumsy Wink

The thing is that "after the loop" doesn't necessarily need to mean that there should be an empty line added imho: if my method called is something like the code below, I'm explicitly trying to avoid an empty line added. It's confusing to me that the generated code adds a newline after each method call instead of before it...

def foo '''
	bar'''

Thanks anyhow,
Chris
Previous Topic:how to avoid compiling Xtend classes in running Eclipse
Next Topic:Content Assist don't work in first column of second line...
Goto Forum:
  


Current Time: Mon Jul 28 00:34:15 EDT 2014

Powered by FUDForum. Page generated in 0.02863 seconds