Idea for plugin (maybe for InspectionGadgets)

When InspectionGadgets tell me that I have a magic number,
I would like to have the intention to replace the magic
number with the appropriate constant.

Let's say I have this code:

Putting the cursor on the first '10' in the Dimension call
and pressing Alt-Enter should present a list with the
- Introduce Constant (same as existing refactoring)
- Use WIDTH (10)
- Use HEIGHT (10)

The choices in the list are those constants whose value
matches the number that is to be replaced.

Can it be done?


1 comment
Comment actions Permalink

At present, no. The "Introduce Constant" refactoring isn't available in the Open API. I've got an open Tracker request for it (and a few other refactorings that would make good inspection quickfixes), but until JetBrains opens it I have no way to connect.


--Dave Griffith


Please sign in to leave a comment.