Skip to content

Commit

Permalink
Merge pull request #35555 from mkouba/issue-35523
Browse files Browse the repository at this point in the history
Qute: fix regression in the value resolver generator
  • Loading branch information
mkouba authored Aug 25, 2023
2 parents fd0f246 + 98c5026 commit 996f6b5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,6 @@ private Descriptors() {
CompletionStage.class);
public static final FieldDescriptor RESULTS_TRUE = FieldDescriptor.of(Results.class, "TRUE", CompletedStage.class);
public static final FieldDescriptor RESULTS_FALSE = FieldDescriptor.of(Results.class, "FALSE", CompletedStage.class);
public static final FieldDescriptor RESULTS_NULL = FieldDescriptor.of(Results.class, "NULL", CompletedStage.class);

}
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,12 @@ public void accept(BytecodeCreator bc) {
&& returnType.asPrimitiveType().primitive() == Primitive.BOOLEAN) {
completeBoolean(bc, invokeRet);
} else if (method.returnType().name().equals(DotNames.BOOLEAN)) {
BytecodeCreator isNull = bc.ifNull(invokeRet).trueBranch();
isNull.returnValue(isNull.readStaticField(Descriptors.RESULTS_NULL));
completeBoolean(bc, bc.invokeVirtualMethod(Descriptors.BOOLEAN_VALUE, invokeRet));
} else if (isEnum(returnType)) {
BytecodeCreator isNull = bc.ifNull(invokeRet).trueBranch();
isNull.returnValue(isNull.readStaticField(Descriptors.RESULTS_NULL));
completeEnum(index.getClassByName(returnType.name()), valueResolver, invokeRet, bc);
} else {
bc.returnValue(bc.invokeStaticMethod(Descriptors.COMPLETED_STAGE_OF, invokeRet));
Expand Down Expand Up @@ -536,11 +540,11 @@ private boolean completeEnum(ClassInfo enumClass, ClassCreator valueResolver, Re
BytecodeCreator match;
if (ifThenElse == null) {
ifThenElse = bc.ifThenElse(
Gizmo.equals(bc, result, bc.readStaticField(enumConstantField)));
Gizmo.equals(bc, bc.readStaticField(enumConstantField), result));
match = ifThenElse.then();
} else {
match = ifThenElse.elseIf(
b -> Gizmo.equals(b, result, b.readStaticField(enumConstantField)));
b -> Gizmo.equals(b, b.readStaticField(enumConstantField), result));
}
match.returnValue(match.invokeVirtualMethod(
enumConstantMethod.getMethodDescriptor(), match.getThis()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,18 @@ public boolean hasName() {
return name != null;
}

public Boolean isActive() {
public boolean isActive() {
return true;
}

public Boolean isActiveObject() {
return true;
}

public Boolean isActiveObjectNull() {
return null;
}

public boolean hasItems() {
return false;
}
Expand All @@ -45,6 +53,10 @@ public MyEnum myEnum() {
return MyEnum.BAR;
}

public MyEnum myEnumNull() {
return null;
}

public List<String> getList(int limit, String dummy) {
AtomicInteger idx = new AtomicInteger(0);
return Stream.generate(() -> "" + idx.getAndIncrement())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public void testWithEngine() throws Exception {
}
Engine engine = builder.build();
assertEquals(" FOO ", engine.parse("{#if isActive} {name.toUpperCase} {/if}").render(new MyService()));
assertEquals(" FOO ", engine.parse("{#if isActiveObject} {name.toUpperCase} {/if}").render(new MyService()));
assertEquals("", engine.parse("{#if isActiveObjectNull} {name.toUpperCase} {/if}").render(new MyService()));
assertEquals(" FOO ", engine.parse("{#if active} {name.toUpperCase} {/if}").render(new MyService()));
assertEquals(" FOO ", engine.parse("{#if !hasItems} {name.toUpperCase} {/if}").render(new MyService()));
assertEquals(" FOO ", engine.parse("{#if !items} {name.toUpperCase} {/if}").render(new MyService()));
Expand All @@ -138,6 +140,7 @@ public void testWithEngine() throws Exception {
assertEquals("5",
engine.parse("{#each service.getDummyVarargs(5)}{it}{/}").data("service", new MyService())
.render());
assertEquals("BAR::", engine.parse("{myEnum}::{myEnumNull}").render(new MyService()));

// Namespace resolvers
assertEquals("OK", engine.parse("{#if enum is MyEnum:BAR}OK{/if}").data("enum", MyEnum.BAR).render());
Expand Down

0 comments on commit 996f6b5

Please sign in to comment.