Replace field with accessor

Is there an intention or refactoring option that can replace direct  field access with their accessor? (i.e. getXXX or isXXX method). Right  now it'd be handy if I could do this over a selected area of code too.  Possibly via a plugin?

Closest match I could find is  encapulate fields, but what I'm after is more fixing code that ignores  any such encapulation (legacy).


PS tried accessors plugin (2008) without much luck, didn't appear to activate in IDEA 11 at all?

4 comments
Comment actions Permalink

The encapsulate fields refactoring should do exactly what you need.

0
Comment actions Permalink

Didn't appear to? keeps telling me theres no changes to make. In this case the accessor methods already exist, but they've not been used? I want to replace these direct field usages with the accessor.

I'll give it another couple of tries.

0
Comment actions Permalink

Inline the accessor beforehand?

0
Comment actions Permalink

Think I've worked it out thanks, problems seemed to be acessors where on a parent object, seems "enapsulate fields" only works on locally defined ones. In this case I wanted to replace all direct field usage for a couple of methods (selection), where encapsulate fields is a bit more whole class based (which is sensible, but sometimes I prefer baby-steps when refactoring).

Other thing I noticed is some of our devs didn't honor the java bean covention of isXXX for boolean accessors. Encapsulate fields creates these isXXX methods but also keeps the orginal forms of same acessors but now delegated to the new accessor. This was a bit awkward, felt like duplicating methods was worse than the devs using a slightly wrong naming convention.

It's still useful though thanks.

0

Please sign in to leave a comment.