diff --git a/platform/duplicates-analysis/src/com/intellij/dupLocator/index/DuplicatesInspectionBase.java b/platform/duplicates-analysis/src/com/intellij/dupLocator/index/DuplicatesInspectionBase.java index 7a5f834a2cd7..09711d7568f6 100644 --- a/platform/duplicates-analysis/src/com/intellij/dupLocator/index/DuplicatesInspectionBase.java +++ b/platform/duplicates-analysis/src/com/intellij/dupLocator/index/DuplicatesInspectionBase.java @@ -33,6 +33,7 @@ import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.roots.TestSourcesFilter; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileWithId; @@ -109,8 +110,14 @@ public class DuplicatesInspectionBase extends LocalInspectionTool { int hash2 = (int)(hash >> 32); LocalQuickFix viewAllDupesFix = isOnTheFly && hash != 0 ? createShowOtherDupesFix(virtualFile, offset, (int)hash, hash2) : null; + + boolean onlyExtractable = Registry.is("duplicates.inspection.only.extractable"); LocalQuickFix extractMethodFix = - isOnTheFly && hash != 0 ? createExtractMethodFix(targetElement, rangeInElement, (int)hash, hash2) : null; + (isOnTheFly || onlyExtractable) && hash != 0 ? createExtractMethodFix(targetElement, rangeInElement, (int)hash, hash2) : null; + if (onlyExtractable) { + if (extractMethodFix == null) return null; + if (!isOnTheFly) extractMethodFix = null; + } ProblemDescriptor descriptor = manager .createProblemDescriptor(targetElement, rangeInElement, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly, fix, diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index df71d9c805b4..bb8db6d7f5c1 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -1227,3 +1227,6 @@ batch.inspections.process.by.default.jvm.languages.description=When building gra junit4.search.4.tests.in.classpath=true junit4.search.4.tests.in.classpath.description=Search for tests in the module output + +duplicates.inspection.only.extractable=false +duplicates.inspection.only.extractable.description=Highlight duplicate code only if it can be extracted into a method