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 17:04:00 UTC

[groovy] branch danielsun/tweak-print-try-catch-finally-statement updated: tweak printing property expression

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


The following commit(s) were added to refs/heads/danielsun/tweak-print-try-catch-finally-statement by this push:
     new 056031e  tweak printing property expression
056031e is described below

commit 056031efb37bd907ddff24183287719576c7ad7c
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Jul 25 01:03:32 2021 +0800

    tweak printing property expression
---
 .../groovy/groovy/console/ui/AstNodeToScriptAdapter.groovy |  9 +++++++--
 .../groovy/console/ui/AstNodeToScriptAdapterTest.groovy    | 14 +++++++-------
 2 files changed, 14 insertions(+), 9 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 00fbef8..a2db572 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
@@ -799,7 +799,12 @@ class AstNodeToScriptVisitor implements CompilationUnit.IPrimaryClassNodeOperati
 
     @Override
     void visitPropertyExpression(PropertyExpression expression) {
-        expression?.objectExpression?.visit this
+        if (expression?.objectExpression instanceof VariableExpression) {
+            visitVariableExpression((VariableExpression) expression?.objectExpression, false)
+        } else {
+            expression?.objectExpression?.visit this
+        }
+
         if (expression?.spreadSafe) {
             print '*'
         } else if (expression?.isSafe()) {
@@ -838,8 +843,8 @@ class AstNodeToScriptVisitor implements CompilationUnit.IPrimaryClassNodeOperati
         print expression.text
     }
 
+    @Override
     void visitVariableExpression(VariableExpression expression, boolean spacePad = true) {
-
         if (spacePad) {
             print ' ' + expression.name + ' '
         } else {
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 00bbfa4..6da1763 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
@@ -799,7 +799,7 @@ final class AstNodeToScriptAdapterTest extends GroovyTestCase {
         '''
         String result = compileToScript(script, CompilePhase.SEMANTIC_ANALYSIS)
         assert result.contains('java.lang.Object x = (([4, 5, 6]) as java.lang.String[])')
-        assert result.contains('[1, 2, 3] << new java.lang.Integer[ x .length]')
+        assert result.contains('[1, 2, 3] << new java.lang.Integer[x.length]')
     }
 
     void testSpreadDot() {
@@ -810,8 +810,8 @@ final class AstNodeToScriptAdapterTest extends GroovyTestCase {
         '''
         String result = compileToScript(script, CompilePhase.SEMANTIC_ANALYSIS)
         assert result.contains("java.lang.Object x = [['a': 11, 'b': 12], ['a': 21, 'b': 22]]")
-        assert result.contains('assert x .a == [11, 21] : null')
-        assert result.contains('assert x *.a == [11, 21] : null')
+        assert result.contains('assert x.a == [11, 21] : null')
+        assert result.contains('assert x*.a == [11, 21] : null')
     }
 
     void testSpreadNotationNullHandling() {
@@ -823,9 +823,9 @@ final class AstNodeToScriptAdapterTest extends GroovyTestCase {
 
         String result = compileToScript(script, CompilePhase.SEMANTIC_ANALYSIS)
         assert result.contains("java.lang.Object x = [['a': 11, 'b': 12], ['a': 21, 'b': 22], null]")
-        assert result.contains('assert x *.a == [11, 21, null] : null')
-        assert result.contains('assert x *.a == x.collect({ ')
-        assert result.contains('it ?.a')
+        assert result.contains('assert x*.a == [11, 21, null] : null')
+        assert result.contains('assert x*.a == x.collect({ ')
+        assert result.contains('it?.a')
         assert result.contains('}) : null')
     }
 
@@ -837,7 +837,7 @@ final class AstNodeToScriptAdapterTest extends GroovyTestCase {
         '''
         String result = compileToScript(script, CompilePhase.SEMANTIC_ANALYSIS)
         assert result.contains("java.lang.Object x = [['a': 21, 'b': 22], null, new MyClass()]")
-        assert result.contains("assert x *.a == [21, null, 'abc'] : null")
+        assert result.contains("assert x*.a == [21, null, 'abc'] : null")
     }
 
     void testSpreadNotationForMethodsOnLists() {