You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/11/26 14:55:58 UTC

[commons-lang] branch master updated: LANG-1618 - Add GenericArrayType (#661)

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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new b74c697  LANG-1618 - Add GenericArrayType (#661)
b74c697 is described below

commit b74c697bba6d3e16941b669de6cca5e25ee1675f
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Thu Nov 26 15:55:48 2020 +0100

    LANG-1618 - Add GenericArrayType (#661)
---
 .../apache/commons/lang3/reflect/TypeUtils.java    |  4 ++
 .../commons/lang3/reflect/TypeUtilsTest.java       | 44 ++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
index bad3a56..0d20e6c 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
@@ -372,6 +372,10 @@ public class TypeUtils {
             return containsTypeVariables(getImplicitLowerBounds(wild)[0])
                 || containsTypeVariables(getImplicitUpperBounds(wild)[0]);
         }
+        if (type instanceof GenericArrayType) {
+            final GenericArrayType array = (GenericArrayType) type;
+            return containsTypeVariables(array.getGenericComponentType());
+        }
         return false;
     }
 
diff --git a/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java b/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java
index 3570a9a..379ab80 100644
--- a/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java
@@ -39,6 +39,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.TreeSet;
 
 import org.apache.commons.lang3.reflect.testbed.Foo;
@@ -100,6 +101,27 @@ class AClass extends AAClass<String>.BBClass<Number> {
         enclosingInstance.super();
     }
 }
+@SuppressWarnings("rawtypes")
+abstract class Test1<G> {
+    public abstract Object m0();
+    public abstract String[] m1();
+    public abstract <E> E[] m2();
+    public abstract <E> List<? extends E> m3();
+    public abstract <E extends Enum<E>> List<? extends Enum<E>> m4();
+    public abstract List<? extends Enum<?>> m5();
+    public abstract List<? super Enum<?>> m6();
+    public abstract List<?> m7();
+    public abstract Map<? extends Enum<?>, ? super Enum<?>> m8();
+    public abstract <K, V> Map<? extends K, ? super V[]> m9();
+    public abstract <K, V> Map<? extends K, V[]> m10();
+    public abstract <K, V> Map<? extends K, List<V[]>> m11();
+    public abstract List m12();
+    public abstract Map m13();
+    public abstract Properties m14();
+    public abstract G m15();
+    public abstract List<G> m16();
+    public abstract Enum m17();
+}
 
 /**
  * Test TypeUtils
@@ -211,6 +233,28 @@ public class TypeUtilsTest<B> {
     }
 
     @Test
+    public void testContainsTypeVariables() throws Exception {
+        assertFalse(TypeUtils.containsTypeVariables(Test1.class.getMethod("m0").getGenericReturnType()));
+        assertFalse(TypeUtils.containsTypeVariables(Test1.class.getMethod("m1").getGenericReturnType()));
+        assertTrue(TypeUtils.containsTypeVariables(Test1.class.getMethod("m2").getGenericReturnType()));
+        assertTrue(TypeUtils.containsTypeVariables(Test1.class.getMethod("m3").getGenericReturnType()));
+        assertTrue(TypeUtils.containsTypeVariables(Test1.class.getMethod("m4").getGenericReturnType()));
+        assertFalse(TypeUtils.containsTypeVariables(Test1.class.getMethod("m5").getGenericReturnType()));
+        assertFalse(TypeUtils.containsTypeVariables(Test1.class.getMethod("m6").getGenericReturnType()));
+        assertFalse(TypeUtils.containsTypeVariables(Test1.class.getMethod("m7").getGenericReturnType()));
+        assertFalse(TypeUtils.containsTypeVariables(Test1.class.getMethod("m8").getGenericReturnType()));
+        assertTrue(TypeUtils.containsTypeVariables(Test1.class.getMethod("m9").getGenericReturnType()));
+        assertTrue(TypeUtils.containsTypeVariables(Test1.class.getMethod("m10").getGenericReturnType()));
+        assertTrue(TypeUtils.containsTypeVariables(Test1.class.getMethod("m11").getGenericReturnType()));
+        assertTrue(TypeUtils.containsTypeVariables(Test1.class.getMethod("m12").getGenericReturnType()));
+        assertTrue(TypeUtils.containsTypeVariables(Test1.class.getMethod("m13").getGenericReturnType()));
+        assertFalse(TypeUtils.containsTypeVariables(Test1.class.getMethod("m14").getGenericReturnType()));
+        assertTrue(TypeUtils.containsTypeVariables(Test1.class.getMethod("m15").getGenericReturnType()));
+        assertTrue(TypeUtils.containsTypeVariables(Test1.class.getMethod("m16").getGenericReturnType()));
+        assertTrue(TypeUtils.containsTypeVariables(Test1.class.getMethod("m17").getGenericReturnType()));
+    }
+
+    @Test
     public void testDetermineTypeVariableAssignments() throws SecurityException,
             NoSuchFieldException {
         final ParameterizedType iterableType = (ParameterizedType) getClass().getField("iterable")