Skip to content

Commit

Permalink
Merge pull request #970 from jasonkung22/fix_class_load_inner_enum
Browse files Browse the repository at this point in the history
fix: Fix if it was inner enumeration, classLoader load class maybe fail
  • Loading branch information
shalousun authored Nov 27, 2024
2 parents fe0532f + 35c19e8 commit ece1222
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/ly/doc/builder/ProjectDocConfigBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ private void initClassFilesMap() {
ClassLoader classLoader = apiConfig.getClassLoader();
try {
if (Objects.isNull(classLoader)) {
enumClass = Class.forName(cls.getFullyQualifiedName());
enumClass = Class.forName(cls.getBinaryName());
}
else {
enumClass = classLoader.loadClass(cls.getFullyQualifiedName());
enumClass = classLoader.loadClass(cls.getBinaryName());
}
enumClassMap.put(cls.getFullyQualifiedName(), enumClass);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/ly/doc/helper/ParamsBuildHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ public static String handleEnumComment(JavaClass javaClass, ProjectDocConfigBuil
String enumComments = javaClass.getComment();
if (Boolean.TRUE.equals(projectBuilder.getApiConfig().getInlineEnum())) {
ApiDataDictionary dataDictionary = projectBuilder.getApiConfig()
.getDataDictionary(javaClass.getCanonicalName());
.getDataDictionary(javaClass.getBinaryName());
if (Objects.isNull(dataDictionary)) {
// the output format should be unified ( as same as the "else" output)
comment = comment + "<br/>[Enum: " + JavaClassUtil.getEnumParams(javaClass) + "]";
Expand All @@ -833,7 +833,7 @@ public static String handleEnumComment(JavaClass javaClass, ProjectDocConfigBuil
if (enumClass.isInterface()) {
ClassLoader classLoader = projectBuilder.getApiConfig().getClassLoader();
try {
enumClass = classLoader.loadClass(javaClass.getFullyQualifiedName());
enumClass = classLoader.loadClass(javaClass.getBinaryName());
}
catch (ClassNotFoundException e) {
return comment;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ly/doc/utils/DocUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ public static List<ApiDocDict> buildDictionary(ApiConfig config, JavaProjectBuil
}

for (Class<? extends Enum<?>> enumClass : enumImplementSet) {
JavaClass javaClass = javaProjectBuilder.getClassByName(enumClass.getCanonicalName());
JavaClass javaClass = javaProjectBuilder.getClassByName(enumClass.getName());
if (Objects.nonNull(javaClass.getTagByName(DocTags.IGNORE))) {
continue;
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/ly/doc/utils/JavaClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,10 @@ private static Class<?> loadEnumClass(JavaClass javaClass, ProjectDocConfigBuild
ClassLoader classLoader = apiConfig.getClassLoader();
try {
if (Objects.nonNull(classLoader)) {
return classLoader.loadClass(javaClass.getFullyQualifiedName());
return classLoader.loadClass(javaClass.getBinaryName());
}
else {
return Class.forName(javaClass.getFullyQualifiedName());
return Class.forName(javaClass.getBinaryName());
}
}
catch (ClassNotFoundException e) {
Expand Down Expand Up @@ -605,7 +605,7 @@ public static EnumInfo getEnumInfo(JavaClass javaClass, ProjectDocConfigBuilder

ApiConfig apiConfig = builder.getApiConfig();
ClassLoader classLoader = apiConfig.getClassLoader();
ApiDataDictionary dataDictionary = apiConfig.getDataDictionary(javaClass.getFullyQualifiedName());
ApiDataDictionary dataDictionary = apiConfig.getDataDictionary(javaClass.getBinaryName());

EnumInfo enumInfo = new EnumInfo();
String comment = javaClass.getComment();
Expand All @@ -620,7 +620,7 @@ public static EnumInfo getEnumInfo(JavaClass javaClass, ProjectDocConfigBuilder
Class<?> enumClass = dataDictionary.getEnumClass();
if (enumClass.isInterface()) {
try {
enumClass = classLoader.loadClass(javaClass.getFullyQualifiedName());
enumClass = classLoader.loadClass(javaClass.getBinaryName());
}
catch (ClassNotFoundException e) {
return enumInfo;
Expand Down Expand Up @@ -1120,10 +1120,10 @@ private static String getFieldGenericType(JavaField javaField, ClassLoader class
try {
Class<?> c;
if (Objects.nonNull(classLoader)) {
c = classLoader.loadClass(javaField.getDeclaringClass().getCanonicalName());
c = classLoader.loadClass(javaField.getDeclaringClass().getBinaryName());
}
else {
c = Class.forName(javaField.getDeclaringClass().getCanonicalName());
c = Class.forName(javaField.getDeclaringClass().getBinaryName());
}
Field f = c.getDeclaredField(name);
f.setAccessible(true);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/ly/doc/utils/JavaFieldUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ public static String getConstantsFieldValue(ClassLoader classLoader, JavaClass j
try {
Class<?> c;
if (Objects.nonNull(classLoader)) {
c = classLoader.loadClass(javaClass.getFullyQualifiedName());
c = classLoader.loadClass(javaClass.getBinaryName());
}
else {
c = Class.forName(javaClass.getFullyQualifiedName());
c = Class.forName(javaClass.getBinaryName());
}
Field[] fields = c.getDeclaredFields();
for (Field f : fields) {
Expand Down

0 comments on commit ece1222

Please sign in to comment.