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 2022/06/26 16:19:36 UTC

[groovy] branch GROOVY_4_0_X updated (e33edbe99d -> 297c840802)

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

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


    from e33edbe99d GROOVY-10153: resolve implicit wildcard bounding once type resolved
     new dc6319c522 Trivial refactoring: remove redundant type casting
     new 297c840802 Add 2 more test cases for lambda

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/reflection/MixinInMetaClass.java        |  6 ++--
 src/test/groovy/transform/stc/LambdaTest.groovy    | 32 ++++++++++++++++++++++
 2 files changed, 35 insertions(+), 3 deletions(-)


[groovy] 02/02: Add 2 more test cases for lambda

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

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

commit 297c840802b79af22ea48695af906f064a034333
Author: Daniel Sun <su...@apache.org>
AuthorDate: Mon Jun 27 00:19:01 2022 +0800

    Add 2 more test cases for lambda
---
 src/test/groovy/transform/stc/LambdaTest.groovy | 32 +++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/test/groovy/transform/stc/LambdaTest.groovy b/src/test/groovy/transform/stc/LambdaTest.groovy
index a0165db6a7..fab0a303f4 100644
--- a/src/test/groovy/transform/stc/LambdaTest.groovy
+++ b/src/test/groovy/transform/stc/LambdaTest.groovy
@@ -309,6 +309,38 @@ final class LambdaTest {
         '''
     }
 
+    @Test
+    void testCollectors1() {
+        assertScript '''
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            
+            @CompileStatic
+            def test() {
+                Set<String> set = ['a', 'b', 'c'] as Set
+                assert [a: 'a', b: 'b', c: 'c'] == set.stream().collect(Collectors.toMap(e -> e, e -> e))
+            }
+            
+            test()
+        '''
+    }
+
+    @Test
+    void testCollectors2() {
+        assertScript '''
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            
+            @CompileStatic
+            def test() {
+                Set<String> set = ['a', 'b', 'c'] as Set
+                assert [a: 'a', b: 'b', c: 'c'] == set.stream().collect(Collectors.toMap(e -> e, e -> e, (o1, o2) -> o2))
+            }
+            
+            test()
+        '''
+    }
+
     @Test
     void testFunctionWithLocalVariables() {
         assertScript '''


[groovy] 01/02: Trivial refactoring: remove redundant type casting

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

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

commit dc6319c5225068262df611d55ed48a1f658740d7
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Jun 25 19:59:55 2022 +0800

    Trivial refactoring: remove redundant type casting
    
    (cherry picked from commit cd7d21e994d0355aaa3058498849c80397c4aff6)
---
 src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java b/src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java
index 93c075c56d..308bbb0463 100644
--- a/src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java
+++ b/src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java
@@ -110,7 +110,7 @@ public class MixinInMetaClass {
 
         ExpandoMetaClass mc = (ExpandoMetaClass) self;
 
-        List<MetaMethod> arr = new ArrayList<MetaMethod>();
+        List<MetaMethod> arr = new ArrayList<>();
         for (Class categoryClass : categoryClasses) {
 
             final CachedClass cachedCategoryClass = ReflectionCache.getCachedClass(categoryClass);
@@ -152,8 +152,8 @@ public class MixinInMetaClass {
             }
         }
 
-        for (Object res : arr) {
-            final MetaMethod metaMethod = (MetaMethod) res;
+        for (MetaMethod res : arr) {
+            final MetaMethod metaMethod = res;
             if (metaMethod.getDeclaringClass().isAssignableFrom(selfClass))
                 mc.registerInstanceMethod(metaMethod);
             else {