groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] 03/04: GROOVY-9183: refactor to simplify (closes #1109)
Date Mon, 02 Dec 2019 01:47:19 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 58bd3aca889d708c0c96e240a3db0baebbfa410e
Author: Paul King <paulk@asert.com.au>
AuthorDate: Mon Dec 2 11:41:16 2019 +1000

    GROOVY-9183: refactor to simplify (closes #1109)
---
 .../codehaus/groovy/transform/NamedVariantASTTransformation.java | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
b/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
index 9316a07..146ad7f 100644
--- a/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
@@ -49,6 +49,7 @@ import static org.apache.groovy.ast.tools.ClassNodeUtils.addGeneratedConstructor
 import static org.apache.groovy.ast.tools.ClassNodeUtils.addGeneratedMethod;
 import static org.apache.groovy.ast.tools.ClassNodeUtils.isInnerClass;
 import static org.apache.groovy.ast.tools.VisibilityUtils.getVisibility;
+import static org.codehaus.groovy.antlr.PrimitiveHelper.getDefaultValueForPrimitive;
 import static org.codehaus.groovy.ast.ClassHelper.MAP_TYPE;
 import static org.codehaus.groovy.ast.ClassHelper.STRING_TYPE;
 import static org.codehaus.groovy.ast.ClassHelper.boolean_TYPE;
@@ -205,13 +206,7 @@ public class NamedVariantASTTransformation extends AbstractASTTransformation
{
     }
 
     private Expression getDefaultExpression(ClassNode pType) {
-        if (isPrimitiveType(pType)) {
-            if (boolean_TYPE.equals(pType)) {
-                return constX(Boolean.FALSE);
-            }
-            return castX(getWrapper(pType), constX(0));
-        }
-        return nullX();
+        return Optional.ofNullable(getDefaultValueForPrimitive(pType)).orElse(nullX());
     }
 
     private boolean hasDuplicates(final MethodNode mNode, final List<String> propNames,
final String next) {


Mime
View raw message