public static Type getSuperType()

in sdk/core/azure-core-rest/src/main/java/com/azure/android/core/rest/implementation/TypeUtil.java [83:121]


    public static Type getSuperType(final Type type) {
        synchronized (SUPER_TYPE_MAP_LOCK) {
            Type superType = SUPER_TYPE_MAP.get(type);
            if (superType == null) {
                if (type instanceof ParameterizedType) {
                    final ParameterizedType parameterizedType = (ParameterizedType) type;
                    final Type genericSuperClass = ((Class<?>) parameterizedType.getRawType()).getGenericSuperclass();

                    if (genericSuperClass instanceof ParameterizedType) {
                        /*
                         * Find erased generic types for the super class and replace
                         * with actual type arguments from the parameterized type
                         */
                        final Type[] superTypeArguments = getTypeArguments(genericSuperClass);
                        final Type[] typeParameters =
                            ((GenericDeclaration) parameterizedType.getRawType()).getTypeParameters();
                        int k = 0;

                        for (int i = 0; i < superTypeArguments.length; i++) {
                            for (int j = 0; j < typeParameters.length; j++) {
                                if (typeParameters[j].equals(superTypeArguments[i])) {
                                    superTypeArguments[i] = parameterizedType.getActualTypeArguments()[k++];
                                    break;
                                }
                            }
                        }
                        superType = createParameterizedType(((ParameterizedType) genericSuperClass).getRawType(),
                            superTypeArguments);
                    } else {
                        superType = genericSuperClass;
                    }
                } else {
                    superType = ((Class<?>) type).getGenericSuperclass();
                }
                SUPER_TYPE_MAP.put(type, superType);
            }
            return superType;
        }
    }