You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/07/24 16:43:45 UTC

[groovy] branch danielsun/tweak-print-try-catch-finally-statement created (now f79168f)

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a change to branch danielsun/tweak-print-try-catch-finally-statement
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at f79168f  tweak printing try-catch-finally statement

This branch includes the following new commits:

     new f79168f  tweak printing try-catch-finally statement

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[groovy] 01/01: tweak printing try-catch-finally statement

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch danielsun/tweak-print-try-catch-finally-statement
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit f79168f0747efe36cf24d0382d235fd5ba3503a3
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Jul 25 00:43:10 2021 +0800

    tweak printing try-catch-finally statement
---
 .../groovy/groovy/console/ui/AstNodeToScriptAdapter.groovy | 14 ++++++++------
 .../groovy/console/ui/AstNodeToScriptAdapterTest.groovy    |  9 +++++++++
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstNodeToScriptAdapter.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstNodeToScriptAdapter.groovy
index d1c3330..00fbef8 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstNodeToScriptAdapter.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstNodeToScriptAdapter.groovy
@@ -992,13 +992,15 @@ class AstNodeToScriptVisitor implements CompilationUnit.IPrimaryClassNodeOperati
         statement?.catchStatements?.each { CatchStatement catchStatement ->
             visitCatchStatement(catchStatement)
         }
-        print 'finally { '
-        printLineBreak()
-        indented {
-            statement?.finallyStatement?.visit this
+        if (statement?.finallyStatement !instanceof EmptyStatement) {
+            print 'finally { '
+            printLineBreak()
+            indented {
+                statement?.finallyStatement?.visit this
+            }
+            print '} '
+            printLineBreak()
         }
-        print '} '
-        printLineBreak()
     }
 
     @Override
diff --git a/subprojects/groovy-console/src/test/groovy/groovy/console/ui/AstNodeToScriptAdapterTest.groovy b/subprojects/groovy-console/src/test/groovy/groovy/console/ui/AstNodeToScriptAdapterTest.groovy
index 89b6354..00bbfa4 100644
--- a/subprojects/groovy-console/src/test/groovy/groovy/console/ui/AstNodeToScriptAdapterTest.groovy
+++ b/subprojects/groovy-console/src/test/groovy/groovy/console/ui/AstNodeToScriptAdapterTest.groovy
@@ -661,6 +661,15 @@ final class AstNodeToScriptAdapterTest extends GroovyTestCase {
         assert result.contains('catch (java.lang.Exception e) {')
         assert result.contains('catch (java.lang.RuntimeException e) {')
         assert result.contains('finally {')
+
+        script = '''\
+            try {
+                println 123
+            } catch (e) {
+                println 234
+            }'''
+        result = compileToScript(script, CompilePhase.SEMANTIC_ANALYSIS)
+        assert !result.contains('finally {')
     }
 
     void testSuperAndThisCalls() {