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