Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Auto format Xtext textual model
Auto format Xtext textual model [message #1858651] Thu, 13 April 2023 10:28 Go to next message
Eclipse UserFriend
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 11:33 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Auto format Xtext textual model [message #1858655 is a reply to message #1858654] Thu, 13 April 2023 12:08 Go to previous messageGo to next message
Eclipse UserFriend
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 12:16 Go to previous messageGo to next message
Eclipse UserFriend
so the question is totally different: how to i format on resource save
this is easy

n_r.save(SaveOptions.newBuilder().format().getOptions().toOptionsMap());
Re: Auto format Xtext textual model [message #1858658 is a reply to message #1858656] Thu, 13 April 2023 17:37 Go to previous messageGo to next message
Eclipse UserFriend
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] Thu, 13 April 2023 23:13 Go to previous message
Eclipse UserFriend
Can you please provide a complete reproducer
Grammar,
Formatter,
Unit test
Previous Topic:IProposalConflictHelper not respecting Module binding
Next Topic:Design question: resolving dependency between Ecore and builtin types
Goto Forum:
  


Current Time: Tue Apr 22 16:48:13 EDT 2025

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

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

Back to the top