Apex duplicate code detection support using either JetBrains' feature or PMD CPD
- 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)
-
Account Deactivated -
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.
-
repo owner Well I'll be...I have a first cut at it working. It shows duplicates both in real-time:
and can be run en masse to analyze the larger code base:
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.
-
reporter Woop woop, that’s so cool; thanks alot
-
Account Deactivated That’s awesome. Thanks Scott.
-
repo owner - changed status to resolved
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.
-
repo owner Updating the title to reflect the actual resolution.
- Log in to comment
Reference: Finding duplicated code with CPD | PMD Source Code Analyzer