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) {
|
} catch (Exception e) {
|
||||||
// fall through
|
// fall through
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String upperName = Character.toUpperCase(name.charAt(0)) + name.substring(1);
|
||||||
try {
|
try {
|
||||||
m = clazz.getDeclaredMethod(
|
m = clazz.getDeclaredMethod("get" + upperName);
|
||||||
"get" + Character.toUpperCase(name.charAt(0)) + name.substring(1));
|
|
||||||
if (!m.getReturnType().equals(void.class)) {
|
if (!m.getReturnType().equals(void.class)) {
|
||||||
if (!m.isAccessible()) {
|
if (!m.isAccessible()) {
|
||||||
m.setAccessible(true);
|
m.setAccessible(true);
|
||||||
@@ -94,6 +95,19 @@ public class DefaultCollector extends BasicCollector
|
|||||||
// fall through
|
// 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();
|
Class<?> sclass = clazz.getSuperclass();
|
||||||
if (sclass != Object.class && sclass != null) {
|
if (sclass != Object.class && sclass != null) {
|
||||||
return getMethod(clazz.getSuperclass(), name);
|
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 public void testSkipVoidReturn () {
|
||||||
test("bar", "{{foo}}", new Object() {
|
test("bar", "{{foo}}", new Object() {
|
||||||
void foo () {}
|
void foo () {}
|
||||||
|
|||||||
Reference in New Issue
Block a user