public static Object initClassTypeWithDefaultValue()

in dubbo-api-docs/dubbo-api-docs-core/src/main/java/org/apache/dubbo/apidocs/utils/ClassTypeUtil.java [140:218]


    public static Object initClassTypeWithDefaultValue(Type genericType, Class<?> classType, int processCount,
                                                       boolean isBuildClassAttribute,
                                                       Map<String, String> methodPrarmGenericTypeAndNamesMap) {
        if (processCount >= PROCESS_COUNT_MAX) {
            LOG.warn("The depth of bean has exceeded 10 layers, the deeper layer will be ignored! " +
                "Please modify the parameter structure or check whether there is circular reference in bean!");
            return null;
        }
        processCount++;

        Object initResult = initClassTypeWithDefaultValueNoProceeField(genericType, classType, processCount,
            methodPrarmGenericTypeAndNamesMap);
        if (null != initResult) {
            return initResult;
        }

        Map<String, String> genericTypeAndNamesMap;
        if (genericType instanceof ParameterizedType) {
            ParameterizedType parameterTypeImpl = (ParameterizedType) genericType;
            Type rawType = parameterTypeImpl.getRawType();
            if (rawType instanceof Class<?>) {
                TypeVariable<? extends Class<?>>[] typeVariables = ((Class<?>) rawType).getTypeParameters();
                Type[] actualTypeArguments = parameterTypeImpl.getActualTypeArguments();
                genericTypeAndNamesMap = new HashMap<>(typeVariables.length);
                for (int i = 0; i < typeVariables.length; i++) {
                    genericTypeAndNamesMap.put(typeVariables[i].getTypeName(), actualTypeArguments[i].getTypeName());
                }
            } else {
                genericTypeAndNamesMap = Collections.emptyMap();
            }
        } else {
            genericTypeAndNamesMap = Collections.emptyMap();
        }

        Map<String, Object> result = new HashMap<>(16);
        if (isBuildClassAttribute) {
            result.put(CLASS_FIELD_NAME, classType.getCanonicalName());
        }
        // get all fields
        List<Field> allFields = getAllFields(null, classType);
        for (Field field2 : allFields) {
            if (SKIP_FIELD_SERIALVERSIONUID.equals(field2.getName()) || SKIP_FIELD_THIS$0.equals(field2.getName())) {
                continue;
            }
            if (String.class.isAssignableFrom(field2.getType())) {
                if (field2.isAnnotationPresent(RequestParam.class)) {
                    RequestParam requestParam = field2.getAnnotation(RequestParam.class);
                    result.put(field2.getName(), requestParam.value());
                } else if (field2.isAnnotationPresent(ResponseProperty.class)) {
                    ResponseProperty responseProperty = field2.getAnnotation(ResponseProperty.class);
                    StringBuilder strValue = new StringBuilder(responseProperty.value());
                    if (StringUtils.isNotBlank(responseProperty.example())) {
                        strValue.append(SQUARE_BRACKET_LEFT).append(RESPONSE_STR_EXAMPLE)
                            .append(responseProperty.example()).append(SQUARE_BRACKET_RIGHT);
                    }
                    result.put(field2.getName(), strValue.toString());
                } else {
                    // It's string, but there's no annotation
                    result.put(field2.getName(), initClassTypeWithDefaultValue(field2.getGenericType(), field2.getType(),
                        processCount, methodPrarmGenericTypeAndNamesMap));
                }
            } else {
                // Check if the type of the property is generic
                String genericTypeName = genericTypeAndNamesMap.get(field2.getGenericType().getTypeName());
                if (StringUtils.isNotBlank(genericTypeName)) {
                    // The type of the attribute is generic. Find the generic from the definition of
                    // the class in which the attribute is located
                    result.put(field2.getName(), initClassTypeWithDefaultValue(makeParameterizedType(genericTypeName),
                        makeClass(genericTypeName),
                        processCount, true, methodPrarmGenericTypeAndNamesMap));
                } else {
                    // Not generic
                    result.put(field2.getName(), initClassTypeWithDefaultValue(field2.getGenericType(), field2.getType(),
                        processCount, methodPrarmGenericTypeAndNamesMap));
                }
            }
        }
        return result;
    }