Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Get textual representation from model
Get textual representation from model [message #1822864] Mon, 16 March 2020 08:12 Go to next message
Loredana Hozan is currently offline Loredana HozanFriend
Messages: 34
Registered: January 2019
Member
Hello,
I have implemented a wizard that builds my dsl file. In the wizard i have implemented an xtext editor (using: https://github.com/cdietrich/mql/blob/master/org.eclipse.xtext.mql.ui/src/org/eclipse/xtext/mqrepl/ui/handler/ModelQueryLanguageDialog.java ) which i need for the implementation of the last part of my dsl file. The issue that i have is, i have created a synthetic resource for the embedded editor, and i have managed to load the properties of the dsl file (name, imported dsl files, global variables) into the dsl instance, but i don't know how to get its textual representation for the editor. The editor should contain only a small part from the file, and i want to be able to use variables and data that should be in the file, but not visible in the editor. I have tried using serialization, but i got
com.google.inject.ConfigurationException: Guice configuration errors: 1) No implementation for org.eclipse.xtext.parsetree.reconstr.IParseTreeConstructor was bound.

and, unfortunately , i am not authorized to make changes to the dsl grammar that i'm using. I also tried to get the textual representation from the file, but i haven't managed to find a way that works, i guess because it's synthetic. There are the options of saving the file and deleting it if the user does not want to save it, or building it manually, but i really don't think these are the best way to do it. So the main question is, how can i get the textual representation from the Instance and use it in the editor?
Re: Get textual representation from model [message #1822868 is a reply to message #1822864] Mon, 16 March 2020 08:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
which ISerializer do you use.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Get textual representation from model [message #1822895 is a reply to message #1822868] Mon, 16 March 2020 13:20 Go to previous messageGo to next message
Loredana Hozan is currently offline Loredana HozanFriend
Messages: 34
Registered: January 2019
Member
i have used the following code:
Injector injectorGuice=new DslStandaloneSetup().createInjectorAndDoEMFRegistration();
Serializer serializer=injectorGuice.getInstance(Serializer.class);
String textualForm=serializer.serialize(dslInstance);

and
Injector injectorGuice=Guice.createInjector(new DslRuntimeModule());
Serializer serializer=injectorGuice.getInstance(Serializer.class);
String textualForm=serializer.serialize(dslInstance);

and i tried : org.eclipse.xtext.parsetree.reconstr.Serializer and org.eclipse.xtext.serializer.impl.Serializer with each implementation;
With the second Serializer, i get a different error, that it can not serialize one of the imported dsl files. The first one gives the error from the first message.
Re: Get textual representation from model [message #1822901 is a reply to message #1822895] Mon, 16 March 2020 13:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
the org.eclipse.xtext.serializer.impl.Serializer
if you create the resourceset and resources correct then it should work.
therefore we would need the detailed error messages


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Get textual representation from model [message #1822923 is a reply to message #1822901] Mon, 16 March 2020 20:49 Go to previous messageGo to next message
Loredana Hozan is currently offline Loredana HozanFriend
Messages: 34
Registered: January 2019
Member
I am implementing the IEditedResourceProvider interface with:
URI resourceUri = URI.createURI("synthetic:/temproraryFile-1.0.0.valid");
XtextResourceSetProvider resourceProvider = (XtextResourceSetProvider) IResourceServiceProvider.Registry.INSTANCE
					.getResourceServiceProvider(resourceUri).get(IResourceSetProvider.class);
resourceSet = resourceProvider.get(ResourcesPlugin.getWorkspace().getRoot().getProject(projectName));
validXtextResource = (XtextResource) resourceSet.createResource(resourceUri);
resourceSet.getResources().add(validXtextResource);

and after that i get the xtextResource and fill it's contents with the dsl properties, in debug i can see that the xtext resource was successfully updated and contains all the properties, but i get the import issue whne i try to serialize.
One interesting thing i have found in the dsl source code is that in the generated class: public class RuleSemanticSequencer extends CommonSemanticSequencer i have :
	EPackage epackage = semanticObject.eClass().getEPackage();
		ParserRule rule = context.getParserRule();
		Action action = context.getAssignedAction();
		Set<Parameter> parameters = context.getEnabledBooleanParameters();
		if (epackage == CommonPackage.eINSTANCE)
			switch (semanticObject.eClass().getClassifierID()) {
                              cases that come from CommonPackage (including the Import of the dsl files that are not of type Rule Dsl Language
                        }
                else if (epackage == RulePackage.eINSTANCE)
			switch (semanticObject.eClass().getClassifierID()) {
                              cases which come from the rule dsl language
                        }

and i think it reads the epackage as Rule and not Common, thus it can not find case of import of a different dsl file, but not sure as i can see that it also goes to a method that returns the dsl import from the common language. This is the error that i get :
java.lang.RuntimeException: Could not serialize ModelImportDeclaration via backtracking.
Constraint:ModelImportDeclaration_VirtualModelImportDeclaration_ModelImportDeclaration returns ModelImportDeclaration: (referenced=[Model|MODEL_FQN] | referenced=[Model|VIRTUAL_MODEL_FQN]);
Values: referenced(1)
Re: Get textual representation from model [message #1822937 is a reply to message #1822923] Tue, 17 March 2020 06:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i have no idea from the information you have and this is something that goes beyond what i can do here.
this is specific to your dsl and so you need to find a specific solution

(referenced=[Model|MODEL_FQN] | referenced=[Model|VIRTUAL_MODEL_FQN]);

is a unusal pattern.



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Get textual representation from model [message #1822939 is a reply to message #1822937] Tue, 17 March 2020 06:55 Go to previous messageGo to next message
Loredana Hozan is currently offline Loredana HozanFriend
Messages: 34
Registered: January 2019
Member
thank you for replying, for now i will try to build the text myself, and i will talk with a member of the dsl team
Re: Get textual representation from model [message #1822944 is a reply to message #1822939] Tue, 17 March 2020 08:10 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

One possible cause of weird things happening is accidental development code; you may have multiple variants of some declarations as a consequence of experimental copies / partial refactorings. These can be completely baffling until you find them; then they are just embarrassing.

Starting again with the minimum that you need in a clean workspace can help avoid the clutter.

Regards

Ed Willink
Previous Topic:Understanding lambdas
Next Topic:Palladio Component Model (PCM) simulations not working in Eclipse
Goto Forum:
  


Current Time: Sat Apr 20 07:38:29 GMT 2024

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

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

Back to the top