[SOLVED] Could we generate code for existing resources without xtext.builder.participant? [message #1739269] |
Fri, 29 July 2016 08:35 |
Belqassim Djafer 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 #1739295 is a reply to message #1739279] |
Fri, 29 July 2016 12:51 |
Belqassim Djafer 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 |
|
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
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06078 seconds