Issue with formatting line breaks [message #1786100] |
Wed, 25 April 2018 10:17  |
Eclipse User |
|
|
|
Hello :)
I am currently trying to apply some formatting rules on my textual model which inserts line breaks after and before each curly bracket. Although this is what I want in general, I need to make an exception for one grammar rule/element.
This is my formatting code:
// set indentation inside all curly brackets
// set line wrap after each left curly bracket
// set line wrap around each right curly bracket
for (org.eclipse.xtext.util.Pair<Keyword, Keyword> p : f.findKeywordPairs("{", "}")) {
c.setIndentationIncrement().after(p.getFirst());
c.setIndentationDecrement().before(p.getSecond());
c.setLinewrap().after(p.getFirst());
c.setLinewrap().around(p.getSecond());
}
Now let's say I have an element type which I don't want this formatting rule to be applied to. Below is my grammar for that element, where you can see that there is curly bracket and I don't want it to have line break after and before.
WCA returns Modifiable:
{WCA} name=ID '{'
override=Override?
guard=Guard?
segment=Action
'}'
;
Should I add anything in my formatting code ?
Any help would be appreciated.
Thanks,
Parsa
|
|
|
|
|
|
Re: Issue with formatting line breaks [message #1786124 is a reply to message #1786123] |
Wed, 25 April 2018 16:08  |
Eclipse User |
|
|
|
Thanks a lot Christian, it works perfectly.
Just for people who might have the same issue as mine, below is the if statement:
for (org.eclipse.xtext.util.Pair<Keyword, Keyword> p : f.findKeywordPairs("{", "}")) {
if (!(p.first.equals(f.WCAAccess.leftCurlyBracketKeyword_2) &&
p.second.equals(f.WCAAccess.rightCurlyBracketKeyword_6))) {
c.setIndentationIncrement().after(p.getFirst());
c.setIndentationDecrement().before(p.getSecond());
c.setLinewrap().after(p.getFirst());
c.setLinewrap().around(p.getSecond());
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.08423 seconds