Safe Delete: Support secondary constructors and delegation calls
This commit is contained in:
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import com.intellij.psi.PsiReference
|
||||
import com.intellij.psi.search.SearchScope
|
||||
import org.jetbrains.kotlin.asJava.KotlinLightElement
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.codegen.PropertyCodegen
|
||||
import org.jetbrains.kotlin.asJava.KotlinLightMethod
|
||||
@@ -108,20 +109,22 @@ public fun PsiElement.processDelegationCallConstructorUsages(scope: SearchScope,
|
||||
}
|
||||
|
||||
private fun PsiElement.processDelegationCallKotlinConstructorUsages(scope: SearchScope, process: (JetConstructorDelegationCall) -> Unit) {
|
||||
val klass = when (this) {
|
||||
is JetSecondaryConstructor -> getClassOrObject()
|
||||
is JetClass -> this
|
||||
val element = unwrapped
|
||||
val klass = when (element) {
|
||||
is JetSecondaryConstructor -> element.getClassOrObject()
|
||||
is JetClass -> element
|
||||
else -> return
|
||||
}
|
||||
|
||||
if (klass !is JetClass || this !is JetDeclaration) return
|
||||
val descriptor = constructor ?: return
|
||||
if (klass !is JetClass || element !is JetDeclaration) return
|
||||
val descriptor = element.constructor ?: return
|
||||
|
||||
processClassDelegationCallsToSpecifiedConstructor(klass, descriptor, process)
|
||||
processInheritorsDelegatingCallToSpecifiedConstructor(klass, scope, descriptor, process)
|
||||
}
|
||||
|
||||
private fun PsiElement.processDelegationCallJavaConstructorUsages(scope: SearchScope, process: (JetConstructorDelegationCall) -> Unit) {
|
||||
if (this is KotlinLightElement<*, *>) return
|
||||
if (!(this is PsiMethod && isConstructor())) return
|
||||
val klass = getContainingClass() ?: return
|
||||
val descriptor = getJavaMethodDescriptor() as? ConstructorDescriptor ?: return
|
||||
|
||||
+16
-10
@@ -27,10 +27,7 @@ import com.intellij.psi.PsiParameter
|
||||
import com.intellij.psi.search.searches.ReferencesSearch
|
||||
import com.intellij.refactoring.safeDelete.JavaSafeDeleteProcessor
|
||||
import com.intellij.refactoring.safeDelete.NonCodeUsageSearchInfo
|
||||
import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteOverrideAnnotation
|
||||
import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteOverridingMethodUsageInfo
|
||||
import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteReferenceJavaDeleteUsageInfo
|
||||
import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteReferenceSimpleDeleteUsageInfo
|
||||
import com.intellij.refactoring.safeDelete.usageInfo.*
|
||||
import com.intellij.usageView.UsageInfo
|
||||
import org.jetbrains.kotlin.asJava.*
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
@@ -45,6 +42,7 @@ import java.util.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.deleteElementAndCleanParent
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.processDelegationCallConstructorUsages
|
||||
|
||||
public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
override fun handlesElement(element: PsiElement): Boolean = element.canDeleteElement()
|
||||
@@ -161,9 +159,19 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
}
|
||||
}
|
||||
|
||||
val searchInfo = when (element) {
|
||||
is JetClassOrObject ->
|
||||
element.toLightClass()?.let { klass -> findUsagesByJavaProcessor(klass, false) }
|
||||
fun findDelegationCallUsages(element: PsiElement) {
|
||||
element.processDelegationCallConstructorUsages(element.getUseScope()) {
|
||||
usages.add(SafeDeleteReferenceSimpleDeleteUsageInfo(it, element, false))
|
||||
}
|
||||
}
|
||||
|
||||
return when (element) {
|
||||
is JetClassOrObject -> {
|
||||
element.toLightClass()?.let { klass ->
|
||||
findDelegationCallUsages(klass)
|
||||
findUsagesByJavaProcessor(klass, false)
|
||||
}
|
||||
}
|
||||
|
||||
is JetNamedFunction -> {
|
||||
if (element.isLocal()) {
|
||||
@@ -195,9 +203,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
findUsagesByJavaProcessor(element)
|
||||
|
||||
else -> null
|
||||
}
|
||||
|
||||
return if (searchInfo != null) searchInfo else getSearchInfo(element)
|
||||
} ?: getSearchInfo(element)
|
||||
}
|
||||
|
||||
override fun findConflicts(element: PsiElement, allElementsToDelete: Array<out PsiElement>): MutableCollection<String>? {
|
||||
|
||||
@@ -16,19 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.refactoring.safeDelete
|
||||
|
||||
import org.jetbrains.kotlin.psi.JetNamedFunction
|
||||
import com.intellij.psi.PsiMethod
|
||||
import org.jetbrains.kotlin.psi.JetModifierListOwner
|
||||
import org.jetbrains.kotlin.psi.JetProperty
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch
|
||||
import org.jetbrains.kotlin.asJava.unwrapped
|
||||
import org.jetbrains.kotlin.psi.JetParameter
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetPropertyAccessor
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||
import org.jetbrains.kotlin.psi.JetTypeParameter
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
|
||||
public fun PsiElement.canDeleteElement(): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user