Support getters from default methods in interfaces.
Fortunately this did not require using any JDK 1.8-specific APIs, just searching (via reflection) through the set of interfaces implemented by a class in addition to its super-classes. One downside is that the transitive set of all implemented interfaces could be much larger than the super-class chain, but this is the last thing we search, so in theory we only even get here if we were about to fail to find the getter entirely. This also means that our tests have to be compiled and run with Java 8, because I was not in the mood to figure out how to do all the complex Maven jockeying to have a special JDK8 profile and disable JDK8 tests in the normal profile and re-enable them in the JDK8 profile and blah blah blah, just shoot me now.
This commit is contained in:
@@ -41,6 +41,22 @@ public class MustacheTest
|
||||
});
|
||||
}
|
||||
|
||||
public interface HasDefault {
|
||||
default String getFoo () { return "bar"; }
|
||||
}
|
||||
public interface Interloper extends HasDefault {
|
||||
default String getFoo () { return "bang"; }
|
||||
}
|
||||
@Test public void testDefaultMethodVariable () {
|
||||
test("bar", "{{foo}}", new HasDefault() {
|
||||
});
|
||||
test("bang", "{{foo}}", new Interloper() {
|
||||
});
|
||||
test("bong", "{{foo}}", new Interloper() {
|
||||
public String getFoo () { return "bong"; }
|
||||
});
|
||||
}
|
||||
|
||||
@Test public void testPropertyVariable () {
|
||||
test("bar", "{{foo}}", new Object() {
|
||||
String getFoo () { return "bar"; }
|
||||
|
||||
Reference in New Issue
Block a user