ParameterDeclaration tpd = paramMap.get(paramNameQualifiers[0]);
TypeMirror type = tpd.getType();
MethodDeclaration getterMethod = null;
FieldDeclaration field = null;
for (int i = 1; i < paramNameQualifiers.length; i++) {
getterMethod = null;
field = null;
// loop through superclasses until we find a match or run out of superclasses
while (type != null) {
if (type instanceof DeclaredType == false) {
throw new ControlException(buildMessage(parameterName, method.getSimpleName()));
}
TypeDeclaration td = ((DeclaredType) type).getDeclaration();
//
// abort if Map!!! No further checking can be done.
//
if (td.getQualifiedName().equals("java.util.Map")) {
return;
}
Collection<? extends MethodDeclaration> methods =
DeclarationFilter.FILTER_PUBLIC.filter(td.getMethods());
for (MethodDeclaration m : methods) {
String upperFirst = paramNameQualifiers[i].substring(0,1).toUpperCase();
if (paramNameQualifiers[i].length() > 1) {
upperFirst = upperFirst + paramNameQualifiers[i].substring(1);
}
if (m.getSimpleName().equals("get" + upperFirst)
|| m.getSimpleName().equals("is" + upperFirst)) {
getterMethod = m;
}
}
if (getterMethod == null) {
Collection<FieldDeclaration> fields =
DeclarationFilter.FILTER_PUBLIC.filter(td.getFields());
for (FieldDeclaration fd : fields) {
if (fd.getSimpleName().equals(paramNameQualifiers[i])) {
field = fd;
}
}
}
// try the super-class
if (getterMethod == null && field == null) {
if (td instanceof ClassDeclaration) {
type = ((ClassDeclaration) td).getSuperclass();
continue;
}
}
break;
} // while
// found a match, get its type and continue within the for loop
if (getterMethod != null) {
type = getterMethod.getReturnType();
} else if (field != null) {
type = field.getType();
} else {
throw new ControlException(buildMessage(parameterName, method.getSimpleName()));
}
}
}