diff --git a/java/java-impl-refactorings/src/com/intellij/java/refactoring/suggested/JavaSuggestedRefactoringAvailability.kt b/java/java-impl-refactorings/src/com/intellij/java/refactoring/suggested/JavaSuggestedRefactoringAvailability.kt index cac58c4ec6d6..5fb38df1a094 100644 --- a/java/java-impl-refactorings/src/com/intellij/java/refactoring/suggested/JavaSuggestedRefactoringAvailability.kt +++ b/java/java-impl-refactorings/src/com/intellij/java/refactoring/suggested/JavaSuggestedRefactoringAvailability.kt @@ -22,7 +22,7 @@ class JavaSuggestedRefactoringAvailability(refactoringSupport: SuggestedRefactor // disable refactoring suggestion for method which overrides another method override fun shouldSuppressRefactoringForDeclaration(state: SuggestedRefactoringState): Boolean { if (state.anchor !is PsiMethod && state.anchor !is PsiCallExpression) return false - val restoredDeclarationCopy = state.refactoringSupport.stateChanges.findDeclaration(state.restoredDeclarationCopy()) + val restoredDeclarationCopy = state.restoredDeclarationCopy() return restoredDeclarationCopy is PsiMethod && restoredDeclarationCopy.findSuperMethods().isNotEmpty() } @@ -39,7 +39,7 @@ class JavaSuggestedRefactoringAvailability(refactoringSupport: SuggestedRefactor if (state.additionalData[HAS_USAGES] == null) { val declarationCopy = state.restoredDeclarationCopy() - val useScope = declarationCopy.useScope + val useScope = declarationCopy?.useScope if (useScope is LocalSearchScope) { val hasUsages = ReferencesSearch.search(declarationCopy, useScope).findFirst() != null yield(state.withAdditionalData(HAS_USAGES, hasUsages)) diff --git a/platform/lang-api/src/com/intellij/refactoring/suggested/SuggestedRefactoringState.kt b/platform/lang-api/src/com/intellij/refactoring/suggested/SuggestedRefactoringState.kt index 554399438646..60ca600d62ce 100644 --- a/platform/lang-api/src/com/intellij/refactoring/suggested/SuggestedRefactoringState.kt +++ b/platform/lang-api/src/com/intellij/refactoring/suggested/SuggestedRefactoringState.kt @@ -109,10 +109,10 @@ class SuggestedRefactoringState( private var restoredDeclarationCopy: PsiElement? = null - fun restoredDeclarationCopy(): PsiElement { + fun restoredDeclarationCopy(): PsiElement? { require(errorLevel != ErrorLevel.INCONSISTENT) { "restoredDeclarationCopy() should not be invoked for inconsistent state" } val decl = declaration - if (decl !== anchor) return decl!! + if (decl !== anchor) return decl if (restoredDeclarationCopy == null) { restoredDeclarationCopy = createRestoredDeclarationCopy() } diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/suggested/KotlinSuggestedRefactoringAvailability.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/suggested/KotlinSuggestedRefactoringAvailability.kt index cd5ca27010d4..1a99c6f1666d 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/suggested/KotlinSuggestedRefactoringAvailability.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/refactoring/suggested/KotlinSuggestedRefactoringAvailability.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.util.Key import com.intellij.psi.PsiNamedElement import com.intellij.psi.search.LocalSearchScope import com.intellij.psi.search.searches.ReferencesSearch +import com.intellij.refactoring.RefactoringBundle import com.intellij.refactoring.suggested.* import com.intellij.refactoring.suggested.SuggestedRefactoringSupport.Parameter import com.intellij.refactoring.suggested.SuggestedRefactoringSupport.Signature @@ -34,7 +35,7 @@ class KotlinSuggestedRefactoringAvailability(refactoringSupport: SuggestedRefact return iterator { if (state.additionalData[HAS_USAGES] == null) { val declarationCopy = state.restoredDeclarationCopy() - val useScope = declarationCopy.useScope + val useScope = declarationCopy?.useScope if (useScope is LocalSearchScope) { val hasUsages = ReferencesSearch.search(declarationCopy, useScope).findFirst() != null yield(state.withAdditionalData(HAS_USAGES, hasUsages)) @@ -139,7 +140,7 @@ class KotlinSuggestedRefactoringAvailability(refactoringSupport: SuggestedRefact val oldSignature = state.oldSignature val newSignature = state.newSignature - val updateUsagesData = SuggestedChangeSignatureData.create(state, USAGES) + val updateUsagesData = SuggestedChangeSignatureData.create(state, RefactoringBundle.message("suggested.refactoring.usages")) val updateOverridesData = overridesName?.let { updateUsagesData.copy(nameOfStuffToUpdate = it) } if (newSignature.parameters.size > oldSignature.parameters.size) { @@ -212,9 +213,13 @@ class KotlinSuggestedRefactoringAvailability(refactoringSupport: SuggestedRefact private fun KtCallableDeclaration.overridesName(): String? { return when { - hasModifier(KtTokens.ABSTRACT_KEYWORD) -> IMPLEMENTATIONS - hasModifier(KtTokens.OPEN_KEYWORD) -> OVERRIDES - containingClassOrObject?.isInterfaceClass() == true -> if (hasBody()) OVERRIDES else IMPLEMENTATIONS + hasModifier(KtTokens.ABSTRACT_KEYWORD) -> RefactoringBundle.message("suggested.refactoring.implementations") + hasModifier(KtTokens.OPEN_KEYWORD) -> RefactoringBundle.message("suggested.refactoring.overrides") + containingClassOrObject?.isInterfaceClass() == true -> if (hasBody()) { + RefactoringBundle.message("suggested.refactoring.overrides") + } else { + RefactoringBundle.message("suggested.refactoring.implementations") + } isExpectDeclaration() -> "actual declarations" else -> null } diff --git a/python/src/com/jetbrains/python/refactoring/suggested/PySuggestedRefactoringSupport.kt b/python/src/com/jetbrains/python/refactoring/suggested/PySuggestedRefactoringSupport.kt index 624524b874e6..abf746e5bcac 100644 --- a/python/src/com/jetbrains/python/refactoring/suggested/PySuggestedRefactoringSupport.kt +++ b/python/src/com/jetbrains/python/refactoring/suggested/PySuggestedRefactoringSupport.kt @@ -40,7 +40,7 @@ class PySuggestedRefactoringSupport : SuggestedRefactoringSupport { internal fun shouldSuppressRefactoringForDeclaration(state: SuggestedRefactoringState): Boolean { // don't merge with `shouldBeSuppressed` because `shouldBeSuppressed` could be invoked in EDT and resolve below could slow down it val element = state.restoredDeclarationCopy() - return PyiUtil.isOverload(element, TypeEvalContext.codeAnalysis(element.project, element.containingFile)) + return element == null || PyiUtil.isOverload(element, TypeEvalContext.codeAnalysis(element.project, element.containingFile)) } private fun shouldBeSuppressed(element: PsiElement): Boolean {