Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Indent after first line
Indent after first line [message #1732738] Thu, 19 May 2016 11:48 Go to next message
Maged Elaasar is currently offline Maged ElaasarFriend
Messages: 23
Registered: September 2013
Junior Member
I am using Xtext 2.9 formatter2 API.

I am trying to figure out how to cause the formatter to produce indentation like in the following example:

relation X
   from Y
   to Z


In other words, I would like to insert new lines before "from" and "to" and indent them.

My current code looks like this:

	def dispatch format(Relationship relationship, extension IFormattableDocument document) {
		relationship.prepend[newLines = 2]
		relationship.regionFor.keyword("from").prepend[newLine]
		relationship.regionFor.keyword("to").prepend[newLine]
	}


which adds the new lines but not the indentation. How do I modify it, to add the indentation? Thanks in advance.

[Updated on: Thu, 19 May 2016 12:16]

Report message to a moderator

Re: Indent after first line [message #1732739 is a reply to message #1732738] Thu, 19 May 2016 18:46 Go to previous messageGo to next message
Maged Elaasar is currently offline Maged ElaasarFriend
Messages: 23
Registered: September 2013
Junior Member
I just realized that my example above did not have indentation, but I meant to have an indentation right before "from" and right before "to".
Re: Indent after first line [message #1732740 is a reply to message #1732739] Thu, 19 May 2016 19:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
How does your grammar look like

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Indent after first line [message #1732741 is a reply to message #1732740] Thu, 19 May 2016 19:27 Go to previous messageGo to next message
Maged Elaasar is currently offline Maged ElaasarFriend
Messages: 23
Registered: September 2013
Junior Member
Here is some of my grammer rules:

Entity:
	(isAbstract?='abstract')? 'entity' name=ID
;

Relationship:
	((isSymmetric?='symmetric')? &
	(isAsymmetric?='asymmetric')?)
	'relationship' name=ID
	'from' source=[Entity]
	'to' target=[Entity]
;
Re: Indent after first line [message #1732742 is a reply to message #1732741] Thu, 19 May 2016 19:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
set(relationship.regionFor.keyword("from").previousHiddenRegion, relationship.regionFor.feature(MyDslPackage.Literals.RELATIONSHIP_SOURCE).nextHiddenRegion)[indent]
set(relationship.regionFor.keyword("to").previousHiddenRegion, relationship.regionFor.feature(MyDslPackage.Literals.RELATIONSHIP_TARGET).nextHiddenRegion)[indent]


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Indent after first line [message #1732745 is a reply to message #1732742] Thu, 19 May 2016 19:39 Go to previous messageGo to next message
Maged Elaasar is currently offline Maged ElaasarFriend
Messages: 23
Registered: September 2013
Junior Member
Works perfect! Thank you Chris.
Re: Indent after first line [message #1733236 is a reply to message #1732745] Wed, 25 May 2016 15:41 Go to previous messageGo to next message
Vinicius Pereira is currently offline Vinicius PereiraFriend
Messages: 50
Registered: March 2014
Member
Hi Maged,

where you created the method to indent the lines? I saw your 'def dispatch format' method, but I don't know where to do the same here.

Thanks
Re: Indent after first line [message #1733238 is a reply to message #1733236] Wed, 25 May 2016 15:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
If you add a

formatter = { generateStub = true} to the workflow you will get a stub class generated. Add you methods there


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Indent after first line [message #1733239 is a reply to message #1733238] Wed, 25 May 2016 16:11 Go to previous messageGo to next message
Vinicius Pereira is currently offline Vinicius PereiraFriend
Messages: 50
Registered: March 2014
Member
Thanks! I will try.
Re: Indent after first line [message #1755434 is a reply to message #1733239] Fri, 03 March 2017 10:48 Go to previous message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 56
Registered: May 2015
Member
Example :
typesDecl.interior[indent] // Indente after TypeDecl and until the end of the region
Previous Topic:After Update to 2.11: Error after Clean Projects
Next Topic:Resolving of URIs in XMI files
Goto Forum:
  


Current Time: Fri Mar 29 06:33:45 GMT 2024

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

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

Back to the top