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/09/17 09:20:30 UTC

[groovy] branch GROOVY_3_0_X updated (43ca9b0 -> b815887)

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

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


    from 43ca9b0  GROOVY-9247: Bump gradle to 5.6.2
     new e13dc12  GROOVY-9229, GROOVY-9233: added missing closure parameter metadata
     new f925b19  GROOVY-9240: relax signature of RGM.traverse(File, Map, ...)
     new 74268ea  Added named param annotations
     new 8c15968  GROOVY-9249: Bump junit to 5.5.2
     new 0e932f8  fix javadoc
     new 159be78  GROOVY-9236: Avoid unnecessary resolving
     new 893905e  add some tests and clean up some tests
     new b815887  fix javadoc

The 8 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:
 .../java/groovy/transform/AnnotationCollector.java |   1 +
 .../codehaus/groovy/control/ResolveVisitor.java    |   6 +-
 .../groovy/runtime/DefaultGroovyMethods.java       |   2 +-
 .../groovy/runtime/ResourceGroovyMethods.java      |  63 ++++--
 .../groovy/bugs/groovy9236/Groovy9236.groovy}      |   4 +-
 .../bugs/groovy9236/Groovy9236SamePkg.groovy}      |   4 +-
 .../Outer.groovy => groovy9236/Main.groovy}        |  12 +-
 .../PackageAndImportAnnotationTest.groovy          |  19 +-
 .../{Groovy4418Bug.groovy => Groovy4418.groovy}    |   4 +-
 ...ructorParameterBug.groovy => Groovy8063.groovy} |  49 +++--
 .../bugs/{Groovy9031.groovy => Groovy9204.groovy}  |  50 +++--
 .../bugs/{Groovy9184.groovy => Groovy9213.groovy}  |  38 ++--
 .../bugs/{Groovy9153.groovy => Groovy9240.groovy}  |  15 +-
 .../{Groovy9243Bug.groovy => Groovy9243.groovy}    |  17 +-
 .../groovy/bugs/groovy9236/Groovy9236Bug.groovy    | 124 ++++++++++++
 .../{Groovy7276Bug.groovy => Groovy7276.groovy}    |   2 +-
 .../groovy-sql/src/main/java/groovy/sql/Sql.java   | 224 +++++++++++----------
 subprojects/groovy-test-junit5/build.gradle        |   4 +-
 18 files changed, 426 insertions(+), 212 deletions(-)
 copy src/{test/groovy/script/scriptHelloWorld.groovy => test-resources/groovy/bugs/groovy9236/Groovy9236.groovy} (93%)
 copy src/{test/groovy/script/scriptHelloWorld.groovy => test-resources/groovy/bugs/groovy9236/Groovy9236SamePkg.groovy} (93%)
 copy src/test-resources/groovy/bugs/{groovy4287/Outer.groovy => groovy9236/Main.groovy} (80%)
 rename src/test/groovy/bugs/{Groovy4418Bug.groovy => Groovy4418.groovy} (98%)
 copy src/test/groovy/bugs/{ConstructorParameterBug.groovy => Groovy8063.groovy} (58%)
 copy src/test/groovy/bugs/{Groovy9031.groovy => Groovy9204.groovy} (60%)
 copy src/test/groovy/bugs/{Groovy9184.groovy => Groovy9213.groovy} (62%)
 copy src/test/groovy/bugs/{Groovy9153.groovy => Groovy9240.groovy} (66%)
 rename src/test/groovy/bugs/{Groovy9243Bug.groovy => Groovy9243.groovy} (73%)
 create mode 100644 src/test/groovy/bugs/groovy9236/Groovy9236Bug.groovy
 rename src/test/org/codehaus/groovy/classgen/asm/sc/bugs/{Groovy7276Bug.groovy => Groovy7276.groovy} (96%)


[groovy] 07/08: add some tests and clean up some tests

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

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

commit 893905e1b7412de6dde577a1ec62acb5aff69990
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Sep 12 17:10:14 2019 -0500

    add some tests and clean up some tests
---
 .../PackageAndImportAnnotationTest.groovy          | 19 ++++--
 .../{Groovy4418Bug.groovy => Groovy4418.groovy}    |  4 +-
 src/test/groovy/bugs/Groovy8063.groovy             | 64 ++++++++++++++++++
 src/test/groovy/bugs/Groovy9204.groovy             | 78 ++++++++++++++++++++++
 src/test/groovy/bugs/Groovy9213.groovy             | 53 +++++++++++++++
 .../{Groovy9243Bug.groovy => Groovy9243.groovy}    | 17 +++--
 .../{Groovy7276Bug.groovy => Groovy7276.groovy}    |  2 +-
 7 files changed, 224 insertions(+), 13 deletions(-)

diff --git a/src/test/groovy/annotations/PackageAndImportAnnotationTest.groovy b/src/test/groovy/annotations/PackageAndImportAnnotationTest.groovy
index 304ef79..cfeac15 100644
--- a/src/test/groovy/annotations/PackageAndImportAnnotationTest.groovy
+++ b/src/test/groovy/annotations/PackageAndImportAnnotationTest.groovy
@@ -18,23 +18,32 @@
  */
 package groovy.annotations
 
-class PackageAndImportAnnotationTest extends GroovyTestCase {
+import groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+@CompileStatic
+final class PackageAndImportAnnotationTest {
+
+    @Test
     void testTransformationOfPropertyInvokedOnThis() {
-        assertScript """
+        assertScript '''
             def x = new groovy.annotations.MyClass()
             assert x.class.annotations[0].value() == 60
             assert x.class.package.annotations[0].value() == 30
             new AntBuilder().with {
                 mkdir(dir:'temp')
                 delete(file:'temp/log.txt')
-                taskdef(name:'groovyc', classname:"org.codehaus.groovy.ant.Groovyc")
+                taskdef(name:'groovyc', classname:'org.codehaus.groovy.ant.Groovyc')
                 groovyc(srcdir:'src/test', destdir:'temp', includes:'groovy/annotations/MyClass.groovy')
                 def text = new File('temp/log.txt').text
+                delete(dir:'temp')
+
                 assert text.contains('ClassNode 60')
                 assert text.contains('PackageNode 40')
                 assert text.contains('ImportNode 50')
-                delete(dir:'temp')
             }
-        """
+        '''
     }
 }
diff --git a/src/test/groovy/bugs/Groovy4418Bug.groovy b/src/test/groovy/bugs/Groovy4418.groovy
similarity index 98%
rename from src/test/groovy/bugs/Groovy4418Bug.groovy
rename to src/test/groovy/bugs/Groovy4418.groovy
index f96537d..8a7239b 100644
--- a/src/test/groovy/bugs/Groovy4418Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4418.groovy
@@ -18,12 +18,14 @@
  */
 package groovy.bugs
 
+import groovy.transform.CompileStatic
 import org.junit.Test
 
 import static groovy.test.GroovyAssert.assertScript
 import static groovy.test.GroovyAssert.shouldFail
 
-final class Groovy4418Bug {
+@CompileStatic
+final class Groovy4418 {
 
     @Test
     void testStaticFieldAccess() {
diff --git a/src/test/groovy/bugs/Groovy8063.groovy b/src/test/groovy/bugs/Groovy8063.groovy
new file mode 100644
index 0000000..2644329
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8063.groovy
@@ -0,0 +1,64 @@
+/*
+ *  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.Ignore
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+import static groovy.test.GroovyAssert.shouldFail
+
+@CompileStatic
+final class Groovy8063 {
+
+    @Test
+    void testTypeAnnotationWithQualifiedInnerClassReference() {
+        assertScript '''
+            @interface Anno {
+                Class value()
+            }
+
+            @Anno(value=Outer.Inner)
+            class Outer {
+                static class Inner {}
+            }
+
+            new Outer()
+        '''
+    }
+
+    @Test @Ignore
+    void testTypeAnnotationWithUnqualifiedInnerClassReference() {
+        def err = shouldFail '''
+            @interface Anno {
+                Class value()
+            }
+
+            @Anno(value=Inner) // type annotation is outside the class scope
+            class Outer {
+                static class Inner {}
+            }
+
+            new Outer()
+        '''
+
+        assert err =~ / X /
+    }
+}
diff --git a/src/test/groovy/bugs/Groovy9204.groovy b/src/test/groovy/bugs/Groovy9204.groovy
new file mode 100644
index 0000000..d6fc95f
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9204.groovy
@@ -0,0 +1,78 @@
+/*
+ *  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.test.NotYetImplemented
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
+import org.junit.Test
+
+final class Groovy9204 {
+
+    @Test @NotYetImplemented
+    void testGenerics() {
+        def config = new CompilerConfiguration(
+            targetDirectory: File.createTempDir(),
+            jointCompilationOptions: [memStub: true]
+        )
+
+        def parentDir = File.createTempDir()
+        try {
+            def a = new File(parentDir, 'A.java')
+            a.write '''
+                public class A {
+                    public String meth() {
+                        return "hello";
+                    }
+                }
+
+                abstract class One<T extends A> {
+                    protected T field;
+                }
+
+                abstract class Two<T extends A> extends One<T> {
+                }
+
+                abstract class Three extends Two<A> {
+                }
+            '''
+            def b = new File(parentDir, 'B.groovy')
+            b.write '''
+                @groovy.transform.CompileStatic
+                class B extends Three {
+                    def test() {
+                        field.meth() // typeof(field) should be A
+                        //    ^^^^ Cannot find matching method java.lang.Object#meth()
+                    }
+                }
+            '''
+
+            def loader = new GroovyClassLoader(this.class.classLoader)
+            def cu = new JavaAwareCompilationUnit(config, loader)
+            cu.addSources(a, b)
+            cu.compile()
+
+            Class clazz = loader.loadClass('B')
+            assert clazz.newInstance().test() == 'hello'
+        } finally {
+            parentDir.deleteDir()
+            config.targetDirectory.deleteDir()
+        }
+    }
+}
diff --git a/src/test/groovy/bugs/Groovy9213.groovy b/src/test/groovy/bugs/Groovy9213.groovy
new file mode 100644
index 0000000..2e8980c
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9213.groovy
@@ -0,0 +1,53 @@
+/*
+ *  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.codehaus.groovy.control.CompilerConfiguration
+import org.junit.Ignore
+import org.junit.Test
+
+import static org.codehaus.groovy.control.ParserPluginFactory.antlr2
+import static org.codehaus.groovy.control.ParserPluginFactory.antlr4
+
+@CompileStatic @Ignore
+final class Groovy9213 {
+
+    @Test(timeout=15000L)
+    void testUnmatchedParenInLongScript2() {
+        def config = new CompilerConfiguration()
+        config.pluginFactory = antlr2()
+
+        new GroovyShell(config).evaluate('''
+            int a = 0
+            (
+        ''' + ('a = 0\n' * 50))
+    }
+
+    @Test(timeout=15000L)
+    void testUnmatchedParenInLongScript4() {
+        def config = new CompilerConfiguration()
+        config.pluginFactory = antlr4(config)
+
+        new GroovyShell(config).evaluate('''
+            int a = 0
+            (
+        ''' + ('a = 0\n' * 50))
+    }
+}
diff --git a/src/test/groovy/bugs/Groovy9243Bug.groovy b/src/test/groovy/bugs/Groovy9243.groovy
similarity index 73%
rename from src/test/groovy/bugs/Groovy9243Bug.groovy
rename to src/test/groovy/bugs/Groovy9243.groovy
index e0fb10b..c03e211 100644
--- a/src/test/groovy/bugs/Groovy9243Bug.groovy
+++ b/src/test/groovy/bugs/Groovy9243.groovy
@@ -18,15 +18,20 @@
  */
 package groovy.bugs
 
+import groovy.transform.CompileStatic
 import org.codehaus.groovy.tools.GroovyStarter
+import org.junit.Test
 
-class Groovy9243Bug extends GroovyTestCase {
-    void testResolveNestedClassFromBaseType() {
-        def mainScriptPath = new File(this.getClass().getResource('/groovy/bugs/groovy9243/Main.groovy').toURI()).absolutePath
-        runScript(mainScriptPath)
+@CompileStatic
+final class Groovy9243 {
+
+    private static void runScript(String path) {
+        GroovyStarter.main('--main', 'groovy.ui.GroovyMain', path)
     }
 
-    static void runScript(String path) {
-        GroovyStarter.main(new String[] { "--main", "groovy.ui.GroovyMain", path })
+    @Test
+    void testResolveNestedClassFromBaseType() {
+        def mainScriptPath = new File(getClass().getResource('/groovy/bugs/groovy9243/Main.groovy').toURI()).absolutePath
+        runScript(mainScriptPath)
     }
 }
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7276Bug.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7276.groovy
similarity index 96%
rename from src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7276Bug.groovy
rename to src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7276.groovy
index 69bcdf1..97d8529 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7276Bug.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7276.groovy
@@ -22,7 +22,7 @@ import groovy.test.NotYetImplemented
 import groovy.transform.stc.StaticTypeCheckingTestCase
 import org.codehaus.groovy.classgen.asm.sc.StaticCompilationTestSupport
 
-final class Groovy7276Bug extends StaticTypeCheckingTestCase implements StaticCompilationTestSupport {
+final class Groovy7276 extends StaticTypeCheckingTestCase implements StaticCompilationTestSupport {
 
     void testShouldGoThroughPrivateBridgeAccessor() {
         assertScript '''


[groovy] 04/08: GROOVY-9249: Bump junit to 5.5.2

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

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

commit 8c15968d71e1d8c5103e4634858303930c83767a
Author: Daniel.Sun <re...@hotmail.com>
AuthorDate: Tue Sep 10 07:55:29 2019 +0800

    GROOVY-9249: Bump junit to 5.5.2
---
 subprojects/groovy-test-junit5/build.gradle | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/subprojects/groovy-test-junit5/build.gradle b/subprojects/groovy-test-junit5/build.gradle
index fdaea1b..4ea7b74 100644
--- a/subprojects/groovy-test-junit5/build.gradle
+++ b/subprojects/groovy-test-junit5/build.gradle
@@ -18,8 +18,8 @@
  */
 
 ext {
-    junit5Version = '5.5.1'
-    junit5PlatformVersion = '1.5.1'
+    junit5Version = '5.5.2'
+    junit5PlatformVersion = '1.5.2'
 }
 
 dependencies {


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

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

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

commit f925b19903ec2fed27e2af68d58b363c0b1d1df9
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] 05/08: fix javadoc

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

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

commit 0e932f8c0c742cc75d613634a186d550248833c3
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed Sep 11 05:45:40 2019 +1000

    fix javadoc
---
 src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 2049292..2a1e515 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -6678,7 +6678,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      *
      * @param self The array of values to average
      * @return The average of all of the items
-     * @see #average(java.util.Iterable)
+     * @see #sum(java.lang.Object[])
      * @since 3.0.0
      */
     public static Object average(Object[] self) {


[groovy] 06/08: GROOVY-9236: Avoid unnecessary resolving

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

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

commit 159be783726c9c89f39af43d7da714cb185f1726
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Aug 31 04:19:53 2019 +0800

    GROOVY-9236: Avoid unnecessary resolving
---
 .../codehaus/groovy/control/ResolveVisitor.java    |   6 +-
 .../groovy/bugs/groovy9236/Groovy9236.groovy       |  23 ++++
 .../bugs/groovy9236/Groovy9236SamePkg.groovy       |  23 ++++
 .../groovy/bugs/groovy9236/Main.groovy             |  31 ++++++
 .../groovy/bugs/groovy9236/Groovy9236Bug.groovy    | 124 +++++++++++++++++++++
 5 files changed, 204 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index 958a233..9d96690 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -496,12 +496,12 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
             return true;
         }
 
-        return resolveNestedClass(type) ||
+        return  resolveNestedClass(type) ||
                 resolveFromModule(type, testModuleImports) ||
                 resolveFromCompileUnit(type) ||
                 resolveFromDefaultImports(type, testDefaultImports) ||
-                resolveFromStaticInnerClasses(type, testStaticInnerClasses) ||
-                resolveToOuter(type);
+                resolveToOuter(type) ||
+                resolveFromStaticInnerClasses(type, testStaticInnerClasses);
     }
 
     private boolean resolveNestedClass(ClassNode type) {
diff --git a/src/test-resources/groovy/bugs/groovy9236/Groovy9236.groovy b/src/test-resources/groovy/bugs/groovy9236/Groovy9236.groovy
new file mode 100644
index 0000000..ef1a1ac
--- /dev/null
+++ b/src/test-resources/groovy/bugs/groovy9236/Groovy9236.groovy
@@ -0,0 +1,23 @@
+/*
+ *  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.groovy9236
+
+interface Groovy9236 {
+
+}
\ No newline at end of file
diff --git a/src/test-resources/groovy/bugs/groovy9236/Groovy9236SamePkg.groovy b/src/test-resources/groovy/bugs/groovy9236/Groovy9236SamePkg.groovy
new file mode 100644
index 0000000..69a5f56
--- /dev/null
+++ b/src/test-resources/groovy/bugs/groovy9236/Groovy9236SamePkg.groovy
@@ -0,0 +1,23 @@
+/*
+ *  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.groovy9236
+
+class Groovy9236SamePkg {
+
+}
\ No newline at end of file
diff --git a/src/test-resources/groovy/bugs/groovy9236/Main.groovy b/src/test-resources/groovy/bugs/groovy9236/Main.groovy
new file mode 100644
index 0000000..e1767b4
--- /dev/null
+++ b/src/test-resources/groovy/bugs/groovy9236/Main.groovy
@@ -0,0 +1,31 @@
+/*
+ *  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.groovy9236
+
+class Outer {
+    static class Groovy9236 {}
+
+    def test() {
+        assert new Groovy9236()
+        assert new Outer.Groovy9236()
+        assert new Groovy9236SamePkg()
+    }
+}
+
+new Outer().test()
diff --git a/src/test/groovy/bugs/groovy9236/Groovy9236Bug.groovy b/src/test/groovy/bugs/groovy9236/Groovy9236Bug.groovy
new file mode 100644
index 0000000..0ad30d0
--- /dev/null
+++ b/src/test/groovy/bugs/groovy9236/Groovy9236Bug.groovy
@@ -0,0 +1,124 @@
+/*
+ *  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.groovy9236
+
+import org.codehaus.groovy.tools.GroovyStarter
+
+class Groovy9236Bug extends GroovyTestCase {
+    /* groovy-3.0.0-beta-3 will try to guess and load the following classes:
+Script1$_p_lambda1BeanInfo
+Script1$_p_lambda1Customizer
+Script1BeanInfo
+Script1Customizer
+groovy$transform$CompileStatic
+groovy.lang.GroovyObject$Collectors
+groovy.lang.GroovyObject$CompileStatic
+groovy.lang.GroovyObject$groovy$transform$CompileStatic
+groovy.lang.GroovyObject$java$util$stream$Collectors
+groovy.lang.GroovyObject$java$util$stream$Stream
+groovy.lang.groovy$transform$CompileStatic
+groovy.lang.java$util$stream$Collectors
+groovy.lang.java$util$stream$Stream
+groovy.transform$CompileStatic
+groovy.util.groovy$transform$CompileStatic
+groovy.util.java$util$stream$Collectors
+groovy.util.java$util$stream$Stream
+java$util$stream$Collectors
+java$util$stream$Stream
+java.io.groovy$transform$CompileStatic
+java.io.java$util$stream$Collectors
+java.io.java$util$stream$Stream
+java.lang.groovy$transform$CompileStatic
+java.lang.java$util$stream$Collectors
+java.lang.java$util$stream$Stream
+java.net.groovy$transform$CompileStatic
+java.net.java$util$stream$Collectors
+java.net.java$util$stream$Stream
+java.util$stream$Collectors
+java.util$stream$Stream
+java.util.groovy$transform$CompileStatic
+java.util.java$util$stream$Collectors
+java.util.java$util$stream$Stream
+java.util.stream$Collectors
+java.util.stream$Stream
+     */
+    void testAvoidUnnecessaryResolving() {
+        def cl = new Groovy9236ClassLoader()
+        def gs = new GroovyShell(cl)
+        gs.evaluate('''
+                import groovy.transform.CompileStatic
+                import java.util.stream.Collectors
+                import java.util.stream.Stream
+                
+                @CompileStatic
+                void p() {
+                    assert [2, 3, 4] == [1, 2, 3].stream().map(e -> e.plus 1).collect(Collectors.toList())
+                }
+                
+                p()
+        ''')
+
+        final classNamesShouldAvoidToGuess = ['java.lang.java$util$stream$Collectors',
+                                              'java.util.java$util$stream$Collectors',
+                                              'java.io.java$util$stream$Collectors',
+                                              'java.net.java$util$stream$Collectors',
+                                              'groovy.lang.java$util$stream$Collectors',
+                                              'groovy.util.java$util$stream$Collectors',
+                                              'java$util$stream$Collectors',
+                                              'java.util$stream$Collectors',
+                                              'java.util.stream$Collectors',
+                                              'java.lang.groovy$transform$CompileStatic',
+                                              'java.util.groovy$transform$CompileStatic',
+                                              'java.io.groovy$transform$CompileStatic',
+                                              'java.net.groovy$transform$CompileStatic',
+                                              'groovy.lang.groovy$transform$CompileStatic',
+                                              'groovy.util.groovy$transform$CompileStatic',
+                                              'groovy$transform$CompileStatic',
+                                              'groovy.transform$CompileStatic',
+                                              'java.lang.java$util$stream$Stream',
+                                              'java.util.java$util$stream$Stream',
+                                              'java.io.java$util$stream$Stream',
+                                              'java.net.java$util$stream$Stream',
+                                              'groovy.lang.java$util$stream$Stream',
+                                              'groovy.util.java$util$stream$Stream',
+                                              'java$util$stream$Stream',
+                                              'java.util$stream$Stream',
+                                              'java.util.stream$Stream']
+
+        assert cl.guessedClassNameList.every(n -> !classNamesShouldAvoidToGuess.contains(n))
+    }
+
+    void testResolvingPrecedence() {
+        def mainScriptPath = new File(this.getClass().getResource('/groovy/bugs/groovy9236/Main.groovy').toURI()).absolutePath
+        runScript(mainScriptPath)
+    }
+
+    static void runScript(String path) {
+        GroovyStarter.main(new String[] { "--main", "groovy.ui.GroovyMain", path })
+    }
+
+    private static class Groovy9236ClassLoader extends GroovyClassLoader {
+        def guessedClassNameList = []
+
+        protected Class<?> findClass(final String name) throws ClassNotFoundException {
+            guessedClassNameList << name
+            super.findClass(name)
+        }
+    }
+}


[groovy] 01/08: GROOVY-9229, GROOVY-9233: added missing closure parameter metadata

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

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

commit e13dc12950383d06b48d71a1a39419c8cb97b04f
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Sep 3 11:07:22 2019 -0500

    GROOVY-9229, GROOVY-9233: added missing closure parameter metadata
---
 .../groovy-sql/src/main/java/groovy/sql/Sql.java   | 224 +++++++++++----------
 1 file changed, 114 insertions(+), 110 deletions(-)

diff --git a/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java b/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
index 52589c5..e7e45dc 100644
--- a/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
+++ b/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
@@ -28,6 +28,7 @@ import groovy.transform.stc.SimpleType;
 import org.codehaus.groovy.runtime.InvokerHelper;
 
 import javax.sql.DataSource;
+
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
@@ -133,7 +134,7 @@ import static org.apache.groovy.sql.extensions.SqlExtensions.toRowResult;
  * [ID:20, NAME:Grails, URL:http://grails.org]
  * [ID:40, NAME:Gradle, URL:http://gradle.org]
  * </pre>
- * Also, <code>eachRow</code> and <code>rows</code> support paging.  Here's an example: 
+ * Also, <code>eachRow</code> and <code>rows</code> support paging.  Here's an example:
  * <pre>
  * sql.eachRow('select * from PROJECT', 2, 2) { row {@code ->}
  *     println "${row.name.padRight(10)} ($row.url)"
@@ -144,7 +145,7 @@ import static org.apache.groovy.sql.extensions.SqlExtensions.toRowResult;
  * Grails     (http://grails.org)
  * Griffon    (http://griffon.codehaus.org)
  * </pre>
- * 
+ *
  * Finally, we should clean up:
  * <pre>
  * sql.close()
@@ -294,7 +295,7 @@ public class Sql implements AutoCloseable {
      * @see #newInstance(String)
      * @throws SQLException if a database access error occurs
      */
-    public static void withInstance(String url, Closure c) throws SQLException {
+    public static void withInstance(String url, @ClosureParams(value=SimpleType.class, options="groovy.sql.Sql") Closure c) throws SQLException {
         try (Sql sql = newInstance(url)) {
             c.call(sql);
         }
@@ -330,7 +331,8 @@ public class Sql implements AutoCloseable {
      * @see #newInstance(String, java.util.Properties)
      * @throws SQLException if a database access error occurs
      */
-    public static void withInstance(String url, Properties properties, Closure c) throws SQLException {
+    public static void withInstance(String url, Properties properties, @ClosureParams(value=SimpleType.class, options="groovy.sql.Sql") Closure c)
+            throws SQLException {
         try (Sql sql = newInstance(url, properties)) {
             c.call(sql);
         }
@@ -371,7 +373,7 @@ public class Sql implements AutoCloseable {
      * @throws SQLException if a database access error occurs
      * @throws ClassNotFoundException if the driver class cannot be found or loaded
      */
-    public static void withInstance(String url, Properties properties, String driverClassName, Closure c)
+    public static void withInstance(String url, Properties properties, String driverClassName, @ClosureParams(value=SimpleType.class, options="groovy.sql.Sql") Closure c)
             throws SQLException, ClassNotFoundException {
         try (Sql sql = newInstance(url, properties, driverClassName)) {
             c.call(sql);
@@ -408,7 +410,8 @@ public class Sql implements AutoCloseable {
      * @see #newInstance(String, String, String)
      * @throws SQLException if a database access error occurs
      */
-    public static void withInstance(String url, String user, String password, Closure c) throws SQLException {
+    public static void withInstance(String url, String user, String password, @ClosureParams(value=SimpleType.class, options="groovy.sql.Sql") Closure c)
+            throws SQLException {
         try (Sql sql = newInstance(url, user, password)) {
             c.call(sql);
         }
@@ -449,7 +452,7 @@ public class Sql implements AutoCloseable {
      * @throws SQLException if a database access error occurs
      * @throws ClassNotFoundException if the driver class cannot be found or loaded
      */
-    public static void withInstance(String url, String user, String password, String driverClassName, Closure c)
+    public static void withInstance(String url, String user, String password, String driverClassName, @ClosureParams(value=SimpleType.class, options="groovy.sql.Sql") Closure c)
             throws SQLException, ClassNotFoundException {
         try (Sql sql = newInstance(url, user, password, driverClassName)) {
             c.call(sql);
@@ -484,7 +487,7 @@ public class Sql implements AutoCloseable {
      * @throws SQLException if a database access error occurs
      * @throws ClassNotFoundException if the driver class cannot be found or loaded
      */
-    public static void withInstance(String url, String driverClassName, Closure c)
+    public static void withInstance(String url, String driverClassName, @ClosureParams(value=SimpleType.class, options="groovy.sql.Sql") Closure c)
             throws SQLException, ClassNotFoundException {
         try (Sql sql = newInstance(url, driverClassName)) {
             c.call(sql);
@@ -523,7 +526,7 @@ public class Sql implements AutoCloseable {
      *     resultSetConcurrency: CONCUR_READ_ONLY
      * )
      * </pre>
-     * 
+     *
      * @param args a Map contain further arguments
      * @return a new Sql instance with a connection
      * @throws SQLException           if a database access error occurs
@@ -632,7 +635,9 @@ public class Sql implements AutoCloseable {
             // readonly Map otherwise seen as Map<String, Serializable>
             @NamedParam(value = "unused", type = Object.class)
             Map<String, Object> args,
-            Closure c) throws SQLException, ClassNotFoundException {
+            @ClosureParams(value=SimpleType.class, options="groovy.sql.Sql")
+            Closure c)
+                throws SQLException, ClassNotFoundException {
         try (Sql sql = newInstance(args)) {
             c.call(sql);
         }
@@ -1696,7 +1701,6 @@ public class Sql implements AutoCloseable {
         return rows(sql, offset, maxRows, null);
     }
 
-
     /**
      * Performs the given SQL query and return the rows of the result set.
      * In addition, the <code>metaClosure</code> will be called once passing in the
@@ -2363,7 +2367,7 @@ public class Sql implements AutoCloseable {
      * @throws SQLException if a database access error occurs
      * @since 2.3.2
      */
-    public void execute(String sql, Closure processResults) throws SQLException {
+    public void execute(String sql, @ClosureParams(value=SimpleType.class, options={"boolean,java.util.List<groovy.sql.GroovyRowResult>", "boolean,int"}) Closure processResults) throws SQLException {
         Connection connection = createConnection();
         Statement statement = null;
         try {
@@ -2450,7 +2454,7 @@ public class Sql implements AutoCloseable {
      * @see #execute(String, Closure)
      * @since 2.3.2
      */
-    public void execute(String sql, List<Object> params, Closure processResults) throws SQLException {
+    public void execute(String sql, List<Object> params, @ClosureParams(value=SimpleType.class, options={"boolean,java.util.List<groovy.sql.GroovyRowResult>", "boolean,int"}) Closure processResults) throws SQLException {
         Connection connection = createConnection();
         PreparedStatement statement = null;
         try {
@@ -2507,7 +2511,7 @@ public class Sql implements AutoCloseable {
      * @throws SQLException if a database access error occurs
      * @since 2.3.2
      */
-    public void execute(Map params, String sql, Closure processResults) throws SQLException {
+    public void execute(Map params, String sql, @ClosureParams(value=SimpleType.class, options={"boolean,java.util.List<groovy.sql.GroovyRowResult>", "boolean,int"}) Closure processResults) throws SQLException {
         execute(sql, singletonList(params), processResults);
     }
 
@@ -2547,7 +2551,7 @@ public class Sql implements AutoCloseable {
      * @see #execute(String, List, Closure)
      * @since 2.3.2
      */
-    public void execute(String sql, Object[] params, Closure processResults) throws SQLException {
+    public void execute(String sql, Object[] params, @ClosureParams(value=SimpleType.class, options={"boolean,java.util.List<groovy.sql.GroovyRowResult>", "boolean,int"}) Closure processResults) throws SQLException {
         execute(sql, Arrays.asList(params), processResults);
     }
 
@@ -2593,7 +2597,7 @@ public class Sql implements AutoCloseable {
      * @see #execute(String, List, Closure)
      * @since 2.3.2
      */
-    public void execute(GString gstring, Closure processResults) throws SQLException {
+    public void execute(GString gstring, @ClosureParams(value=SimpleType.class, options={"boolean,java.util.List<groovy.sql.GroovyRowResult>", "boolean,int"}) Closure processResults) throws SQLException {
         List<Object> params = getParameters(gstring);
         String sql = asSql(gstring, params);
         execute(sql, params, processResults);
@@ -3165,7 +3169,7 @@ public class Sql implements AutoCloseable {
      * @param closure called for each row with a GroovyResultSet
      * @throws SQLException if a database access error occurs
      */
-    public void call(String sql, List<Object> params, Closure closure) throws Exception {
+    public void call(String sql, List<Object> params, @ClosureParams(value=SimpleType.class, options="java.lang.Object[]") Closure closure) throws Exception {
         callWithRows(sql, params, NO_RESULT_SETS, closure);
     }
 
@@ -3202,7 +3206,7 @@ public class Sql implements AutoCloseable {
      * @see #call(String, List, Closure)
      * @see #expand(Object)
      */
-    public void call(GString gstring, Closure closure) throws Exception {
+    public void call(GString gstring, @ClosureParams(value=SimpleType.class, options="java.lang.Object[]") Closure closure) throws Exception {
         List<Object> params = getParameters(gstring);
         String sql = asSql(gstring, params);
         call(sql, params, closure);
@@ -3233,7 +3237,7 @@ public class Sql implements AutoCloseable {
      * @throws SQLException if a database access error occurs
      * @see #callWithRows(String, List, Closure)
      */
-    public List<GroovyRowResult> callWithRows(GString gstring, Closure closure) throws SQLException {
+    public List<GroovyRowResult> callWithRows(GString gstring, @ClosureParams(value=SimpleType.class, options="java.lang.Object[]") Closure closure) throws SQLException {
         List<Object> params = getParameters(gstring);
         String sql = asSql(gstring, params);
         return callWithRows(sql, params, closure);
@@ -3263,7 +3267,7 @@ public class Sql implements AutoCloseable {
      * @throws SQLException if a database access error occurs
      * @see #callWithRows(GString, Closure)
      */
-    public List<GroovyRowResult> callWithRows(String sql, List<Object> params, Closure closure) throws SQLException {
+    public List<GroovyRowResult> callWithRows(String sql, List<Object> params, @ClosureParams(value=SimpleType.class, options="java.lang.Object[]") Closure closure) throws SQLException {
         return callWithRows(sql, params, FIRST_RESULT_SET, closure).get(0);
     }
 
@@ -3292,7 +3296,7 @@ public class Sql implements AutoCloseable {
      * @throws SQLException if a database access error occurs
      * @see #callWithAllRows(String, List, Closure)
      */
-    public List<List<GroovyRowResult>> callWithAllRows(GString gstring, Closure closure) throws SQLException {
+    public List<List<GroovyRowResult>> callWithAllRows(GString gstring, @ClosureParams(value=SimpleType.class, options="java.lang.Object[]") Closure closure) throws SQLException {
         List<Object> params = getParameters(gstring);
         String sql = asSql(gstring, params);
         return callWithAllRows(sql, params, closure);
@@ -3322,92 +3326,11 @@ public class Sql implements AutoCloseable {
      * @throws SQLException if a database access error occurs
      * @see #callWithRows(GString, Closure)
      */
-    public List<List<GroovyRowResult>> callWithAllRows(String sql, List<Object> params, Closure closure) throws SQLException {
+    public List<List<GroovyRowResult>> callWithAllRows(String sql, List<Object> params, @ClosureParams(value=SimpleType.class, options="java.lang.Object[]") Closure closure) throws SQLException {
         return callWithRows(sql, params, ALL_RESULT_SETS, closure);
     }
 
     /**
-     * Base internal method for call(), callWithRows(), and callWithAllRows() style of methods.
-     * <p>
-     * Performs a stored procedure call with the given parameters,
-     * calling the closure once with all result objects,
-     * and also returning the rows of the ResultSet(s) (if processResultSets is set to
-     * Sql.FIRST_RESULT_SET, Sql.ALL_RESULT_SETS)
-     * <p>
-     * Main purpose of processResultSets param is to retain original call() method
-     * performance when this is set to Sql.NO_RESULT_SETS
-     * <p>
-     * Resource handling is performed automatically where appropriate.
-     *
-     * @param sql     the sql statement
-     * @param params  a list of parameters
-     * @param processResultsSets the result sets to process, either Sql.NO_RESULT_SETS, Sql.FIRST_RESULT_SET, or Sql.ALL_RESULT_SETS
-     * @param closure called once with all out parameter results
-     * @return a list of GroovyRowResult objects
-     * @throws SQLException if a database access error occurs
-     * @see #callWithRows(String, List, Closure)
-     */
-    protected List<List<GroovyRowResult>> callWithRows(String sql, List<Object> params, int processResultsSets, Closure closure) throws SQLException {
-        Connection connection = createConnection();
-        CallableStatement statement = null;
-        List<GroovyResultSet> resultSetResources = new ArrayList<GroovyResultSet>();
-        try {
-            statement = getCallableStatement(connection, sql, params);
-            boolean hasResultSet = statement.execute();
-            List<Object> results = new ArrayList<Object>();
-            int indx = 0;
-            int inouts = 0;
-            for (Object value : params) {
-                if (value instanceof OutParameter) {
-                    if (value instanceof ResultSetOutParameter) {
-                        GroovyResultSet resultSet = CallResultSet.getImpl(statement, indx);
-                        resultSetResources.add(resultSet);
-                        results.add(resultSet);
-                    } else {
-                        Object o = statement.getObject(indx + 1);
-                        if (o instanceof ResultSet) {
-                            GroovyResultSet resultSet = new GroovyResultSetProxy((ResultSet) o).getImpl();
-                            results.add(resultSet);
-                            resultSetResources.add(resultSet);
-                        } else {
-                            results.add(o);
-                        }
-                    }
-                    inouts++;
-                }
-                indx++;
-            }
-            closure.call(results.toArray(new Object[inouts]));
-            List<List<GroovyRowResult>> resultSets = new ArrayList<List<GroovyRowResult>>();
-            if (processResultsSets == NO_RESULT_SETS) {
-                resultSets.add(new ArrayList<GroovyRowResult>());
-                return resultSets;
-            }
-            //Check both hasResultSet and getMoreResults() because of differences in vendor behavior
-            if (!hasResultSet) {
-                hasResultSet = statement.getMoreResults();
-            }
-            while (hasResultSet && (processResultsSets != NO_RESULT_SETS)) {
-                resultSets.add(asList(sql, statement.getResultSet()));
-                if (processResultsSets == FIRST_RESULT_SET) {
-                    break;
-                } else {
-                    hasResultSet = statement.getMoreResults();
-                }
-            }
-            return resultSets;
-        } catch (SQLException e) {
-            LOG.warning("Failed to execute: " + sql + " because: " + e.getMessage());
-            throw e;
-        } finally {
-            for (GroovyResultSet rs : resultSetResources) {
-                closeResources(null, null, rs);
-            }
-            closeResources(connection, statement);
-        }
-    }
-
-    /**
      * If this SQL object was created with a Connection then this method closes
      * the connection. If this SQL object was created from a DataSource then
      * this method only frees any cached objects (statements in particular).
@@ -3540,7 +3463,7 @@ public class Sql implements AutoCloseable {
      * @param closure the given closure
      * @throws SQLException if a database error occurs
      */
-    public void cacheConnection(Closure closure) throws SQLException {
+    public void cacheConnection(@ClosureParams(value=SimpleType.class, options="java.sql.Connection") Closure closure) throws SQLException {
         boolean savedCacheConnection = cacheConnection;
         cacheConnection = true;
         Connection connection = null;
@@ -3565,7 +3488,7 @@ public class Sql implements AutoCloseable {
      * @param closure the given closure
      * @throws SQLException if a database error occurs
      */
-    public void withTransaction(Closure closure) throws SQLException {
+    public void withTransaction(@ClosureParams(value=SimpleType.class, options="java.sql.Connection") Closure closure) throws SQLException {
         boolean savedCacheConnection = cacheConnection;
         cacheConnection = true;
         Connection connection = null;
@@ -3650,7 +3573,7 @@ public class Sql implements AutoCloseable {
      *                      database fails to execute properly or attempts to return a result set.
      * @see #withBatch(int, Closure)
      */
-    public int[] withBatch(Closure closure) throws SQLException {
+    public int[] withBatch(@ClosureParams(value=SimpleType.class, options="groovy.sql.BatchingStatementWrapper") Closure closure) throws SQLException {
         return withBatch(0, closure);
     }
 
@@ -3699,7 +3622,7 @@ public class Sql implements AutoCloseable {
      * @see BatchingStatementWrapper
      * @see Statement
      */
-    public int[] withBatch(int batchSize, Closure closure) throws SQLException {
+    public int[] withBatch(int batchSize, @ClosureParams(value=SimpleType.class, options="groovy.sql.BatchingStatementWrapper") Closure closure) throws SQLException {
         Connection connection = createConnection();
         BatchingStatementWrapper statement = null;
         boolean savedWithinBatch = withinBatch;
@@ -3763,7 +3686,7 @@ public class Sql implements AutoCloseable {
      * @see BatchingPreparedStatementWrapper
      * @see PreparedStatement
      */
-    public int[] withBatch(String sql, Closure closure) throws SQLException {
+    public int[] withBatch(String sql, @ClosureParams(value=SimpleType.class, options="groovy.sql.BatchingPreparedStatementWrapper") Closure closure) throws SQLException {
         return withBatch(0, sql, closure);
     }
 
@@ -3837,7 +3760,7 @@ public class Sql implements AutoCloseable {
      * @see BatchingPreparedStatementWrapper
      * @see PreparedStatement
      */
-    public int[] withBatch(int batchSize, String sql, Closure closure) throws SQLException {
+    public int[] withBatch(int batchSize, String sql, @ClosureParams(value=SimpleType.class, options="groovy.sql.BatchingPreparedStatementWrapper") Closure closure) throws SQLException {
         Connection connection = createConnection();
         List<Tuple> indexPropList = null;
         SqlWithParams preCheck = buildSqlWithIndexedProps(sql);
@@ -3878,7 +3801,7 @@ public class Sql implements AutoCloseable {
      * @throws SQLException if a database error occurs
      * @see #setCacheStatements(boolean)
      */
-    public void cacheStatements(Closure closure) throws SQLException {
+    public void cacheStatements(@ClosureParams(value=SimpleType.class, options="java.sql.Connection") Closure closure) throws SQLException {
         boolean savedCacheStatements = cacheStatements;
         cacheStatements = true;
         Connection connection = null;
@@ -3896,6 +3819,87 @@ public class Sql implements AutoCloseable {
     //-------------------------------------------------------------------------
 
     /**
+     * Base internal method for call(), callWithRows(), and callWithAllRows() style of methods.
+     * <p>
+     * Performs a stored procedure call with the given parameters,
+     * calling the closure once with all result objects,
+     * and also returning the rows of the ResultSet(s) (if processResultSets is set to
+     * Sql.FIRST_RESULT_SET, Sql.ALL_RESULT_SETS)
+     * <p>
+     * Main purpose of processResultSets param is to retain original call() method
+     * performance when this is set to Sql.NO_RESULT_SETS
+     * <p>
+     * Resource handling is performed automatically where appropriate.
+     *
+     * @param sql     the sql statement
+     * @param params  a list of parameters
+     * @param processResultsSets the result sets to process, either Sql.NO_RESULT_SETS, Sql.FIRST_RESULT_SET, or Sql.ALL_RESULT_SETS
+     * @param closure called once with all out parameter results
+     * @return a list of GroovyRowResult objects
+     * @throws SQLException if a database access error occurs
+     * @see #callWithRows(String, List, Closure)
+     */
+    protected List<List<GroovyRowResult>> callWithRows(String sql, List<Object> params, int processResultsSets, @ClosureParams(value=SimpleType.class, options="java.lang.Object[]") Closure closure) throws SQLException {
+        Connection connection = createConnection();
+        CallableStatement statement = null;
+        List<GroovyResultSet> resultSetResources = new ArrayList<GroovyResultSet>();
+        try {
+            statement = getCallableStatement(connection, sql, params);
+            boolean hasResultSet = statement.execute();
+            List<Object> results = new ArrayList<Object>();
+            int indx = 0;
+            int inouts = 0;
+            for (Object value : params) {
+                if (value instanceof OutParameter) {
+                    if (value instanceof ResultSetOutParameter) {
+                        GroovyResultSet resultSet = CallResultSet.getImpl(statement, indx);
+                        resultSetResources.add(resultSet);
+                        results.add(resultSet);
+                    } else {
+                        Object o = statement.getObject(indx + 1);
+                        if (o instanceof ResultSet) {
+                            GroovyResultSet resultSet = new GroovyResultSetProxy((ResultSet) o).getImpl();
+                            results.add(resultSet);
+                            resultSetResources.add(resultSet);
+                        } else {
+                            results.add(o);
+                        }
+                    }
+                    inouts++;
+                }
+                indx++;
+            }
+            closure.call(results.toArray(new Object[inouts]));
+            List<List<GroovyRowResult>> resultSets = new ArrayList<List<GroovyRowResult>>();
+            if (processResultsSets == NO_RESULT_SETS) {
+                resultSets.add(new ArrayList<GroovyRowResult>());
+                return resultSets;
+            }
+            //Check both hasResultSet and getMoreResults() because of differences in vendor behavior
+            if (!hasResultSet) {
+                hasResultSet = statement.getMoreResults();
+            }
+            while (hasResultSet && (processResultsSets != NO_RESULT_SETS)) {
+                resultSets.add(asList(sql, statement.getResultSet()));
+                if (processResultsSets == FIRST_RESULT_SET) {
+                    break;
+                } else {
+                    hasResultSet = statement.getMoreResults();
+                }
+            }
+            return resultSets;
+        } catch (SQLException e) {
+            LOG.warning("Failed to execute: " + sql + " because: " + e.getMessage());
+            throw e;
+        } finally {
+            for (GroovyResultSet rs : resultSetResources) {
+                closeResources(null, null, rs);
+            }
+            closeResources(connection, statement);
+        }
+    }
+
+    /**
      * Useful helper method which handles resource management when executing a
      * query which returns a result set.
      * Derived classes of Sql can override "createQueryCommand" and then call


[groovy] 08/08: fix javadoc

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

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

commit b815887b529bbdb90a6635ea3e1f9b15a363ede4
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Sep 14 05:35:18 2019 +1000

    fix javadoc
---
 src/main/java/groovy/transform/AnnotationCollector.java | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/main/java/groovy/transform/AnnotationCollector.java b/src/main/java/groovy/transform/AnnotationCollector.java
index 769698d..4112825 100644
--- a/src/main/java/groovy/transform/AnnotationCollector.java
+++ b/src/main/java/groovy/transform/AnnotationCollector.java
@@ -171,6 +171,7 @@ import java.lang.annotation.Target;
  * </pre>
  * 
  * @see org.codehaus.groovy.transform.AnnotationCollectorTransform
+ * @since 2.1.0
  */
 @java.lang.annotation.Documented
 @Retention(RetentionPolicy.RUNTIME)


[groovy] 03/08: Added named param annotations

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

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

commit 74268ea5ebd6dfd81720c48cc0e585f1f511d176
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);
     }