Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » VIATRA » How to get Xtext resource
How to get Xtext resource [message #1744196] Fri, 23 September 2016 10:13 Go to next message
Minh Tu Ton That is currently offline Minh Tu Ton ThatFriend
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 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
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 Go to previous messageGo to next message
Minh Tu Ton That is currently offline Minh Tu Ton ThatFriend
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

Re: How to get Xtext resource [message #1744252 is a reply to message #1744212] Fri, 23 September 2016 15:33 Go to previous messageGo to next message
Minh Tu Ton That is currently offline Minh Tu Ton ThatFriend
Messages: 17
Registered: January 2015
Junior Member
Well, I found the workaround. Use the

Injector injector = EMFPatternLanguageActivator.getInstance().getInjector(EMFPatternLanguageActivator.ORG_ECLIPSE_INCQUERY_PATTERNLANGUAGE_EMF_EMFPATTERNLANGUAGE);


instead. This avoids the above exception.

Best regards,
Tu
Re: How to get Xtext resource [message #1744255 is a reply to message #1744252] Fri, 23 September 2016 16:02 Go to previous message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
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
Previous Topic:Interface change from IncQuery 0.7 to 0.8
Next Topic:Alternative for RunOnce engine in v1.0.0
Goto Forum:
  


Current Time: Tue Apr 23 12:27:02 GMT 2024

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

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

Back to the top