groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] 21/23: Improve code style (closes #995)
Date Thu, 26 Sep 2019 00:26:40 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

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

    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 +-
 .../codehaus/groovy/control/CompilerConfiguration.java  |  8 ++++----
 .../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 +----
 12 files changed, 21 insertions(+), 43 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 ffb6f70..f4617dd 100644
--- a/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
+++ b/src/main/java/org/apache/groovy/ast/tools/ClassNodeUtils.java
@@ -298,7 +298,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/CompilerConfiguration.java b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
index bf383bb..407085f 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -448,8 +448,8 @@ public class CompilerConfiguration {
     private void handleOptimizationOption(Map<String, Boolean> options, String optionName,
String sysOptionName) {
         String propValue = getSystemPropertySafe(sysOptionName);
         boolean optionEnabled = propValue == null
-                ? (DEFAULT == null ? false : Boolean.TRUE.equals(DEFAULT.getOptimizationOptions().get(optionName)))
-                : Boolean.valueOf(propValue);
+                ? (DEFAULT != null && Boolean.TRUE.equals(DEFAULT.getOptimizationOptions().get(optionName)))
+                : Boolean.parseBoolean(propValue);
 
         if (optionEnabled) {
             options.put(optionName, Boolean.TRUE);
@@ -459,8 +459,8 @@ public class CompilerConfiguration {
     private void handleJointCompilationOption(Map<String, Object> options, String optionName,
String sysOptionName) {
         String propValue = getSystemPropertySafe(sysOptionName);
         boolean optionEnabled = propValue == null
-                ? (DEFAULT == null ? false : Boolean.TRUE.equals(DEFAULT.getJointCompilationOptions().get(optionName)))
-                : Boolean.valueOf(propValue);
+                ? (DEFAULT != null && Boolean.TRUE.equals(DEFAULT.getJointCompilationOptions().get(optionName)))
+                : Boolean.parseBoolean(propValue);
 
         if (optionEnabled) {
             options.put(optionName, Boolean.TRUE);
diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index 9d96690..0e4fced 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -647,10 +647,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 cbe28f9..c31be6b 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 09c4525..5f6a9b0 100644
--- a/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
+++ b/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
@@ -214,7 +214,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);
         }
@@ -433,7 +433,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) {
@@ -956,11 +956,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 008803b..f1a8646 100644
--- a/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java
+++ b/src/main/java/org/codehaus/groovy/runtime/MetaClassHelper.java
@@ -903,10 +903,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) {
@@ -923,9 +920,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)
{
@@ -934,9 +929,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) {
@@ -946,9 +939,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 c7fc0a5..0b40fd0 100644
--- a/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
+++ b/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
@@ -647,8 +647,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 879064f..1d286a5 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -765,10 +765,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