Skip to content

Commit 2e50b88

Browse files
committed
Qute: fix ValueResolverGenerator
- fix incorrect resolution when a type declares multiple overloaded methods - related to #47092
1 parent f670074 commit 2e50b88

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/extensions/StringTemplateExtensionsTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ public class StringTemplateExtensionsTest {
1919

2020
@RegisterExtension
2121
static final QuarkusUnitTest config = new QuarkusUnitTest()
22-
.withApplicationRoot(root -> root.addAsResource(
23-
new StringAsset("{str:eval('Hello {name}!')}"),
24-
"templates/hello.txt"));
22+
.withApplicationRoot(root -> root
23+
.addAsResource(
24+
new StringAsset("{str:eval('Hello {name}!')}"),
25+
"templates/hello.txt")
26+
.addAsResource(
27+
// https://github.com/quarkusio/quarkus/issues/47092
28+
// This will trigger value resolver generation for StringBuilder
29+
new StringAsset("{str:builder.append('Qute').append(\" is\").append(' cool!')}"),
30+
"templates/builder.txt"));
2531

2632
@Inject
2733
Engine engine;

independent-projects/qute/generator/src/main/java/io/quarkus/qute/generator/ValueResolverGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,8 @@ private void matchMethods(String matchName, int matchParamsCount, Collection<Met
894894
} else {
895895
tryCatch.invokeVirtualMethod(Descriptors.COMPLETABLE_FUTURE_COMPLETE, whenRet, invokeRet);
896896
}
897+
// Always return from the matching block so that other matching methods are not used
898+
paramMatchScope.returnVoid();
897899
}
898900
}
899901

independent-projects/qute/generator/src/test/java/io/quarkus/qute/generator/SimpleGeneratorTest.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import java.util.concurrent.CompletionStage;
1414
import java.util.concurrent.TimeUnit;
1515

16+
import org.jboss.jandex.AnnotationInstance;
17+
import org.jboss.jandex.AnnotationValue;
1618
import org.jboss.jandex.ClassInfo;
1719
import org.jboss.jandex.DotName;
1820
import org.jboss.jandex.Index;
@@ -39,15 +41,16 @@ public class SimpleGeneratorTest {
3941
public static void init() throws IOException {
4042
TestClassOutput classOutput = new TestClassOutput();
4143
Index index = index(MyService.class, PublicMyService.class, BaseService.class, MyItem.class, String.class,
42-
CompletionStage.class, List.class, MyEnum.class);
44+
CompletionStage.class, List.class, MyEnum.class, StringBuilder.class);
4345
ClassInfo myServiceClazz = index.getClassByName(DotName.createSimple(MyService.class.getName()));
4446
ValueResolverGenerator generator = ValueResolverGenerator.builder().setIndex(index).setClassOutput(classOutput)
4547
.addClass(myServiceClazz)
46-
.addClass(index.getClassByName(DotName.createSimple(PublicMyService.class.getName())))
47-
.addClass(index.getClassByName(DotName.createSimple(MyItem.class.getName())))
48-
.addClass(index.getClassByName(DotName.createSimple(String.class.getName())))
49-
.addClass(index.getClassByName(DotName.createSimple(List.class.getName())))
50-
.addClass(index.getClassByName(DotName.createSimple(MyEnum.class.getName())))
48+
.addClass(index.getClassByName(PublicMyService.class))
49+
.addClass(index.getClassByName(MyItem.class))
50+
.addClass(index.getClassByName(String.class))
51+
.addClass(index.getClassByName(List.class))
52+
.addClass(index.getClassByName(MyEnum.class))
53+
.addClass(index.getClassByName(StringBuilder.class), stringBuilderTemplateData())
5154
.build();
5255

5356
generator.generate();
@@ -146,6 +149,7 @@ public void testWithEngine() throws Exception {
146149
assertEquals("OK", engine.parse("{#if enum is MyEnum:BAR}OK{/if}").data("enum", MyEnum.BAR).render());
147150
assertEquals("one", engine.parse("{MyEnum:valueOf('ONE').name}").render());
148151
assertEquals("10", engine.parse("{io_quarkus_qute_generator_MyService:getDummy(5)}").render());
152+
assertEquals("foo", engine.parse("{builder.append('foo')}").data("builder", new StringBuilder()).render());
149153
}
150154

151155
@Test
@@ -192,4 +196,15 @@ public static Index index(Class<?>... classes) throws IOException {
192196
return indexer.complete();
193197
}
194198

199+
private static AnnotationInstance stringBuilderTemplateData() {
200+
AnnotationValue ignoreValue = AnnotationValue.createArrayValue(ValueResolverGenerator.IGNORE, new AnnotationValue[] {});
201+
AnnotationValue targetValue = AnnotationValue.createClassValue("target",
202+
Type.create(ValueResolverGenerator.TEMPLATE_DATA, Kind.CLASS));
203+
AnnotationValue propertiesValue = AnnotationValue.createBooleanValue(ValueResolverGenerator.PROPERTIES, false);
204+
AnnotationValue ignoreSuperclassesValue = AnnotationValue.createBooleanValue(ValueResolverGenerator.IGNORE_SUPERCLASSES,
205+
true);
206+
return AnnotationInstance.create(ValueResolverGenerator.TEMPLATE_DATA, null,
207+
new AnnotationValue[] { targetValue, ignoreValue, propertiesValue, ignoreSuperclassesValue });
208+
}
209+
195210
}

0 commit comments

Comments
 (0)