Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Cann't get Array Type elements?
Cann't get Array Type elements? [message #1691863] Fri, 10 April 2015 04:31 Go to next message
Eclipse UserFriend
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 05:25 Go to previous messageGo to next message
Eclipse UserFriend
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;
Re: Cann't get Array Type elements? [message #1691883 is a reply to message #1691877] Fri, 10 April 2015 05:48 Go to previous message
Eclipse UserFriend
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: Sun Jul 13 22:28:03 EDT 2025

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

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

Back to the top