]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Search deeply for generic superclass in ReflectionUtils 90/2690/1
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 5 Dec 2018 09:18:47 +0000 (11:18 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Mon, 25 Feb 2019 11:16:18 +0000 (11:16 +0000)
gitlab #224

Needed for district.

Change-Id: I3f3decead033c62726c5919b2b3f36b786de5135
(cherry picked from commit 8905e67e82991121305889e6474a124d6ec79bf8)

bundles/org.simantics.utils/src/org/simantics/utils/ReflectionUtils.java

index b9d794e4043d2fc73346fd77049fcf7fc67cbe06..7f0f6c589a4c8f290db1c48eccf915535e477340 100644 (file)
@@ -58,6 +58,14 @@ public class ReflectionUtils {
     public static <T> Class<T> getSingleParameterTypeExtending(Class<?> clazz) {
 
         Type t = clazz.getGenericSuperclass();
+        while (t instanceof Class<?>) {
+            Class<?> cl = (Class) t;
+            t = cl.getGenericSuperclass();
+            if (t == null) {
+                // according to javadoc, we have reached java.lang.Object so no can do
+                break;
+            }
+        }
         if(t instanceof Class<?>) {
             throw new UnsupportedOperationException("Missing parameter type for input class '" + clazz.getCanonicalName() + "'");
         } else if (t instanceof ParameterizedType) {