Detect builder-style setter

Previously, a setter method that was returning the current instance was
not identified as a "setter" by the configuration processor. As a result,
builder-style APIs were not covered by the configuration metadata.

If a setter returns either void or the current class, it is now
recognized as a valid setter.

Fixes gh-1854
This commit is contained in:
Stephane Nicoll
2014-11-08 16:41:22 +00:00
parent 5946a44b7b
commit 2786234eb4
3 changed files with 51 additions and 1 deletions

View File

@@ -91,7 +91,12 @@ class TypeElementMembers {
private boolean isSetter(ExecutableElement method) {
final String name = method.getSimpleName().toString();
return name.startsWith("set") && method.getParameters().size() == 1
&& (TypeKind.VOID == method.getReturnType().getKind());
&& (isSetterReturnType(method));
}
private boolean isSetterReturnType(ExecutableElement method) {
return (TypeKind.VOID == method.getReturnType().getKind()
|| method.getEnclosingElement().asType().equals(method.getReturnType()));
}
private String getAccessorName(String methodName) {