[xcore] How to set a class type variable [message #1736545] |
Thu, 30 June 2016 05:38  |
Eclipse User |
|
|
|
I have an xcore file with the following classes:
class Information {
String sName
String birthday
String age
}
class Directory {
String name
String address
contains Information xInfo
}
The variables in the class Directory is set by xtext thru the grammar configuration by the user, except for xInfo. I need to set the xInfo after all the grammar has been read.
The xInfo variable is set during validation. So, I have an xtend method that sets this.
public static val aDirs = new ArrayList<Directory>
public static val aInfo = new ArrayList<Information>
def public setInfo()
{
for (m: aDirs)
{
val x = aInfo.findFirst[m.name.equals(SName)]
if (x != null)
m.xInfo = x //print also shows that this is correctly set.
}
}
def public printInfo()
{
for (m: aDirs)
{
if (m.xInfo == null) // ERROR: m.xInfo is null again!
{
// do nothing
}
}
}
With the two methods above, I called setInfo() and then printInfo(), but in printInfo(), xInfo variable is null again.
aDirs and aInfos are stored during transform.
Am I doing this right? How can we set a class type in xtend?
|
|
|
|
|
|
|
Re: [xcore] How to set a class type variable [message #1736740 is a reply to message #1736665] |
Fri, 01 July 2016 08:00  |
Eclipse User |
|
|
|
Chris,
Comments below.
On 30.06.2016 22:52, chris yo wrote:
> Hi Ed,
>
> I tried to change it to a reference. So my xcore is now like this:
>
>
> class Information {
> String sName
> String birthday
> String age
> }
>
> class Directory {
> String name
> String address
> refers Information xInfo
> }
>
>
> The implementation code stays the same. But I am still getting the
> same problem.
It was never clear to me what your original problem was. I did explain
that validation is not the place to change your model.
> Does it still need its own copy in this case?
No, in this case the Information needs to be contained somewhere else.
In any case, you should set breakpoints and figure out what is going on.
|
|
|
Powered by
FUDForum. Page generated in 0.06656 seconds