You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2019/04/16 07:29:05 UTC

[groovy] branch master updated (be7961a -> 241eca6)

This is an automated email from the ASF dual-hosted git repository.

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


    from be7961a  GROOVY-9085: Add INOUT stored procedure example to asciidoc doc for groovy-sql (closes #893)
     new 645b914  remove codenarc warnings
     new 1bb3e04  remove codenarc warnings
     new 241eca6  remove codenarc warnings

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/test/groovy/PrimitiveTypesTest.groovy          | 21 +++--
 src/test/groovy/bugs/Groovy4078Bug.groovy          | 98 +++++++++++-----------
 .../operator/BigIntegerOperationsTest.groovy       |  2 +-
 src/test/groovy/util/ProxyGeneratorTest.groovy     |  3 +-
 .../reflection/GroovyClassValueFactoryTest.groovy  | 30 ++++---
 .../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 +-
 10 files changed, 89 insertions(+), 86 deletions(-)


[groovy] 01/03: remove codenarc warnings

Posted by pa...@apache.org.
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 645b91492ddf563fc37322920bde5aedae6bb060
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Apr 16 16:51:35 2019 +1000

    remove codenarc warnings
---
 .../reflection/GroovyClassValueFactoryTest.groovy  | 30 ++++++++++------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/src/test/org/codehaus/groovy/reflection/GroovyClassValueFactoryTest.groovy b/src/test/org/codehaus/groovy/reflection/GroovyClassValueFactoryTest.groovy
index e265758..c3033d1 100644
--- a/src/test/org/codehaus/groovy/reflection/GroovyClassValueFactoryTest.groovy
+++ b/src/test/org/codehaus/groovy/reflection/GroovyClassValueFactoryTest.groovy
@@ -18,29 +18,27 @@
  */
 package org.codehaus.groovy.reflection
 
-import java.util.concurrent.atomic.AtomicInteger;
-
-import groovy.util.GroovyTestCase;
+import java.util.concurrent.atomic.AtomicInteger
 
 import org.codehaus.groovy.reflection.GroovyClassValue.ComputeValue
 
 class GroovyClassValueFactoryTest extends GroovyTestCase {
-	public void testCreateGroovyClassValue(){
-		final AtomicInteger counter = new AtomicInteger();
+	void testCreateGroovyClassValue(){
+		final AtomicInteger counter = new AtomicInteger()
 		GroovyClassValue<String> classValue = GroovyClassValueFactory.createGroovyClassValue(new ComputeValue<String>(){
 			String computeValue(Class<?> type){
 				counter.incrementAndGet()
-				return type.name;
+				return type.name
 			}
-		});
-		assertEquals("retrieved String class value", String.class.getName(), classValue.get(String.class))
-		assertEquals("computeValue correctly invoked 1 time", 1, counter.value)
-		assertEquals("retrieved String class value", String.class.getName(), classValue.get(String.class))
-		assertEquals("computeValue correctly invoked 1 time", 1, counter.value)
-		assertEquals("retrieved Integer class value", Integer.class.getName(), classValue.get(Integer.class))
-		assertEquals("computeValue correctly invoked 2 times", 2, counter.value)
-		classValue.remove(String.class)
-		assertEquals("retrieved String class value", String.class.getName(), classValue.get(String.class))
-		assertEquals("computeValue correctly invoked 3 times", 3, counter.value)
+		})
+		assertEquals("retrieved String class value", String.name, classValue.get(String))
+		assertEquals("computeValue correctly invoked 1 time", 1, counter.get())
+		assertEquals("retrieved String class value", String.name, classValue.get(String))
+		assertEquals("computeValue correctly invoked 1 time", 1, counter.get())
+		assertEquals("retrieved Integer class value", Integer.name, classValue.get(Integer))
+		assertEquals("computeValue correctly invoked 2 times", 2, counter.get())
+		classValue.remove(String)
+		assertEquals("retrieved String class value", String.name, classValue.get(String))
+		assertEquals("computeValue correctly invoked 3 times", 3, counter.get())
 	}
 }


[groovy] 02/03: remove codenarc warnings

Posted by pa...@apache.org.
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 1bb3e041672f719745cbc523b7d342296014791a
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Apr 16 17:02:30 2019 +1000

    remove codenarc warnings
---
 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, 73 insertions(+), 69 deletions(-)

diff --git a/src/test/groovy/PrimitiveTypesTest.groovy b/src/test/groovy/PrimitiveTypesTest.groovy
index eacd6d8..15cf1b7 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,15 +85,14 @@ class PrimitiveTypesTest extends GroovyTestCase {
     }
 
     void testBigInteger2BigDecimal() {
-        BigInteger big = new BigInteger(Long.MAX_VALUE)
+        BigInteger big = BigInteger.valueOf(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 1f755d5..9bf88c5 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 = 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')
-        }
-    }
-}
+/*
+ *  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')
+        }
+    }
+}
diff --git a/src/test/groovy/operator/BigIntegerOperationsTest.groovy b/src/test/groovy/operator/BigIntegerOperationsTest.groovy
index 22bffc8..21f79e8 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 = new BigInteger(Long.MAX_VALUE) + 1
+        def value = BigInteger.valueOf(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 11d916e..a6f54fd 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 { new BigInteger(it) }.toArray()
-        assert target.reduce(new BigInteger(1), { BigInteger a, BigInteger b -> a * b }, numbersFrom1to1000).bitCount() == 3788
+        def numbersFrom1to1000 = (1..1000).collect { BigInteger.valueOf(it) }.toArray()
+        assert target.reduce(BigInteger.ONE, { 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 ae176e0..63123d9 100644
--- a/subprojects/groovy-ant/src/main/java/groovy/util/AntBuilder.java
+++ b/subprojects/groovy-ant/src/main/java/groovy/util/AntBuilder.java
@@ -35,6 +35,7 @@ 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;
@@ -320,7 +321,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);
-            fireTaskStarted.setAccessible(true);
+            ReflectionUtils.trySetAccessible(fireTaskStarted);
             fireTaskStarted.invoke(project, task);
 
             Object realThing;
@@ -354,7 +355,7 @@ public class AntBuilder extends BuilderSupport {
         finally {
             try {
                 final Method fireTaskFinished = Project.class.getDeclaredMethod("fireTaskFinished", Task.class, Throwable.class);
-                fireTaskFinished.setAccessible(true);
+                ReflectionUtils.trySetAccessible(fireTaskFinished);
                 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 15825f5..f235771 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,6 +36,7 @@ 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;
@@ -430,7 +431,7 @@ public class Groovy extends Java {
             try {
                 final Object propsHandler = project.getClass().getMethod("getPropsHandler").invoke(project);
                 final Field contextField = propsHandler.getClass().getDeclaredField("context");
-                contextField.setAccessible(true);
+                ReflectionUtils.trySetAccessible(contextField);
                 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 17d0e09..7293b3e 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,12 +183,14 @@ 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 SimpleFileVisitor)
+            as GroovyFileVisitor)
 '''
 
         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 f31dbfb..0069d92 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,6 +21,7 @@ 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;
@@ -81,13 +82,13 @@ public class ClosureTriggerBinding implements TriggerBinding, SourceBinding {
                     }
                     try {
                         boolean acc = constructor.isAccessible();
-                        constructor.setAccessible(true);
+                        ReflectionUtils.trySetAccessible(constructor);
                         Closure localCopy = (Closure) constructor.newInstance(args);
                         if (!acc) { constructor.setAccessible(false); }
                         localCopy.setResolveStrategy(Closure.DELEGATE_ONLY);
                         for (Field f:closureClass.getDeclaredFields()) {
                             acc = f.isAccessible();
-                            f.setAccessible(true);
+                            ReflectionUtils.trySetAccessible(f);
                             if (f.getType() == Reference.class) {
                                 delegate.fields.put(f.getName(),
                                         (BindPathSnooper) ((Reference) f.get(localCopy)).get());


[groovy] 03/03: remove codenarc warnings

Posted by pa...@apache.org.
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 241eca618c7bff385f9a80117ebddda24d13cdf6
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Apr 16 17:28:41 2019 +1000

    remove codenarc warnings
---
 src/test/groovy/util/ProxyGeneratorTest.groovy | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/test/groovy/util/ProxyGeneratorTest.groovy b/src/test/groovy/util/ProxyGeneratorTest.groovy
index 53af084..5e165c2 100644
--- a/src/test/groovy/util/ProxyGeneratorTest.groovy
+++ b/src/test/groovy/util/ProxyGeneratorTest.groovy
@@ -93,7 +93,8 @@ class ProxyGeneratorTest extends GroovyTestCase {
         assert 3 == testClass[2]
         testClass[3] = 99
         assert 99 == testClass[3]
-        testClass.removeRange(1, 3)
+        testClass.removeAt(2)
+        testClass.removeAt(1)
         assert [1, 99, 5] == testClass
     }