Changes inside init blocks should be considered out of block modifications
This commit is contained in:
+2
@@ -28,6 +28,7 @@ import com.intellij.psi.impl.PsiTreeChangePreprocessor
|
|||||||
import com.intellij.psi.util.PsiModificationTracker
|
import com.intellij.psi.util.PsiModificationTracker
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tested in OutOfBlockModificationTestGenerated
|
* Tested in OutOfBlockModificationTestGenerated
|
||||||
@@ -112,6 +113,7 @@ class KotlinCodeBlockModificationListener(modificationTracker: PsiModificationTr
|
|||||||
|
|
||||||
//TODO: other types
|
//TODO: other types
|
||||||
val blockDeclaration = KtPsiUtil.getTopmostParentOfTypes(element, *BLOCK_DECLARATION_TYPES) ?: return false
|
val blockDeclaration = KtPsiUtil.getTopmostParentOfTypes(element, *BLOCK_DECLARATION_TYPES) ?: return false
|
||||||
|
if (blockDeclaration.parents.any { it !is KtClassBody && it !is KtClassOrObject && it !is KtFile }) return false // should not be local declaration
|
||||||
|
|
||||||
when (blockDeclaration) {
|
when (blockDeclaration) {
|
||||||
is KtNamedFunction -> {
|
is KtNamedFunction -> {
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// TRUE
|
||||||
|
|
||||||
|
class A {
|
||||||
|
init {
|
||||||
|
fun f() {
|
||||||
|
<caret>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// TRUE
|
||||||
|
|
||||||
|
class A {
|
||||||
|
init {
|
||||||
|
<caret>
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -53,6 +53,12 @@ public class OutOfBlockModificationTestGenerated extends AbstractOutOfBlockModif
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("FunInInitBlock.kt")
|
||||||
|
public void testFunInInitBlock() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/outOfBlock/FunInInitBlock.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("FunNoBody.kt")
|
@TestMetadata("FunNoBody.kt")
|
||||||
public void testFunNoBody() throws Exception {
|
public void testFunNoBody() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/outOfBlock/FunNoBody.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/outOfBlock/FunNoBody.kt");
|
||||||
@@ -185,6 +191,12 @@ public class OutOfBlockModificationTestGenerated extends AbstractOutOfBlockModif
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("InitBlock.kt")
|
||||||
|
public void testInitBlock() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/outOfBlock/InitBlock.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("Object_FunNoType_Block.kt")
|
@TestMetadata("Object_FunNoType_Block.kt")
|
||||||
public void testObject_FunNoType_Block() throws Exception {
|
public void testObject_FunNoType_Block() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/outOfBlock/Object_FunNoType_Block.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/outOfBlock/Object_FunNoType_Block.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user