@@ -23,7 +23,7 @@ protected CsvBlock(@NotNull ASTNode node, CsvFormattingInfo formattingInfo) {
2323
2424 @ Override
2525 protected List <Block > buildChildren () {
26- List <CsvBlock > blocks = buildChildrenRecursive (getNode ().getFirstChildNode ());
26+ List <CsvBlock > blocks = buildChildrenInternal (getNode ().getFirstChildNode ());
2727 List <Block > result = new ArrayList <>();
2828 CsvColumnInfo currentColumnInfo = null ;
2929 CsvBlockField currentField = null ;
@@ -46,21 +46,27 @@ protected List<Block> buildChildren() {
4646 return result ;
4747 }
4848
49- private List <CsvBlock > buildChildrenRecursive (ASTNode node ) {
49+ private List <CsvBlock > buildChildrenInternal (ASTNode node ) {
50+ List <ASTNode > todoNodes = new ArrayList <>();
51+ todoNodes .add (node );
5052 List <CsvBlock > blocks = new ArrayList <>();
51- while (node != null ) {
53+ while (todoNodes .size () > 0 ) {
54+ node = todoNodes .remove (todoNodes .size () - 1 );
55+ if (node == null ) {
56+ continue ;
57+ }
5258 IElementType elementType = node .getElementType ();
5359 if (elementType == TokenType .ERROR_ELEMENT || elementType == TokenType .BAD_CHARACTER ) {
5460 break ;
5561 }
62+ todoNodes .add (node .getTreeNext ());
5663 if (elementType == CsvTypes .FIELD ) {
5764 blocks .add (new CsvBlockField (node , formattingInfo ));
5865 } else {
5966 CsvBlockElement block = new CsvBlockElement (node , formattingInfo );
6067 blocks .add (block );
61- blocks . addAll ( buildChildrenRecursive ( node .getFirstChildNode () ));
68+ todoNodes . add ( node .getFirstChildNode ());
6269 }
63- node = node .getTreeNext ();
6470 }
6571 return blocks ;
6672 }
0 commit comments