IPP/IG: suggestions

Hello Dave

I am not sure whether you are still supporting and enhancing IPP/IG or you handed it over to JetBrains. For the time being, I am posting my suggestions here.

While I was doing some code cleanup, a few suggestions came to my mind:

1. It'd be nice to have an intention to merge adjacent string/character literals. For example:

would become

This could be expanded even further: to merge numeric literals with strings as well.

2. A suggestion to replace the following implicit string conversion:

with


3. A suggestion to remove redundant toString() call in string concatenation:

with

Strictly speaking, it is not a completely redundant call, because it implies null pointer check, but it most of the cases it is a sign of a poor coding standard.

4. Split/join binary operators in assignments
This is almost always feasible, except for the case when the variable is present on both sides of the assignment.
Example:

could be split as:

... and possibly joined back into one statement later.

6 comments
Comment actions Permalink

1-3 are nice. I'll put 'em on the IPP/IG todo lists. 4 I'm not sure the point of. The "before" case looks much better, particularly if "i" can be made final (which it can't in the "after" case.

(To your implicit question: IPP/IG maintenance is on a temporary hiatus. Whether that hiatus ends with me putting in a bunch of fixes or mailing everything off to Max is still to be determined, although things look hopeful.)

--Dave

0
Comment actions Permalink

Hi Dave,

I have a couple more suggestions:

Since IG is used primarily to enforce good coding practices (aka. enforcing
coding standards & guidelines), it would be nice if there was a quick way to
generate a coding standards/guidelines document (HTML/PDF/RTF) from the
rules.

Along those same lines, it would be nice if each rule could be marked as
either a standard or a guideline (instead of error or warning). Guidelines
would be marked in one color, Standards in another. I know that it's only
semantics; but truthfully, error vs warning doesn't really mean what it
says. The code will compile even if the box is red and the compiler won't
complain about either one.

And finally, since most coding standards allow for justified violations of
standards and guidelines, it would be nice to add an intention that would
insert a "Standard or Guideline Violation Justification" comment on the line
above the marked rule violation.
Here's the hard part: If the justification comment exists, then the rule
violation would be lowered in priority. A violated standard with
justification would be marked in yellow; while a violated guidline with
justification would be ignored (or marked in an even lower priority color).
I'm not sure how you would map the comment to the rule violation, maybe
using javadoc-like tags in the comment. A tool window like the TODO window
would be usefull in quickly reviewing all of the justification comments
during code reviews.

I'm not sure if these are realistic suggestions, but I know that they would
be extremely useful.

Thanks,

Tim


0
Comment actions Permalink

3. A suggestion to remove redundant toString() call in string concatenation:

 String s = "foo=" + foo.toString();]]>

with

 String s = "foo=" + foo;]]>

Strictly speaking, it is not a completely redundant call, because it implies null pointer check, but it most of the cases it is a sign of a poor coding standard.


Writing
String s = "foo=" + foo.toString();
has one advantage: you can search for usages of foo's toString() and
find this usage.

+1 to all other suggestions

Tom

0
Comment actions Permalink

Writing
String s = "foo=" + foo.toString();
has one advantage: you can search for usages of foo's
toString() and
find this usage.


That's one of the things that I'd like to open an SCR for. Sometimes I want to lookup usages of toString(), which is overridden in some class. To the best of my knowledge, IDEA does not search for implicit toString() calls, which happen inside concatenation operator.

0
Comment actions Permalink

Regarding case 4.

Yesterday I had to do a great job of joining adjacent assignments in the legacy code (reverting them to the "before" state). The intention would help me a lot.

However, I can imagine that in some cases the right-hand side expression is so complicated that it is better written as a series of assignments. Hint -- there may be two generation options ("compact" and "verbose" form):

and

0
Comment actions Permalink


All very interesting suggestions, and they would go a long way toward making IDEA an amazing QA tool, as it is already an amazing development tool. Unfortunately, none of these can be accomplished within the scope of InspectionGadgets. These are features at the level of the built-in Inspection tool itself, and couldn't be added via the open inspection API. JetBrains will need to do these. You should submit Tracker items for them (checking first for duplicates, I know there's a duplicate for the "justification" feature).

--Dave Griffith

0

Please sign in to leave a comment.