New “Magic Constant” Inspection
Wednesday, February 15th, 2012Have you ever cursed an API which uses magic integer constants instead of the proper enumeration?

What should I pass as the titleJustification parameter here? 0 or 1?
Can I pass “42″ for the titlePosition parameter? Even Javadoc won’t know.
Actually, you must use one of the constants in the TitledBorder class to make the code correct:

I call these constants “magic” because sometimes it is far from easy to figure them out.
Here comes a new “Magic constant” inspection that looks for usages of methods/variables which expect “magic constants” as their arguments:

Then it helps you to replace plain numbers or strings with a proper magic constant:

