Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Get the value of a reference from Value Converter
Get the value of a reference from Value Converter [message #1102980] Fri, 06 September 2013 09:08 Go to next message
Ashwini Nayak is currently offline Ashwini NayakFriend
Messages: 19
Registered: July 2013
Junior Member
Hello,

I have 2 classes in my xcore, say,
Class A
{
...
}

Class B
{
...
}

In my xtext grammar, I have a rule for each of the classes.

Rule for Class A:
------------------------
A:
"attribute" attribute=AttributeRule
..... //other attributes
B
....//other attributes
;

Here, B is a part of rule, A.


Rule for Class B:
------------------------
B:
..
;

Rule for AttributeRule:
-----------------------
AttributeRule:
..
;




I have a ValueConverter class for the rule, AttributeRule. In my ValueConverter class, I get the values for all the attributes of Rule A, but B is null (even though B is a part of A).
How do I get the value of B from ValueConverter class?

Thanks in advance.

[Updated on: Fri, 06 September 2013 09:11]

Report message to a moderator

Re: Get the value of a reference from Value Converter [message #1103004 is a reply to message #1102980] Fri, 06 September 2013 09:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi are you sure it is a value converter. A value converter converts a
string to a value and vice versa.
Thus it knows nothing of the context. Can you please elaborate a bit
more what you actually try to achieve?

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Get the value of a reference from Value Converter [message #1103021 is a reply to message #1103004] Fri, 06 September 2013 09:53 Go to previous messageGo to next message
Ashwini Nayak is currently offline Ashwini NayakFriend
Messages: 19
Registered: July 2013
Junior Member
For an attribute of rule A, I am using ValueConverter.

ValueConverter class
---------------------
toValue(string val, INode node)
{
...
//do calculation
}


Here, if I do node.getSemanticElement(), I get A. I get the values of all attributes of A here by calling get() method.
I have a method to get B - A.getB() which should return the reference B. But, it returns null.
I am not able to get the reference B.(My Class A has a reference to Class B as told in my previous comment.)

[Updated on: Fri, 06 September 2013 10:07]

Report message to a moderator

Re: Get the value of a reference from Value Converter [message #1103030 is a reply to message #1103021] Fri, 06 September 2013 10:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi is b a cross reference? Is so you have the problem that linking
did not take place at this point. What I still don't understand: why
all the calculation.

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Get the value of a reference from Value Converter [message #1103061 is a reply to message #1103030] Fri, 06 September 2013 10:42 Go to previous messageGo to next message
Ashwini Nayak is currently offline Ashwini NayakFriend
Messages: 19
Registered: July 2013
Junior Member
Hi Christian,

Sorry, the problem I mentioned was not very clear.
I have made an attempt to write it clearly in this comment.

Rule A:
-------
"name" name=ID "{"
"index" index = Index
"type" b=[B]
"}"
;

Rule for Index
--------------
Index:
INT | Double
;

Rule B:
-------
"name" name=ID "{"
"size" size = INT
"}"

ValueConverter class
--------------------
@ValueConverter(rule = "Index")
toValue(String string, INode node){
......
......
}


The data in my editor looks like this:

name A {
index 2.3
type B {
size 1
}
}

Within my toValue() method, I convert the value of 'index' to the required form.
I want to set some value to the 'size' field of B within this method.
And that size value should get reflected in the editor. Is this possible?

I tried to get the reference B from this method. But, it returns null.

Thanks

[Updated on: Fri, 06 September 2013 11:24]

Report message to a moderator

Re: Get the value of a reference from Value Converter [message #1103069 is a reply to message #1103061] Fri, 06 September 2013 10:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Shouldn't that be b=B

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Get the value of a reference from Value Converter [message #1103070 is a reply to message #1103061] Fri, 06 September 2013 10:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Or is it b=[B]

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Get the value of a reference from Value Converter [message #1103095 is a reply to message #1103070] Fri, 06 September 2013 11:22 Go to previous messageGo to next message
Ashwini Nayak is currently offline Ashwini NayakFriend
Messages: 19
Registered: July 2013
Junior Member
Yes. Its is b=[B]
Re: Get the value of a reference from Value Converter [message #1103107 is a reply to message #1103095] Fri, 06 September 2013 11:35 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hmm strange

Can you please share a runnable example grammar and model? Is the b
object contained in A or not.

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtext 2.4.3 is available
Next Topic:Extend Terminal Rule
Goto Forum:
  


Current Time: Thu Apr 25 08:17:57 GMT 2024

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

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

Back to the top