Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 08:35 Go to next message
Belqassim Djafer is currently offline Belqassim DjaferFriend
Messages: 10
Registered: August 2014
Junior Member
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 13:42]

Report message to a 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 08:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
is it intended that you use the same file extension for both?
if yes where is your customization for content types ? (content describer etc?)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 29 July 2016 08:41]

Report message to a 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 08:54 Go to previous messageGo to next message
Belqassim Djafer is currently offline Belqassim DjaferFriend
Messages: 10
Registered: August 2014
Junior Member
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 09:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739277 is a reply to message #1739276] Fri, 29 July 2016 09:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
another problem: never never ever call standalonesetup from eclipse

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739279 is a reply to message #1739277] Fri, 29 July 2016 09:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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>


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739280 is a reply to message #1739277] Fri, 29 July 2016 09:15 Go to previous messageGo to next message
Belqassim Djafer is currently offline Belqassim DjaferFriend
Messages: 10
Registered: August 2014
Junior Member
Thank you

[Updated on: Fri, 29 July 2016 09:16]

Report message to a 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 12:51 Go to previous messageGo to next message
Belqassim Djafer is currently offline Belqassim DjaferFriend
Messages: 10
Registered: August 2014
Junior Member
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 13:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739301 is a reply to message #1739300] Fri, 29 July 2016 13:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
and no i dont have any docs or samples on that.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739302 is a reply to message #1739301] Fri, 29 July 2016 13:41 Go to previous messageGo to next message
Belqassim Djafer is currently offline Belqassim DjaferFriend
Messages: 10
Registered: August 2014
Junior Member
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 13:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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>


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739305 is a reply to message #1739304] Fri, 29 July 2016 13:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
(am not quite sure when to qualify the contentTypeIdentifier and when not

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Could we generate code for existing resources without xtext.builder.participant? [message #1739315 is a reply to message #1739305] Fri, 29 July 2016 14:35 Go to previous message
Belqassim Djafer is currently offline Belqassim DjaferFriend
Messages: 10
Registered: August 2014
Junior Member
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 Apr 19 21:51:48 GMT 2024

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

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

Back to the top