Skip to content

Commit

Permalink
move more parts of info fetching to try-catch
Browse files Browse the repository at this point in the history
  • Loading branch information
ZZZank committed Mar 24, 2024
1 parent 739b33d commit 13f3d75
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions src/main/java/com/probejs/info/ClassInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,45 +60,49 @@ private ClassInfo(Class<?> clazz) {
isFunctionalInterface =
isInterface &&
Arrays.stream(clazzRaw.getAnnotations()).anyMatch(a -> a instanceof FunctionalInterface);
superClass = ofCache(clazzRaw.getSuperclass());
interfaces =
Arrays.stream(clazzRaw.getInterfaces()).map(ClassInfo::ofCache).collect(Collectors.toList());

constructorInfo = new ArrayList<>();
parameters = new ArrayList<>();
methodInfo = new ArrayList<>();
fieldInfo = new ArrayList<>();
try {
constructorInfo.addAll(
Arrays
.stream(clazzRaw.getConstructors())
.map(ConstructorInfo::new)
.collect(Collectors.toList())
);
parameters.addAll(
Arrays
.stream(clazzRaw.getTypeParameters())
.map(InfoTypeResolver::resolveType)
.collect(Collectors.toList())
);
methodInfo.addAll(
Arrays
.stream(clazzRaw.getMethods())
.filter(method -> method.getDeclaringClass() == clazzRaw || !ProbeJS.CONFIG.trimming)
.map(m -> new MethodInfo(m, clazz))
.filter(m -> ClassResolver.acceptMethod(m.getName()))
.filter(m -> !m.shouldHide())
.collect(Collectors.toList())
);
fieldInfo.addAll(
Arrays
.stream(clazzRaw.getFields())
.filter(field -> !ProbeJS.CONFIG.trimming || field.getDeclaringClass() == clazzRaw)
.map(FieldInfo::new)
.filter(f -> ClassResolver.acceptField(f.getName()))
.filter(f -> !f.shouldHide())
.collect(Collectors.toList())
);
} catch (NoClassDefFoundError e) {
// https://github.com/ZZZank/ProbeJS-Forge/issues/2
ProbeJS.LOGGER.error("Unable to fetch infos for class '{}'", clazzRaw.getName());
}
superClass = ofCache(clazzRaw.getSuperclass());
interfaces =
Arrays.stream(clazzRaw.getInterfaces()).map(ClassInfo::ofCache).collect(Collectors.toList());

parameters =
Arrays
.stream(clazzRaw.getTypeParameters())
.map(InfoTypeResolver::resolveType)
.collect(Collectors.toList());

methodInfo =
Arrays
.stream(clazzRaw.getMethods())
.filter(method -> method.getDeclaringClass() == clazzRaw || !ProbeJS.CONFIG.trimming)
.map(m -> new MethodInfo(m, clazz))
.filter(m -> ClassResolver.acceptMethod(m.getName()))
.filter(m -> !m.shouldHide())
.collect(Collectors.toList());

fieldInfo =
Arrays
.stream(clazzRaw.getFields())
.filter(field -> !ProbeJS.CONFIG.trimming || field.getDeclaringClass() == clazzRaw)
.map(FieldInfo::new)
.filter(f -> ClassResolver.acceptField(f.getName()))
.filter(f -> !f.shouldHide())
.collect(Collectors.toList());

//Resolve types - rollback everything till Object
applySuperGenerics(methodInfo, fieldInfo);
Expand Down

0 comments on commit 13f3d75

Please sign in to comment.