[Xtext/Xtend] Issue when calling xtext generator from a context menu [message #1174732] |
Thu, 07 November 2013 09:30 |
Davide G Messages: 36 Registered: October 2013 |
Member |
|
|
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. =\
|
|
|
|
Re: [Xtext/Xtend] Issue when calling xtext generator from a context menu [message #1174760 is a reply to message #1174740] |
Thu, 07 November 2013 09:50 |
Davide G Messages: 36 Registered: October 2013 |
Member |
|
|
Hi christian, the problem is that i can't get any output from eclipse. When i debug the code from handler and step from doGenerate method, it goes to this block of code of MethodRequestor.java class ("execute" method):
catch (InvocationTargetException e) {
Throwable originalException = e.getCause();
throw new InjectionException((originalException != null) ? originalException : e);
} finally {
I also noticed that the project field for fsa was null, by nothing changed adding
fsa.setProjet(Project);
before calling doGenerate
[Updated on: Thu, 07 November 2013 09:51] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05083 seconds