Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Xtend Recursive method issues(Xtend Recursive method issues)
Xtend Recursive method issues [message #1080649] Tue, 06 August 2013 04:02 Go to next message
Ankit Agarwal is currently offline Ankit Agarwal
Messages: 33
Registered: March 2012
Member
Hi,

I have a java class with two methods like :

public List<Node> collectSubNodes(Node node)
{
List<Node> nodeList = new ArrayList<Node>();
collectSubStatesOfState(node, nodeList );
return nodeList ;
}

private void collectSubNodesOfNode(Node node, List<Node> nodeList )
{
if(node!= null)
{
EList<Vertex> subnodes = node.getSubNodes();
for(Vertex vertex : subnodes )
{
if(vertex instanceof Node )
{
Node subNode = (Node )vertex;
nodeList.add(subNode );
collectSubNodesOfNode(subNode, nodeList);
}
}

}
}


I want to write this in an *.ext class, i tried with

cached List[Node ] collectSubNodes(Node this) :
subNodes.typeSelect(Node).addAll(subNodes.typeSelect(Node).collectSubNodes())
;

but i am getting StackOverflow exception, May be it is going in infinite loop.
but i am struggling to write as it is recursive method and should return a list with all the details. Please help me in writing the same.
Re: Xtend Recursive method issues [message #1081031 is a reply to message #1080649] Tue, 06 August 2013 14:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 5861
Registered: July 2009
Senior Member
HI,

i actually cannot reproduce this. sure you have a tree and not a graph?
Re: Xtend Recursive method issues [message #1081392 is a reply to message #1080649] Wed, 07 August 2013 03:11 Go to previous message
Karsten Thoms is currently offline Karsten Thoms
Messages: 353
Registered: July 2009
Location: Dortmund
Senior Member

The method collectSubNodes() calls collectSubStatesOfState(), and not the method collectSubNodesOfNode().

You should write a unit test to test your Java method.


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Previous Topic:[Acceleo] Access to siblings of resource roots
Next Topic:JET2 Transform slow on Mac
Goto Forum:
  


Current Time: Thu Apr 24 14:54:55 EDT 2014

Powered by FUDForum. Page generated in 0.10222 seconds