Cross reference to duplicate items in the model [message #1803647] |
Wed, 06 March 2019 01:49  |
Eclipse User |
|
|
|
Hello,
When the model has duplicate items, cross reference always goes to the first one or randomly.
I want to achieve cross reference to a particular item based on condition. I have created a sample xtext project.
Grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
conts+=Cont* procs+=Proc*;
Cont:
'Cont' name=ID '{' items+=Item* '}' ;
Item: 'Item' name=ID;
Proc:
'Link' item1=[Item|ID] 'OF' con1=[Cont|ID] 'TO' item2=[Item|ID] 'OF' con2=[Cont|ID]
;
MyDslScopeProvider:
class MyDslScopeProvider extends AbstractMyDslScopeProvider {
override getScope(EObject context, EReference reference) {
if(context instanceof Proc){
if(reference.featureID == MyDslPackage.PROC__ITEM1 || reference.featureID == MyDslPackage.PROC__ITEM2){
val rootElement = EcoreUtil2.getContainerOfType(context, Model);
val candidates = getItems(rootElement)
return Scopes.scopeFor(candidates)
}
}
return super.getScope(context, reference);
}
def List<EObject> getItems(Model model) {
var retList = newArrayList
for(cont : model.conts){
for(item : cont.items){
retList.add(item)
}
}
retList
}
}
Sample Model:
Cont container1 {
Item item1
}
Cont container2 {
Item item1
}
Link item1 OF container1 TO item1 OF container2
In the sample model, I want the cross reference on "item1" to go to correct definition based on container. That means "item1 OF container1" should point to item1 defined in container1 and " item1 OF container2" should point to item1 defined in container2.
Is it possible to achieve?
Kindly help me with this regard.
Thanks and regards,
Virag Purnam
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03560 seconds