Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Auto format Xtext textual model
Auto format Xtext textual model [message #1858651] Thu, 13 April 2023 14:28 Go to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi,
I am using Java to generate a textual model. While I have defined a custom formatter, the generated files are not automatically formatted. I have to do that manually. Is there a way I can do that automatically in Java for instance?
Re: Auto format Xtext textual model [message #1858654 is a reply to message #1858651] Thu, 13 April 2023 15:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Is there a reason you don't create the model as ast programmatically?

Igöf you have text you need to parse it before you can format it


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Auto format Xtext textual model [message #1858655 is a reply to message #1858654] Thu, 13 April 2023 16:08 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
After selecting the elements that I want from the source model I use the following method in order to create the new file:

private static void save(Element element, ResourceSet resourceSet) throws IOException {
		Package n_p = MyPackageFactory.eINSTANCE.createPackage();
		n_p.getPackagedElement().add(EcoreUtil.copy(element));
		Resource n_r = resourceSet.createResource(URI.createURI( element.getName() + ".text"));
		n_r.getContents().add(n_p);
		n_r.getResourceSet().getResources().add(n_r);
		n_r.save(null);
	}
Re: Auto format Xtext textual model [message #1858656 is a reply to message #1858655] Thu, 13 April 2023 16:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
so the question is totally different: how to i format on resource save
this is easy

n_r.save(SaveOptions.newBuilder().format().getOptions().toOptionsMap());


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Auto format Xtext textual model [message #1858658 is a reply to message #1858656] Thu, 13 April 2023 21:37 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Christian,
Thanks for your help. I tried this out but it did not work :/
Re: Auto format Xtext textual model [message #1858660 is a reply to message #1858658] Fri, 14 April 2023 03:13 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Can you please provide a complete reproducer
Grammar,
Formatter,
Unit test


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:IProposalConflictHelper not respecting Module binding
Next Topic:Design question: resolving dependency between Ecore and builtin types
Goto Forum:
  


Current Time: Fri Mar 29 00:30:23 GMT 2024

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

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

Back to the top