Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cann't get Array Type elements?
Cann't get Array Type elements? [message #1691863] Fri, 10 April 2015 08:31 Go to next message
Bob Tao is currently offline Bob TaoFriend
Messages: 23
Registered: March 2015
Junior Member
Hi all!

I'v know how to define array type grammar, like this:
UclArrayValue:
	'['
		(elements+=UclArrayElement (',' elements+=UclArrayElement)*)?
	']'
;
UclArrayElement:
	INT | STRING |UclObjectValue
;


the language example:
Product prod222
{
	prodID : 222;
	attributes[ "xxx","yyy"  ]; 
}


I can't get the UclArrayValue's elements instance.
my java code is as:
if(value instanceof UclArrayValue)
		{
			ArrayList attValueList=new ArrayList();
			
			UclArrayValue arrayValue=(UclArrayValue)value;
			EList<UclArrayElement> arrayElements=arrayValue.getElements();
			EList<EObject> sss=arrayValue.eContents();
			TreeIterator<EObject> iter=arrayValue.eAllContents();
			while(iter.hasNext())
			{
				EObject eo=iter.next();
				System.out.println(eo.toString());
			}
			for(UclArrayElement ele:arrayElements)
			{
				attValueList.add(ele.toString());
			}
		}

all the APIs can't give me elements list. getElements(),eContents() and eAllContents() return empty EList.

the XText version is 2.7.3.

thanks!
Re: Cann't get Array Type elements? [message #1691877 is a reply to message #1691863] Fri, 10 April 2015 09:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

is UclObjectValue a Object?

if so you may actually want to do

UclArrayElement:
value=AbstractValue
;

AbstractValue:
StringValue | IntValue| UclObjectValue;

IntValue:
value=INT;

StringValue:
value=STRING;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cann't get Array Type elements? [message #1691883 is a reply to message #1691877] Fri, 10 April 2015 09:48 Go to previous message
Bob Tao is currently offline Bob TaoFriend
Messages: 23
Registered: March 2015
Junior Member
Hi Christian,

Yes, UclObjectValue is a Object.
I try the means you provided, which is correct.
I can get the elements value.
Thank you very much!
Previous Topic:xtext-32 bits does not start
Next Topic:RichString in Xbase
Goto Forum:
  


Current Time: Fri Apr 19 04:32:25 GMT 2024

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

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

Back to the top