Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » how to create an external cross-reference in the AST
how to create an external cross-reference in the AST [message #1823441] Thu, 26 March 2020 18:50 Go to next message
L R is currently offline L RFriend
Messages: 12
Registered: July 2019
Junior Member
I am attempting to create a model using the model factory. I can create cross-references that link within the AST, but I can not discern how to create an external cross-reference. As an example, using the 15-minute tutorial grammar (https://www.eclipse.org/Xtext/documentation/102_domainmodelwalkthrough.html).

I want to create the following model using the model factory:
entity Test {
	f1 : String
}


In this example "String" is a cross-reference to the datatypes.dmodel. I can create the rest of the model using the following code:
Domainmodel dm = DomainmodelFactory.eINSTANCE.createDomainmodel();
Entity en = DomainmodelFactory.eINSTANCE.createEntity();
dm.getElements().add(en);
en.setName("Test");
Feature fea = DomainmodelFactory.eINSTANCE.createFeature();
en.getFeatures().add(fea);
fea.setName("f1");


The only remaining step is to set fea Type to something using fea.setType(). Ideally, I could create some object, set its name to "String", and then use it for the assignment.

I could envision a process where I search the global scope and find the dataype String in file datatypes.dmodel. This seems like a lot of work to do to just resolve this external cross reference.
Re: how to create an external cross-reference in the AST [message #1823443 is a reply to message #1823441] Thu, 26 March 2020 18:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

do you run in eclipse or standalone? who run the code above?
is there another file with the String already existing?
if you use a resourceset with all resources in standalone mode,
and a resourceset created with IResourceSetProvider.get(iproject) in eclipse and give the resource an uri in that project
then you should be able to ask the scope provider for a (Data)type with the name String


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to create an external cross-reference in the AST [message #1823444 is a reply to message #1823443] Thu, 26 March 2020 19:07 Go to previous messageGo to next message
L R is currently offline L RFriend
Messages: 12
Registered: July 2019
Junior Member
This code would be used as part of a translation from one grammar to another. In this example, String would exist in the datatypes.dmodel file. However, I would not always expect for that file to have been created. (I might be able to constrain that, but would prefer not to.).

Do you know of an example someplace showing how to query the scope provider?
Re: how to create an external cross-reference in the AST [message #1823445 is a reply to message #1823444] Thu, 26 March 2020 19:10 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
so you want to transform both at once?
then you have to use
org.eclipse.xtext.ui.resource.LiveScopeResourceSetInitializer
in eclipse

section on create methods
in https://www.eclipse.org/xtend/documentation/202_xtend_classes_members.html#methods

might also be helpful

you can simply call scopeProvider.getScope(contextObject, Reference)
with context object the objectz holding the reference
and Reference = MyDslPackage.Literals.HOLDINGTYPE_REFERENCENAME

and the call scope.getSingleElement(QualifiedName)

note:
the contextObject needs to be part of the
eresource in the resourceset
at this point in time


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 26 March 2020 19:17]

Report message to a moderator

Previous Topic:Cannot set backtrack to false
Next Topic:Xtext-maven-plugin with sources
Goto Forum:
  


Current Time: Wed Apr 24 19:31:45 GMT 2024

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

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

Back to the top