You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2022/11/15 14:54:01 UTC

[groovy] branch master updated: `CastExpression`: indicate coercion in `getText()` and `toString()`

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

emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 9c5bf340b1 `CastExpression`: indicate coercion in `getText()` and `toString()`
9c5bf340b1 is described below

commit 9c5bf340b1bab67485a34b5a4477ea6e90ff43c7
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Nov 15 08:44:51 2022 -0600

    `CastExpression`: indicate coercion in `getText()` and `toString()`
---
 src/main/java/org/codehaus/groovy/ast/expr/CastExpression.java | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/expr/CastExpression.java b/src/main/java/org/codehaus/groovy/ast/expr/CastExpression.java
index b760573d9d..7c35eda473 100644
--- a/src/main/java/org/codehaus/groovy/ast/expr/CastExpression.java
+++ b/src/main/java/org/codehaus/groovy/ast/expr/CastExpression.java
@@ -88,7 +88,7 @@ public class CastExpression extends Expression {
 
     @Override
     public String toString() {
-        return super.toString() +"[(" + getType().getName() + ") " + expression + "]";
+        return super.toString() + "[" + getText() + "]";
     }
 
     @Override
@@ -108,7 +108,10 @@ public class CastExpression extends Expression {
 
     @Override
     public String getText() {
-        return "(" + getType().toString(false) + ") " + expression.getText(); // TODO: add alternate for "as"?
+        if (isCoerce()) {
+            return expression.getText() + " as " + getType().toString(false);
+        }
+        return "(" + getType().toString(false) + ") " + expression.getText();
     }
 
     @Override