groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] branch master updated: GROOVY-9153: follow-up refactor - further cases which could cause issues down the track
Date Tue, 06 Aug 2019 05:50:42 GMT
This is an automated email from the ASF dual-hosted git repository.

paulk 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 73314d6  GROOVY-9153: follow-up refactor - further cases which could cause issues
down the track
73314d6 is described below

commit 73314d6291ff64a00e91fd3cf351cd7ef69cf7cd
Author: Paul King <paulk@asert.com.au>
AuthorDate: Tue Aug 6 15:50:11 2019 +1000

    GROOVY-9153: follow-up refactor - further cases which could cause issues down the track
---
 src/main/java/groovy/util/logging/Commons.java               |  4 +++-
 src/main/java/groovy/util/logging/Log.java                   |  4 +++-
 src/main/java/groovy/util/logging/Log4j.java                 |  4 +++-
 src/main/java/groovy/util/logging/Log4j2.java                |  4 +++-
 src/main/java/groovy/util/logging/Slf4j.java                 |  4 +++-
 .../java/org/codehaus/groovy/antlr/AntlrParserPlugin.java    |  8 +++++---
 .../java/org/codehaus/groovy/ast/decompiled/Annotations.java |  4 +++-
 .../groovy/ast/decompiled/MemberSignatureParser.java         |  4 +++-
 .../java/org/codehaus/groovy/ast/stmt/AssertStatement.java   | 12 ++++++++----
 .../java/org/codehaus/groovy/ast/stmt/ReturnStatement.java   |  4 +++-
 .../java/org/codehaus/groovy/ast/tools/GeneralUtils.java     |  4 ++++
 .../org/codehaus/groovy/classgen/asm/AssertionWriter.java    | 11 +++++++----
 .../groovy/classgen/asm/sc/StaticInvocationWriter.java       |  3 ++-
 .../groovy/transform/AutoCloneASTTransformation.java         |  5 +++--
 .../codehaus/groovy/transform/FieldASTTransformation.java    |  3 ++-
 .../org/codehaus/groovy/transform/LazyASTTransformation.java |  3 ++-
 .../groovy/transform/TupleConstructorASTTransformation.java  | 11 +++++++++--
 .../groovy/transform/stc/StaticTypeCheckingVisitor.java      |  1 -
 src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java     |  4 +++-
 .../parser/antlr4/TryWithResourcesASTTransformation.java     |  3 ++-
 20 files changed, 71 insertions(+), 29 deletions(-)

diff --git a/src/main/java/groovy/util/logging/Commons.java b/src/main/java/groovy/util/logging/Commons.java
index ef7e381..3f7c950 100644
--- a/src/main/java/groovy/util/logging/Commons.java
+++ b/src/main/java/groovy/util/logging/Commons.java
@@ -38,6 +38,8 @@ import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 import java.util.Locale;
 
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+
 /**
  * This local transform adds a logging ability to your program using
  * Apache Commons logging. Every method call on a unbound variable named <i>log</i>
@@ -109,7 +111,7 @@ public @interface Commons {
             return new TernaryExpression(
                     new BooleanExpression(condition),
                     originalExpression,
-                    ConstantExpression.NULL);
+                    nullX());
         }
    }
 }
diff --git a/src/main/java/groovy/util/logging/Log.java b/src/main/java/groovy/util/logging/Log.java
index f99d278..b9414c8 100644
--- a/src/main/java/groovy/util/logging/Log.java
+++ b/src/main/java/groovy/util/logging/Log.java
@@ -41,6 +41,8 @@ import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 import java.util.Locale;
 
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+
 /**
  * This local transform adds a logging ability to your program using
  * java.util.logging. Every method call on a unbound variable named <i>log</i>
@@ -121,7 +123,7 @@ public @interface Log {
             return new TernaryExpression(
                     new BooleanExpression(condition),
                     originalExpression,
-                    ConstantExpression.NULL);
+                    nullX());
 
         }
     }
diff --git a/src/main/java/groovy/util/logging/Log4j.java b/src/main/java/groovy/util/logging/Log4j.java
index 1db7bf9..34b75b3 100644
--- a/src/main/java/groovy/util/logging/Log4j.java
+++ b/src/main/java/groovy/util/logging/Log4j.java
@@ -39,6 +39,8 @@ import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 import java.util.Locale;
 
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+
 /**
  * This local transform adds a logging ability to your program using
  * Log4j logging. Every method call on a unbound variable named <i>log</i>
@@ -121,7 +123,7 @@ public @interface Log4j {
             return new TernaryExpression(
                     new BooleanExpression(condition),
                     originalExpression,
-                    ConstantExpression.NULL);
+                    nullX());
         }
     }
 }
diff --git a/src/main/java/groovy/util/logging/Log4j2.java b/src/main/java/groovy/util/logging/Log4j2.java
index d9a8a8a..0d4e20f 100644
--- a/src/main/java/groovy/util/logging/Log4j2.java
+++ b/src/main/java/groovy/util/logging/Log4j2.java
@@ -38,6 +38,8 @@ import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 import java.util.Locale;
 
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+
 /**
  * This local transform adds a logging ability to your program using
  * Log4j2 logging. Every method call on a unbound variable named <i>log</i>
@@ -109,7 +111,7 @@ public @interface Log4j2 {
             return new TernaryExpression(
                     new BooleanExpression(condition),
                     originalExpression,
-                    ConstantExpression.NULL);
+                    nullX());
         }
     }
 }
diff --git a/src/main/java/groovy/util/logging/Slf4j.java b/src/main/java/groovy/util/logging/Slf4j.java
index 4f7da07..9760caa 100644
--- a/src/main/java/groovy/util/logging/Slf4j.java
+++ b/src/main/java/groovy/util/logging/Slf4j.java
@@ -38,6 +38,8 @@ import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 import java.util.Locale;
 
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+
 /**
  * This local transform adds a logging ability to your program using
  * LogBack logging. Every method call on a unbound variable named <i>log</i>
@@ -109,7 +111,7 @@ public @interface Slf4j {
             return new TernaryExpression(
                     new BooleanExpression(condition),
                     originalExpression,
-                    ConstantExpression.NULL);
+                    nullX());
         }
     }
 
diff --git a/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java b/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
index c8f97d4..e3f6abb 100644
--- a/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
+++ b/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
@@ -131,6 +131,8 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
 
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+
 /**
  * A parser plugin which adapts the JSR Antlr Parser to the Groovy runtime
  */
@@ -1443,7 +1445,7 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin,
Groovy
         if (node != null) {
             messageExpression = expression(node);
         } else {
-            messageExpression = ConstantExpression.NULL;
+            messageExpression = nullX();
         }
         AssertStatement assertStatement = new AssertStatement(booleanExpression, messageExpression);
         configureAST(assertStatement, assertNode);
@@ -1617,7 +1619,7 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin,
Groovy
         //if (exprNode == null) {
         //    exprNode = node.getNextSibling();
         //}
-        Expression expression = exprNode == null ? ConstantExpression.NULL : expression(exprNode);
+        Expression expression = exprNode == null ? nullX() : expression(exprNode);
         ReturnStatement returnStatement = new ReturnStatement(expression);
         configureAST(returnStatement, node);
         return returnStatement;
@@ -2810,7 +2812,7 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin,
Groovy
 
     protected Expression blockExpression(AST node) {
         AST codeNode = node.getFirstChild();
-        if (codeNode == null) return ConstantExpression.NULL;
+        if (codeNode == null) return nullX();
         if (codeNode.getType() == EXPR && codeNode.getNextSibling() == null) {
             // Simplify common case of {expr} to expr.
             return expression(codeNode);
diff --git a/src/main/java/org/codehaus/groovy/ast/decompiled/Annotations.java b/src/main/java/org/codehaus/groovy/ast/decompiled/Annotations.java
index 07f0f63..9415ddc 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/Annotations.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/Annotations.java
@@ -33,6 +33,8 @@ import java.lang.reflect.Array;
 import java.util.List;
 import java.util.Map;
 
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+
 class Annotations {
     static AnnotationNode createAnnotationNode(AnnotationStub annotation, AsmReferenceResolver
resolver) {
         ClassNode classNode = resolver.resolveClassNullable(Type.getType(annotation.className).getClassName());
@@ -70,7 +72,7 @@ class Annotations {
 
         if (value instanceof AnnotationStub) {
             AnnotationNode annotationNode = createAnnotationNode((AnnotationStub) value,
resolver);
-            return annotationNode != null ? new AnnotationConstantExpression(annotationNode)
: ConstantExpression.NULL;
+            return annotationNode != null ? new AnnotationConstantExpression(annotationNode)
: nullX();
         }
 
         if (value != null && value.getClass().isArray()) {
diff --git a/src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java b/src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java
index 0cefbe2..dd73433 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java
@@ -34,6 +34,8 @@ import org.objectweb.asm.signature.SignatureVisitor;
 import java.util.List;
 import java.util.Map;
 
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+
 /**
  * Utility methods for lazy class loading
  */
@@ -134,7 +136,7 @@ class MemberSignatureParser {
                 result.setAnnotationDefault(true);
             } else {
                 // Seems wrong but otherwise some tests fail (e.g. TestingASTTransformsTest)
-                result.setCode(new ReturnStatement(ConstantExpression.NULL));
+                result.setCode(new ReturnStatement(nullX()));
             }
 
         }
diff --git a/src/main/java/org/codehaus/groovy/ast/stmt/AssertStatement.java b/src/main/java/org/codehaus/groovy/ast/stmt/AssertStatement.java
index 2adab38..363e5ac 100644
--- a/src/main/java/org/codehaus/groovy/ast/stmt/AssertStatement.java
+++ b/src/main/java/org/codehaus/groovy/ast/stmt/AssertStatement.java
@@ -23,6 +23,8 @@ import org.codehaus.groovy.ast.expr.BooleanExpression;
 import org.codehaus.groovy.ast.expr.ConstantExpression;
 import org.codehaus.groovy.ast.expr.Expression;
 
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+
 /**
  * Represents an assert statement.
  * E.g.:
@@ -34,16 +36,16 @@ public class AssertStatement extends Statement {
 
     private BooleanExpression booleanExpression;
     private Expression messageExpression;
-    
+
     public AssertStatement(BooleanExpression booleanExpression) {
-        this(booleanExpression, ConstantExpression.NULL);
+        this(booleanExpression, nullX());
     }
-    
+
     public AssertStatement(BooleanExpression booleanExpression, Expression messageExpression)
{
         this.booleanExpression = booleanExpression;
         this.messageExpression = messageExpression;
     }
-    
+
     public void visit(GroovyCodeVisitor visitor) {
         visitor.visitAssertStatement(this);
     }
@@ -55,9 +57,11 @@ public class AssertStatement extends Statement {
     public BooleanExpression getBooleanExpression() {
         return booleanExpression;
     }
+
     public void setBooleanExpression(BooleanExpression booleanExpression) {
         this.booleanExpression = booleanExpression;
     }
+
     public void setMessageExpression(Expression messageExpression) {
         this.messageExpression = messageExpression;
     }
diff --git a/src/main/java/org/codehaus/groovy/ast/stmt/ReturnStatement.java b/src/main/java/org/codehaus/groovy/ast/stmt/ReturnStatement.java
index bfa34d8..432fe63 100644
--- a/src/main/java/org/codehaus/groovy/ast/stmt/ReturnStatement.java
+++ b/src/main/java/org/codehaus/groovy/ast/stmt/ReturnStatement.java
@@ -22,6 +22,8 @@ import org.codehaus.groovy.ast.GroovyCodeVisitor;
 import org.codehaus.groovy.ast.expr.ConstantExpression;
 import org.codehaus.groovy.ast.expr.Expression;
 
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+
 /**
  * A return statement
  */
@@ -30,7 +32,7 @@ public class ReturnStatement extends Statement {
      * Only used for synthetic return statements emitted by the compiler.
      * For comparisons use isReturningNullOrVoid() instead.
      */
-    public static final ReturnStatement RETURN_NULL_OR_VOID = new ReturnStatement(ConstantExpression.NULL);
+    public static final ReturnStatement RETURN_NULL_OR_VOID = new ReturnStatement(nullX());
 
     private Expression expression;
     
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
index 6050500..aec0b5d 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
@@ -693,6 +693,10 @@ public class GeneralUtils {
         return new BinaryExpression(lhv, NE, rhv);
     }
 
+    public static Expression nullX() {
+        return new ConstantExpression(null);
+    }
+
     public static BooleanExpression notNullX(Expression argExpr) {
         return new BooleanExpression(new BinaryExpression(argExpr, NE, new ConstantExpression(null)));
     }
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/AssertionWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/AssertionWriter.java
index 2200c30..b25fed6 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/AssertionWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/AssertionWriter.java
@@ -67,10 +67,9 @@ public class AssertionWriter {
     public void writeAssertStatement(AssertStatement statement) {
         MethodVisitor mv = controller.getMethodVisitor();
         OperandStack operandStack = controller.getOperandStack();
-        
-        boolean rewriteAssert = true;
+
         // don't rewrite assertions with message
-        rewriteAssert = statement.getMessageExpression() == ConstantExpression.NULL;
+        boolean rewriteAssert = isNull(statement.getMessageExpression());
         AssertionTracker oldTracker = assertionTracker;
         Janitor janitor = new Janitor();
         final Label tryStart = new Label();
@@ -149,7 +148,11 @@ public class AssertionWriter {
         // power asserts
         janitor.cleanup();
     }
-    
+
+    private boolean isNull(Expression messageExpression) {
+        return messageExpression instanceof ConstantExpression && ((ConstantExpression)
messageExpression).isNullExpression();
+    }
+
     private void writeSourcelessAssertText(AssertStatement statement) {
         MethodVisitor mv = controller.getMethodVisitor();
         OperandStack operandStack = controller.getOperandStack();
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
index 9539b53..1d0c6e7 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
@@ -75,6 +75,7 @@ import static org.apache.groovy.ast.tools.ClassNodeUtils.samePackageName;
 import static org.codehaus.groovy.ast.ClassHelper.CLOSURE_TYPE;
 import static org.codehaus.groovy.ast.ClassHelper.OBJECT_TYPE;
 import static org.codehaus.groovy.ast.ClassHelper.getWrapper;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
 import static org.codehaus.groovy.transform.sc.StaticCompilationMetadataKeys.PRIVATE_BRIDGE_METHODS;
 import static org.codehaus.groovy.transform.stc.StaticTypesMarker.PARAMETER_TYPE;
 import static org.objectweb.asm.Opcodes.ACONST_NULL;
@@ -258,7 +259,7 @@ public class StaticInvocationWriter extends InvocationWriter {
                     }
                 }
             }
-            ArgumentListExpression newArgs = new ArgumentListExpression(target.isStatic()?new
ConstantExpression(null):fixedReceiver);
+            ArgumentListExpression newArgs = new ArgumentListExpression(target.isStatic()
? nullX() : fixedReceiver);
             for (Expression expression : args.getExpressions()) {
                 newArgs.addExpression(expression);
             }
diff --git a/src/main/java/org/codehaus/groovy/transform/AutoCloneASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/AutoCloneASTTransformation.java
index fd967dc..4e5809e 100644
--- a/src/main/java/org/codehaus/groovy/transform/AutoCloneASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/AutoCloneASTTransformation.java
@@ -73,6 +73,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.ifS;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.isInstanceOfX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.isOrImplements;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.localVarX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.param;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.params;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.propX;
@@ -216,11 +217,11 @@ public class AutoCloneASTTransformation extends AbstractASTTransformation
{
     }
 
     private static Expression callCloneDynamicX(Expression target) {
-        return callX(INVOKER_TYPE, "invokeMethod", args(target, constX("clone"), ConstantExpression.NULL));
+        return callX(INVOKER_TYPE, "invokeMethod", args(target, constX("clone"), nullX()));
     }
 
     private static Expression callCloneDirectX(Expression direct) {
-        return ternaryX(equalsNullX(direct), ConstantExpression.NULL, callX(direct, "clone"));
+        return ternaryX(equalsNullX(direct), nullX(), callX(direct, "clone"));
     }
 
     private static void createSimpleClone(ClassNode cNode, List<FieldNode> fieldNodes,
List<String> excludes) {
diff --git a/src/main/java/org/codehaus/groovy/transform/FieldASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/FieldASTTransformation.java
index 4deb112..7cee52a 100644
--- a/src/main/java/org/codehaus/groovy/transform/FieldASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/FieldASTTransformation.java
@@ -58,6 +58,7 @@ import static org.apache.groovy.util.BeanUtils.capitalize;
 import static org.codehaus.groovy.ast.ClassHelper.make;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.assignX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.block;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.param;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.params;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.propX;
@@ -171,7 +172,7 @@ public class FieldASTTransformation extends ClassCodeExpressionTransformer
imple
                     // TODO make EmptyExpression work
                     // partially works but not if only thing in script
                     // return EmptyExpression.INSTANCE;
-                    return new ConstantExpression(null);
+                    return nullX();
                 }
                 addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script
body.", expr);
                 return expr;
diff --git a/src/main/java/org/codehaus/groovy/transform/LazyASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/LazyASTTransformation.java
index aeaa58d..f8767c0 100644
--- a/src/main/java/org/codehaus/groovy/transform/LazyASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/LazyASTTransformation.java
@@ -54,6 +54,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.declS;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.ifElseS;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.localVarX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.notNullX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.param;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.params;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.propX;
@@ -68,7 +69,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.varX;
 public class LazyASTTransformation extends AbstractASTTransformation {
 
     private static final ClassNode SOFT_REF = makeWithoutCaching(SoftReference.class, false);
-    private static final Expression NULL_EXPR = ConstantExpression.NULL;
+    private static final Expression NULL_EXPR = nullX();
 
     public void visit(ASTNode[] nodes, SourceUnit source) {
         init(nodes, source);
diff --git a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
index 8dd0f7a..1422fe7 100644
--- a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
@@ -33,6 +33,7 @@ import org.codehaus.groovy.ast.ConstructorNode;
 import org.codehaus.groovy.ast.FieldNode;
 import org.codehaus.groovy.ast.Parameter;
 import org.codehaus.groovy.ast.PropertyNode;
+import org.codehaus.groovy.ast.expr.BooleanExpression;
 import org.codehaus.groovy.ast.expr.ClosureExpression;
 import org.codehaus.groovy.ast.expr.ConstantExpression;
 import org.codehaus.groovy.ast.expr.Expression;
@@ -73,6 +74,8 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.equalsNullX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.getAllProperties;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.ifElseS;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.ifS;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.isNullX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.params;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.propX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt;
@@ -298,14 +301,18 @@ public class TupleConstructorASTTransformation extends AbstractASTTransformation
     }
 
     private static Expression providedOrDefaultInitialValue(FieldNode fNode) {
-        Expression initialExp = fNode.getInitialExpression() != null ? fNode.getInitialExpression()
: ConstantExpression.NULL;
+        Expression initialExp = fNode.getInitialExpression() != null ? fNode.getInitialExpression()
: nullX();
         final ClassNode paramType = fNode.getType();
-        if (ClassHelper.isPrimitiveType(paramType) && initialExp.equals(ConstantExpression.NULL))
{
+        if (ClassHelper.isPrimitiveType(paramType) && isNull(initialExp)) {
             initialExp = primitivesInitialValues.get(paramType.getTypeClass());
         }
         return initialExp;
     }
 
+    private static boolean isNull(Expression exp) {
+        return exp instanceof ConstantExpression && ((ConstantExpression) exp).isNullExpression();
+    }
+
     public static void addSpecialMapConstructors(int modifiers, ClassNode cNode, String message,
boolean addNoArg) {
         Parameter[] parameters = params(new Parameter(LHMAP_TYPE, "__namedArgs"));
         BlockStatement code = new BlockStatement();
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 6963641..37a3c58 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -325,7 +325,6 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
 
     protected final ReturnAdder.ReturnStatementListener returnListener = new ReturnAdder.ReturnStatementListener()
{
         public void returnStatementAdded(final ReturnStatement returnStatement) {
-            if (returnStatement.getExpression() == ConstantExpression.NULL) return;
             if (isNullConstant(returnStatement.getExpression())) return;
             checkReturnType(returnStatement);
             if (typeCheckingContext.getEnclosingClosure() != null) {
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
index 2b48db4..c8dda68 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
@@ -61,6 +61,8 @@ import java.lang.reflect.WildcardType;
 import java.security.Permission;
 import java.util.List;
 
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+
 /**
  * java 5 based functions
  */
@@ -358,7 +360,7 @@ public class Java5 implements VMPlugin {
 
     private static void setMethodDefaultValue(MethodNode mn, Method m) {
         Object defaultValue = m.getDefaultValue();
-        ConstantExpression cExp = ConstantExpression.NULL;
+        ConstantExpression cExp = (ConstantExpression) nullX();
         if (defaultValue!=null) cExp = new ConstantExpression(defaultValue);
         mn.setCode(new ReturnStatement(cExp));
         mn.setAnnotationDefault(true);
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/TryWithResourcesASTTransformation.java
b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/TryWithResourcesASTTransformation.java
index d3fc646..04fba60 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/TryWithResourcesASTTransformation.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/TryWithResourcesASTTransformation.java
@@ -43,6 +43,7 @@ import java.util.Collections;
 import java.util.List;
 
 import static org.codehaus.groovy.ast.tools.GeneralUtils.localVarX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
 import static org.codehaus.groovy.runtime.DefaultGroovyMethods.asBoolean;
 import static org.codehaus.groovy.syntax.Token.newSymbol;
 
@@ -204,7 +205,7 @@ public class TryWithResourcesASTTransformation {
                         new DeclarationExpression(
                                 primaryExcX,
                                 newSymbol(Types.ASSIGN, -1, -1),
-                                new ConstantExpression(null)
+                                nullX()
                         )
                 );
         astBuilder.appendStatementsToBlockStatement(blockStatement, primaryExcDeclarationStatement);


Mime
View raw message