groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] 01/04: Revert "remove codenarc warnings"
Date Tue, 16 Apr 2019 09:43:14 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 7c4bbb911a8f02d423adbf96a076c13d339fed23
Author: Paul King <paulk@asert.com.au>
AuthorDate: Tue Apr 16 17:44:20 2019 +1000

    Revert "remove codenarc warnings"
    
    This reverts commit 1bb3e041672f719745cbc523b7d342296014791a.
---
 src/test/groovy/PrimitiveTypesTest.groovy          | 21 ++---
 src/test/groovy/bugs/Groovy4078Bug.groovy          | 98 +++++++++++-----------
 .../operator/BigIntegerOperationsTest.groovy       |  2 +-
 .../transform/tailrec/TailRecursiveExamples.groovy |  4 +-
 .../src/main/java/groovy/util/AntBuilder.java      |  5 +-
 .../main/java/org/codehaus/groovy/ant/Groovy.java  |  3 +-
 .../tools/shell/util/PackageHelperImpl.groovy      |  4 +-
 .../groovy/binding/ClosureTriggerBinding.java      |  5 +-
 8 files changed, 69 insertions(+), 73 deletions(-)

diff --git a/src/test/groovy/PrimitiveTypesTest.groovy b/src/test/groovy/PrimitiveTypesTest.groovy
index 15cf1b7..eacd6d8 100644
--- a/src/test/groovy/PrimitiveTypesTest.groovy
+++ b/src/test/groovy/PrimitiveTypesTest.groovy
@@ -21,35 +21,35 @@ package groovy
 class PrimitiveTypesTest extends GroovyTestCase {
 
     int getInt() {
-        return 1
+        return 1;
     }
     
     short getShort() {
-        return 1
+        return 1;
     }
     
     boolean getBoolean() {
-        return true
+        return true;
     }
     
     double getDouble() {
-        return 1.0
+        return 1.0;
     }
     
     float getFloat() {
-        return 1.0
+        return 1.0;
     }
     
     byte getByte() {
-        return 1
+        return 1;
     }
     
     long getLong() {
-        return 1
+        return 1;
     }
 
     char getChar() {
-        return 'a'
+        return 'a';
     }
     
     int getNextInt(int i) {
@@ -85,14 +85,15 @@ class PrimitiveTypesTest extends GroovyTestCase {
     }
 
     void testBigInteger2BigDecimal() {
-        BigInteger big = BigInteger.valueOf(Long.MAX_VALUE)
+        BigInteger big = new BigInteger(Long.MAX_VALUE)
         assert big.longValue() == testMethod(big).longValueExact()
     }
 
     private testMethod(BigDecimal bd) {
-        return bd
+        return bd;
     }
 
+
     static void main(args) {
         new PrimitiveTypesTest().testPrimitiveTypes()
     }
diff --git a/src/test/groovy/bugs/Groovy4078Bug.groovy b/src/test/groovy/bugs/Groovy4078Bug.groovy
index 9bf88c5..1f755d5 100644
--- a/src/test/groovy/bugs/Groovy4078Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4078Bug.groovy
@@ -1,49 +1,49 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package groovy.bugs
-
-class Groovy4078Bug extends GroovyTestCase {
-    void testInfiniteLoopDetectionInStepUsage() {
-        (2..2).step 0, {assert it != null} //IntRange
-        
-        ('b'..'b').step 0, {assert it != null} //ObjectRange
-        
-        5.step( 5, 1 ) { assert it != null } // DGM.step(), int
-        
-        5.0.step (5.0, 1 ) { assert it != null } // DGM.step(), BigDecimal
-        
-        def from = BigInteger.valueOf(5)
-        def to = BigInteger.valueOf(5)
-        from.step (to, 1 ) { assert it != null }  // DGM.step(), BigInteger
-
-        try{
-            (1..2).step 0, {assert it != null} //IntRange
-            fail('Should have failed as step size 0 causes infinite loop')
-        } catch(ex) {
-            assert ex.message.contains('Infinite loop detected due to step size of 0')
-        }
-                      
-        try{
-            ('a'..'b').step 0, {assert it != null} // ObjectRange
-            fail('Should have failed as step size 0 causes infinite loop')
-        } catch(ex) {
-            assert ex.message.contains('Infinite loop detected due to step size of 0')
-        }
-    }
-}
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs
+
+class Groovy4078Bug extends GroovyTestCase {
+    void testInfiniteLoopDetectionInStepUsage() {
+        (2..2).step 0, {assert it != null} //IntRange
+        
+        ('b'..'b').step 0, {assert it != null} //ObjectRange
+        
+        5.step( 5, 1 ) { assert it != null } // DGM.step(), int
+        
+        5.0.step (5.0, 1 ) { assert it != null } // DGM.step(), BigDecimal
+        
+        def from = new BigInteger(5)
+        def to = new BigInteger(5)
+        from.step (to, 1 ) { assert it != null }  // DGM.step(), BigInteger
+
+        try{
+            (1..2).step 0, {assert it != null} //IntRange
+            fail('Should have failed as step size 0 causes infinite loop')
+        } catch(ex) {
+            assert ex.message.contains('Infinite loop detected due to step size of 0')
+        }
+                      
+        try{
+            ('a'..'b').step 0, {assert it != null} // ObjectRange
+            fail('Should have failed as step size 0 causes infinite loop')
+        } catch(ex) {
+            assert ex.message.contains('Infinite loop detected due to step size of 0')
+        }
+    }
+}
diff --git a/src/test/groovy/operator/BigIntegerOperationsTest.groovy b/src/test/groovy/operator/BigIntegerOperationsTest.groovy
index 21f79e8..22bffc8 100644
--- a/src/test/groovy/operator/BigIntegerOperationsTest.groovy
+++ b/src/test/groovy/operator/BigIntegerOperationsTest.groovy
@@ -58,7 +58,7 @@ class BigIntegerOperationsTest extends GroovyTestCase {
     }
     
     void testAsOperatorPrecisionLoss() {
-        def value = BigInteger.valueOf(Long.MAX_VALUE) + 1
+        def value = new BigInteger(Long.MAX_VALUE) + 1
         def value2 = value as BigInteger
         assert value == value2
     }
diff --git a/src/test/org/codehaus/groovy/transform/tailrec/TailRecursiveExamples.groovy b/src/test/org/codehaus/groovy/transform/tailrec/TailRecursiveExamples.groovy
index a6f54fd..11d916e 100644
--- a/src/test/org/codehaus/groovy/transform/tailrec/TailRecursiveExamples.groovy
+++ b/src/test/org/codehaus/groovy/transform/tailrec/TailRecursiveExamples.groovy
@@ -66,8 +66,8 @@ class TailRecursiveExamples {
         assert target.reduce(0, plus, 1, 5, 10) == 16
         assert target.reduce(99, plus, 1, 5, 10, 98) == 213
 
-        def numbersFrom1to1000 = (1..1000).collect { BigInteger.valueOf(it) }.toArray()
-        assert target.reduce(BigInteger.ONE, { BigInteger a, BigInteger b -> a * b },
numbersFrom1to1000).bitCount() == 3788
+        def numbersFrom1to1000 = (1..1000).collect { new BigInteger(it) }.toArray()
+        assert target.reduce(new BigInteger(1), { BigInteger a, BigInteger b -> a * b
}, numbersFrom1to1000).bitCount() == 3788
     }
 
     @Test
diff --git a/subprojects/groovy-ant/src/main/java/groovy/util/AntBuilder.java b/subprojects/groovy-ant/src/main/java/groovy/util/AntBuilder.java
index 63123d9..ae176e0 100644
--- a/subprojects/groovy-ant/src/main/java/groovy/util/AntBuilder.java
+++ b/subprojects/groovy-ant/src/main/java/groovy/util/AntBuilder.java
@@ -35,7 +35,6 @@ import org.apache.tools.ant.dispatch.DispatchUtils;
 import org.apache.tools.ant.helper.AntXMLContext;
 import org.apache.tools.ant.helper.ProjectHelper2;
 import org.codehaus.groovy.ant.FileScanner;
-import org.codehaus.groovy.reflection.ReflectionUtils;
 import org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
@@ -321,7 +320,7 @@ public class AntBuilder extends BuilderSupport {
         try {
             // Have to call fireTestStared/fireTestFinished via reflection as they unfortunately
have protected access in Project
             final Method fireTaskStarted = Project.class.getDeclaredMethod("fireTaskStarted",
Task.class);
-            ReflectionUtils.trySetAccessible(fireTaskStarted);
+            fireTaskStarted.setAccessible(true);
             fireTaskStarted.invoke(project, task);
 
             Object realThing;
@@ -355,7 +354,7 @@ public class AntBuilder extends BuilderSupport {
         finally {
             try {
                 final Method fireTaskFinished = Project.class.getDeclaredMethod("fireTaskFinished",
Task.class, Throwable.class);
-                ReflectionUtils.trySetAccessible(fireTaskFinished);
+                fireTaskFinished.setAccessible(true);
                 fireTaskFinished.invoke(project, task, reason);
             }
             catch (Exception e) {
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
index f235771..15825f5 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
@@ -36,7 +36,6 @@ import org.apache.tools.ant.util.FileUtils;
 import org.codehaus.groovy.control.CompilationFailedException;
 import org.codehaus.groovy.control.CompilerConfiguration;
 import org.codehaus.groovy.control.customizers.ImportCustomizer;
-import org.codehaus.groovy.reflection.ReflectionUtils;
 import org.codehaus.groovy.runtime.InvokerHelper;
 import org.codehaus.groovy.runtime.ResourceGroovyMethods;
 import org.codehaus.groovy.tools.ErrorReporter;
@@ -431,7 +430,7 @@ public class Groovy extends Java {
             try {
                 final Object propsHandler = project.getClass().getMethod("getPropsHandler").invoke(project);
                 final Field contextField = propsHandler.getClass().getDeclaredField("context");
-                ReflectionUtils.trySetAccessible(contextField);
+                contextField.setAccessible(true);
                 final Object context = contextField.get(propsHandler);
                 mavenPom = InvokerHelper.invokeMethod(context, "getProject", EMPTY_OBJECT_ARRAY);
             }
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/util/PackageHelperImpl.groovy
b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/util/PackageHelperImpl.groovy
index 7293b3e..17d0e09 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/util/PackageHelperImpl.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/util/PackageHelperImpl.groovy
@@ -183,14 +183,12 @@ def filterClassName(Path path) {
     }
 }
 
-class GroovyFileVisitor extends SimpleFileVisitor {}
-
 // walk each file and directory, possibly storing directories as packages, and files as classes
 Files.walkFileTree(fs.getPath('modules'),
         [preVisitDirectory: { dir, attrs -> filterPackageName(dir); FileVisitResult.CONTINUE
},
          visitFile: { file, attrs -> filterClassName(file); FileVisitResult.CONTINUE}
         ]
-            as GroovyFileVisitor)
+            as SimpleFileVisitor)
 '''
 
         Set<String> jigsawPackages = (Set<String>) shell.getProperty('result')
diff --git a/subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/ClosureTriggerBinding.java
b/subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/ClosureTriggerBinding.java
index 0069d92..f31dbfb 100644
--- a/subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/ClosureTriggerBinding.java
+++ b/subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/ClosureTriggerBinding.java
@@ -21,7 +21,6 @@ package org.codehaus.groovy.binding;
 import groovy.lang.Closure;
 import groovy.lang.GroovyObjectSupport;
 import groovy.lang.Reference;
-import org.codehaus.groovy.reflection.ReflectionUtils;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
@@ -82,13 +81,13 @@ public class ClosureTriggerBinding implements TriggerBinding, SourceBinding
{
                     }
                     try {
                         boolean acc = constructor.isAccessible();
-                        ReflectionUtils.trySetAccessible(constructor);
+                        constructor.setAccessible(true);
                         Closure localCopy = (Closure) constructor.newInstance(args);
                         if (!acc) { constructor.setAccessible(false); }
                         localCopy.setResolveStrategy(Closure.DELEGATE_ONLY);
                         for (Field f:closureClass.getDeclaredFields()) {
                             acc = f.isAccessible();
-                            ReflectionUtils.trySetAccessible(f);
+                            f.setAccessible(true);
                             if (f.getType() == Reference.class) {
                                 delegate.fields.put(f.getName(),
                                         (BindPathSnooper) ((Reference) f.get(localCopy)).get());


Mime
View raw message