Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [Xtext/Xtend] Issue when calling xtext generator from a context menu(doGenerate() method from filesystemaccess2 class catches an InvocationTargetException)
[Xtext/Xtend] Issue when calling xtext generator from a context menu [message #1174732] Thu, 07 November 2013 04:30 Go to next message
Eclipse UserFriend
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 #1174740 is a reply to message #1174732] Thu, 07 November 2013 04:31 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

can you post the exception?
Re: [Xtext/Xtend] Issue when calling xtext generator from a context menu [message #1174760 is a reply to message #1174740] Thu, 07 November 2013 04:50 Go to previous messageGo to next message
Eclipse UserFriend
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 04:51] by Moderator

Re: [Xtext/Xtend] Issue when calling xtext generator from a context menu [message #1174783 is a reply to message #1174760] Thu, 07 November 2013 05:04 Go to previous messageGo to next message
Eclipse UserFriend
Update: i replaced filesystemaccess2 with the old,deprecated filesystemaccess, and now it works! How can this be possible??
Re: [Xtext/Xtend] Issue when calling xtext generator from a context menu [message #1174796 is a reply to message #1174783] Thu, 07 November 2013 05:14 Go to previous message
Eclipse UserFriend
Hi,

maybe something gets not injected?
without trace i cannot say.
Previous Topic:absolute windows path of an URI
Next Topic:Customizing Xtext Model
Goto Forum:
  


Current Time: Mon Jul 07 08:15:05 EDT 2025

Powered by FUDForum. Page generated in 0.08936 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top