Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Formatter2: how to correctly format a block (indentation)
Formatter2: how to correctly format a block (indentation) [message #1693828] Tue, 28 April 2015 14:58 Go to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 35
Registered: March 2015
Member
Hey,

I'm trying to format something like this:

enumeration Enum1 {
	
	
			/** documentation */
		literal A;
	
	/** documentation */
literal B;
	
		literal C;
	
}


my formatter2 based formatting code looks like this:

	def dispatch void format(Enumeration enumeration, extension IFormattableDocument document) {
		enumeration.regionForKeyword("{").append[newLine; increaseIndentation]
		for (EnumerationLiteral literals : enumeration.getLiterals()) {
			format(literals, document);
		}
		enumeration.regionForKeyword("}").prepend[newLine; decreaseIndentation].append[newLine]
	}


the format(EnumerationLiteral) method does /not/ exist - it seems that the formatter2 fragment only generates methods for things that contain other elements - which the literals do not. Is it a problem that this method is not there? The default is an empty method enyhow, and actually I don't (currently) want to format the literal itself.

When run, the above code produces this:

enumeration Enum1 {
	/** documentation */
	literal A;
	
	/** documentation */
literal B;
	
		literal C;
}


which is close, but not quite there Wink

Whey is the indentation of the first comment and literal corrected, but the other literals stay where they are?

Any hints appreciated!

P.S.: good thing is that the first comment is formatted correctly, which was not possible with the old formatting API.
Re: Formatter2: how to correctly format a block (indentation) [message #1693852 is a reply to message #1693828] Tue, 28 April 2015 18:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
looks like a bug to me (not generating the method)

but adding it and formatting the newline does the

def dispatch void format(EnumerationLiteral l, extension IFormattableDocument document) {
		l.prepend[newLine]
	}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 28 April 2015 18:27]

Report message to a moderator

Re: Formatter2: how to correctly format a block (indentation) [message #1693885 is a reply to message #1693852] Wed, 29 April 2015 06:58 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 35
Registered: March 2015
Member
Thanks, that helped Smile

Is there any way to influence the formatting of a ML_COMMENT (or any other hidden object)?
Re: Formatter2: how to correctly format a block (indentation) [message #1694096 is a reply to message #1693885] Thu, 30 April 2015 14:18 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 35
Registered: March 2015
Member
ping Smile
Re: Formatter2: how to correctly format a block (indentation) [message #1694111 is a reply to message #1694096] Thu, 30 April 2015 15:00 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
if i knew the aswer i would have answered

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:assigned value will possible override itself
Next Topic:Xtext debugging without Xbase
Goto Forum:
  


Current Time: Tue Apr 23 10:55:10 GMT 2024

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

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

Back to the top