Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [xtext2.1] problem implementing custom formatter(How to re-create formatting as displayed in the IDE?)
[xtext2.1] problem implementing custom formatter [message #756090] Thu, 10 November 2011 20:17 Go to next message
Scott Finnie is currently offline Scott FinnieFriend
Messages: 94
Registered: October 2011
Member
I would like to implement a formatter that emulates the IDE default. e.g newline after semicolon, 2 space indentation after opening brace, etc.

So firstly: is there a quick way to achieve this?

As a first step I tried un-commenting the three rules in the auto-generated class as follows:

public class OoaFormatter extends AbstractDeclarativeFormatter {
	
   @Override
   protected void configureFormatting(FormattingConfig c) {
		
// It's usually a good idea to activate the following three statements.
// They will add and preserve newlines around comments
   c.setLinewrap(0, 1, 2).before(getGrammarAccess().getSL_COMMENTRule());
   c.setLinewrap(0, 1, 2).before(getGrammarAccess().getML_COMMENTRule());
   c.setLinewrap(0, 1, 1).after(getGrammarAccess().getML_COMMENTRule());
   }
}


However this generates an error in the IDE for each of the three calls to setLineWrap:

The method getML_COMMENTRule() is undefined for the type IGrammarAccess


So I looked at the docs and tried the code there:

  
//...
  @Override
  protected void configureFormatting(FormattingConfig c) {
    OoaGrammarAccess f = getGrammarAccess(); //error
//...  


However the call to getGrammarAccess() produces another error:

Type mismatch: cannot convert from IGrammarAccess to OoaGrammarAccess 


Before I chase this down I'd appreciate any suggestions on how best to proceed. Examples especially appreciated.

Thanks.
Re: [xtext2.1] problem implementing custom formatter [message #756091 is a reply to message #756090] Thu, 10 November 2011 20:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

a downcast to OoaGrammarAccess doesnt work?
(see domainmodel example)

~Christian


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

[Updated on: Thu, 10 November 2011 20:23]

Report message to a moderator

Re: [xtext2.1] problem implementing custom formatter [message #756092 is a reply to message #756091] Thu, 10 November 2011 20:26 Go to previous message
Scott Finnie is currently offline Scott FinnieFriend
Messages: 94
Registered: October 2011
Member
doh! Thanks.
Previous Topic:Problems with multidimensional arrays
Next Topic:[Xtext 2.1] Problems extending Xbase
Goto Forum:
  


Current Time: Fri Apr 19 01:31:23 GMT 2024

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

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

Back to the top