Apex duplicate code detection support using either JetBrains' feature or PMD CPD

Issue #2054 resolved
Jason van Beukering created an issue
  • PMD provides duplicate checking via CLI, would it be possible to incorporate this into IC so that this are highlighted as inspection issues within relevant Jetbrains IDE?

Comments (7)

  1. Scott Wells repo owner

    I like this idea, but before integrating CPD I'm investigating the first-class duplicate code detection feature in JetBrains IDEs to see what's required to add Apex support. That would be much more tightly-integrated, and if done properly could also be integrated with extraction refactoring quick fixes to assist with not just detection but also minimization of duplicate code.

    Hopefully that will be bear fruit, but if not I'll look at integrating CPD into IC2. Note that because of how CPD works--it must scan the entire code base to build an index of duplicate candidates--it would be a bulk code inspection and not a real-time integration.

  2. Scott Wells repo owner

    Well I'll be...I have a first cut at it working. It shows duplicates both in real-time:

    Apex_Duplicate_Code_Detection_Inline.png

    and can be run en masse to analyze the larger code base:

    Apex_Duplicate_Code_Detection_Results.png

    I haven't implemented any special quick fixes, e.g., to extract repeated code into a common method, but even in its current form this is quite useful. I'll see if I can get it cleaned up for inclusion in this week's build.

  3. Scott Wells repo owner

    Delivered in 2.2.1.2. Note that JetBrains' duplicate code detection is only available in commercial IDEs, so it won't be available if you're using IC2 with a Community Edition IDE.

    If you see any unexpected or sub-optimal duplicate code reporting for Apex, feel free to log a new bug with a simple example that reproduces the behavior.

  4. Log in to comment