mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
[refactoring] restoredDeclarationCopy() may return null now
GitOrigin-RevId: 4c1a8b71e6484d2b7f62c0b193269c43274bedbe
This commit is contained in:
committed by
intellij-monorepo-bot
parent
11a49fde4c
commit
16ee770c44
@@ -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))
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user