public static List < Statement > asStatementList ( Statement node ) { if ( node instanceof Block ) { return ( ( Block ) node ) . getStatements ( ) ; } TreeNode parent = node . getParent ( ) ; if ( parent instanceof Block ) { List < Statement > stmts = ( ( Block ) parent ) . getStatements ( ) ; for ( int i = 0 ; i < stmts . size ( ) ; i ++ ) { if ( stmts . get ( i ) == node ) { return stmts . subList ( i , i + 1 ) ; } } } return new LonelyStatementList ( node ) ; }
Returns the given statement as a list of statements that can be added to . If node is a Block then returns it s statement list . If node is the direct child of a Block returns the sublist containing node as the only element . Otherwise creates a new Block node in the place of node and returns its list of statements .