Question

For our pure data classes, we don't use getters or setters. When refactoring old code, I would like to be able to quickly replace (typically Eclipse-generated) calls to getters & setters with direct field access.

Is there a plugin that does that?

Note: I'm not interested in the pros & cons of encapsulation or not, that has already been discussed too many times.

So, I would like to replace:

myData.setValue(17);
int value = myData.getValue();

with:

myData.value = 17;
int value = myData.value;
Was it helpful?

Solution

You can use the existing inline method refactoring. Just make the field in question public and then execute that refactoring. If your code base is too large to do this by hand, you might have a look at How to execute inline refactoring programmatically using JDT/LTK?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top