Unit Test with cross-references to an external emf model [message #1781440] |
Wed, 07 February 2018 11:09 |
Chris X Messages: 60 Registered: November 2017 |
Member |
|
|
Hi guys,
I have a similar setup to https://typefox.io/linking-xtext-models-with-other-emf-models. From my language it's possible to refer to elements of an instance of an external emf model.
Reference:
'ref' ref=[ecore::EObject|ID]
This works well!
But I want to do some parsing test without the IDE now.
'''
ref Element1
'''.parse.assertNotNull
So far I build the following class
class MydslWithDependenciesInjectorProvider extends MydslInjectorProvider {
override internalCreateInjector() {
ExternalModelStandaloneSetup.doSetup
return super.internalCreateInjector
}
}
@RunWith(XtextRunner)
@InjectWith(MydslWithDependenciesInjectorProvider)
class ParsingTest {
And the StandaloneSetup of my external model looks like this
class ExternalModelStandaloneSetup implements ISetup {
@Inject
private FileExtensionProvider fileExtensionProvider;
@Inject
private IResourceServiceProvider resourceServiceProvider;
@Inject
private IResourceServiceProvider.Registry registry;
override createInjectorAndDoEMFRegistration() {
val injector = Guice.createInjector(new ExternalmodelRuntimeModule)
injector.injectMembers(this)
for(fileExt: fileExtensionProvider.fileExtensions)
registry.extensionToFactoryMap.put(fileExt, resourceServiceProvider)
// the following implicitly registers the EPackage to the registry
val externalmodelPackage = ExternalmodelPackage.eINSTANCE
return injector
}
def static void doSetup() {
new ExternalModelStandaloneSetup().createInjectorAndDoEMFRegistration()
}
}
But I have no idea how to continue. It would be very nice if someone can give me a small example.
Many thanks!!!
[Updated on: Wed, 07 February 2018 11:11] Report message to a moderator
|
|
|
|
|
|
|
Re: Unit Test with cross-references to an external emf model [message #1781473 is a reply to message #1781472] |
Wed, 07 February 2018 16:47 |
|
no i mean something like in the setups e.g. as it is generated
@SuppressWarnings("all")
public class DomainmodelStandaloneSetupGenerated implements ISetup {
@Override
public Injector createInjectorAndDoEMFRegistration() {
XbaseStandaloneSetup.doSetup();
Injector injector = createInjector();
register(injector);
return injector;
}
public Injector createInjector() {
return Guice.createInjector(new DomainmodelRuntimeModule());
}
public void register(Injector injector) {
if (!EPackage.Registry.INSTANCE.containsKey("http://www.xtext.org/example/Domainmodel")) {
EPackage.Registry.INSTANCE.put("http://www.xtext.org/example/Domainmodel", DomainmodelPackage.eINSTANCE);
}
IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("dmodel", resourceFactory);
IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("dmodel", serviceProvider);
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Unit Test with cross-references to an external emf model [message #1781479 is a reply to message #1781473] |
Wed, 07 February 2018 17:31 |
Chris X Messages: 60 Registered: November 2017 |
Member |
|
|
Hi Christian,
my external model is not generated by a second DSL. It's a separate EMF-Project.
class ExternalmodelStandaloneSetup implements ISetup {
@Inject
private FileExtensionProvider fileExtensionProvider;
@Inject
private IResourceServiceProvider.Registry registry;
override Injector createInjectorAndDoEMFRegistration() {
val Injector injector = createInjector();
register(injector);
return injector;
}
def static void doSetup() {
new ExternalmodelStandaloneSetup().createInjectorAndDoEMFRegistration()
}
def public Injector createInjector() {
return Guice.createInjector(new ExternalmodelRuntimeModule());
}
def public void register(Injector injector) {
if (!EPackage.Registry.INSTANCE.containsKey("http://www.example.com/externmodel/Externmodel")) {
EPackage.Registry.INSTANCE.put("http://www.example.com/externmodel/Externmodel", ExternmodelPackage.eINSTANCE);
}
/* At this point I get the exception: "com.google.inject.ConfigurationException: Guice configuration errors:
1) No implementation for org.eclipse.xtext.resource.IResourceFactory was bound.
while locating org.eclipse.xtext.resource.IResourceFactory */
val resourceFactory = injector.getInstance(IResourceFactory.class);
val serviceProvider = injector.getInstance(IResourceServiceProvider.class);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("externalmodel", resourceFactory);
IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("externalmodel", serviceProvider);
}
In the line "val service Provider ..." I get the following exception (see in code comment)
1) So where do I have to bound the IResourceFactory?
2) And is the Standalonesetup for the externalmodel okay or did I mis something?
3) Is it right that I have to register the factory for the XtextResourceSet? Would it be also okay to register the externalmodel in the Standalonesetup of mydsl?
@All
If someone has a link to an example, then I would be very grateful. I searched for examples but found nothing, only examples for multiple DSLs with cross references like this one https://github.com/szarnekow/testing-multiple-dsls.
Many thanks and sorry for the newbie questions
[Updated on: Wed, 07 February 2018 17:58] Report message to a moderator
|
|
|
Re: Unit Test with cross-references to an external emf model [message #1781489 is a reply to message #1781479] |
Wed, 07 February 2018 19:49 |
|
arrrgggg
from terminal standalonesetup:
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"ecore", new EcoreResourceFactoryImpl());
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"xmi", new XMIResourceFactoryImpl());
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xtextbin"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"xtextbin", new BinaryGrammarResourceFactoryImpl());
if (!EPackage.Registry.INSTANCE.containsKey(XtextPackage.eNS_URI))
EPackage.Registry.INSTANCE.put(XtextPackage.eNS_URI, XtextPackage.eINSTANCE);
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
Re: Unit Test with cross-references to an external emf model [message #1781530 is a reply to message #1781527] |
Thu, 08 February 2018 08:56 |
|
the point is:
your external stuff provides a IResourceSerivce provider for your external metamodel and files. this resourceserviceprovider enables you do refer to this elements from any xtext dsl.
if you want to make sure that this works standalone the code has to ensure
- epackage and resource factory are registered
- the resourceserviceprovider is registered.
both should be done from the standalonesetup you provider
you then can call the standalonesetup from your dsls standalonesetup and or injector provider
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Unit Test with cross-references to an external emf model [message #1781533 is a reply to message #1781530] |
Thu, 08 February 2018 09:20 |
Chris X Messages: 60 Registered: November 2017 |
Member |
|
|
Okay no mistake so far ... most likely:)
Respect to the example of https://github.com/TypeFox/Xtext-XMI "both should be done from the standalonesetup you provider" means:
In the TreeStandalonesetup I have to
1) register the Epackage and create a ResourceFactory for the treemodel and register it
2) register the resource service provider
In the tests package of mydsl create a class
class MydslWithDependenciesInjectorProvider extends MydslInjectorProvider {
override internalCreateInjector() {
TreeStandaloneSetup.doSetup
return super.internalCreateInjector
}
}
and call it in the unit test class/es with:
@InjectWith(MydslWithDependenciesInjectorProvider)
Hope understand you correct...
And many many thanks. I'm really happy about so much help!! You and the other guys do a really greate job !!!
[Updated on: Thu, 08 February 2018 09:34] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04683 seconds