private Node tryFoldTry ( Node n ) { checkState ( n . isTry ( ) , n ) ; Node body = n . getFirstChild ( ) ; Node catchBlock = body . getNext ( ) ; Node finallyBlock = catchBlock . getNext ( ) ; // Removes TRYs that had its CATCH removed and/or empty FINALLY. if ( ! catchBlock . hasChildren ( ) && ( finallyBlock == null || ! finallyBlock . hasChildren ( ) ) ) { n . removeChild ( body ) ; n . replaceWith ( body ) ; reportChangeToEnclosingScope ( body ) ; return body ; } // Only leave FINALLYs if TRYs are empty if ( ! body . hasChildren ( ) ) { NodeUtil . redeclareVarsInsideBranch ( catchBlock ) ; reportChangeToEnclosingScope ( n ) ; if ( finallyBlock != null ) { n . removeChild ( finallyBlock ) ; n . replaceWith ( finallyBlock ) ; } else { n . detach ( ) ; } return finallyBlock ; } return n ; }
Remove try blocks without catch blocks and with empty or not existent finally blocks . Or only leave the finally blocks if try body blocks are empty