Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtext 2.2.1] Simple conditional formatting?
[Xtext 2.2.1] Simple conditional formatting? [message #819095] Mon, 12 March 2012 13:39 Go to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Greetings,

As part of formatting, I'd like to group all the imports in a file. For example:

import "abc.proto";

import "xyz.proto";
message Person {
}


can be formatted into:

import "abc.proto";
import "xyz.proto";

message Person {
}


I've been trying to find a way to say "if next element is not an import, add an extra line break". Is it possible with the default formatting infrastructure in Xtext?

I've been looking everywhere and I haven't found anything. I also thought that the method 'getMatcherProvider' in 'AbstractDeclarativeFormatter' would help, but I couldn't figure out if that would be the case.

As always, any help will be greatly appreciated Smile

Cheers!
-Alex
Re: [Xtext 2.2.1] Simple conditional formatting? [message #819916 is a reply to message #819095] Tue, 13 March 2012 13:43 Go to previous messageGo to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
It seems that this should work:

  @Override protected void configureFormatting(FormattingConfig c) {
    ProtobufGrammarAccess g = (ProtobufGrammarAccess) getGrammarAccess();
    c.setLinewrap(2).between(g.getNormalImportRule(), g.getMessageRule());



The problem is that it does nothing. Is this a bug or a misunderstanding of what 'between' should do?

Many thanks!
-Alex

[Updated on: Tue, 13 March 2012 13:44]

Report message to a moderator

Re: [Xtext 2.2.1] Simple conditional formatting? [message #819971 is a reply to message #819095] Tue, 13 March 2012 15:05 Go to previous messageGo to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
(Looks like my reply disappeared. Here it goes again)

It seems that this should work:

  @Override protected void configureFormatting(FormattingConfig c) {
    ProtobufGrammarAccess g = (ProtobufGrammarAccess) getGrammarAccess();
    c.setLinewrap(2).between(g.getNormalImportRule(), g.getMessageRule());



The problem is that it does nothing. Is this a bug or a misunderstanding of what 'between' should do?

Many thanks!
-Alex
Re: [Xtext 2.2.1] Simple conditional formatting? [message #826291 is a reply to message #819916] Wed, 21 March 2012 22:41 Go to previous messageGo to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Hey guys,

Sorry to bother you again. I've been spending some time debugging and understanding the formatter code, but so far no real progress from my side.

Any thoughts on this issue?

Many thanks!
-Alex
Re: [Xtext 2.2.1] Simple conditional formatting? [message #827218 is a reply to message #819971] Fri, 23 March 2012 02:43 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Alex,

yes, this may be a bug - between should be the way to go for your use
case. Did you try to use the root elements of your parser rules in the
between clause?

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

Am 13.03.12 11:05, schrieb Alex Ruiz:
> (Looks like my reply disappeared. Here it goes again)
> It seems that this should work:
>
>
> @Override protected void configureFormatting(FormattingConfig c) {
> ProtobufGrammarAccess g = (ProtobufGrammarAccess) getGrammarAccess();
> c.setLinewrap(2).between(g.getNormalImportRule(), g.getMessageRule());
>
>
>
> The problem is that it does nothing. Is this a bug or a misunderstanding
> of what 'between' should do?
>
> Many thanks!
> -Alex
Previous Topic:Get corret scope context for ambiguities
Next Topic:Scope Traversal
Goto Forum:
  


Current Time: Fri Apr 26 16:11:50 GMT 2024

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

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

Back to the top