[Xtext/Xtend] Issue when calling xtext generator from a context menu [message #1174732] |
Thu, 07 November 2013 04:30  |
Eclipse User |
|
|
|
Hi, I'm having troubles in calling the generator from a context menu. I correctly (i think) set up the plugin file, the handler, everything. When i select the generation command from the context menu the handler is called, but the method doGenerate from filesystemaccess2 class catches an InvocationTargetException. Here's the document with the interest sections from plugin.xml, generationhandler.java and generator xtend file. Can you see something wrong?
Here's the plugin.xml part
<!--
<extension
point="org.eclipse.xtext.builder.participant">
<participant
class="org.cnr.ui.DocgenExecutableExtensionFactory:org.eclipse.xtext.builder.IXtextBuilderParticipant">
</participant>
</extension>
-->
<extension
point="org.eclipse.ui.handlers">
<handler
class="org.cnr.ui.DocgenExecutableExtensionFactory:org.cnr.PassiDocGen.ui.GenerationHandler"
commandId="org.cnr.PassiDocGen.ui.handler.GenerationCommand">
</handler>
</extension>
<extension
point="org.eclipse.ui.commands">
<command name="Generate Code"
id="org.cnr.PassiDocGen.ui.handler.GenerationCommand">
</command>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
<command
commandId="org.cnr.PassiDocGen.ui.handler.GenerationCommand"
style="push">
<visibleWhen
checkEnabled="false">
<iterate>
<adapt type="org.eclipse.core.resources.IResource">
<test property="org.eclipse.core.resources.name"
value="*.mydsl"/>
</adapt>
</iterate>
</visibleWhen>
</command>
</menuContribution>
</extension>
This is the handler method:
@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());
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;
}
And this is the xtend generator method
override void doGenerate(Resource resource, IFileSystemAccess fsa)
{
for (g : resource.allContents.toIterable.filter(Model))
{
fsa.generateFile("salut.txt",g.compile)
}
}
def compile(Model m)
'''
Hello?!?
'''
I hope someone can help me. =\
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08936 seconds