Skip to main content



      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 15:17 Go to next message
Eclipse UserFriend
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 15:22 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

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

~Christian

[Updated on: Thu, 10 November 2011 15:23] by Moderator

Re: [xtext2.1] problem implementing custom formatter [message #756092 is a reply to message #756091] Thu, 10 November 2011 15:26 Go to previous message
Eclipse UserFriend
doh! Thanks.
Previous Topic:Problems with multidimensional arrays
Next Topic:[Xtext 2.1] Problems extending Xbase
Goto Forum:
  


Current Time: Tue Jul 08 22:05:14 EDT 2025

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

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

Back to the top