Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Indent after first line
Indent after first line [message #1732738] Thu, 19 May 2016 07:48 Go to next message
Eclipse UserFriend
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 08:16] by Moderator

Re: Indent after first line [message #1732739 is a reply to message #1732738] Thu, 19 May 2016 14:46 Go to previous messageGo to next message
Eclipse UserFriend
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 15:08 Go to previous messageGo to next message
Eclipse UserFriend
How does your grammar look like
Re: Indent after first line [message #1732741 is a reply to message #1732740] Thu, 19 May 2016 15:27 Go to previous messageGo to next message
Eclipse UserFriend
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 15:21 Go to previous messageGo to next message
Eclipse UserFriend
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]
Re: Indent after first line [message #1732745 is a reply to message #1732742] Thu, 19 May 2016 15:39 Go to previous messageGo to next message
Eclipse UserFriend
Works perfect! Thank you Chris.
Re: Indent after first line [message #1733236 is a reply to message #1732745] Wed, 25 May 2016 11:41 Go to previous messageGo to next message
Eclipse UserFriend
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 11:58 Go to previous messageGo to next message
Eclipse UserFriend
If you add a

formatter = { generateStub = true} to the workflow you will get a stub class generated. Add you methods there
Re: Indent after first line [message #1733239 is a reply to message #1733238] Wed, 25 May 2016 12:11 Go to previous messageGo to next message
Eclipse UserFriend
Thanks! I will try.
Re: Indent after first line [message #1755434 is a reply to message #1733239] Fri, 03 March 2017 05:48 Go to previous message
Eclipse UserFriend
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: Sat May 17 06:45:46 EDT 2025

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

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

Back to the top