Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Null attribute values in cross-reference from other file
Null attribute values in cross-reference from other file [message #1821729] Wed, 19 February 2020 09:01 Go to next message
kolchanov Mising name is currently offline kolchanov Mising nameFriend
Messages: 20
Registered: October 2011
Junior Member
I need help with I hope simple cross reference issue.
My test grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Model:
     (imports+=Import)?
     section=Section   
;
FQN: ID ("." ID)*;
Import:
	'import' importURI=[Section|STRING];

Section: 'section' name=STRING
	items+= (Entity  | Dictionary | Rule)*	;

Entity:        'entity' name=ID;
Dictionary:
        'RecommendedValues' 'for' entity=[Entity|FQN]
        '[' values+= RecommendedValueItem+ ']' ;
RecommendedValueItem:   name=STRING;

Rule:
        'Selected' 'value' 'for' entity=[Entity|FQN] 'in' '[' (values+=Value)? ']';

Value:
	value1=[RecommendedValueItem|FQN] '->' value2 [RecommendedValueItem|FQN];


Scope Provider:
@Override
	public IScope getScope(EObject context, EReference ref) {

		if (ref == MyDslPackage.Literals.VALUE__VALUE1) {
 			if (context instanceof Entity) {
 				// Entity from the same has valid name value
 				// Entity from different file has null name value
				System.out.println (((Entity) context).getName());
			}
		}	
		
		return super.getScope(context, ref);
	}

DSL files:
section "base"
entity E1
entity E2
RecommendedValues for E1 [ "V1" "V2"]
RecommendedValues for E2 [ "V3" "V4"]


import "base"

section "rules"
entity Local
RecommendedValues for Local [ "L1" "L2"]
Selected value for Local in [ L1 -> L2 ]


I need get name attribute for Entity from different file, but it has null value.
Re: Null attribute values in cross-reference from other file [message #1821732 is a reply to message #1821729] Wed, 19 February 2020 09:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
the question makes no sense to me

- to have import uri you have to enable that in global scoping
- if (ref == MyDslPackage.Literals.VALUE__VALUE1) { if (context instanceof Entity) { can never be true
-maybe you mean instanceof Dictionary.
- context may be Value so you might have to walk up the tree manally in scoping (depending on content assist/build)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Null attribute values in cross-reference from other file [message #1821734 is a reply to message #1821732] Wed, 19 February 2020 09:25 Go to previous messageGo to next message
kolchanov Mising name is currently offline kolchanov Mising nameFriend
Messages: 20
Registered: October 2011
Junior Member
- "to have import uri you have to enable that in global scoping"
I have not enabled global scoping because I still don't now how to do this.
-"maybe you mean instanceof Dictionary"
It is indeed Entity. I've checked this one in debug many times.
- "context may be Value so you might have to walk up the tree manally in scoping"
This is my goal but I can't because Entity attrs are null.

I have vanilla project with only two modified files: MyDsl.xtext and MyDslScopeProvider
Re: Null attribute values in cross-reference from other file [message #1821735 is a reply to message #1821734] Wed, 19 February 2020 09:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Entity: 'entity' name=ID;

=> there is no enity in context.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Null attribute values in cross-reference from other file [message #1821737 is a reply to message #1821735] Wed, 19 February 2020 10:22 Go to previous messageGo to next message
kolchanov Mising name is currently offline kolchanov Mising nameFriend
Messages: 20
Registered: October 2011
Junior Member
=> there is no enity in context.

I've published the whole project to https://github.com/kolchanov/org.xtext.example.mydsl.parent

Eclipse DSL Tools
Version: 2019-12 (4.14.0)

Xtend SDK
Version: 2.20.0.v20191202-1256
Build id: 20191202-1153
Re: Null attribute values in cross-reference from other file [message #1821738 is a reply to message #1821735] Wed, 19 February 2020 10:28 Go to previous messageGo to next message
kolchanov Mising name is currently offline kolchanov Mising nameFriend
Messages: 20
Registered: October 2011
Junior Member
Please ignore this link.
I'll update this topic later after global scoping configuration
Re: Null attribute values in cross-reference from other file [message #1821750 is a reply to message #1821738] Wed, 19 February 2020 14:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
the scope provider in the example differs from the one in the post - but i dont get any NPEs

RecommendedValues for base.E2 [ "V3" "V4"]

=> i assume the problem in you not implementing/fixing the global scoping


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Null attribute values in cross-reference from other file [message #1821754 is a reply to message #1821750] Wed, 19 February 2020 15:24 Go to previous messageGo to next message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 177
Registered: July 2009
Location: Canada
Senior Member
Hi,

Hitting content assist in your DSL editor shows you a list of items (IEObjectDescription instances) to choose from. The value of the reference (entity in the Rule) is set after you have chosen an item from the list.

In your Scope provider, you are printing the Entity name. The Entity reference is not yet initialized, which is why the value returned is null.

Put a breakpoint at the 37 in your scope provider implementation and inspect the Rule instance, and you'll understand what I am trying to say.



Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Re: Null attribute values in cross-reference from other file [message #1821790 is a reply to message #1821754] Thu, 20 February 2020 08:01 Go to previous messageGo to next message
kolchanov Mising name is currently offline kolchanov Mising nameFriend
Messages: 20
Registered: October 2011
Junior Member
I have a stupid question -
Is it possible to force reference initialization ?
Re: Null attribute values in cross-reference from other file [message #1821791 is a reply to message #1821790] Thu, 20 February 2020 08:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
it happens automatically if your scoping config is right.
so does your problem happen
-standlone
-eclipse?
- did you do adaptions for global scoping


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Null attribute values in cross-reference from other file [message #1821806 is a reply to message #1821791] Thu, 20 February 2020 12:40 Go to previous messageGo to next message
kolchanov Mising name is currently offline kolchanov Mising nameFriend
Messages: 20
Registered: October 2011
Junior Member
Thank you for your attention.

Currently I have no problem with simplified grammar but have with real grammar.
So I trying to reproduce the issue.
Re: Null attribute values in cross-reference from other file [message #1821811 is a reply to message #1821791] Thu, 20 February 2020 13:20 Go to previous message
kolchanov Mising name is currently offline kolchanov Mising nameFriend
Messages: 20
Registered: October 2011
Junior Member
Thank you for your attention.

Currently I have no problem with simplified grammar but have with real grammar.
So I trying to reproduce the issue.
Previous Topic:Using Xtext DSL as a rule engine on runtime
Next Topic:XText maven build fails out of the box
Goto Forum:
  


Current Time: Thu Apr 25 15:03:31 GMT 2024

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

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

Back to the top