Use Xtext infrastructure in standalone application [message #831242] |
Wed, 28 March 2012 16:59 |
Bastian Mueller Messages: 4 Registered: March 2012 |
Junior Member |
|
|
Hi,
I defined a Ecore metamodel and created an Xtext grammar, that is importing it. Now I tried to create a standalone application that is able to load a file. When generating the metamodel from the grammar, it works just fine, but when importing a metamodel, there are issues with registering the generated model code.
I followed the suggestions in the Xtext FAQ ("How do I load my model in a standalone Java application?") and also tried to load the package and register the factory. However, after registering the factory, I get the following error:
Exception in thread "main" java.lang.ClassCastException:
Test.impl.TestFactoryImpl cannot be cast to
org.eclipse.emf.ecore.resource.Resource$Factory
The same problem seems to have been already discussed in the thread 657914
(sorry, the forum doesn't allow me to post links yet...)
Still, there's no solution. Trying the Impl versions of the classes results in the same issue. Right now the code for loading looks like this:
Injector injector = new TestDSLStandaloneSetup()
.createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
TestPackage.eINSTANCE.eClass();
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap()
.put("test", TestFactory.eINSTANCE);
Resource resource =
resourceSet.getResource(URI.createURI("samples/test.test"), true);
System.out.println(resource.getContents().get(0));
I attached a minimum workspace including the 3 projects (metamodel, Xtext grammar and standalone application), to illustrate the issue. It doesn't inlcude the dependencies, due to the size limit (com.google.inject_3.0.0.no_aop.jar, org.eclipse.emf.ecore_2.7.0.v20120127-1122.jar, org.eclipse.emf.common_2.7.0.v20120127-1122.jar, org.eclipse.xtext_2.3.0.v201203201034.jar, org.eclipse.emf.ecore.xmi_2.7.0.v20120127-1122.jar)
Thanks
|
|
|
|
Powered by
FUDForum. Page generated in 0.02651 seconds