Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » how to override and bind ImportUriResolver
how to override and bind ImportUriResolver [message #1736617] Thu, 30 June 2016 15:08 Go to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
I would like to implement different (in house) resolution protocols for the URIs used by the ImportUriGlobalScopeProvider.

I overrided ImportUriGlobalScopeProvider and bound it in my RuntimeModule. However, I do not see how to provide a custom ImportUriResolver to my custom ImportUriGlobalScopeProvider.

thanks in advance for your help
Re: how to override and bind ImportUriResolver [message #1736618 is a reply to message #1736617] Thu, 30 June 2016 15:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14652
Registered: July 2009
Senior Member
adding a simple binding does not work ?


public Class<? extends ImportUriResolver> bindImportUriResolver() {
return MyImportUriResolver.class;
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to override and bind ImportUriResolver [message #1736619 is a reply to message #1736618] Thu, 30 June 2016 15:20 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
Hi, thanks for your help,


Do you mean in the RuntimeModule? If so, there is no method bindImportUriResolver in the superclasses of "AbstractMyDslruntimeModule"

Steve
Re: how to override and bind ImportUriResolver [message #1736620 is a reply to message #1736619] Thu, 30 June 2016 15:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14652
Registered: July 2009
Senior Member
there does not need to be a superclass method

you can add a

public Class<? extends IYourService> bindIYourService() {
return YourServiceImpl.class;
}

as well.

see the docs on the conventions https://www.eclipse.org/Xtext/documentation/302_configuration.html#dependency-injection


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to override and bind ImportUriResolver [message #1736625 is a reply to message #1736620] Thu, 30 June 2016 16:05 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
Thanks a lot it did the trick.
Re: how to override and bind ImportUriResolver [message #1736966 is a reply to message #1736625] Mon, 04 July 2016 17:17 Go to previous messageGo to next message
Serge Lamikhov is currently offline Serge LamikhovFriend
Messages: 26
Registered: May 2016
Junior Member
Hi,

I had a similar problem and resolved it in accordance to the advice above.

It works great in the generated editor, but it looks like MyImportUriResolver is not invoked when parsing is done in tests. My guess is that something is still missing in injection. Would you please advise what should I look for?

Thank you,
Serge
Re: how to override and bind ImportUriResolver [message #1736967 is a reply to message #1736966] Mon, 04 July 2016 17:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14652
Registered: July 2009
Senior Member
where did you add the binding and what do you do in your tests? can you share a reproducable example

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to override and bind ImportUriResolver [message #1736970 is a reply to message #1736967] Mon, 04 July 2016 17:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14652
Registered: July 2009
Senior Member
p.s.: and no MyImportUriResolver will not magically feed the resourceset. you have to add all resources to the resourceset yourself when standalone

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to override and bind ImportUriResolver [message #1736971 is a reply to message #1736967] Mon, 04 July 2016 18:01 Go to previous messageGo to next message
Serge Lamikhov is currently offline Serge LamikhovFriend
Messages: 26
Registered: May 2016
Junior Member
Hi Christian,
I have create a minimalist project to demonstrate the failing test. Please find it attached with this message.
Thank you,
Serge
Re: how to override and bind ImportUriResolver [message #1736973 is a reply to message #1736971] Mon, 04 July 2016 18:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14652
Registered: July 2009
Senior Member
YOur uri converters makes limited sense in a standalone app.

@InjectWith(MyDslInjectorProvider)
class MyDslParsingTest{

	@Inject
	ParseHelper<Model> parseHelper
	@Test 
	def void loadModel() {
		new StandaloneSetup().platformUri = ".."
		URIConverter.URI_MAP.put(URI.createURI("platform:/plugin/org.xtext.example.mydsl/"), URI.createURI("platform:/resource/org.xtext.example.mydsl/"))
		val result = parseHelper.parse('''
           import my1

           usage AAAAA
		''')
		Assert.assertNotNull(result)
		Assert.assertEquals((result.usages.get(0) as Usage).name.name, "AAAAA")
	}
}




Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to override and bind ImportUriResolver [message #1736982 is a reply to message #1736973] Mon, 04 July 2016 19:00 Go to previous messageGo to next message
Serge Lamikhov is currently offline Serge LamikhovFriend
Messages: 26
Registered: May 2016
Junior Member
Thanks a lot!

I also mark question on StackOverflow http://stackoverflow.com/questions/37440304/predefined-definitions-in-xtext-script with reference to this page.
Thank you again,
Serge
Re: how to override and bind ImportUriResolver [message #1738097 is a reply to message #1736982] Fri, 15 July 2016 17:38 Go to previous messageGo to next message
Serge Lamikhov is currently offline Serge LamikhovFriend
Messages: 26
Registered: May 2016
Junior Member
Hi Christian,

Implementation based on ImportUriResolver you helped to resolve works just great in Xtext editor.

I am able to parse and retrieve entities resided in script file and also all referenced entities. Would you please advise how it is possible to retrieve entities resided in 'included' file, but not referenced in the script itself.

For example, in previous example:
           import my1
           usage AAAAA


due to the referencing, AAAAA is appears in parsed Model, but similar un-referenced entity (BBBBB) is not not a part of parsed model.
I am retrieving the model by the following code:
            IXtextDocument xtextDocument = editor.getDocument();
            
            Model model = xtextDocument.readOnly(new IUnitOfWork<Model, XtextResource>() {
                @Override
                public Model exec(XtextResource state) throws Exception {
                    EList<EObject> list = state.getContents();
                    if (list != null && list.size() != 0) {
                        return (Model) state.getContents().get(0);
                    }
                    return null;
                }
            });


Would you please advise what is the proper mechanism to retrieve the whole parsed content? Same question in relation to standalone parsing.

Thank you,
Serge
Re: how to override and bind ImportUriResolver [message #1738099 is a reply to message #1738097] Fri, 15 July 2016 17:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14652
Registered: July 2009
Senior Member
I don't understand this question. The resource contains only the stuff it contains.
You can follow references to other resources.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to override and bind ImportUriResolver [message #1738100 is a reply to message #1738099] Fri, 15 July 2016 17:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14652
Registered: July 2009
Senior Member
Thus you have to read the included file explicitly

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to override and bind ImportUriResolver [message #1738102 is a reply to message #1738100] Fri, 15 July 2016 17:44 Go to previous messageGo to next message
Serge Lamikhov is currently offline Serge LamikhovFriend
Messages: 26
Registered: May 2016
Junior Member
Will it be possible to 'merge' both result models for both script files?
Re: how to override and bind ImportUriResolver [message #1738103 is a reply to message #1738102] Fri, 15 July 2016 17:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14652
Registered: July 2009
Senior Member
Nothing automatic. Xtext has no include semantic. You have to assemble that yoursef

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to override and bind ImportUriResolver [message #1738104 is a reply to message #1738103] Fri, 15 July 2016 17:49 Go to previous message
Serge Lamikhov is currently offline Serge LamikhovFriend
Messages: 26
Registered: May 2016
Junior Member
Understood. Thank you!
Previous Topic:Serialization and concrete syntax validation
Next Topic:Problems Using XText Language in Java project.
Goto Forum:
  


Current Time: Sat Feb 24 14:03:29 GMT 2024

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

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

Back to the top