Referencing classes from different ecore using qualified names in my DSL [message #1740098] |
Tue, 09 August 2016 08:08 |
Michal Zyla Messages: 18 Registered: August 2016 |
Junior Member |
|
|
Hi
I'm trying to build a dsl with follwing syntax to reference by qualified names EClasses from an ecore defined in seperate file. I',m aiming for the following syntax:
select Epacket1.Epacket2.MyEClass
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate mydsl "mydsl"
Model:
"select" type=[ecore::EClass]
;
Currently I'm confused how should I aproach this. I would by glad for any pointers what should I implement, how should i change my syntax to achieve this.
Regards
Michal
[Updated on: Wed, 22 February 2017 09:51] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Referencing classes from different ecore using qualified names in my DSL [message #1740190 is a reply to message #1740189] |
Wed, 10 August 2016 09:20 |
Michal Zyla Messages: 18 Registered: August 2016 |
Junior Member |
|
|
There is no special project for the dsl files nor a folder on the disk. So i guess it is hanging in the air. I would like I to be in memory if it's possible.
This is the code that creates the ditor:
IResourceSetProvider resourceSetProvider = injector.getInstance(IResourceSetProvider.class);
FileExtensionProvider extensionProvider = injector.getInstance(FileExtensionProvider.class);
ResourceSet resourceSet = resourceSetProvider.get(null);
URI uri = URI.createURI("synthetic:/query." + extensionProvider.getPrimaryFileExtension());
XtextResource xtextResource = (XtextResource) resourceSet.createResource(uri);
resourceSet.getResources().add(xtextResource);
Resource createResource = resourceSet.createResource(URI.createURI("platform:/plugin/my.ecore.plugin/model/model.ecore"));
resourceSet.getResources().add(createResource);
IEditedResourceProvider queryResourceProvider = new IEditedResourceProvider() {
@Override
public XtextResource createResource()
{
return xtextResource;
}
};
EmbeddedEditorFactory editorFactory = injector.getInstance(EmbeddedEditorFactory.class);
QueryHandlerDialog queryHandlerDialog = new QueryHandlerDialog(shell, editorFactory, queryResourceProvider);
int open = queryHandlerDialog.open();
[Updated on: Wed, 10 August 2016 09:28] Report message to a moderator
|
|
|
|
|
|
|
Re: Referencing classes from different ecore using qualified names in my DSL [message #1740197 is a reply to message #1740196] |
Wed, 10 August 2016 11:04 |
|
i had to change the grammar to accept qualified names.
then the following works for me
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
ProjectDescription projectDescription = new ProjectDescription();
projectDescription.setName("dummy");
projectDescription.attachToEmfObject(resourceSet);
Map<String, ResourceDescriptionsData> dataMap = Maps.<String, ResourceDescriptionsData>newHashMap();
final ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(dataMap, resourceSet);
ResourceDescriptionsData data = new ResourceDescriptionsData(Lists.newArrayList());
index.setContainer(projectDescription.getName(), data);
FileExtensionProvider extensionProvider = injector.getInstance(FileExtensionProvider.class);
URI uri = URI.createURI("synthetic:/query." + extensionProvider.getPrimaryFileExtension());
XtextResource xtextResource = (XtextResource) resourceSet.createResource(uri);
resourceSet.getResources().add(xtextResource);
Resource createResource = resourceSet.createResource(
URI.createURI("platform:/plugin/myModel/model/myModel.ecore"));
try {
createResource.load(null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
resourceSet.getResources().add(createResource);
IResourceDescription resourceDescription = IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(createResource.getURI()).getResourceDescriptionManager().getResourceDescription(createResource);
data.addDescription(createResource.getURI(), resourceDescription);
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
Powered by
FUDForum. Page generated in 0.04752 seconds