forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fixes quarkusio#43489 - consider default methods in class hierarchy; previously, interface default methods were only considered if a ValueResolver was generated for an interface - also consider inherited fields in a class hierarchy (cherry picked from commit bc206a1)
- Loading branch information
Showing
13 changed files
with
212 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...projects/qute/generator/src/test/java/io/quarkus/qute/generator/hierarchy/FirstLevel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.quarkus.qute.generator.hierarchy; | ||
|
||
public interface FirstLevel { | ||
|
||
default int firstLevel() { | ||
return 1; | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
...jects/qute/generator/src/test/java/io/quarkus/qute/generator/hierarchy/HierarchyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.quarkus.qute.generator.hierarchy; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.Index; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.qute.Engine; | ||
import io.quarkus.qute.EngineBuilder; | ||
import io.quarkus.qute.ValueResolver; | ||
import io.quarkus.qute.generator.SimpleGeneratorTest; | ||
import io.quarkus.qute.generator.TestClassOutput; | ||
import io.quarkus.qute.generator.ValueResolverGenerator; | ||
|
||
public class HierarchyTest { | ||
|
||
static Set<String> generatedTypes = new HashSet<>(); | ||
|
||
@BeforeAll | ||
public static void init() throws IOException { | ||
TestClassOutput classOutput = new TestClassOutput(); | ||
Index index = SimpleGeneratorTest.index(Level1.class, Level2.class, Level3.class, Level4.class, FirstLevel.class, | ||
SecondLevel.class); | ||
ValueResolverGenerator generator = ValueResolverGenerator.builder().setIndex(index).setClassOutput(classOutput) | ||
.addClass(index.getClassByName(DotName.createSimple(Level4.class.getName()))) | ||
.build(); | ||
|
||
generator.generate(); | ||
generatedTypes.addAll(generator.getGeneratedTypes()); | ||
} | ||
|
||
@Test | ||
public void testHierarchy() throws Exception { | ||
EngineBuilder builder = Engine.builder().addDefaults(); | ||
for (String generatedType : generatedTypes) { | ||
builder.addValueResolver((ValueResolver) SimpleGeneratorTest.newResolver(generatedType)); | ||
} | ||
Engine engine = builder.build(); | ||
|
||
Level4 level4 = new Level4(); | ||
assertEquals(1, level4.getLevel1()); | ||
assertEquals(1, level4.firstLevel()); | ||
assertEquals(2, level4.secondLevel()); | ||
assertEquals(4, level4.getLevel4()); | ||
assertEquals(4, level4.overridenLevel); | ||
|
||
assertEquals("1::1::2::4::4", | ||
engine.parse( | ||
"{level.level1}::{level.firstLevel}::{level.secondLevel}::{level.getLevel4}::{level.overridenLevel}") | ||
.render(Map.of("level", level4))); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...ent-projects/qute/generator/src/test/java/io/quarkus/qute/generator/hierarchy/Level1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.quarkus.qute.generator.hierarchy; | ||
|
||
public class Level1 implements FirstLevel { | ||
|
||
public int firstLevel = 1; | ||
|
||
public int getLevel1() { | ||
return 1; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ent-projects/qute/generator/src/test/java/io/quarkus/qute/generator/hierarchy/Level2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.quarkus.qute.generator.hierarchy; | ||
|
||
public class Level2 extends Level1 implements SecondLevel { | ||
|
||
public int getLevel2() { | ||
return 2; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ent-projects/qute/generator/src/test/java/io/quarkus/qute/generator/hierarchy/Level3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.quarkus.qute.generator.hierarchy; | ||
|
||
public class Level3 extends Level2 { | ||
|
||
public int overridenLevel = 3; | ||
|
||
public int getLevel3() { | ||
return 3; | ||
} | ||
|
||
// This method should be overriden | ||
public int getLevel4() { | ||
return 34; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...ent-projects/qute/generator/src/test/java/io/quarkus/qute/generator/hierarchy/Level4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.quarkus.qute.generator.hierarchy; | ||
|
||
public class Level4 extends Level3 { | ||
|
||
public int overridenLevel = 4; | ||
|
||
public int getLevel4() { | ||
return 4; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...rojects/qute/generator/src/test/java/io/quarkus/qute/generator/hierarchy/SecondLevel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.quarkus.qute.generator.hierarchy; | ||
|
||
public interface SecondLevel { | ||
|
||
default int secondLevel() { | ||
return 2; | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
integration-tests/qute/src/main/java/io/quarkus/it/qute/DefaultMethodResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.quarkus.it.qute; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import io.quarkus.qute.TemplateInstance; | ||
|
||
@Path("/defaultmethod") | ||
public class DefaultMethodResource { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public TemplateInstance get() { | ||
return new hello(new Name()); | ||
} | ||
|
||
record hello(Name name) implements TemplateInstance { | ||
}; | ||
|
||
public static class Name implements Something { | ||
|
||
public String name() { | ||
return "M"; | ||
} | ||
} | ||
|
||
public interface Something { | ||
|
||
String name(); | ||
|
||
default String fullName() { | ||
return name() + "K"; | ||
} | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
integration-tests/qute/src/main/resources/templates/DefaultMethodResource/hello.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello {name.fullName}! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters