Skip to main content



      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 10:58 Go to next message
Eclipse UserFriend
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 14:26 Go to previous messageGo to next message
Eclipse UserFriend
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]
	}

[Updated on: Tue, 28 April 2015 14:27] by Moderator

Re: Formatter2: how to correctly format a block (indentation) [message #1693885 is a reply to message #1693852] Wed, 29 April 2015 02:58 Go to previous messageGo to next message
Eclipse UserFriend
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 10:18 Go to previous messageGo to next message
Eclipse UserFriend
ping Smile
Re: Formatter2: how to correctly format a block (indentation) [message #1694111 is a reply to message #1694096] Thu, 30 April 2015 11:00 Go to previous message
Eclipse UserFriend
if i knew the aswer i would have answered
Previous Topic:assigned value will possible override itself
Next Topic:Xtext debugging without Xbase
Goto Forum:
  


Current Time: Sat Jul 19 18:52:11 EDT 2025

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

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

Back to the top