Let's assume that Melon has three fields (type, weight, and ripe) and defines only a getter for type and a setter for ripe:
public class Melon { private String type; private int weight; private boolean ripe; ... public String getType() { return type; } public void setRipe(boolean ripe) { this.ripe = ripe; } ...}
In order to generate the missing getters and setters, we start by identifying them. The following solution loops the declared fields of the given class and assumes that a foo field doesn't have a getter if the following apply:
- There is no get/isFoo() method
- The return type is not the same as the field type
- The number of arguments is not 0
For each missing getter, this solution adds in a map an entry ...