From 0a9f6223b1b99310fb36d1295c867986560a3823 Mon Sep 17 00:00:00 2001 From: shalousun Date: Sun, 30 May 2021 21:04:03 +0800 Subject: [PATCH] Fix Null point. --- .../com/power/doc/helper/JsonBuildHelper.java | 9 +------ .../power/doc/helper/ParamsBuildHelper.java | 9 +------ .../java/com/power/doc/utils/DocUtil.java | 27 +++++++++++++++++++ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/power/doc/helper/JsonBuildHelper.java b/src/main/java/com/power/doc/helper/JsonBuildHelper.java index f285363b..e7f1dc30 100644 --- a/src/main/java/com/power/doc/helper/JsonBuildHelper.java +++ b/src/main/java/com/power/doc/helper/JsonBuildHelper.java @@ -396,14 +396,7 @@ public static String buildJson(String typeName, String genericCanonicalName, Object value = JavaClassUtil.getEnumValue(javaClass, Boolean.FALSE); data0.append(value).append(","); } else { - String[] gNameArr = DocClassUtil.getSimpleGicName(fieldGicName); - if (gNameArr.length > 0) { - String gName = gNameArr[0]; - if (gName.length() == 1) { - String gicName = genericMap.get(gName) != null ? genericMap.get(gName) : globGicName[0]; - fieldGicName = fieldGicName.replace(gName,gicName); - } - } + fieldGicName = DocUtil.formatFieldTypeGicName(genericMap, globGicName, fieldGicName); data0.append(buildJson(subTypeName, fieldGicName, isResp, nextLevel, registryClasses, builder)).append(","); } } diff --git a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java index 78a33260..7eefcfa8 100644 --- a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java +++ b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java @@ -490,14 +490,7 @@ public static List buildParams(String className, String pre, int level } else { commonHandleParam(paramList, param, isRequired, NO_COMMENTS_FOUND + appendComment, since, strRequired); } - String[] gNameArr = DocClassUtil.getSimpleGicName(fieldGicName); - if (gNameArr.length > 0) { - String gName = gNameArr[0]; - if (gName.length() == 1) { - String gicName = genericMap.get(gName) != null ? genericMap.get(gName) : globGicName[0]; - fieldGicName = fieldGicName.replace(gName,gicName); - } - } + fieldGicName = DocUtil.formatFieldTypeGicName(genericMap, globGicName, fieldGicName); fieldPid = paramList.size() + pid; paramList.addAll(buildParams(fieldGicName, preBuilder.toString(), nextLevel, isRequired, isResp, registryClasses, projectBuilder, groupClasses, fieldPid, jsonRequest)); diff --git a/src/main/java/com/power/doc/utils/DocUtil.java b/src/main/java/com/power/doc/utils/DocUtil.java index a4e1efe8..b8c259a8 100644 --- a/src/main/java/com/power/doc/utils/DocUtil.java +++ b/src/main/java/com/power/doc/utils/DocUtil.java @@ -609,4 +609,31 @@ public static List buildDictionary(ApiConfig config, JavaProjectBuil return apiDocDictList; } + /** + * Format field Type + * @param genericMap genericMap + * @param globGicName + * @param fieldGicName + * @return string + */ + public static String formatFieldTypeGicName(Map genericMap, String[] globGicName, String fieldGicName) { + String[] gNameArr = DocClassUtil.getSimpleGicName(fieldGicName); + if (gNameArr.length > 0) { + String gName = gNameArr[0]; + if (gName.length() == 1) { + String gicName = ""; + if (Objects.nonNull(genericMap.get(gName))) { + gicName = genericMap.get(gName); + } + if (globGicName.length > 0) { + gicName = globGicName[0]; + } + if (StringUtil.isNotEmpty(gicName)) { + fieldGicName = fieldGicName.replace(gName, gicName); + } + } + } + return fieldGicName; + } + }