use correct safe delete processor for members of local classes and objects
#KT-8894 Fixed
This commit is contained in:
@@ -251,8 +251,7 @@ public class LightClassUtil {
|
|||||||
return getPsiClass(((JetConstructor) declaration).getContainingClassOrObject());
|
return getPsiClass(((JetConstructor) declaration).getContainingClassOrObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection unchecked
|
if (!canGenerateLightClass(declaration)) {
|
||||||
if (PsiTreeUtil.getParentOfType(declaration, JetFunction.class, JetProperty.class) != null) {
|
|
||||||
// Can't get wrappers for internal declarations. Their classes are not generated during calcStub
|
// Can't get wrappers for internal declarations. Their classes are not generated during calcStub
|
||||||
// with ClassBuilderMode.LIGHT_CLASSES mode, and this produces "Class not found exception" in getDelegate()
|
// with ClassBuilderMode.LIGHT_CLASSES mode, and this produces "Class not found exception" in getDelegate()
|
||||||
return null;
|
return null;
|
||||||
@@ -274,6 +273,11 @@ public class LightClassUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean canGenerateLightClass(JetDeclaration declaration) {
|
||||||
|
//noinspection unchecked
|
||||||
|
return PsiTreeUtil.getParentOfType(declaration, JetFunction.class, JetProperty.class) == null;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static PropertyAccessorsPsiMethods extractPropertyAccessors(
|
private static PropertyAccessorsPsiMethods extractPropertyAccessors(
|
||||||
@NotNull JetDeclaration jetDeclaration,
|
@NotNull JetDeclaration jetDeclaration,
|
||||||
|
|||||||
+2
-2
@@ -192,7 +192,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
is JetNamedFunction -> {
|
is JetNamedFunction -> {
|
||||||
if (element.isLocal()) {
|
if (!LightClassUtil.canGenerateLightClass(element)) {
|
||||||
findKotlinDeclarationUsages(element)
|
findKotlinDeclarationUsages(element)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -204,7 +204,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
|||||||
findUsagesByJavaProcessor(element, false)
|
findUsagesByJavaProcessor(element, false)
|
||||||
|
|
||||||
is JetProperty -> {
|
is JetProperty -> {
|
||||||
if (element.isLocal()) {
|
if (!LightClassUtil.canGenerateLightClass(element)) {
|
||||||
findKotlinDeclarationUsages(element)
|
findKotlinDeclarationUsages(element)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
open class SampleParent { var field = 0 }
|
||||||
|
|
||||||
|
fun context() {
|
||||||
|
var v = object : SampleParent() { var ad<caret>dition = 0 }
|
||||||
|
println(v.field)
|
||||||
|
println(v.addition)
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
property context.<no name provided>.addition has 1 usage that is not safe to delete.
|
||||||
@@ -534,6 +534,12 @@ public class JetSafeDeleteTestGenerated extends AbstractJetSafeDeleteTest {
|
|||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/safeDelete/deleteProperty/kotlinProperty/propertyExt2.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/safeDelete/deleteProperty/kotlinProperty/propertyExt2.kt");
|
||||||
doPropertyTest(fileName);
|
doPropertyTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("propertyInLocalObject.kt")
|
||||||
|
public void testPropertyInLocalObject() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/safeDelete/deleteProperty/kotlinProperty/propertyInLocalObject.kt");
|
||||||
|
doPropertyTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/safeDelete/deleteProperty/kotlinPropertyWithJava")
|
@TestMetadata("idea/testData/safeDelete/deleteProperty/kotlinPropertyWithJava")
|
||||||
|
|||||||
Reference in New Issue
Block a user