groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emil...@apache.org
Subject [groovy] 01/01: GROOVY-9340: return type, not type redirect
Date Thu, 19 Dec 2019 16:42:06 GMT
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 <eric.milles@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


Mime
View raw message