Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 313289 - [formatter/api] Allow formatting based on model and parse tree (aka semantic formatting)
Summary: [formatter/api] Allow formatting based on model and parse tree (aka semantic ...
Status: RESOLVED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 1.0.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-18 03:53 EDT by Sven Efftinge CLA
Modified: 2016-07-21 04:17 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Efftinge CLA 2010-05-18 03:53:08 EDT
Currently we only support specifying formatting rules against the grammar. In many common situations it is needed or at least easier to define formatting based on the actual parsed model.
Comment 1 Moritz Eysholdt CLA 2010-05-18 05:42:13 EDT
It would be great to have the current EObject from the semantic model available in the formatter. This would allow to make formatting decisions based on the values of EAttributes, the amounts of values within an EList, etc...

To pass the current AbstractNode to the formatter would be possible, too, but one shouldn't expect too much from it:
- At first, when the formatter is called by the ParseTreeConstructor, some tokens might bot have an AbstractNode. The ParseTreeConstructor is called when XtextResource.save() is called. Some tokens don't have an AbstractNode when the semantic model has been modified *after* it has been created by the parser. E.g. by applying a Quickfix. Furthermore, *no* token will have an AbstractNode if the semantic model has not been created by the parser (e.g. an M2M transformation, EMyPackageFactory or read from XMI).
- At second, the node model isn't needed to "access state of the parser", i.e. to see how the current stack of rule calls looks like. This information is implicitly available since it is possible to assign formatting instructions to rule calls and parser rules.

However, these changes, would break API, so it's probably to late for Helios.
Comment 2 Moritz Eysholdt CLA 2016-07-21 04:17:37 EDT
This does work with the new formatter infrastructure.