groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] branch GROOVY_2_5_X updated: Port Improve code style (closes #995)
Date Mon, 23 Sep 2019 05:14:49 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
     new 6030a7e  Port Improve code style (closes #995)
6030a7e is described below

commit 6030a7e7efce37ef14063cd4316338787a6136dd
Author: Bo Zhang <zhangbodut@gmail.com>
AuthorDate: Fri Aug 16 14:10:11 2019 +0800

    Port Improve code style (closes #995)
---
 .../org/apache/groovy/ast/tools/ClassNodeUtils.java     |  2 +-
 src/main/java/org/codehaus/groovy/antlr/LineColumn.java |  4 +---
 src/main/java/org/codehaus/groovy/ast/GenericsType.java |  2 +-
 .../org/codehaus/groovy/control/ResolveVisitor.java     |  5 +----
 .../codehaus/groovy/control/StaticImportVisitor.java    |  2 +-
 .../java/org/codehaus/groovy/runtime/InvokerHelper.java |  8 ++++----
 .../org/codehaus/groovy/runtime/MetaClassHelper.java    | 17 ++++-------------
 .../java/org/codehaus/groovy/runtime/NullObject.java    |  2 +-
 .../groovy/runtime/m12n/ExtensionModuleRegistry.java    |  6 +-----
 .../runtime/typehandling/DefaultTypeTransformation.java |  3 +--
 .../codehaus/groovy/tools/javac/JavaStubGenerator.java  |  5 +----
 11 files changed, 17 insertions(+), 39 deletions(-)

diff --git a/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java b/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
index 2de1ff9..9f88b89 100644
--- a/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
+++ b/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
@@ -300,7 +300,7 @@ public class ClassNodeUtils {
         if (accessorName.startsWith("get") || accessorName.startsWith("is") || accessorName.startsWith("set"))
{
             int prefixLength = accessorName.startsWith("is") ? 2 : 3;
             return accessorName.length() > prefixLength;
-        };
+        }
         return false;
     }
 
diff --git a/src/main/java/org/codehaus/groovy/antlr/LineColumn.java b/src/main/java/org/codehaus/groovy/antlr/LineColumn.java
index ab0e3a7..054104a 100644
--- a/src/main/java/org/codehaus/groovy/antlr/LineColumn.java
+++ b/src/main/java/org/codehaus/groovy/antlr/LineColumn.java
@@ -45,9 +45,7 @@ public class LineColumn {
         final LineColumn lineColumn = (LineColumn) that;
 
         if (column != lineColumn.column) return false;
-        if (line != lineColumn.line) return false;
-
-        return true;
+        return line == lineColumn.line;
     }
 
     public int hashCode() {
diff --git a/src/main/java/org/codehaus/groovy/ast/GenericsType.java b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
index 60cc6a7..1e68788 100644
--- a/src/main/java/org/codehaus/groovy/ast/GenericsType.java
+++ b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
@@ -309,7 +309,7 @@ public class GenericsType extends ASTNode {
             }
             if (lowerBound!=null) {
                 if (!lowerBound.redirect().isUsingGenerics()) {
-                    if (!compareGenericsWithBound(classNode, lowerBound)) return false;
+                    return compareGenericsWithBound(classNode, lowerBound);
                 }
             }
             return true;
diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index b6ec7ec..86e5675 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -609,10 +609,7 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
             }
         }
 
-        if (resolveFromDefaultImports(type, DEFAULT_IMPORTS)) {
-            return true;
-        }
-        return false;
+        return resolveFromDefaultImports(type, DEFAULT_IMPORTS);
     }
 
 
diff --git a/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java b/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java
index 16d7e5e..f979dbd 100644
--- a/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java
@@ -501,7 +501,7 @@ public class StaticImportVisitor extends ClassCodeExpressionTransformer
{
             ImportNode importNode = starImports.get(currentClass.getName());
             starImportType = importNode == null ? null : importNode.getType();
             expression = findStaticMethod(starImportType, name, args);
-            if (expression != null) return expression;
+            return expression;
         } else {
             for (ImportNode importNode : starImports.values()) {
                 starImportType = importNode == null ? null : importNode.getType();
diff --git a/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java b/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
index 76fc8b6..5fc580b 100644
--- a/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
+++ b/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
@@ -212,7 +212,7 @@ public class InvokerHelper {
             GroovyObject pogo = (GroovyObject) object;
             pogo.setProperty(property, newValue);
         } else if (object instanceof Class) {
-            metaRegistry.getMetaClass((Class) object).setProperty((Class) object, property,
newValue);
+            metaRegistry.getMetaClass((Class) object).setProperty(object, property, newValue);
         } else {
             ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(object).setProperty(object,
property, newValue);
         }
@@ -414,7 +414,7 @@ public class InvokerHelper {
         if (message == null || "".equals(message)) {
             throw new PowerAssertionError(expression.toString());
         }
-        throw new AssertionError(String.valueOf(message) + ". Expression: " + expression);
+        throw new AssertionError(message + ". Expression: " + expression);
     }
 
     public static Object runScript(Class scriptClass, String[] args) {
@@ -937,11 +937,11 @@ public class InvokerHelper {
         }
         if (value instanceof String) {
             // value is a regular expression.
-            return StringGroovyMethods.bitwiseNegate((CharSequence)value.toString());
+            return StringGroovyMethods.bitwiseNegate(value.toString());
         }
         if (value instanceof GString) {
             // value is a regular expression.
-            return StringGroovyMethods.bitwiseNegate((CharSequence)value.toString());
+            return StringGroovyMethods.bitwiseNegate(value.toString());
         }
         if (value instanceof ArrayList) {
             // value is a list.
diff --git a/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java b/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java
index 5d745d4..11c1064 100644
--- a/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java
+++ b/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java
@@ -914,10 +914,7 @@ public class MetaClassHelper {
     }
 
     public static boolean sameClasses(Class[] params) {
-        if (params.length != 0)
-            return false;
-
-        return true;
+        return params.length == 0;
     }
 
     public static boolean sameClasses(Class[] params, Object arg1) {
@@ -934,9 +931,7 @@ public class MetaClassHelper {
             return false;
 
         if (params[0] != getClassWithNullAndWrapper(arg1)) return false;
-        if (params[1] != getClassWithNullAndWrapper(arg2)) return false;
-
-        return true;
+        return params[1] == getClassWithNullAndWrapper(arg2);
     }
 
     public static boolean sameClasses(Class[] params, Object arg1, Object arg2, Object arg3)
{
@@ -945,9 +940,7 @@ public class MetaClassHelper {
 
         if (params[0] != getClassWithNullAndWrapper(arg1)) return false;
         if (params[1] != getClassWithNullAndWrapper(arg2)) return false;
-        if (params[2] != getClassWithNullAndWrapper(arg3)) return false;
-
-        return true;
+        return params[2] == getClassWithNullAndWrapper(arg3);
     }
 
     public static boolean sameClasses(Class[] params, Object arg1, Object arg2, Object arg3,
Object arg4) {
@@ -957,9 +950,7 @@ public class MetaClassHelper {
         if (params[0] != getClassWithNullAndWrapper(arg1)) return false;
         if (params[1] != getClassWithNullAndWrapper(arg2)) return false;
         if (params[2] != getClassWithNullAndWrapper(arg3)) return false;
-        if (params[3] != getClassWithNullAndWrapper(arg4)) return false;
-        
-        return true;
+        return params[3] == getClassWithNullAndWrapper(arg4);
     }
 
     public static boolean sameClass(Class[] params, Object arg) {
diff --git a/src/main/java/org/codehaus/groovy/runtime/NullObject.java b/src/main/java/org/codehaus/groovy/runtime/NullObject.java
index 48f9170..12787f4 100644
--- a/src/main/java/org/codehaus/groovy/runtime/NullObject.java
+++ b/src/main/java/org/codehaus/groovy/runtime/NullObject.java
@@ -132,7 +132,7 @@ public class NullObject extends GroovyObjectSupport {
      * @return nothing
      */
     public Object plus(Object o) {
-        throw new NullPointerException("Cannot execute null+" + String.valueOf(o));
+        throw new NullPointerException("Cannot execute null+" + o);
     }
 
     /**
diff --git a/src/main/java/org/codehaus/groovy/runtime/m12n/ExtensionModuleRegistry.java b/src/main/java/org/codehaus/groovy/runtime/m12n/ExtensionModuleRegistry.java
index 77d53d3..a225f3d 100644
--- a/src/main/java/org/codehaus/groovy/runtime/m12n/ExtensionModuleRegistry.java
+++ b/src/main/java/org/codehaus/groovy/runtime/m12n/ExtensionModuleRegistry.java
@@ -50,11 +50,7 @@ public class ExtensionModuleRegistry {
     }
 
     public boolean hasModule(final String moduleName) {
-        if (null == getModule(moduleName)) {
-            return false;
-        }
-
-        return true;
+        return null != getModule(moduleName);
     }
 
     public ExtensionModule getModule(final String moduleName) {
diff --git a/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
b/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
index 222bf67..a41bbbe 100644
--- a/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
+++ b/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
@@ -645,8 +645,7 @@ public class DefaultTypeTransformation {
             if (Objects.equals(k1, k2)) {
                 Object v1 = ((Map.Entry) left).getValue();
                 Object v2 = ((Map.Entry) right).getValue();
-                if (v1 == v2 || (v1 != null && DefaultTypeTransformation.compareEqual(v1,
v2)))
-                    return true;
+                return v1 == v2 || (v1 != null && DefaultTypeTransformation.compareEqual(v1,
v2));
             }
             return false;
         }
diff --git a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
index 64b3ee9..c99cf43 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -707,10 +707,7 @@ public class JavaStubGenerator {
         if (isDefaultTraitImpl(methodNode)) {
             return false;
         }
-        if ((methodNode.getModifiers() & Opcodes.ACC_ABSTRACT) != 0) {
-            return true;
-        }
-        return false;
+        return (methodNode.getModifiers() & Opcodes.ACC_ABSTRACT) != 0;
     }
 
     private static boolean isDefaultTraitImpl(final MethodNode methodNode) {


Mime
View raw message