Code cleanup: KotlinSafeDeleteProcessor
This commit is contained in:
+9
-10
@@ -43,7 +43,6 @@ import org.jetbrains.kotlin.idea.refactoring.checkSuperMethods
|
|||||||
import org.jetbrains.kotlin.idea.refactoring.formatClass
|
import org.jetbrains.kotlin.idea.refactoring.formatClass
|
||||||
import org.jetbrains.kotlin.idea.refactoring.formatFunction
|
import org.jetbrains.kotlin.idea.refactoring.formatFunction
|
||||||
import org.jetbrains.kotlin.idea.references.KtReference
|
import org.jetbrains.kotlin.idea.references.KtReference
|
||||||
import org.jetbrains.kotlin.idea.search.usagesSearch.buildProcessDelegationCallConstructorUsagesTask
|
|
||||||
import org.jetbrains.kotlin.idea.search.usagesSearch.processDelegationCallConstructorUsages
|
import org.jetbrains.kotlin.idea.search.usagesSearch.processDelegationCallConstructorUsages
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
@@ -68,9 +67,7 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
|||||||
deleteSet.any { element -> JavaSafeDeleteProcessor.isInside(it, element.unwrapped) }
|
deleteSet.any { element -> JavaSafeDeleteProcessor.isInside(it, element.unwrapped) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSearchInfo(element: PsiElement): NonCodeUsageSearchInfo {
|
fun getSearchInfo(element: PsiElement) = NonCodeUsageSearchInfo(getIgnoranceCondition(), element)
|
||||||
return NonCodeUsageSearchInfo(getIgnoranceCondition(), element)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun findUsagesByJavaProcessor(element: PsiElement, forceReferencedElementUnwrapping: Boolean): NonCodeUsageSearchInfo? {
|
fun findUsagesByJavaProcessor(element: PsiElement, forceReferencedElementUnwrapping: Boolean): NonCodeUsageSearchInfo? {
|
||||||
val javaUsages = ArrayList<UsageInfo>()
|
val javaUsages = ArrayList<UsageInfo>()
|
||||||
@@ -89,7 +86,7 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
|||||||
|
|
||||||
is SafeDeleteOverrideAnnotation ->
|
is SafeDeleteOverrideAnnotation ->
|
||||||
usageInfo.smartPointer.element?.let { usageElement ->
|
usageInfo.smartPointer.element?.let { usageElement ->
|
||||||
if (usageElement.toLightMethods().all { method -> method.findSuperMethods().size == 0 }) {
|
if (usageElement.toLightMethods().all { method -> method.findSuperMethods().isEmpty() }) {
|
||||||
KotlinSafeDeleteOverrideAnnotation(usageElement, usageInfo.referencedElement)
|
KotlinSafeDeleteOverrideAnnotation(usageElement, usageInfo.referencedElement)
|
||||||
}
|
}
|
||||||
else null
|
else null
|
||||||
@@ -214,11 +211,13 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is PsiMethod ->
|
is PsiMethod -> {
|
||||||
findUsagesByJavaProcessor(element, false)
|
findUsagesByJavaProcessor(element, false)
|
||||||
|
}
|
||||||
|
|
||||||
is PsiClass ->
|
is PsiClass -> {
|
||||||
findUsagesByJavaProcessor(element, false)
|
findUsagesByJavaProcessor(element, false)
|
||||||
|
}
|
||||||
|
|
||||||
is KtProperty -> {
|
is KtProperty -> {
|
||||||
if (element.isLocal) {
|
if (element.isLocal) {
|
||||||
@@ -255,13 +254,13 @@ class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
|||||||
|
|
||||||
val bindingContext = (element as KtElement).analyze()
|
val bindingContext = (element as KtElement).analyze()
|
||||||
|
|
||||||
val declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element)
|
val declarationDescriptor =
|
||||||
if (declarationDescriptor !is CallableMemberDescriptor) return null
|
bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, element] as? CallableMemberDescriptor ?: return null
|
||||||
|
|
||||||
return declarationDescriptor.overriddenDescriptors
|
return declarationDescriptor.overriddenDescriptors
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.filter { overridenDescriptor -> overridenDescriptor.modality == Modality.ABSTRACT }
|
.filter { overridenDescriptor -> overridenDescriptor.modality == Modality.ABSTRACT }
|
||||||
.mapTo(ArrayList<String>()) { overridenDescriptor ->
|
.mapTo(ArrayList()) { overridenDescriptor ->
|
||||||
KotlinBundle.message(
|
KotlinBundle.message(
|
||||||
"x.implements.y",
|
"x.implements.y",
|
||||||
formatFunction(declarationDescriptor, true),
|
formatFunction(declarationDescriptor, true),
|
||||||
|
|||||||
Reference in New Issue
Block a user