Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 313042

Summary: Improve formatter
Product: [Modeling] EMFT Reporter: Moritz Eysholdt <moritz.eysholdt>
Component: MWEAssignee: Project Inbox <emft-mwe-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: sven.efftinge
Version: 1.0   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Moritz Eysholdt CLA 2010-05-16 15:02:29 EDT
protected void configureFormatting(FormattingConfig c) {
  Mwe2GrammarAccess f = (Mwe2GrammarAccess) getGrammarAccess();

  c.setAutoLinewrap(120);

  // Module
  ModuleElements me = f.getModuleAccess();
  c.setLinewrap(2).between(me.getCanonicalNameAssignment_2(), me.getImportsAssignment_3());
  c.setLinewrap().after(me.getImportsAssignment_3());
  c.setLinewrap(2).between(me.getImportsAssignment_3(), me.getDeclaredPropertiesAssignment_4());
  c.setLinewrap().after(me.getDeclaredPropertiesAssignment_4());
  c.setLinewrap(2).between(me.getDeclaredPropertiesAssignment_4(), me.getRootAssignment_5());

  // A linewrap after each Value. Please note that it is now possible to assign the formatting instruction to the parser rule call. 
  c.setLinewrap().after(f.getValueRule());

  // Parenthesis
  for (Pair<Keyword, Keyword> pair : f.findKeywordPairs("{", "}")) {
    c.setLinewrap().after(pair.getFirst());
    c.setLinewrap().after(pair.getSecond());
    c.setIndentation(pair.getFirst(), pair.getSecond());
    c.setNoSpace().between(pair.getFirst(), pair.getSecond());
  }

  // No space in property refs.
  c.setNoSpace().after(f.getPropertyReferenceAccess().getDollarSignLeftCurlyBracketKeyword_0());
  c.setNoSpace().before(f.getPropertyReferenceAccess().getRightCurlyBracketKeyword_2());

  // Keep some linewraps before/after comments.
  c.setLinewrap(0, 1, 2).before(f.getSL_COMMENTRule());
  c.setLinewrap(0, 1, 2).before(f.getML_COMMENTRule());
  c.setLinewrap(0, 1, 1).after(f.getML_COMMENTRule());
}
Comment 1 Sven Efftinge CLA 2010-08-09 12:32:28 EDT
Is this still valid? What aspect should be improved?
Comment 2 Moritz Eysholdt CLA 2010-08-10 04:14:36 EDT
This ticket was about committing the formatting-config from above to MWE2 since I'm not a committer of MWE. As far as I remember it has been done, even before the Helios release.