Xtend generation called but not working in Runtime [message #1719606] |
Sat, 09 January 2016 20:16 |
André Ribeiro Messages: 55 Registered: January 2013 |
Member |
|
|
Hello,
I've followed this Christian Dietrich's tutorial to call the Xtend generator for a Xtext-based DSL from a context menu. My problem is that nothing is generated in the "src-gen" folder, despite the handler associated to the command is being called and executed. I've tested running this in debug mode and the handler is executed without throwing any exceptions.
The only difference to the tutorial is that I've replaced the deprecated EclipseResourceFileSystemAccess by EclipseResourceFileSystemAccess2. I don't know if the problem is related with the EclipseResourceFileSystemAccess2 that could be not properly set.
The code of my handler is the following:
public class GenerationHandler extends AbstractHandler implements IHandler {
@Inject
private IGenerator generator;
@Inject
private Provider<EclipseResourceFileSystemAccess2> fileAccessProvider;
@Inject
IResourceDescriptions resourceDescriptions;
@Inject
IResourceSetProvider resourceSetProvider;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IFile) {
IFile file = (IFile) firstElement;
IProject project = file.getProject();
IFolder srcGenFolder = project.getFolder("src-gen");
if (!srcGenFolder.exists()) {
try {
srcGenFolder.create(true, true,
new NullProgressMonitor());
} catch (CoreException e) {
return null;
}
}
final EclipseResourceFileSystemAccess2 fsa = fileAccessProvider.get();
fsa.setOutputPath(srcGenFolder.getFullPath().toString());
fsa.setMonitor(new NullProgressMonitor());
fsa.setProject(project);
URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
ResourceSet rs = resourceSetProvider.get(project);
Resource r = rs.getResource(uri, true);
generator.doGenerate(r, fsa);
}
}
return null;
}
@Override
public boolean isEnabled() {
return true;
}
}
When I activate the IBuilderParticipant in the plugin.xml the code is properly generated.
Can someone help me with this?
Thank you very much!
André Ribeiro
IST Lisbon
Portugal
|
|
|
|
|
[SOLVED] Re: Xtend generation called but not working in Runtime [message #1719631 is a reply to message #1719619] |
Sun, 10 January 2016 14:46 |
André Ribeiro Messages: 55 Registered: January 2013 |
Member |
|
|
Hi Christian,
You're the best! This worked:
Christian Dietrich wrote on Sun, 10 January 2016 07:28
fsa.setOutputPath("src-gen");
The solution was so simple that I feel a bit ashamed, but to be honest I didn't know how the output directory handling works for EclipseResourceFileSystemAccess2.
Thank you very much!
André Ribeiro
IST Lisbon
Portugal
|
|
|
Powered by
FUDForum. Page generated in 0.01812 seconds