Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to set indentation in formatter?
How to set indentation in formatter? [message #723561] Thu, 08 September 2011 19:58 Go to next message
steven reinisch is currently offline steven reinischFriend
Messages: 33
Registered: July 2009
Member
hi,

I am working with this grammar (snippet):


Entity returns modulob::Entity:
	(annotations+=Annotation)*
	(isAbstract?='abstract')? 'entity' name=ID (':' super=[modulob::Entity])?'{'
		(features+=Feature)*
	'}'
;

Annotation returns modulob::Annotation:
	'@' option=ConfigOption (':' value=ConfigValue)?
;

Feature returns modulob::Feature:
	(isIndexed?='indexed')?
	(isContainment?='-[')?
	type=TypeRef name=ID ('=' defaultValue=ValueObject)? 
	('<->' inverse=[modulob::Feature | QualifiedName])?
	(';')?
;


With these formatting rules:

protected void configureFormatting(FormattingConfig c) {
  c.setLinewrap(2).after(((DataDslGrammarAccess)getGrammarAccess()).getEntityModelAccess().getVersionSTRINGTerminalRuleCall_3_0());
  c.setLinewrap().after(((DataDslGrammarAccess)getGrammarAccess()).getEntityRule());
  c.setLinewrap().after(((DataDslGrammarAccess)getGrammarAccess()).getEntityAccess().getAnnotationsAssignment_0());
  c.setNoSpace().after(((DataDslGrammarAccess)getGrammarAccess()).getAnnotationAccess().getCommercialAtKeyword_0());
  c.setNoSpace().after(((DataDslGrammarAccess)getGrammarAccess()).getAnnotationAccess().getColonKeyword_2_0());
  c.setNoSpace().after(((DataDslGrammarAccess)getGrammarAccess()).getAnnotationAccess().getOptionAssignment_1());
  c.setNoSpace().after(((DataDslGrammarAccess)getGrammarAccess()).getAnnotationAccess().getValueAssignment_2_1());
  c.setLinewrap().after(((DataDslGrammarAccess)getGrammarAccess()).getEntityAccess().getLeftCurlyBracketKeyword_5());
  c.setLinewrap().after(((DataDslGrammarAccess)getGrammarAccess()).getFeatureAccess().getSemicolonKeyword_6());
}


an entity looks like this:

entity Entry {
String uuid ;
indexed Timestamp timestamp ;
String username ;
String message ;
}


I want to achieve that each feature is indented like this:

entity Entry {
   String uuid ;
   indexed Timestamp timestamp ;
   String username ;
   String message ;
}


I tried to use

c.setWrappedLineIndentation(3);


but with no success. How can one specify indentations using FormattingConfig?

regards,

steven
Re: How to set indentation in formatter? [message #723565 is a reply to message #723561] Thu, 08 September 2011 20:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

what about something like

c.setIndentationIncrement().after(((MyDslGrammarAccess)getGrammarAccess()).getEntityAccess().getLeftCurlyBracketKeyword_4());
c.setIndentationDecrement().before(((MyDslGrammarAccess)getGrammarAccess()).getEntityAccess().getRightCurlyBracketKeyword_6());


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to set indentation in formatter? [message #723690 is a reply to message #723565] Fri, 09 September 2011 07:38 Go to previous messageGo to next message
steven reinisch is currently offline steven reinischFriend
Messages: 33
Registered: July 2009
Member
Christian Dietrich wrote on Thu, 08 September 2011 16:09
Hi,

what about something like

c.setIndentationIncrement().after(((MyDslGrammarAccess)getGrammarAccess()).getEntityAccess().getLeftCurlyBracketKeyword_4());
c.setIndentationDecrement().before(((MyDslGrammarAccess)getGrammarAccess()).getEntityAccess().getRightCurlyBracketKeyword_6());




that did it. I just did not understand what 'setIndentationIncrement' means.

thanks!

steven
Re: How to set indentation in formatter? [message #1702418 is a reply to message #723690] Wed, 22 July 2015 08:58 Go to previous message
Mohsin waqas is currently offline Mohsin waqasFriend
Messages: 33
Registered: June 2015
Member
it means just add one tab increment before or after the specified entry. Smile
Previous Topic:Dispatch methods for the label provider
Next Topic:Containment references with containment proxies in Xtext grammer
Goto Forum:
  


Current Time: Thu Apr 25 05:46:46 GMT 2024

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

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

Back to the top