How to get Xtext resource [message #1744196] |
Fri, 23 September 2016 10:13 |
Minh Tu Ton That Messages: 17 Registered: January 2015 |
Junior Member |
|
|
Hello,
In IncQuery 0.7, the Xtext resource set is obtained as follows:
Injector injector = new EMFPatternLanguageStandaloneSetup().createInjectorAndDoEMFRegistration();
ResourceSet rs = XmiModelUtil.prepareXtextResource(injector);
Now when I migrate to IncQuery 1.0.0, the XmiModelUtil class does not exist any more. I've tried to get the Xtext resource set from the injector like this:
ResourceSet rs = injector.getInstance(XtextResourceSet.class);
but the following exception keeps popping up:
Quote:ERROR Passed org.eclipse.xtext.builder.clustering.CurrentDescriptions is not based on a resource set
java.lang.IllegalStateException: Passed org.eclipse.xtext.builder.clustering.CurrentDescriptions is not based on a resource set
at org.eclipse.xtext.resource.containers.ResourceSetBasedAllContainersStateProvider.getResourceSet(ResourceSetBasedAllContainersStateProvider.java:44)
at org.eclipse.xtext.resource.containers.ResourceSetBasedAllContainersStateProvider.get(ResourceSetBasedAllContainersStateProvider.java:26)
at org.eclipse.xtext.resource.containers.StateBasedContainerManager.getState(StateBasedContainerManager.java:72)
at org.eclipse.xtext.resource.containers.StateBasedContainerManager.internalGetContainerHandle(StateBasedContainerManager.java:97)
at org.eclipse.xtext.resource.containers.StateBasedContainerManager.getVisibleContainers(StateBasedContainerManager.java:50)
at org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager.isAffected(DefaultResourceDescriptionManager.java:138)
at org.eclipse.xtext.builder.clustering.ClusteringBuilderState.queueAffectedResources(ClusteringBuilderState.java:529)
at org.eclipse.xtext.builder.clustering.ClusteringBuilderState.doUpdate(ClusteringBuilderState.java:304)
at org.eclipse.xtext.builder.builderState.AbstractBuilderState.update(AbstractBuilderState.java:115)
at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:248)
at org.eclipse.xtext.builder.impl.XtextBuilder.incrementalBuild(XtextBuilder.java:228)
at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:123)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:205)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:245)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:300)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:303)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:359)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:382)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Do you have any idea what is the proper way to obtain the Xtext resource set with the new IncQuery API ? Thanks in advance.
Best regards,
Tu
[Updated on: Fri, 23 September 2016 10:14] Report message to a moderator
|
|
|
Re: How to get Xtext resource [message #1744205 is a reply to message #1744196] |
Fri, 23 September 2016 11:06 |
Zoltan Ujhelyi Messages: 392 Registered: July 2015 |
Senior Member |
|
|
Hi Tu,
since EMF-IncQuery 0.8, in the most common cases you do not have to parse eiq files manually as you can rely on the generated matchers/query specifications to evaluate the queries. In other words, if you don't use programmatically created graph patterns, you shouldn't even require to have an XtextResourceSet prepared by IncQuery. Furthermore, unless you use IncQuery in a standalone, Eclipse-less environment, it is generally a bad idea to rely on the StandaloneSetup to get an injector, as it might result in quite hard to debug problems by colliding with other registered services.
In other words, please try to evaluate if you can use the generated IQuerySpecification instead of the pattern specifications in the .eiq files; it should simplify your usage of EMF-IncQuery greatly. If you need some more input, please elaborate on the use case you want to achieve, and I can help with providing more details.
If you really need to use the generic API (start your pattern matching process with an eiq file) in a standalone (Eclipse-less) environment, have a look at the old headless example at https://github.com/viatra/org.eclipse.incquery.examples/tree/master/headless-maven/incquery-demo-generic (this is an external mirror of the now archived org.eclipse.incquery.examples repository; the content is also available using the new VIATRA API in the org.eclipse.viatra.examples repository), where such an example is shown with the EMF-IncQuery API 1.1; it should also work with IncQuery 1.0.
I hope this helps; if not, feel free to ask for more details.
Best regards,
Zoltán
|
|
|
Re: How to get Xtext resource [message #1744212 is a reply to message #1744205] |
Fri, 23 September 2016 11:44 |
Minh Tu Ton That Messages: 17 Registered: January 2015 |
Junior Member |
|
|
Hi Zoltan,
Thank you for your answer.
Indeed, in most of our actual code, eiq files are parsed on the fly, generated matchers and specifications are not used. One use case that justifies for this choice is to maintain a dynamic list of queries that can be applied to our model. A query can be added or removed (e.g. when the current IncQuery project is closed) from this list. Since we do not know the queries created by users in advance, we must parse newly created eiq files.
Now to migrate to the new version of IncQuery without refactoring too much our current code, do you have any suggestion? I suppose that the given example only works on standalone application?
Best regards,
Tu
[Updated on: Fri, 23 September 2016 11:52] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03142 seconds