Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 313042 - Improve formatter
Summary: Improve formatter
Status: RESOLVED FIXED
Alias: None
Product: EMFT
Classification: Modeling
Component: MWE (show other bugs)
Version: 1.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-16 15:02 EDT by Moritz Eysholdt CLA
Modified: 2010-08-10 04:14 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.