New inspection possible: duplicate line?

Would it be possible to create a new inspection that checks to see if a line is identical to the previous line? It is analogous to way a word processor flags a repeated word...it is usually a mistake. For example, someone on my current project did some copying and ended up with this:
purchaseTypeSIList.add(new SelectItem(PURCHASE_TYPE_INDIVIDUAL_AD,""));
purchaseTypeSIList.add(new SelectItem(PURCHASE_TYPE_INDIVIDUAL_AD,""));
when what they really wanted was this:
purchaseTypeSIList.add(new SelectItem(PURCHASE_TYPE_INDIVIDUAL_AD,""));
purchaseTypeSIList.add(new SelectItem(PURCHASE_TYPE_PACKAGE,""));

Would the inspection system allow for this type of check?

6 comments
Comment actions Permalink

It certainly would, though we still have to decide if not too many false alarms would be generated.

0
Comment actions Permalink

Twenty minutes total to code it up, whiling a way a lazy meeting with HR. That said, I don't think it should be promoted into main-branch InspectionGadgets until I play with it a while. I want to see both how bad the false-positive issue is, and also whether the condition it checks can be broadened to catch more bugs.

I've got a double handful of inspections like these, which check for conditions that aren't semantic errors, but are likely to be the result of cut-and-paste typos or missing cases. In general, they can be quite powerful, but the false positive problem is real. I might package them up into a non-InspectionGadget plugin, once they are sufficiently mature.

--Dave Griffith

0
Comment actions Permalink

Dave Griffith wrote:

Twenty minutes total to code it up, whiling a way a lazy meeting with HR. That said, I don't think it should be promoted into main-branch InspectionGadgets until I play with it a while. I want to see both how bad the false-positive issue is, and also whether the condition it checks can be broadened to catch more bugs.

I've got a double handful of inspections like these, which check for conditions that aren't semantic errors, but are likely to be the result of cut-and-paste typos or missing cases. In general, they can be quite powerful, but the false positive problem is real. I might package them up into a non-InspectionGadget plugin, once they are sufficiently mature.

--Dave Griffith

wow that was fast!
I could use this inspection! I often find myself hitting ctrl-D by
accident and not realizing that I duplicated a line. You could handle
the false positives aspect by having it turned off by default so that
"power users" who know what they are doing could turn it on and use it.
BTW, it might also be useful if the inspection ignored duplicate
comment lines.

0
Comment actions Permalink

Dave - If you want to get more empirical data running this inspection across other sizable code bases in addition to your own, I'd be glad to help as I'm sure others would.
Created an issue for it:
http://www.jetbrains.net/jira/browse/IDEA-10932

Thanks,
Jon

0
Comment actions Permalink

wow that was fast!

HR meetings provide much scope for coding, if you've got enough pull to bring a laptop.

+BTW, it might also be useful if the inspection ignored duplicate
comment lines.+

It actually checks for adjacent semantically equivalent statements, ignoring whitespace and comments completely.

--Dave Griffith

0
Comment actions Permalink

But, on the other hand, it would be nice if it DID detect the following
kind of comment duplication:

/* comment starts here
/* comment starts here

...

*/
Dave Griffith wrote:

wow that was fast!

HR meetings provide much scope for coding, if you've got enough pull to bring a laptop.

+BTW, it might also be useful if the inspection ignored duplicate
comment lines.+

It actually checks for adjacent semantically equivalent statements, ignoring whitespace and comments completely.

--Dave Griffith


0

Please sign in to leave a comment.