Skip to content

Commit 3f96ccb

Browse files
committed
Fix test failures
1 parent 76ee5dc commit 3f96ccb

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

plugin/src/main/java/io/jenkins/plugins/casc/impl/configurators/DescriptorConfigurator.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,22 @@ private List<String> resolvePossibleNames(Descriptor descriptor) {
6666
return Optional.ofNullable(descriptor.getClass().getAnnotation(Symbol.class))
6767
.map(s -> Arrays.asList(s.value()))
6868
.orElseGet(() -> {
69+
String fallbackName = fromPascalCaseToCamelCase(
70+
unwrapAnonymous(descriptor.getKlass().toJavaClass()).getSimpleName());
71+
6972
Class<?> typeParam = extractDescriptorTypeParameter(descriptor.getClass());
73+
String derivedName = null;
7074

71-
Class<?> targetClass = typeParam != null
72-
? typeParam
73-
: descriptor.getKlass().toJavaClass();
75+
if (typeParam != null) {
76+
Class<?> targetClass = unwrapAnonymous(typeParam);
77+
derivedName = fromPascalCaseToCamelCase(targetClass.getSimpleName());
78+
}
7479

75-
while (targetClass.isAnonymousClass()) {
76-
targetClass = targetClass.getSuperclass();
80+
if (derivedName != null && !derivedName.equals(fallbackName)) {
81+
return Arrays.asList(fallbackName, derivedName);
7782
}
7883

79-
return singletonList(fromPascalCaseToCamelCase(targetClass.getSimpleName()));
84+
return singletonList(fallbackName);
8085
});
8186
}
8287

@@ -111,10 +116,17 @@ private Class<?> extractDescriptorTypeParameter(Class<?> clazz) {
111116

112117
private static String fromPascalCaseToCamelCase(String s) {
113118
if (s == null || s.isEmpty()) {
114-
return s != null ? s : "";
119+
throw new IllegalStateException("Cannot derive configurator name from an empty class name");
115120
}
116121
StringBuilder sb = new StringBuilder(s);
117122
sb.setCharAt(0, Character.toLowerCase(s.charAt(0)));
118123
return sb.toString();
119124
}
125+
126+
private Class<?> unwrapAnonymous(Class<?> clazz) {
127+
while (clazz.isAnonymousClass()) {
128+
clazz = clazz.getSuperclass();
129+
}
130+
return clazz;
131+
}
120132
}

0 commit comments

Comments
 (0)