Skip to content

Commit

Permalink
Merge pull request quarkusio#21028 from mkouba/issue-21008
Browse files Browse the repository at this point in the history
Qute type-safe validation - fix namespace extension methods handling
  • Loading branch information
mkouba authored Oct 27, 2021
2 parents 98ee522 + 5a3e0b0 commit 130a26c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,15 @@ static Match validateNestedExpressions(TemplateAnalysis templateAnalysis, ClassI
ClassInfo returnType = index.getClassByName(method.returnType().name());
if (returnType != null) {
match.setValues(returnType, method.returnType());
if (root.hasHints()) {
// Root is a property with hint
// E.g. 'it<loop#123>' and 'STATUS<when#123>'
if (processHints(templateAnalysis, root.asHintInfo().hints, match, index, expression,
generatedIdsToMatches, incorrectExpressions)) {
// In some cases it's necessary to reset the iterator
iterator = parts.iterator();
}
}
} else {
// Return type not available
return putResult(match, results, expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import static io.quarkus.qute.TemplateExtension.ANY;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.EnumSet;
import java.util.Set;

import javax.enterprise.event.TransactionPhase;
import javax.inject.Inject;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand All @@ -20,6 +24,9 @@ public class NamespaceTemplateExtensionTest {
@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addAsResource(new StringAsset(
"{#for state in domain:states}{state.foo}{/for}"),
"templates/foo.html")
.addClasses(StringExtensions.class, MyEnum.class, EnumExtensions.class));

@Inject
Expand All @@ -43,6 +50,8 @@ public void testTemplateExtensions() {
engine.parse("{str:quark}").render());
assertEquals("QUARKUS!",
engine.parse("{str:quarkus}").render());
assertEquals("openclosed",
engine.getTemplate("foo").render());
}

@TemplateExtension(namespace = "str")
Expand Down Expand Up @@ -73,9 +82,17 @@ static String quarkAny(String key) {
}

public enum MyEnum {

ONE,
TWO
}

public enum State {
OPEN,
CLOSED;

public String getFoo() {
return toString().toLowerCase();
}

}

Expand All @@ -91,6 +108,11 @@ static TransactionPhase enumValue(String value) {
return TransactionPhase.valueOf(value);
}

@TemplateExtension(namespace = "domain")
static Set<State> states() {
return EnumSet.allOf(State.class);
}

}

}

0 comments on commit 130a26c

Please sign in to comment.