The Accessor Plugin provides two intention action which can be used to replace direct accesses of a property of a class with a suitable getter or setter method.
public class Foo {
private int bar;
public int getBar() { return bar; }
public void setBar(int bar) {this.bar = bar; }
}
public class FooTest {
public static void main(String[] args) {
Foo foo = new Foo();
foo.bar = 42;
System.out.println(foo.bar);
}
}
IDEA will highlight the two illegal references to Foo's private bar member. The Accessors plugin will offer to replace these references with a setter or getter method call, respectively. Invoking these two intention actions will turn the second class into the following:
public class FooTest {
public static void main(String[] args) {
Foo foo = new Foo();
foo.setBar(42);
System.out.println(foo.getBar());
}
}