Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Opening Xbase-using Xtext models programmatically
Opening Xbase-using Xtext models programmatically [message #777743] Wed, 11 January 2012 00:07 Go to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 365
Registered: July 2015
Senior Member
Hi,

we are creating an Xbase-using DSL that we would like to open outside the builder. However, opening the file using the traditional EMF Resource API results in a "java.net.MalformedURLException: unknown protocol: java" exception. I also tried to open the model using the Sample Reflective Editor (as suggested in the Xtext FAQ: http://wiki.eclipse.org/Xtext/FAQ#How_can_I_load_my_model_in_the_EMF_reflective_model_editor.C2.A0.3F), with similar results.

The exception is thrown, when my model inferrer tries to ask for the JVMType of a Java class. The code generator works as expected, it finds the referenced type and the generated class looks as expected.

I could reproduce the same issue using the domain model example as well (without any modification).

My question is how to open an Xbase-using DSL both programmatically (e.g. what needs to be registered for the Java type resolving to work) and also in the Sample Reflective Editor (if possible).

Thank you for your help,
Zoltan
Re: Opening Xbase-using Xtext models programmatically [message #778126 is a reply to message #777743] Wed, 11 January 2012 12:54 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3107
Registered: July 2009
Senior Member
Hi Zoltan,

please make sure that your resource set was configured properly, e.g. by
using the IResourceSetProvider

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 11.01.12 01:07, schrieb Zoltan Ujhelyi:
> Hi,
>
> we are creating an Xbase-using DSL that we would like to open outside
> the builder. However, opening the file using the traditional EMF
> Resource API results in a "java.net.MalformedURLException: unknown
> protocol: java" exception. I also tried to open the model using the
> Sample Reflective Editor (as suggested in the Xtext FAQ:
> http://wiki.eclipse.org/Xtext/FAQ#How_can_I_load_my_model_in_the_EMF_reflective_model_editor.C2.A0.3F),
> with similar results.
>
> The exception is thrown, when my model inferrer tries to ask for the
> JVMType of a Java class. The code generator works as expected, it finds
> the referenced type and the generated class looks as expected.
>
> I could reproduce the same issue using the domain model example as well
> (without any modification).
>
> My question is how to open an Xbase-using DSL both programmatically
> (e.g. what needs to be registered for the Java type resolving to work)
> and also in the Sample Reflective Editor (if possible).
>
> Thank you for your help,
> Zoltan
Re: Opening Xbase-using Xtext models programmatically [message #778217 is a reply to message #778126] Wed, 11 January 2012 18:23 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 365
Registered: July 2015
Senior Member
Hi Sebastian,

thanks for your quick answer. Using IResourceSetProvider I managed to open the model; however, the resulting code depends on UI projects (the interface itself is defined in the org.eclipse.xtext.ui project).

For our usage this is not the best direction, we also want to use the parser in a headless environment, but with Eclipse plug-ins available (so e.g. EMF packages are registered using activators; eclipse extensions are available).

Following the direction I initialized a standalone setup, and then asked for the corresponding resource set using the following code:

Injector injector = new EMFPatternLanguageStandaloneSetup()
.createInjectorAndDoEMFRegistration();
if (file == null)
return null;

ResourceSet resourceSet = injector.getInstance(ResourceSet.class);
URI fileURI = URI.createPlatformResourceURI(file.getFullPath()
.toString(), false);
Resource resource = resourceSet.getResource(fileURI, true);

My question would be whether this shall work in all cases, or this setup might cause some issues in the future (e.g. is it any problem that the createInjectorAndDoEMFRegistration method are called multiple times?

Thank you again,
Zoltán Ujhelyi
Re: Opening Xbase-using Xtext models programmatically [message #813094 is a reply to message #778217] Sun, 04 March 2012 20:45 Go to previous message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 365
Registered: July 2015
Senior Member
Hi all,

to answer my own question, after some research I found out that it is not a good idea to re-create the Injectors using the StandaloneSetup class, as singleton objects could be instantiated multiple times.

Instead, in Eclipse GUI environments the correct usage seems to instantiate the extensions using the generated ExecutedExtensionFactory class from the UI project: that allows directly injecting various Xtext-related components using @Inject annotations directly.

For example usage, see the generated extensions of a default Xtext editor (in the UI project).

Zoltán Ujhelyi
Previous Topic:Disabling the generation of GUI contributions of a parent language
Next Topic:[Xtend] How to do equivalent of java Class.forName(String className)
Goto Forum:
  


Current Time: Thu Apr 02 16:55:15 GMT 2020

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

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

Back to the top