Error when reloading resource from a context menu button before xtend 2 generation [message #1014300] |
Mon, 25 February 2013 14:50 |
Fabian G. Messages: 60 Registered: May 2010 Location: Christchurch (NZ) |
Member |
|
|
Hi,
I'm having a strange issue with my dsl model. I have created a context menu button to generate a text file from a model and it seems I'm retrieving an object with the wrong subtype.
I have a grammar using a external metamodel, where the attribute "name" is defined in a supertype element. Here's a simplified example:
Element :
SubElement1 | SubElement2 | SubElement3;
SomeRule :
name="ID" type=[Element | FQN];
FQN :
ID ('.'ID)*
within xtext APIs, no problem to retrieve the right element subtype. In the button handler (and in the xtend class), the type of the attribute "type" is always resolved as the first one in the Element subtype list (SubElement1, even if it is a SubElement2 ou SubElement3). I tested by removing the first in the list, regenerate xtext artifacts, and then it again resolve to the new first one (so here SubElement2).
Here is the code in the handler where I reload the model (in fact, I reload a model referenced in the selected file, maybe the problem is in the reloading process there...):
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveShell(event);
ISelection sel = HandlerUtil.getActiveMenuSelection(event);
IStructuredSelection selection = (IStructuredSelection) sel;
Object object = selection.getFirstElement();
if (object instanceof IFile && ((IFile) object).getFileExtension().equals("dadt")) {
// get selected file
IFile file = (IFile) object;
XtextResourceSet resourceSet = (XtextResourceSet) injector.getInstance(XtextResourceSetProvider.class).get(file.getProject());
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
// retrieve corresponding dad model
Resource resource = resourceSet.getResource(URI.createURI(file.getLocationURI().toString()), true);
DADTPackage model = (DADTPackage) resource.getContents().get(0);
String dadtfile = file.getLocationURI().toString();
URI dadfile = URI.createURI(dadtfile.substring(0, dadtfile.lastIndexOf("/") + 1) + model.getDadmodel().substring(model.getDadmodel().lastIndexOf(".") + 1) + ".dad");
// load the file as a resource
resource = resourceSet.getResource(dadfile, true);
if (resource != null) {
// some more work in here...
// generate new file
generator.doGenerate(resource, fsa);
}
}
return null;
}
Can someone help me?
Thanks a lot,
Fabian
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03238 seconds