How to get Xtext resource [message #1744196] |
Fri, 23 September 2016 06:13  |
Eclipse User |
|
|
|
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 06:14] by Moderator
|
|
|
Re: How to get Xtext resource [message #1744205 is a reply to message #1744196] |
Fri, 23 September 2016 07:06   |
Eclipse User |
|
|
|
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 #1744255 is a reply to message #1744252] |
Fri, 23 September 2016 12:02  |
Eclipse User |
|
|
|
Hi Tu,
the way you have found is the recommended way.
In VIATRA 1.3 we have introduced a new Query Specification Registry that would help you a lot with your use case, as it loads all queries from the workspace, and makes them available programmatically as query specifications, but that is a few versions ahead for you.
Best regards,
Zoltán
|
|
|
Powered by
FUDForum. Page generated in 0.25223 seconds