Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 09:30 Go to next message
Davide G is currently offline Davide GFriend
Messages: 31
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 #1174740 is a reply to message #1174732] Thu, 07 November 2013 09:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13488
Registered: July 2009
Senior Member
Hi,

can you post the exception?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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 Go to previous messageGo to next message
Davide G is currently offline Davide GFriend
Messages: 31
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

Re: [Xtext/Xtend] Issue when calling xtext generator from a context menu [message #1174783 is a reply to message #1174760] Thu, 07 November 2013 10:04 Go to previous messageGo to next message
Davide G is currently offline Davide GFriend
Messages: 31
Registered: October 2013
Member
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 10:14 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13488
Registered: July 2009
Senior Member
Hi,

maybe something gets not injected?
without trace i cannot say.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:absolute windows path of an URI
Next Topic:Customizing Xtext Model
Goto Forum:
  


Current Time: Sat Jul 04 22:49:56 GMT 2020

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

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

Back to the top