Skip to content

Commit

Permalink
fix: include interface generic type parameters in resolution stack
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Edgar <[email protected]>
  • Loading branch information
MikeEdgar committed Dec 16, 2024
1 parent 40c362e commit dc5689b
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ private TypeResolver(AnnotationScannerContext context, UnaryOperator<String> nam
}
}

private void replaceResolutionStack(Deque<Map<String, Type>> replacementStack) {
resolutionStack.clear();
resolutionStack.addAll(replacementStack);
}

/**
* Get the declaring class of the annotation target.
*
Expand Down Expand Up @@ -525,10 +530,7 @@ public static Map<String, TypeResolver> getAllFields(AnnotationScannerContext co
for (Map.Entry<ClassInfo, Type> entry : chain.entrySet()) {
ClassInfo currentClass = entry.getKey();
Type currentType = entry.getValue();

if (currentType.kind() == Type.Kind.PARAMETERIZED_TYPE) {
stack.push(buildParamTypeResolutionMap(currentClass, currentType));
}
maybeAddResolutionParams(stack, currentType, currentClass);

if (skipPropertyScan || (!currentType.equals(leaf) && TypeUtil.isAllOf(context, leafKlazz, currentType))
|| TypeUtil.knownJavaType(currentClass.name())) {
Expand Down Expand Up @@ -556,7 +558,11 @@ public static Map<String, TypeResolver> getAllFields(AnnotationScannerContext co
index.interfaces(currentClass)
.stream()
.filter(type -> !TypeUtil.knownJavaType(type.name()))
.map(index::getClass)
.map(type -> {
ClassInfo clazz = index.getClass(type);
maybeAddResolutionParams(stack, type, clazz);
return clazz;
})
.filter(Objects::nonNull)
.flatMap(clazz -> methods(context, clazz).stream())
.filter(method -> method.name().chars().allMatch(Character::isJavaIdentifierPart))
Expand All @@ -578,6 +584,12 @@ public static Map<String, TypeResolver> getAllFields(AnnotationScannerContext co
return sorted(context, properties, chain.keySet());
}

private static void maybeAddResolutionParams(Deque<Map<String, Type>> stack, Type type, ClassInfo clazz) {
if (type.kind() == Type.Kind.PARAMETERIZED_TYPE && clazz != null) {
stack.push(buildParamTypeResolutionMap(clazz, type));
}
}

private static List<MethodInfo> methods(AnnotationScannerContext context, ClassInfo currentClass) {
if (context.getConfig().sortedPropertiesEnable()) {
return currentClass.methods();
Expand Down Expand Up @@ -935,9 +947,10 @@ private static TypeResolver updateTypeResolvers(AnnotationScannerContext context

if (properties.containsKey(propertyName)) {
resolver = properties.get(propertyName);
Type resolvedPropertyType = getResolvedType(propertyType, stack);

// Only store the accessor/mutator methods if the type of property matches
if (!TypeUtil.equalTypes(resolver.getUnresolvedType(), propertyType)) {
if (!TypeUtil.equalTypes(resolver.resolveType(), resolvedPropertyType)) {
return resolver;
}
} else {
Expand All @@ -951,10 +964,12 @@ private static TypeResolver updateTypeResolvers(AnnotationScannerContext context
if (isWriteMethod) {
if (isHigherPriority(resolver.targetComparator, method, resolver.getWriteMethod())) {
resolver.setWriteMethod(method);
resolver.replaceResolutionStack(stack);
}
} else {
if (isHigherPriority(resolver.targetComparator, method, resolver.getReadMethod())) {
resolver.setReadMethod(method);
resolver.replaceResolutionStack(stack);
}
}

Expand Down

0 comments on commit dc5689b

Please sign in to comment.