Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » firstChild attribute.
firstChild attribute. [message #757708] Mon, 21 November 2011 10:20 Go to next message
haceface is currently offline hacefaceFriend
Messages: 5
Registered: November 2011
Junior Member
Hey,

I would like to get the firstChild attribute of the INode but i just can't find a way how.

public void provideHighlightingFor(final XtextResource resource, IHighlightedPositionAcceptor acceptor) {
		if( resource == null || resource.getParseResult() == null ) return;
		 
		INode root = resource.getParseResult().getRootNode();
		BidiTreeIterator<INode> it = root.getAsTreeIterable().iterator();
		while( it.hasNext() )
		{
			INode node = it.next();
			if ( node instanceof CompositeNodeWithSemanticElement && node.getSemanticElement() instanceof Object
					) {
				setStyles( acceptor, it, OBJECT_ST);
				setStyles( acceptor, node.getAsTreeIterable().reverse().iterator(), null, OBJECT_ST );
			} 
			else if ( node instanceof CompositeNodeWithSemanticElement && node.getSemanticElement() instanceof Array) {
				setStyles( acceptor, it, ARRAY_ST);
				setStyles( acceptor, node.getAsTreeIterable().reverse().iterator(), null, ARRAY_ST );
			} 
			else if( node instanceof CompositeNodeWithSemanticElement  && node.getSemanticElement() instanceof mainObjectType)
			{
				setStyles( acceptor, it, OBJECT_TP);
                                ???//node.getfirstChild()???
			}
		}
	}


Do you know what's the problem with my code since i can't use it. thank you.
Re: firstChild attribute. [message #758202 is a reply to message #757708] Tue, 22 November 2011 10:23 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
I don't know what you are actually trying to do but there's usually _no_
need to cast the implementation classes for nodes. Please use INode,
ICompositeNode and ILeafNode. They do what they promise in the javadocs.
ICompositeNode#getFirstChild is probably what you are looking for. Please
note there #getLastChild, too.

Regards,
Sebastian
--
Need professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

On Mon, 21 Nov 2011 11:20:19 +0100, haceface <forums-noreply@eclipse.org>
wrote:

> Hey,
>
> I would like to get the firstChild attribute of the INode but i just
> can't find a way how. public void provideHighlightingFor(final
> XtextResource resource, IHighlightedPositionAcceptor acceptor) {
> if( resource == null || resource.getParseResult() == null ) return;
> INode root = resource.getParseResult().getRootNode();
> BidiTreeIterator<INode> it = root.getAsTreeIterable().iterator();
> while( it.hasNext() )
> {
> INode node = it.next();
> if ( node instanceof CompositeNodeWithSemanticElement &&
> node.getSemanticElement() instanceof Object
> ) {
> setStyles( acceptor, it, OBJECT_ST);
> setStyles( acceptor, node.getAsTreeIterable().reverse().iterator(),
> null, OBJECT_ST );
> } else if ( node instanceof CompositeNodeWithSemanticElement &&
> node.getSemanticElement() instanceof Array) {
> setStyles( acceptor, it, ARRAY_ST);
> setStyles( acceptor, node.getAsTreeIterable().reverse().iterator(),
> null, ARRAY_ST );
> } else if( node instanceof CompositeNodeWithSemanticElement &&
> node.getSemanticElement() instanceof mainObjectType)
> {
> setStyles( acceptor, it, OBJECT_TP);
> ???//node.getfirstChild()???
> }
> }
> }
>
> Do you know what's the problem with my code since i can't use it. thank
> you.
Previous Topic:xpand extension with xpand doesnt work as expected?
Next Topic:Grammar & Scoping Pattern for variables, functions
Goto Forum:
  


Current Time: Tue Apr 23 14:37:45 GMT 2024

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

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

Back to the top