You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2019/09/10 00:05:58 UTC

[groovy] branch master updated (2572c62 -> 21e363d)

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

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


    from 2572c62  GROOVY-9229, GROOVY-9233: added missing closure parameter metadata
     new 86d51cc  GROOVY-9240: relax signature of RGM.traverse(File, Map, ...)
     new 21e363d  Added named param annotations

The 2 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:
 .../groovy/runtime/ResourceGroovyMethods.java      | 63 +++++++++++++++++-----
 .../bugs/{Groovy9153.groovy => Groovy9240.groovy}  | 15 +++---
 2 files changed, 60 insertions(+), 18 deletions(-)
 copy src/test/groovy/bugs/{Groovy9153.groovy => Groovy9240.groovy} (66%)


[groovy] 01/02: GROOVY-9240: relax signature of RGM.traverse(File, Map, ...)

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 86d51cc2a8fe55a854ee8f2d760123c7d4007c5d
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Aug 30 13:54:17 2019 -0500

    GROOVY-9240: relax signature of RGM.traverse(File, Map, ...)
---
 .../groovy/runtime/ResourceGroovyMethods.java      | 30 ++++++++++-----
 src/test/groovy/bugs/Groovy9240.groovy             | 43 ++++++++++++++++++++++
 2 files changed, 63 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
index 70e0e58..335086a 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
@@ -69,8 +69,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.regex.Pattern;
 
-import static org.codehaus.groovy.runtime.DefaultGroovyMethods.get;
-
 /**
  * This class defines new groovy methods for Readers, Writers, InputStreams and
  * OutputStreams which appear on normal JDK classes inside the Groovy environment.
@@ -1310,13 +1308,24 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
      * @see groovy.io.FileType
      * @since 1.7.1
      */
-    public static void traverse(final File self, final Map<String, Object> options, @ClosureParams(value = SimpleType.class, options = "java.io.File") final Closure closure)
+    public static void traverse(final File self, final Map<String, ?> options, @ClosureParams(value = SimpleType.class, options = "java.io.File") final Closure closure)
             throws FileNotFoundException, IllegalArgumentException {
-        Number maxDepthNumber = DefaultGroovyMethods.asType(options.remove("maxDepth"), Number.class);
-        int maxDepth = maxDepthNumber == null ? -1 : maxDepthNumber.intValue();
-        Boolean visitRoot = DefaultGroovyMethods.asType(get(options, "visitRoot", false), Boolean.class);
-        Boolean preRoot = DefaultGroovyMethods.asType(get(options, "preRoot", false), Boolean.class);
-        Boolean postRoot = DefaultGroovyMethods.asType(get(options, "postRoot", false), Boolean.class);
+        final int maxDepth;
+        final boolean preRoot;
+        final boolean postRoot;
+        final boolean visitRoot;
+
+        {
+            Object maxDepthValue = options.remove("maxDepth");
+            maxDepth = maxDepthValue == null ? -1 : DefaultGroovyMethods.asType(maxDepthValue, Number.class).intValue();
+            Object preRootValue = options.get("preRoot");
+            preRoot = preRootValue == null ? false : DefaultGroovyMethods.asType(preRootValue, Boolean.class).booleanValue();
+            Object postRootValue = options.get("postRoot");
+            postRoot = postRootValue == null ? false : DefaultGroovyMethods.asType(postRootValue, Boolean.class).booleanValue();
+            Object visitRootValue = options.get("visitRoot");
+            visitRoot = visitRootValue == null ? false : DefaultGroovyMethods.asType(visitRootValue, Boolean.class).booleanValue();
+        }
+
         final Closure pre = (Closure) options.get("preDir");
         final Closure post = (Closure) options.get("postDir");
         final FileType type = (FileType) options.get("type");
@@ -1324,6 +1333,7 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
         final Object nameFilter = options.get("nameFilter");
         final Object excludeFilter = options.get("excludeFilter");
         final Object excludeNameFilter = options.get("excludeNameFilter");
+
         Object preResult = null;
         if (preRoot && pre != null) {
             preResult = pre.call(self);
@@ -1405,13 +1415,13 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
      * @see #traverse(java.io.File, java.util.Map, groovy.lang.Closure)
      * @since 1.7.1
      */
-    public static void traverse(final File self, final Map<String, Object> options)
+    public static void traverse(final File self, final Map<String, ?> options)
             throws FileNotFoundException, IllegalArgumentException {
         final Closure visit = (Closure) options.remove("visit");
         traverse(self, options, visit);
     }
 
-    private static FileVisitResult traverse(final File self, final Map<String, Object> options, final Closure closure, final int maxDepth)
+    private static FileVisitResult traverse(final File self, final Map<String, ?> options, final Closure closure, final int maxDepth)
             throws FileNotFoundException, IllegalArgumentException {
         checkDir(self);
         final Closure pre = (Closure) options.get("preDir");
diff --git a/src/test/groovy/bugs/Groovy9240.groovy b/src/test/groovy/bugs/Groovy9240.groovy
new file mode 100644
index 0000000..c25f045
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9240.groovy
@@ -0,0 +1,43 @@
+/*
+ *  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
+
+import groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+@CompileStatic
+final class Groovy9240 {
+
+    @Test
+    void testTraverse() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            void meth(File folder) {
+                // was: [Static type checking] - Cannot call java.io.File#traverse(java.util.Map <java.lang.String, java.lang.Object>, groovy.lang.Closure) with arguments [java.util.LinkedHashMap <java.lang.String, java.io.Serializable>, groovy.lang.Closure]
+                folder.traverse([
+                    type: groovy.io.FileType.FILES,
+                    nameFilter: ~/.*\\.(?i)pdf/
+                ]) { println it }
+            }
+            meth(File.createTempDir())
+        '''
+    }
+}


[groovy] 02/02: Added named param annotations

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 21e363d12520dd4697cdb2e2208df6d30d100569
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Sep 3 10:37:56 2019 -0500

    Added named param annotations
---
 .../groovy/runtime/ResourceGroovyMethods.java      | 37 +++++++++++++++++++---
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
index 335086a..a77627a 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
@@ -25,6 +25,7 @@ import groovy.io.GroovyPrintWriter;
 import groovy.lang.Closure;
 import groovy.lang.MetaClass;
 import groovy.lang.Writable;
+import groovy.transform.NamedParam;
 import groovy.transform.stc.ClosureParams;
 import groovy.transform.stc.FromString;
 import groovy.transform.stc.PickFirstResolver;
@@ -1308,8 +1309,23 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
      * @see groovy.io.FileType
      * @since 1.7.1
      */
-    public static void traverse(final File self, final Map<String, ?> options, @ClosureParams(value = SimpleType.class, options = "java.io.File") final Closure closure)
-            throws FileNotFoundException, IllegalArgumentException {
+    public static void traverse(final File self,
+            @NamedParam(value = "type", type = FileType.class)
+            @NamedParam(value = "preDir", type = Closure.class)
+            @NamedParam(value = "preRoot", type = Boolean.class)
+            @NamedParam(value = "postDir", type = Closure.class)
+            @NamedParam(value = "postRoot", type = Boolean.class)
+            @NamedParam(value = "visitRoot", type = Boolean.class)
+            @NamedParam(value = "maxDepth", type = Integer.class)
+            @NamedParam(value = "filter", type = Object.class)
+            @NamedParam(value = "nameFilter", type = Object.class)
+            @NamedParam(value = "excludeFilter", type = Object.class)
+            @NamedParam(value = "excludeNameFilter", type = Object.class)
+            @NamedParam(value = "sort", type = Closure.class)
+            final Map<String, ?> options,
+            @ClosureParams(value = SimpleType.class, options = "java.io.File")
+            final Closure closure)
+                throws FileNotFoundException, IllegalArgumentException {
         final int maxDepth;
         final boolean preRoot;
         final boolean postRoot;
@@ -1415,8 +1431,21 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
      * @see #traverse(java.io.File, java.util.Map, groovy.lang.Closure)
      * @since 1.7.1
      */
-    public static void traverse(final File self, final Map<String, ?> options)
-            throws FileNotFoundException, IllegalArgumentException {
+    public static void traverse(final File self,
+            @NamedParam(value = "type", type = FileType.class)
+            @NamedParam(value = "preDir", type = Closure.class)
+            @NamedParam(value = "preRoot", type = Boolean.class)
+            @NamedParam(value = "postDir", type = Closure.class)
+            @NamedParam(value = "postRoot", type = Boolean.class)
+            @NamedParam(value = "visitRoot", type = Boolean.class)
+            @NamedParam(value = "maxDepth", type = Integer.class)
+            @NamedParam(value = "filter", type = Object.class)
+            @NamedParam(value = "nameFilter", type = Object.class)
+            @NamedParam(value = "excludeFilter", type = Object.class)
+            @NamedParam(value = "excludeNameFilter", type = Object.class)
+            @NamedParam(value = "sort", type = Closure.class)
+            final Map<String, ?> options)
+                throws FileNotFoundException, IllegalArgumentException {
         final Closure visit = (Closure) options.remove("visit");
         traverse(self, options, visit);
     }