private void appendConsoleLogging ( Node root ) { if ( logDebug && consoleDebugOutput . size ( ) > 0 ) { // Emit code to call console.log on the client Node node = root ; if ( node . getType ( ) == Token . BLOCK ) { node = node . getFirstChild ( ) ; } if ( node . getType ( ) == Token . SCRIPT ) { if ( source == null ) { // This is non-source build. Modify the AST Node firstNode = node . getFirstChild ( ) ; for ( List < String > entry : consoleDebugOutput ) { Node call = new Node ( Token . CALL , new Node ( Token . GETPROP , Node . newString ( Token . NAME , "console" ) , //$NON-NLS-1$ Node . newString ( Token . STRING , "log" ) //$NON-NLS-1$ ) ) ; for ( String str : entry ) { call . addChildToBack ( Node . newString ( str ) ) ; } node . addChildAfter ( new Node ( Token . EXPR_RESULT , call ) , firstNode ) ; } } else { // Non-source build. Modify the AST for ( List < String > entry : consoleDebugOutput ) { StringBuffer sb = new StringBuffer ( "console.log(" ) ; //$NON-NLS-1$ int i = 0 ; for ( String str : entry ) { sb . append ( ( i ++ == 0 ? "" : "," ) + "\"" + StringUtil . escapeForJavaScript ( str ) + "\"" ) ; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } sb . append ( ");\n" ) ; //$NON-NLS-1$ source . appendln ( sb . toString ( ) ) ; } } } } }
Appends the console log output if any to the end of the module