Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Formatting comments
Formatting comments [message #1700394] Thu, 02 July 2015 11:25 Go to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
I was wondering if there is a way to read the document line by line and replace the lines with comments to give them proper indentation.
Is this possible? :
-Read document line by line
-Replace selected parts

Using the old formatting API.
Re: Formatting comments [message #1700411 is a reply to message #1700394] Thu, 02 July 2015 12:55 Go to previous messageGo to next message
aurel pestell is currently offline aurel pestellFriend
Messages: 90
Registered: October 2013
Location: Sweden
Member
I think you can achieve that by adding your own replacer (extending CommentReplacer maybe ?) to that Comment Region.
But you are not using Formatter2 right ?
Re: Formatting comments [message #1700425 is a reply to message #1700411] Thu, 02 July 2015 14:22 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
I am not using formatter2. I am experiencing some problems with it as it doesn't automatically onewhitespace format my document which is something I need. And for example I want to insert a new line after each ';' I don't know how to do that globally without modifying each element's format function. My dsl is big.
Re: Formatting comments [message #1700440 is a reply to message #1700425] Thu, 02 July 2015 15:13 Go to previous messageGo to next message
aurel pestell is currently offline aurel pestellFriend
Messages: 90
Registered: October 2013
Location: Sweden
Member
"I am experiencing some problems with it as it doesn't automatically onewhitespace format my document which is something I need"

I am pretty sure it is possible to achieve that !
Like getting rid of the dispatch method strategy and instead you go through the AST and call the same formatting method on each EObject.
I did something like that for a graph view of a DSL document:

val ti = EcoreUtil.getAllProperContents(resource, false)


protected void doFormat(final Iterator<EObject> ti) {
		while (ti.hasNext()) {
			       EObject eobject = ti.next();
				//TODO: oneSpaceFormat(eobject,document);
				TreeIterator<EObject> subti = eobject.eAllContents();
				EList<EObject> subli = eobject.eCrossReferences();

				if (subti.hasNext()) {
					doFormat(subti);
				}
				if (subli.size() > 0) {
					doFormat(subli.iterator());
				}
		}
	}


I just cleaned and reused code, but I guess it could work like that ?
Re: Formatting comments [message #1700593 is a reply to message #1700440] Sat, 04 July 2015 09:24 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
oneSpaceFormat(eobject,document); Would format each type of eobject specifically?
Re: Formatting comments [message #1700646 is a reply to message #1700593] Mon, 06 July 2015 08:17 Go to previous messageGo to next message
aurel pestell is currently offline aurel pestellFriend
Messages: 90
Registered: October 2013
Location: Sweden
Member
No, it would be one method for all.
Its implementation would be very simple, just something like that as a start:
eobject.append[oneSpace]

Re: Formatting comments [message #1700648 is a reply to message #1700593] Mon, 06 July 2015 08:25 Go to previous messageGo to next message
aurel pestell is currently offline aurel pestellFriend
Messages: 90
Registered: October 2013
Location: Sweden
Member
Sorry I just realized the doFormat code is useless in that case because you can just use the format(EObject eobject, Document doc) method
from the abstractformatter and do your oneSpace formatting. So, very simple.
Stupid from me, sorry again !
Re: Formatting comments [message #1700821 is a reply to message #1700648] Tue, 07 July 2015 12:46 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
I will give it a shot.
Re: Formatting comments [message #1701719 is a reply to message #1700821] Wed, 15 July 2015 08:59 Go to previous message
aurel pestell is currently offline aurel pestellFriend
Messages: 90
Registered: October 2013
Location: Sweden
Member
In 2.8.1, there is org.eclipse.xtext.formatting.impl.OneWhitespaceFormatter. It works well. Have you tried it ?
Previous Topic:[Formatter2] XExpression in a single line only
Next Topic:Xbase in DSL (xtext 2.8)
Goto Forum:
  


Current Time: Tue Apr 23 07:40:58 GMT 2024

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

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

Back to the top