Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [SOLVED] Could we generate code for existing resources without xtext.builder.participant?
[SOLVED] Could we generate code for existing resources without xtext.builder.participant? [message #1739269] Fri, 29 July 2016 04:35 Go to next message
Eclipse UserFriend
Hello everyone,

I have some issues when I try to launch the xtend generator through a main class for existing resources (.extlibrary). It works fine by activating the xtext.builder.participant.

This existing ressources can't be opened with the both of editors (library editor and MyDslEditor), here is the error : mismatched input '<' expecting 'Library'.

FYI: I haven't this kind of issue with the newly created resources which are parsed correctly.

Attached the use case, to reproduce :
1- Import .library, library.edit, library.editor, library.mydsl, library.mydsl.ide and library.mydsl.ui projects in the workspace.
2- Ensure that the line 16 in org.eclipse.emf.examples.library.ui.handlers.XtendGenHandler is not commented in contrast to the line 18.
3- Launch a runtime.
4- Import the LibraryExample project and open My.extlibrary model.
5- Click the green button (xTend generator) in the toolbar.
6- KO: the generator is not started.

You can repeat the above steps to run the generator on the newly created resource (New.extlibrary), comment the line 16 instead 18 in XtendGenHandler class.

Best regards,
Belqassim.

[Updated on: Fri, 29 July 2016 09:42] by Moderator

Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739271 is a reply to message #1739269] Fri, 29 July 2016 04:41 Go to previous messageGo to next message
Eclipse UserFriend
is it intended that you use the same file extension for both?
if yes where is your customization for content types ? (content describer etc?)

[Updated on: Fri, 29 July 2016 04:41] by Moderator

Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739273 is a reply to message #1739271] Fri, 29 July 2016 04:54 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,

Thank you for the quick reply.
Yes I'm using the same extension "extlibrary" for the both of editors, but I can disable the xText editor if this could be problematic.

Here is my ContentTypes configuration

<extension
         point="org.eclipse.core.contenttype.contentTypes">
      <content-type
            base-type="org.eclipse.emf.ecore.xmi"
            file-extensions="extlibrary"
            id="extendedLibrary"
            name="%_UI_EXTLibrary_content_type"
            priority="normal">
         <describer class="org.eclipse.emf.ecore.xmi.impl.RootXMLContentHandlerImpl$Describer">
            <parameter name="namespace" value="http:///org/eclipse/emf/examples/library/extlibrary.ecore/1.0.0"/>
            <parameter name="kind" value="xmi"/>
         </describer>
      </content-type>
   </extension>
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739276 is a reply to message #1739273] Fri, 29 July 2016 05:06 Go to previous messageGo to next message
Eclipse UserFriend
no i mean:

if you use a contenttype for the xmi version, you should use it for the xtext version too.
but you dont. see plugin.xml of yourdsl.ui
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739277 is a reply to message #1739276] Fri, 29 July 2016 05:09 Go to previous messageGo to next message
Eclipse UserFriend
another problem: never never ever call standalonesetup from eclipse
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739279 is a reply to message #1739277] Fri, 29 July 2016 05:13 Go to previous messageGo to next message
Eclipse UserFriend
use val injector = IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(URI.createURI("dummy.extlibrary")).get(Injector)

or inject all the chain to plugin.xml using

<extension
point="org.eclipse.ui.handlers">
<handler
commandId="org.eclipse.emf.examples.library.ui.commands.xtendgenCommand"
class="org.eclipse.emf.examples.library.ui.MyDslExecutableExtensionFactory:org.eclipse.emf.examples.library.ui.handlers.XtendGenHandler">
</handler>
</extension>
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739280 is a reply to message #1739277] Fri, 29 July 2016 05:15 Go to previous messageGo to next message
Eclipse UserFriend
Thank you

[Updated on: Fri, 29 July 2016 05:16] by Moderator

Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739295 is a reply to message #1739279] Fri, 29 July 2016 08:51 Go to previous messageGo to next message
Eclipse UserFriend
I added the contentType to the xtext version too, at the runtime start, I have the following message : Both 'org.eclipse.emf.examples.library' and 'org.eclipse.emf.examples.library.mydsl.ui' register a content parser for 'extendedLibrary'. So the contentType is used for the both of resources.

I use also val injector = IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(URI.createURI("dummy.extlibrary")).get(Injector) instead MyDslStandaloneSetup.

def static main(String[] args, String sourceDirectory) {
		if (args.empty) {
			System::err.println('Aborting: no path to EMF resource provided!')
			return
		}
		val uri = URI.createURI("/LibraryExample/model/My.extlibrary")
		val injector = IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(uri).get(Injector)
		
		val main = injector.getInstance(Main)
		main.runGenerator(args.get(0), sourceDirectory)
	}

	@Inject Provider<ResourceSet> resourceSetProvider

	@Inject IResourceValidator validator

	@Inject GeneratorDelegate generator

	@Inject JavaIoFileSystemAccess fileAccess

	def protected runGenerator(String string, String sourceDirectory) {
		// Load the resource
		val set = resourceSetProvider.get
		val resource = set.getResource(URI.createURI(string), true)

		// Validate the resource
		val issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)
		if (!issues.empty) {
			issues.forEach[System.err.println(it)]
			return
		}

		// Configure and start the generator
		fileAccess.outputPath = sourceDirectory
		val context = new GeneratorContext => [
			cancelIndicator = CancelIndicator.NullImpl
		]
		generator.generate(resource, fileAccess, context)
		System.out.println('Code generation finished.')
	}


But I still have the same error (mismatched input '<' expecting 'Library') and my resource is not parsed.

Do you have some example or documentation for more details please?
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739300 is a reply to message #1739295] Fri, 29 July 2016 09:33 Go to previous messageGo to next message
Eclipse UserFriend
i am not that deep into content types. maybe ed merks can help. i meant something like

<extension
         point="org.eclipse.core.contenttype.contentTypes">
      <content-type
            base-type="org.eclipse.emf.ecore.xmi"
            file-extensions="extlibrary"
            id="extendedLibrary"
            name="%_UI_EXTLibrary_content_type"
            priority="normal">
         <describer class="org.eclipse.emf.examples.library.ui.MyDslContentDescriber">
         </describer>
      </content-type>
   </extension>


	<extension
		point="org.eclipse.ui.editors">
		<editor
			class="org.eclipse.emf.examples.library.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.XtextEditor"
			contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
			default="true"
			id="org.eclipse.emf.examples.library.MyDsl"
			name="MyDsl Editor">
			 <contentTypeBinding contentTypeId="org.eclipse.emf.examples.library.mydsl.ui.extendedLibrary"/>
			
		</editor>
	</extension>

<!-- replaces exsting file ext parser -->
	 <extension point="org.eclipse.emf.ecore.content_parser">
      <parser
            contentTypeIdentifier="extendedLibrary"
            class="org.eclipse.emf.examples.library.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.resource.IResourceFactory"/>
   </extension>


you know there is a URI.createURI(string, contenttype) as well?
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739301 is a reply to message #1739300] Fri, 29 July 2016 09:35 Go to previous messageGo to next message
Eclipse UserFriend
and no i dont have any docs or samples on that.
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739302 is a reply to message #1739301] Fri, 29 July 2016 09:41 Go to previous messageGo to next message
Eclipse UserFriend
I have commented the extension point "org.eclipse.emf.ecore.extension_parser" in my ui/plugin.xml and it works now Smile

Thank you again
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739304 is a reply to message #1739301] Fri, 29 July 2016 09:52 Go to previous messageGo to next message
Eclipse UserFriend
and i missed this one

<!-- replaces existing -->
<extension point="org.eclipse.xtext.content_resourceServiceProvider">
	    <resourceServiceProvider
	        class="org.eclipse.emf.examples.library.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.resource.IResourceUIServiceProvider"
	     contentTypeIdentifier="extendedLibrary">
	    </resourceServiceProvider>
	</extension>
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739305 is a reply to message #1739304] Fri, 29 July 2016 09:53 Go to previous messageGo to next message
Eclipse UserFriend
(am not quite sure when to qualify the contentTypeIdentifier and when not
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739315 is a reply to message #1739305] Fri, 29 July 2016 10:35 Go to previous message
Eclipse UserFriend
It works fine with my actual configuration and I hope I'll not need to change the file once again Wink

When I added this attribute in extension_resourceServiceProvider, the Plugin editor wasn't happy and I have this error "Illegal attribute 'contentTypeIdentifier'", so I left it as it is.

The important thing for me is that my generator works thanks to your help.
Previous Topic:Xtend Code generation for RichStrings (FIXED)
Next Topic:Does it possible to control the highlighting ?
Goto Forum:
  


Current Time: Fri Jul 04 02:58:59 EDT 2025

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

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

Back to the top