public static String convertASTToSource ( ReaderSource readerSource , ASTNode expression ) throws Exception { if ( expression == null ) throw new IllegalArgumentException ( "Null: expression" ) ; StringBuilder result = new StringBuilder ( ) ; for ( int x = expression . getLineNumber ( ) ; x <= expression . getLastLineNumber ( ) ; x ++ ) { String line = readerSource . getLine ( x , null ) ; if ( line == null ) { throw new Exception ( "Error calculating source code for expression. Trying to read line " + x + " from " + readerSource . getClass ( ) ) ; } if ( x == expression . getLastLineNumber ( ) ) { line = line . substring ( 0 , expression . getLastColumnNumber ( ) - 1 ) ; } if ( x == expression . getLineNumber ( ) ) { line = line . substring ( expression . getColumnNumber ( ) - 1 ) ; } //restoring line breaks is important b/c of lack of semicolons result . append ( line ) . append ( ' ' ) ; } String source = result . toString ( ) . trim ( ) ; return source ; }
Converts an expression into the String source . Only some specific expressions like closure expression support this .