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

[groovy] branch GROOVY-9340 created (now 80a20af)

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

emilles pushed a change to branch GROOVY-9340
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at 80a20af  GROOVY-9340: return type, not type redirect

This branch includes the following new commits:

     new 80a20af  GROOVY-9340: return type, not type redirect

The 1 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.



[groovy] 01/01: GROOVY-9340: return type, not type redirect

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

emilles pushed a commit to branch GROOVY-9340
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 80a20afb9694d1ad7d50bf93417b7d0e1aca822e
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Dec 19 10:41:46 2019 -0600

    GROOVY-9340: return type, not type redirect
---
 .../codehaus/groovy/ast/tools/GenericsUtils.java    | 21 ++++++++-------------
 src/test/groovy/transform/stc/LambdaTest.groovy     |  2 +-
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
index 4e65cb1..3ce6be7 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
@@ -971,22 +971,15 @@ public class GenericsUtils {
     }
 
     /**
-     * Get the actual type according to the placeholder name
+     * Gets the actual type according to the placeholder name.
      *
-     * @param placeholderName the placeholder name, e.g. T, E
+     * @param placeholderName the placeholder name (i.e. "T", "E", etc.)
      * @param genericsPlaceholderAndTypeMap the result of {@link #makeDeclaringAndActualGenericsTypeMap(ClassNode, ClassNode)}
-     * @return the actual type
      */
-    public static ClassNode findActualTypeByGenericsPlaceholderName(String placeholderName, Map<GenericsType, GenericsType> genericsPlaceholderAndTypeMap) {
-        for (Map.Entry<GenericsType, GenericsType> entry : genericsPlaceholderAndTypeMap.entrySet()) {
-            GenericsType declaringGenericsType = entry.getKey();
-
-            if (placeholderName.equals(declaringGenericsType.getName())) {
-                return entry.getValue().getType().redirect();
-            }
-        }
-
-        return null;
+    public static ClassNode findActualTypeByGenericsPlaceholderName(final String placeholderName, final Map<GenericsType, GenericsType> genericsPlaceholderAndTypeMap) {
+        return genericsPlaceholderAndTypeMap.entrySet().stream()
+                .filter(entry -> entry.getKey().getName().equals(placeholderName))
+                .map(entry -> entry.getValue().getType()).findFirst().orElse(null);
     }
 
     private static class ParameterizedTypeCacheKey {
@@ -1002,6 +995,7 @@ public class GenericsUtils {
             return genericsClass;
         }
 
+        @SuppressWarnings("unused")
         public void setGenericsClass(ClassNode genericsClass) {
             this.genericsClass = genericsClass;
         }
@@ -1010,6 +1004,7 @@ public class GenericsUtils {
             return actualType;
         }
 
+        @SuppressWarnings("unused")
         public void setActualType(ClassNode actualType) {
             this.actualType = actualType;
         }
diff --git a/src/test/groovy/transform/stc/LambdaTest.groovy b/src/test/groovy/transform/stc/LambdaTest.groovy
index d7b9553..4b2960b 100644
--- a/src/test/groovy/transform/stc/LambdaTest.groovy
+++ b/src/test/groovy/transform/stc/LambdaTest.groovy
@@ -178,7 +178,7 @@ final class LambdaTest {
         '''
     }
 
-    @Test @NotYetImplemented // GROOVY-9340
+    @Test // GROOVY-9340
     void testConsumerWithSelfType() {
         assertScript '''
             @groovy.transform.CompileStatic