From the main or context menu, select Refactor | Find and Replace Code Duplicates. In the dialog that opens, select the scope where IntelliJ IDEA shall look for code duplicates. For each found code duplicate, IntelliJ IDEA will prompt you to confirm the replacement.
Don't Repeat Yourself (DRY): Using DRY or Do not Repeat Yourself principle, you make sure that you stay away from duplicate code as often as you can. Rather you replace the duplicate code with abstractions or use data normalization. To reduce duplicity in a function, one can use loops and trees.
Go to sonar dashboard. Click on Issues. Select your class and issue and further check see rule. Rule id is mentioned in the top right corner of rule description.
Code Inspection: Duplicated code fragmentReports duplicated blocks of code from the selected scope: the same file or the entire project. The inspection features quick-fixes that help you to set the size of detected duplicates, navigate to repetitive code fragments, and compare them in a tool window.
Only available in IntelliJ Ultimate:
To disable duplicate code detection, go to
File → Settings → Editor → Inspections → General → Duplicated code fragment
and uncheck box "Duplicate code fragment".
Add a hint to your code so that others will know your intent:
@SuppressWarnings("Duplicates")
Yes, it's possible, but I would strongly advise against it!
Duplicate code is a form of technical debt. Any duplicated code that contains a bug means you now have a duplicated bug - you then run the risk that when you fix it, you'll only fix it in one place and the duplicate will remain...
If duplicate code warnings are distracting you, then the best strategy for getting rid of them is to remove the code duplication... Your codebase and future maintainers will thank you for it
This answer may be little irrelevant, but I found this helpful, From this answer if you want to disable it for a specific code block, not the entire method or class or ide, then just add the following line just before that code block
//noinspection Duplicates
Note: You can not put any other comment after this line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With