Considering the standard naming convention, check that there exists a method with "get" or "set" prefixed to the name of a field of the class:
public static int[] count(Class<? extends Object> c) {
int[] counts = new int[2];
Field[] fields = c.getDeclaredFields();
Method[] methods = c.getDeclaredMethods();
Set<String> fieldNames = new HashSet<String>();
List<String> methodNames = new ArrayList<String>();
for (Field f : fields){
fieldNames.add(f.getName().toLowerCase());
}
for (Method m : methods){
methodNames.add(m.getName().toLowerCase());
}
for (String name : methodNames){
if(name.startsWith("get") && fieldNames.contains(name.substring(3))){
counts[0]++;
}else if(name.startsWith("set") && fieldNames.contains(name.substring(3))){
counts[1]++;
}
}
return counts;
}
If you want to get all inherited getters/setters as well, replace getDeclaredFields() and getDeclaredMethods() with getFields() and getMethods().
ismethods forbooleans?