Skip to content

Commit

Permalink
Qute: fix regression for optimized generated value resolvers
Browse files Browse the repository at this point in the history
- fix regression introduced in
quarkusio#33984
- if there are multiple type-safe templates with the same parameter
declaration then _no_ or _incomplete_ value resolver may be generated
  • Loading branch information
mkouba authored and danielsoro committed Sep 20, 2024
1 parent 90416a0 commit 42c4851
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ public String apply(String id) {
// Register all param declarations as targets of implicit value resolvers
for (ParameterDeclaration paramDeclaration : templateAnalysis.parameterDeclarations) {
Type type = TypeInfos.resolveTypeFromTypeInfo(paramDeclaration.getTypeInfo());
if (type != null) {
if (type != null && !implicitClassToMembersUsed.containsKey(type.name())) {
implicitClassToMembersUsed.put(type.name(), new HashSet<>());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.quarkus.qute.deployment.generatedresolvers;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.List;

import jakarta.inject.Inject;

import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.qute.CheckedTemplate;
import io.quarkus.qute.Engine;
import io.quarkus.qute.TemplateInstance;
import io.quarkus.qute.ValueResolver;
import io.quarkus.qute.generator.ValueResolverGenerator;
import io.quarkus.test.QuarkusUnitTest;

public class ImplicitValueResolversTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addAsResource(new StringAsset("{name.toUpperCase}"), "templates/hello.html")
.addAsResource(new StringAsset("{name}"), "templates/bye.html")
.addAsResource(new StringAsset("{name}"), "templates/zero.html"));

@CheckedTemplate(basePath = "")
record hello(String name) implements TemplateInstance {
};

@CheckedTemplate(basePath = "")
record bye(String name) implements TemplateInstance {
};

@CheckedTemplate(basePath = "")
record zero(String name) implements TemplateInstance {
};

@Inject
Engine engine;

@Test
public void testImplicitResolvers() {
assertEquals("FOO", new hello("Foo").render());
assertEquals("Bar", new bye("Bar").render());
assertEquals("Baz", new zero("Baz").render());
List<ValueResolver> resolvers = engine.getValueResolvers();
ValueResolver stringResolver = null;
for (ValueResolver valueResolver : resolvers) {
if (valueResolver.getClass().getName().endsWith(ValueResolverGenerator.SUFFIX)
&& valueResolver.getClass().getName().contains("String")) {
stringResolver = valueResolver;
}
}
assertNotNull(stringResolver);
}

}

0 comments on commit 42c4851

Please sign in to comment.