groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emil...@apache.org
Subject [groovy] branch master updated: minor refactor of nullX() usage
Date Fri, 25 Oct 2019 15:57:23 GMT
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 0427a74  minor refactor of nullX() usage
0427a74 is described below

commit 0427a74cb313700e50e7789e739631767ebb0e60
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Fri Oct 25 10:57:17 2019 -0500

    minor refactor of nullX() usage
---
 src/main/java/groovy/util/logging/Commons.java                   | 8 ++------
 src/main/java/groovy/util/logging/Log.java                       | 9 ++-------
 src/main/java/groovy/util/logging/Log4j.java                     | 8 ++------
 src/main/java/groovy/util/logging/Log4j2.java                    | 8 ++------
 src/main/java/groovy/util/logging/Slf4j.java                     | 9 ++-------
 .../org/codehaus/groovy/transform/LazyASTTransformation.java     | 3 +--
 src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java         | 5 +----
 7 files changed, 12 insertions(+), 38 deletions(-)

diff --git a/src/main/java/groovy/util/logging/Commons.java b/src/main/java/groovy/util/logging/Commons.java
index 3f7c950..6146309 100644
--- a/src/main/java/groovy/util/logging/Commons.java
+++ b/src/main/java/groovy/util/logging/Commons.java
@@ -23,12 +23,10 @@ import groovy.transform.Undefined;
 import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.FieldNode;
 import org.codehaus.groovy.ast.expr.ArgumentListExpression;
-import org.codehaus.groovy.ast.expr.BooleanExpression;
 import org.codehaus.groovy.ast.expr.ClassExpression;
 import org.codehaus.groovy.ast.expr.ConstantExpression;
 import org.codehaus.groovy.ast.expr.Expression;
 import org.codehaus.groovy.ast.expr.MethodCallExpression;
-import org.codehaus.groovy.ast.expr.TernaryExpression;
 import org.codehaus.groovy.transform.GroovyASTTransformationClass;
 import org.codehaus.groovy.transform.LogASTTransformation;
 
@@ -39,6 +37,7 @@ import java.lang.annotation.Target;
 import java.util.Locale;
 
 import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.ternaryX;
 
 /**
  * This local transform adds a logging ability to your program using
@@ -108,10 +107,7 @@ public @interface Commons {
                     ArgumentListExpression.EMPTY_ARGUMENTS);
             condition.setImplicitThis(false);
 
-            return new TernaryExpression(
-                    new BooleanExpression(condition),
-                    originalExpression,
-                    nullX());
+            return ternaryX(condition, originalExpression, nullX());
         }
    }
 }
diff --git a/src/main/java/groovy/util/logging/Log.java b/src/main/java/groovy/util/logging/Log.java
index b9414c8..c431bc7 100644
--- a/src/main/java/groovy/util/logging/Log.java
+++ b/src/main/java/groovy/util/logging/Log.java
@@ -25,12 +25,10 @@ import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.FieldNode;
 import org.codehaus.groovy.ast.expr.ArgumentListExpression;
 import org.codehaus.groovy.ast.expr.AttributeExpression;
-import org.codehaus.groovy.ast.expr.BooleanExpression;
 import org.codehaus.groovy.ast.expr.ClassExpression;
 import org.codehaus.groovy.ast.expr.ConstantExpression;
 import org.codehaus.groovy.ast.expr.Expression;
 import org.codehaus.groovy.ast.expr.MethodCallExpression;
-import org.codehaus.groovy.ast.expr.TernaryExpression;
 import org.codehaus.groovy.transform.GroovyASTTransformationClass;
 import org.codehaus.groovy.transform.LogASTTransformation;
 import org.codehaus.groovy.transform.LogASTTransformation.LoggingStrategy;
@@ -42,6 +40,7 @@ import java.lang.annotation.Target;
 import java.util.Locale;
 
 import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.ternaryX;
 
 /**
  * This local transform adds a logging ability to your program using
@@ -120,11 +119,7 @@ public @interface Log {
             MethodCallExpression condition = new MethodCallExpression(logVariable, "isLoggable",
args);
             condition.setImplicitThis(false);
 
-            return new TernaryExpression(
-                    new BooleanExpression(condition),
-                    originalExpression,
-                    nullX());
-
+            return ternaryX(condition, originalExpression, nullX());
         }
     }
 }
diff --git a/src/main/java/groovy/util/logging/Log4j.java b/src/main/java/groovy/util/logging/Log4j.java
index 34b75b3..ccccad5 100644
--- a/src/main/java/groovy/util/logging/Log4j.java
+++ b/src/main/java/groovy/util/logging/Log4j.java
@@ -24,12 +24,10 @@ import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.FieldNode;
 import org.codehaus.groovy.ast.expr.ArgumentListExpression;
 import org.codehaus.groovy.ast.expr.AttributeExpression;
-import org.codehaus.groovy.ast.expr.BooleanExpression;
 import org.codehaus.groovy.ast.expr.ClassExpression;
 import org.codehaus.groovy.ast.expr.ConstantExpression;
 import org.codehaus.groovy.ast.expr.Expression;
 import org.codehaus.groovy.ast.expr.MethodCallExpression;
-import org.codehaus.groovy.ast.expr.TernaryExpression;
 import org.codehaus.groovy.transform.GroovyASTTransformationClass;
 import org.codehaus.groovy.transform.LogASTTransformation;
 
@@ -40,6 +38,7 @@ import java.lang.annotation.Target;
 import java.util.Locale;
 
 import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.ternaryX;
 
 /**
  * This local transform adds a logging ability to your program using
@@ -120,10 +119,7 @@ public @interface Log4j {
             }
             condition.setImplicitThis(false);
 
-            return new TernaryExpression(
-                    new BooleanExpression(condition),
-                    originalExpression,
-                    nullX());
+            return ternaryX(condition, originalExpression, nullX());
         }
     }
 }
diff --git a/src/main/java/groovy/util/logging/Log4j2.java b/src/main/java/groovy/util/logging/Log4j2.java
index 0d4e20f..08f57fc 100644
--- a/src/main/java/groovy/util/logging/Log4j2.java
+++ b/src/main/java/groovy/util/logging/Log4j2.java
@@ -23,12 +23,10 @@ import groovy.transform.Undefined;
 import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.FieldNode;
 import org.codehaus.groovy.ast.expr.ArgumentListExpression;
-import org.codehaus.groovy.ast.expr.BooleanExpression;
 import org.codehaus.groovy.ast.expr.ClassExpression;
 import org.codehaus.groovy.ast.expr.ConstantExpression;
 import org.codehaus.groovy.ast.expr.Expression;
 import org.codehaus.groovy.ast.expr.MethodCallExpression;
-import org.codehaus.groovy.ast.expr.TernaryExpression;
 import org.codehaus.groovy.transform.GroovyASTTransformationClass;
 import org.codehaus.groovy.transform.LogASTTransformation;
 
@@ -39,6 +37,7 @@ import java.lang.annotation.Target;
 import java.util.Locale;
 
 import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.ternaryX;
 
 /**
  * This local transform adds a logging ability to your program using
@@ -108,10 +107,7 @@ public @interface Log4j2 {
                     ArgumentListExpression.EMPTY_ARGUMENTS);
             condition.setImplicitThis(false);
 
-            return new TernaryExpression(
-                    new BooleanExpression(condition),
-                    originalExpression,
-                    nullX());
+            return ternaryX(condition, originalExpression, nullX());
         }
     }
 }
diff --git a/src/main/java/groovy/util/logging/Slf4j.java b/src/main/java/groovy/util/logging/Slf4j.java
index 9760caa..5ee7218 100644
--- a/src/main/java/groovy/util/logging/Slf4j.java
+++ b/src/main/java/groovy/util/logging/Slf4j.java
@@ -23,12 +23,10 @@ import groovy.transform.Undefined;
 import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.FieldNode;
 import org.codehaus.groovy.ast.expr.ArgumentListExpression;
-import org.codehaus.groovy.ast.expr.BooleanExpression;
 import org.codehaus.groovy.ast.expr.ClassExpression;
 import org.codehaus.groovy.ast.expr.ConstantExpression;
 import org.codehaus.groovy.ast.expr.Expression;
 import org.codehaus.groovy.ast.expr.MethodCallExpression;
-import org.codehaus.groovy.ast.expr.TernaryExpression;
 import org.codehaus.groovy.transform.GroovyASTTransformationClass;
 import org.codehaus.groovy.transform.LogASTTransformation;
 
@@ -39,6 +37,7 @@ import java.lang.annotation.Target;
 import java.util.Locale;
 
 import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.ternaryX;
 
 /**
  * This local transform adds a logging ability to your program using
@@ -108,11 +107,7 @@ public @interface Slf4j {
                     ArgumentListExpression.EMPTY_ARGUMENTS);
             condition.setImplicitThis(false);
 
-            return new TernaryExpression(
-                    new BooleanExpression(condition),
-                    originalExpression,
-                    nullX());
+            return ternaryX(condition, originalExpression, nullX());
         }
     }
-
 }
diff --git a/src/main/java/org/codehaus/groovy/transform/LazyASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/LazyASTTransformation.java
index f8767c0..47ae674 100644
--- a/src/main/java/org/codehaus/groovy/transform/LazyASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/LazyASTTransformation.java
@@ -69,7 +69,6 @@ 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 = nullX();
 
     public void visit(ASTNode[] nodes, SourceUnit source) {
         init(nodes, source);
@@ -219,7 +218,7 @@ public class LazyASTTransformation extends AbstractASTTransformation {
         body.addStatement(ifElseS(
                 notNullX(paramExpr),
                 assignS(fieldExpr, ctorX(SOFT_REF, paramExpr)),
-                assignS(fieldExpr, NULL_EXPR)
+                assignS(fieldExpr, nullX())
         ));
         int visibility = ACC_PUBLIC;
         if (fieldNode.isStatic()) visibility |= ACC_STATIC;
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 ff1f0f0..1ab516b 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
@@ -61,8 +61,6 @@ 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
  */
@@ -359,8 +357,7 @@ public class Java5 implements VMPlugin {
     }
 
     private static void setMethodDefaultValue(MethodNode mn, Method m) {
-        Object defaultValue = m.getDefaultValue();
-        ConstantExpression cExp = defaultValue != null ? new ConstantExpression(defaultValue)
: nullX();
+        ConstantExpression cExp = new ConstantExpression(m.getDefaultValue());
         mn.setCode(new ReturnStatement(cExp));
         mn.setAnnotationDefault(true);
     }


Mime
View raw message