safe delete supports new facades
This commit is contained in:
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.load.java.JvmAbi
|
|||||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
|
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||||
import org.jetbrains.kotlin.utils.KotlinVfsUtil
|
import org.jetbrains.kotlin.utils.KotlinVfsUtil
|
||||||
import org.jetbrains.kotlin.utils.rethrow
|
import org.jetbrains.kotlin.utils.rethrow
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -129,15 +130,14 @@ public object LightClassUtil {
|
|||||||
return LightClassGenerationSupport.getInstance(classOrObject.project).getPsiClass(classOrObject)
|
return LightClassGenerationSupport.getInstance(classOrObject.project).getPsiClass(classOrObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getLightClassAccessorMethod(accessor: JetPropertyAccessor): PsiMethod? {
|
public fun getLightClassAccessorMethod(accessor: JetPropertyAccessor): PsiMethod? =
|
||||||
val property = PsiTreeUtil.getParentOfType(accessor, JetProperty::class.java) ?: return null
|
getLightClassAccessorMethods(accessor).firstOrNull()
|
||||||
|
|
||||||
|
public fun getLightClassAccessorMethods(accessor: JetPropertyAccessor): Collection<PsiMethod> {
|
||||||
|
val property = accessor.getNonStrictParentOfType<JetProperty>() ?: return emptyList()
|
||||||
val wrappers = getPsiMethodWrappers(property, true)
|
val wrappers = getPsiMethodWrappers(property, true)
|
||||||
for (wrapper in wrappers) {
|
return wrappers.filter { wrapper -> (accessor.isGetter && !wrapper.name.startsWith(JvmAbi.SETTER_PREFIX)) ||
|
||||||
if ((accessor.isGetter && !wrapper.name.startsWith(JvmAbi.SETTER_PREFIX)) || (accessor.isSetter && wrapper.name.startsWith(JvmAbi.SETTER_PREFIX))) {
|
(accessor.isSetter && wrapper.name.startsWith(JvmAbi.SETTER_PREFIX)) }
|
||||||
return wrapper
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getLightFieldForCompanionObject(companionObject: JetClassOrObject): PsiField? {
|
public fun getLightFieldForCompanionObject(companionObject: JetClassOrObject): PsiField? {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public fun JetDeclaration.toLightElements(): List<PsiNamedElement> =
|
|||||||
is JetProperty -> LightClassUtil.getLightClassPropertyMethods(this).toList()
|
is JetProperty -> LightClassUtil.getLightClassPropertyMethods(this).toList()
|
||||||
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(this).singletonOrEmptyList()
|
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(this).singletonOrEmptyList()
|
||||||
is JetParameter -> ArrayList<PsiNamedElement>().let { elements ->
|
is JetParameter -> ArrayList<PsiNamedElement>().let { elements ->
|
||||||
toPsiParameter()?.let { psiParameter -> elements.add(psiParameter) }
|
toPsiParameters().toCollection(elements)
|
||||||
LightClassUtil.getLightClassPropertyMethods(this).toCollection(elements)
|
LightClassUtil.getLightClassPropertyMethods(this).toCollection(elements)
|
||||||
|
|
||||||
elements
|
elements
|
||||||
@@ -64,21 +64,21 @@ public fun PsiElement.getRepresentativeLightMethod(): PsiMethod? =
|
|||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun JetParameter.toPsiParameter(): PsiParameter? {
|
public fun JetParameter.toPsiParameters(): Collection<PsiParameter> {
|
||||||
val paramList = getNonStrictParentOfType<JetParameterList>() ?: return null
|
val paramList = getNonStrictParentOfType<JetParameterList>() ?: return emptyList()
|
||||||
|
|
||||||
val paramIndex = paramList.getParameters().indexOf(this)
|
val paramIndex = paramList.getParameters().indexOf(this)
|
||||||
val owner = paramList.getParent()
|
val owner = paramList.getParent()
|
||||||
val lightParamIndex = if (owner is JetDeclaration && owner.isExtensionDeclaration()) paramIndex + 1 else paramIndex
|
val lightParamIndex = if (owner is JetDeclaration && owner.isExtensionDeclaration()) paramIndex + 1 else paramIndex
|
||||||
|
|
||||||
val method: PsiMethod =
|
val methods: Collection<PsiMethod> =
|
||||||
when (owner) {
|
when (owner) {
|
||||||
is JetFunction -> LightClassUtil.getLightClassMethod(owner)
|
is JetFunction -> LightClassUtil.getLightClassMethods(owner)
|
||||||
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(owner)
|
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethods(owner)
|
||||||
else -> null
|
else -> null
|
||||||
} ?: return null
|
} ?: return emptyList()
|
||||||
|
|
||||||
return method.getParameterList().getParameters()[lightParamIndex]
|
return methods.map { it.getParameterList().getParameters()[lightParamIndex] }
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun JetTypeParameter.toPsiTypeParameters(): List<PsiTypeParameter> {
|
public fun JetTypeParameter.toPsiTypeParameters(): List<PsiTypeParameter> {
|
||||||
|
|||||||
+4
-3
@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.lexer.JetTokens
|
|||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
|
import org.jetbrains.kotlin.utils.ifEmpty
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||||
@@ -306,9 +307,9 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
|||||||
): Collection<PsiElement>? {
|
): Collection<PsiElement>? {
|
||||||
when (element) {
|
when (element) {
|
||||||
is JetParameter ->
|
is JetParameter ->
|
||||||
return element.toPsiParameter()?.let { psiParameter ->
|
return element.toPsiParameters().flatMap { psiParameter ->
|
||||||
JetRefactoringUtil.checkParametersInMethodHierarchy(psiParameter)
|
JetRefactoringUtil.checkParametersInMethodHierarchy(psiParameter) ?: emptyList()
|
||||||
} ?: Collections.singletonList(element)
|
}.ifEmpty { listOf(element) }
|
||||||
|
|
||||||
is PsiParameter ->
|
is PsiParameter ->
|
||||||
return JetRefactoringUtil.checkParametersInMethodHierarchy(element)
|
return JetRefactoringUtil.checkParametersInMethodHierarchy(element)
|
||||||
|
|||||||
Reference in New Issue
Block a user