package org.jusecase.util;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class GenericTypeResolver {
    public static Class<?> resolve(Type type, Class<?> usecaseClass, int index) {
        Type[] genericInterfaces = usecaseClass.getGenericInterfaces();

        for (Type genericInterface : genericInterfaces) {
            if (ParameterizedType.class.isAssignableFrom(genericInterface.getClass())) {
                ParameterizedType parameterizedType = (ParameterizedType)genericInterface;
                if (parameterizedType.getRawType() == type) {
                    return (Class<?>)(parameterizedType.getActualTypeArguments()[index]);
                }
            }
        }

        ParameterizedType parameterizedType = (ParameterizedType)usecaseClass.getGenericSuperclass();
        if (parameterizedType != null) {
            return (Class<?>)(parameterizedType.getActualTypeArguments()[index]);
        }

        return null;
    }
}

@@ -187,28 +187,21 @@
 lass%3C?%3E 
-usecaseClass
+clazz
 , int in
@@ -242,28 +242,21 @@
 faces = 
-usecaseClass
+clazz
 .getGene
@@ -718,114 +718,155 @@
     
-ParameterizedType parameterizedType = (ParameterizedType)usecaseClass.getGenericSuperclass();%0A        if (
+Type genericSuperclass = clazz.getGenericSuperclass();%0A        if (genericSuperclass instanceof ParameterizedType) %7B%0A            ParameterizedType 
 para
@@ -883,18 +883,48 @@
 ype 
-!
 = 
-null) %7B
+(ParameterizedType) genericSuperclass;
 %0A   
@@ -941,32 +941,33 @@
 eturn (Class%3C?%3E)
+ 
 (parameterizedTy
@@ -1004,32 +1004,162 @@
 dex%5D);%0A        %7D
+ else if (genericSuperclass instanceof Class%3C?%3E) %7B%0A            return resolve(type, (Class%3C?%3E)genericSuperclass, index);%0A        %7D
 %0A%0A        return

Resolve types recursively