From 25793afee8f4d10176bdd2c0c401137d182eb685 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Mon, 4 Oct 2021 09:12:43 +0200 Subject: [PATCH] Qute type-safe validation fix - also include all methods from the interfaces extended by other interfaces (not only from those implemented directly by any class in the hierarchy) - resolves #20512 --- .../quarkus/qute/deployment/QuteProcessor.java | 16 +++++++++++++++- .../typesafe/InterfaceValidationSuccessTest.java | 7 +++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java b/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java index 76a7c6d1a04bc..f2e341003a5e1 100644 --- a/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java +++ b/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java @@ -1708,6 +1708,7 @@ private static TemplateExtensionMethodBuildItem findTemplateExtensionMethod(Info private static AnnotationTarget findProperty(String name, ClassInfo clazz, IndexView index) { Set interfaceNames = new HashSet<>(); while (clazz != null) { + addInterfaces(clazz, index, interfaceNames); interfaceNames.addAll(clazz.interfaceNames()); // Fields for (FieldInfo field : clazz.fields()) { @@ -1756,6 +1757,19 @@ private static AnnotationTarget findProperty(String name, ClassInfo clazz, Index return null; } + private static void addInterfaces(ClassInfo clazz, IndexView index, Set interfaceNames) { + if (clazz == null) { + return; + } + List names = clazz.interfaceNames(); + if (!names.isEmpty()) { + interfaceNames.addAll(names); + for (DotName name : names) { + addInterfaces(index.getClassByName(name), index, interfaceNames); + } + } + } + /** * Find a non-static non-synthetic method with the given name, matching number of params and assignable parameter types. * @@ -1771,7 +1785,7 @@ private static AnnotationTarget findMethod(VirtualMethodPart virtualMethod, Clas IndexView index, Function templateIdToPathFun, Map results) { Set interfaceNames = new HashSet<>(); while (clazz != null) { - interfaceNames.addAll(clazz.interfaceNames()); + addInterfaces(clazz, index, interfaceNames); for (MethodInfo method : clazz.methods()) { if (Modifier.isPublic(method.flags()) && !Modifier.isStatic(method.flags()) && !ValueResolverGenerator.isSynthetic(method.flags()) diff --git a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/typesafe/InterfaceValidationSuccessTest.java b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/typesafe/InterfaceValidationSuccessTest.java index c98a77f1821cd..6806e4af0fe53 100644 --- a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/typesafe/InterfaceValidationSuccessTest.java +++ b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/typesafe/InterfaceValidationSuccessTest.java @@ -20,7 +20,7 @@ public class InterfaceValidationSuccessTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) - .addClasses(Metrics.class, Count.class, Wrapper.class) + .addClasses(Metrics.class, Count.class, Wrapper.class, NumericWrapper.class) .addAsResource(new StringAsset("{@java.util.List list}" + "{list.empty}:{list.toString}"), "templates/list.html") @@ -76,7 +76,10 @@ public interface Wrapper { String name(int age); } - public interface Count extends Wrapper { + public interface NumericWrapper extends Wrapper { + } + + public interface Count extends NumericWrapper { } public interface Metrics {