Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xbase and Xtext cross references
Xbase and Xtext cross references [message #1699214] Mon, 22 June 2015 15:55 Go to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
I am trying to define values and assertions in a xtext grammar and trying to figure out the best way to resolve variables. I have the following grammar (adapted from the domainmodel example and available here:
Entity:
	'entity' name=ValidID ('extends' superType=JvmParameterizedTypeReference)? '{'
	('features'
		features+=Feature*)?
	('vars' '{'
		vars+=XVariableDeclaration* '}')?
	('check' '{'
		assertExpression+=XExpression* '}')?
	'}';


It allows me to declare something like this:

package bla
{
		entity Foobar {
			vars
			{
				val int foo = 1
				var int bar = 2
			}
			check {foo == bar	 
			}
		}
} 


Problem is I would like to be able to resolve foo and bar inside the check() method (and ultimately reference variables from other entities). As the grammar uses both xtext and xbase, I have several questions:
1. What is the best way to do it? Is there any available class/methods I just have to inject to resolve? Or should I extend/write a new component (tune the scoping of the DSL)? In other words, what is the best way to reference the variable inside the XExpression?
2. When using this grammar, I got an error in the eclipse instance that runs the DSL and an exception in my IDE (see below). Is this is a bug and should I fill a bugreport about that?

Thanks for any help!

Julien.



java.lang.NullPointerException
at org.eclipse.xtext.resource.persistence.PortableURIs.toPortableURI(PortableURIs.java:211)
at org.eclipse.xtext.resource.persistence.ResourceStorageWritable$1.writeURI(ResourceStorageWritable.java:128)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.writeURI(BinaryResourceImpl.java:1697)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveEObject(BinaryResourceImpl.java:1196)
at org.eclipse.xtext.resource.persistence.ResourceStorageWritable$1.saveEObject(ResourceStorageWritable.java:143)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveFeatureValue(BinaryResourceImpl.java:1275)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveFeatureValue(BinaryResourceImpl.java:1246)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveEObject(BinaryResourceImpl.java:1219)
at org.eclipse.xtext.resource.persistence.ResourceStorageWritable$1.saveEObject(ResourceStorageWritable.java:143)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveEObjects(BinaryResourceImpl.java:993)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveFeatureValue(BinaryResourceImpl.java:1283)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveFeatureValue(BinaryResourceImpl.java:1246)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveEObject(BinaryResourceImpl.java:1219)
at org.eclipse.xtext.resource.persistence.ResourceStorageWritable$1.saveEObject(ResourceStorageWritable.java:143)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveEObjects(BinaryResourceImpl.java:993)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveFeatureValue(BinaryResourceImpl.java:1283)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveFeatureValue(BinaryResourceImpl.java:1246)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveEObject(BinaryResourceImpl.java:1219)
at org.eclipse.xtext.resource.persistence.ResourceStorageWritable$1.saveEObject(ResourceStorageWritable.java:143)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveEObjects(BinaryResourceImpl.java:993)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveFeatureValue(BinaryResourceImpl.java:1283)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveFeatureValue(BinaryResourceImpl.java:1246)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveEObject(BinaryResourceImpl.java:1219)
at org.eclipse.xtext.resource.persistence.ResourceStorageWritable$1.saveEObject(ResourceStorageWritable.java:143)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveEObjects(BinaryResourceImpl.java:993)
at org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl$EObjectOutputStream.saveResource(BinaryResourceImpl.java:981)
at org.eclipse.xtext.resource.persistence.ResourceStorageWritable.writeContents(ResourceStorageWritable.java:148)
at org.eclipse.xtext.resource.persistence.ResourceStorageWritable.writeEntries(ResourceStorageWritable.java:91)
at org.eclipse.xtext.xbase.resource.BatchLinkableResourceStorageWritable.writeEntries(BatchLinkableResourceStorageWritable.java:56)
at org.eclipse.xtext.resource.persistence.ResourceStorageWritable.writeResource(ResourceStorageWritable.java:57)
at org.eclipse.xtext.resource.persistence.ResourceStorageFacade.saveResource(ResourceStorageFacade.java:146)
at org.eclipse.xtext.builder.BuilderParticipant.saveResourceStorage(BuilderParticipant.java:612)
at org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:523)
at org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:516)
at org.eclipse.xtext.builder.BuilderParticipant.doGenerate(BuilderParticipant.java:501)
at org.eclipse.xtext.builder.BuilderParticipant.doBuild(BuilderParticipant.java:264)
at org.eclipse.xtext.builder.BuilderParticipant.build(BuilderParticipant.java:222)
at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant$DeferredBuilderParticipant.build(RegistryBuilderParticipant.java:161)
at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:69)
at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:244)
at org.eclipse.xtext.builder.impl.XtextBuilder.incrementalBuild(XtextBuilder.java:222)
at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:117)
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:206)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:299)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:302)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:358)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:381)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Re: Xbase and Xtext cross references [message #1699220 is a reply to message #1699214] Mon, 22 June 2015 16:44 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 22/06/2015 17:55, Julien Delange wrote:
> I am trying to define values and assertions in a xtext grammar and
> trying to figure out the best way to resolve variables. I have the
> following grammar (adapted from the domainmodel example and available here:
> Entity:
> 'entity' name=ValidID ('extends'
> superType=JvmParameterizedTypeReference)? '{'
> ('features'
> features+=Feature*)?
> ('vars' '{'
> vars+=XVariableDeclaration* '}')?
> ('check' '{'
> assertExpression+=XExpression* '}')?
> '}';
>
>
> It allows me to declare something like this:
>
> package bla
> {
> entity Foobar {
> vars
> {
> val int foo = 1
> var int bar = 2
> }
> check {foo == bar }
> }
> }
>
> Problem is I would like to be able to resolve foo and bar inside the
> check() method (and ultimately reference variables from other entities).
> As the grammar uses both xtext and xbase, I have several questions:
> 1. What is the best way to do it? Is there any available class/methods I
> just have to inject to resolve? Or should I extend/write a new component
> (tune the scoping of the DSL)? In other words, what is the best way to
> reference the variable inside the XExpression?
> 2. When using this grammar, I got an error in the eclipse instance that
> runs the DSL and an exception in my IDE (see below). Is this is a bug
> and should I fill a bugreport about that?
>

Hi

if you use Xbase you need to implement a model inferrer that maps your
DSL elements into Java elements; in your case you might want to map
variables in "vars" into fields of the class you infer for Foobar; since
you want these variables to be referred to from other entities, the
mapped fields should be public, for example.

Hope this helps
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: Xbase and Xtext cross references [message #1699358 is a reply to message #1699214] Tue, 23 June 2015 14:52 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
Why should I need to declare a mapping? All what I am using is xbase artifacts: XExpression and Xbase. I do not understand what are the mapping I should do then. Can you elaborate? Also, any idea about the exception?

Thanks again for your help!
Re: Xbase and Xtext cross references [message #1699540 is a reply to message #1699358] Wed, 24 June 2015 21:04 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 23/06/2015 16:52, Julien Delange wrote:
> Why should I need to declare a mapping? All what I am using is xbase
> artifacts: XExpression and Xbase. I do not understand what are the
> mapping I should do then. Can you elaborate? Also, any idea about the
> exception?
>
> Thanks again for your help!

The mapping will put XExpressions into a context (e.g., body of a
method, fields of a class), so that scoping and type checking will work
out of the box...

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: Xbase and Xtext cross references [message #1703301 is a reply to message #1699540] Thu, 30 July 2015 12:00 Go to previous message
Ehsan Ahmad is currently offline Ehsan AhmadFriend
Messages: 1
Registered: July 2015
Junior Member
I am having the same problem.
0 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Registering platform uri 'D:\osate-dev-core\eclipse\workspace'
1419 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Adding URI mapping from 'platform:/plugin/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel' to 'platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.genmodel'
1419 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Adding URI mapping from 'platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel' to 'platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel'
1419 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Adding URI mapping from 'platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel' to 'platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.genmodel'
1419 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Adding URI mapping from 'platform:/plugin/org.eclipse.uml2.types/model/Types.genmodel' to 'platform:/resource/org.eclipse.uml2.types/model/Types.genmodel'
1419 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Adding URI mapping from 'platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel' to 'platform:/resource/org.eclipse.uml2.uml/model/UML.genmodel'
1419 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Adding URI mapping from 'platform:/plugin/org.eclipse.emf.codegen.ecore/model/GenModel.ecore' to 'platform:/resource/org.eclipse.emf.codegen.ecore/model/GenModel.ecore'
1419 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Adding URI mapping from 'platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore' to 'platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore'
1419 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Adding URI mapping from 'platform:/plugin/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore' to 'platform:/resource/org.eclipse.uml2.codegen.ecore/model/GenModel.ecore'
1419 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Adding URI mapping from 'platform:/plugin/org.eclipse.uml2.types/model/Types.ecore' to 'platform:/resource/org.eclipse.uml2.types/model/Types.ecore'
1419 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Adding URI mapping from 'platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore' to 'platform:/resource/org.eclipse.uml2.uml/model/UML.ecore'
1435 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Adding generated EPackage 'org.eclipse.emf.ecore.EcorePackage'
1435 [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher - Problems instantiating module org.osate.hybrid.xtex.GenerateHybrid: java.lang.reflect.InvocationTargetException
java.lang.RuntimeException: Problems instantiating module org.osate.hybrid.xtex.GenerateHybrid: java.lang.reflect.InvocationTargetException
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:95)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:62)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:78)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:36)
Caused by: org.eclipse.emf.common.util.WrappedException: java.lang.reflect.InvocationTargetException
at org.eclipse.emf.mwe2.language.factory.SettingProviderImpl$1$1.setValue(SettingProviderImpl.java:56)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalApplyAssignments(Mwe2ExecutionEngine.java:143)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:296)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:66)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalApplyAssignments(Mwe2ExecutionEngine.java:142)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:296)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:66)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:296)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:66)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.create(Mwe2ExecutionEngine.java:62)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:93)
... 4 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.emf.mwe2.language.factory.SettingProviderImpl$1$1.setValue(SettingProviderImpl.java:54)
... 29 more
Caused by: org.eclipse.emf.mwe.core.ConfigurationException: Couldn't find an interface org.eclipse.uml2.types.TypesPackage
at org.eclipse.emf.mwe.utils.StandaloneSetup.addRegisterGeneratedEPackage(StandaloneSetup.java:430)
... 34 more
I have previously solved this issue by setting some project properties but can't remember this time. My previous project is working perfectly within the same environment (Luna 4.4.2 with Xtext 2.8.3).
Previous Topic:Force specific encoding with IFilesystemAccess
Next Topic:Xbase Scoping to inferred Java elements of the same resource
Goto Forum:
  


Current Time: Tue Mar 19 09:29:02 GMT 2024

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

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

Back to the top