Support isFoo for boolean properties.
This is addition to the existing getFoo support.
This commit is contained in:
committed by
Michael Bayne
parent
2aa93d4240
commit
ee4178f549
@@ -81,9 +81,10 @@ public class DefaultCollector extends BasicCollector
|
||||
} catch (Exception e) {
|
||||
// fall through
|
||||
}
|
||||
|
||||
String upperName = Character.toUpperCase(name.charAt(0)) + name.substring(1);
|
||||
try {
|
||||
m = clazz.getDeclaredMethod(
|
||||
"get" + Character.toUpperCase(name.charAt(0)) + name.substring(1));
|
||||
m = clazz.getDeclaredMethod("get" + upperName);
|
||||
if (!m.getReturnType().equals(void.class)) {
|
||||
if (!m.isAccessible()) {
|
||||
m.setAccessible(true);
|
||||
@@ -94,6 +95,19 @@ public class DefaultCollector extends BasicCollector
|
||||
// fall through
|
||||
}
|
||||
|
||||
try {
|
||||
m = clazz.getDeclaredMethod("is" + upperName);
|
||||
if (m.getReturnType().equals(boolean.class) ||
|
||||
m.getReturnType().equals(Boolean.class)) {
|
||||
if (!m.isAccessible()) {
|
||||
m.setAccessible(true);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// fall through
|
||||
}
|
||||
|
||||
Class<?> sclass = clazz.getSuperclass();
|
||||
if (sclass != Object.class && sclass != null) {
|
||||
return getMethod(clazz.getSuperclass(), name);
|
||||
|
||||
@@ -47,6 +47,18 @@ public class MustacheTest
|
||||
});
|
||||
}
|
||||
|
||||
@Test public void testBooleanPropertyVariable () {
|
||||
test("true", "{{foo}}", new Object() {
|
||||
Boolean isFoo () { return true; }
|
||||
});
|
||||
}
|
||||
|
||||
@Test public void testPrimitiveBooleanPropertyVariable () {
|
||||
test("false", "{{foo}}", new Object() {
|
||||
boolean isFoo () { return false; }
|
||||
});
|
||||
}
|
||||
|
||||
@Test public void testSkipVoidReturn () {
|
||||
test("bar", "{{foo}}", new Object() {
|
||||
void foo () {}
|
||||
|
||||
Reference in New Issue
Block a user