diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListener.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListener.kt index 557ef2eea79..223396650b4 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListener.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListener.kt @@ -197,23 +197,24 @@ class KotlinCodeBlockModificationListener( return inBlockElements.isNotEmpty() } - fun isFormattingChange(changeSet: TreeChangeEvent): Boolean = - changeSet.changedElements.all { - changeSet.getChangesByElement(it).affectedChildren.all { c -> c is PsiWhiteSpace } - } - - fun isCommentChange(changeSet: TreeChangeEvent): Boolean = + private fun isCommentChange(changeSet: TreeChangeEvent): Boolean = changeSet.changedElements.all { changedElement -> val changesByElement = changeSet.getChangesByElement(changedElement) changesByElement.affectedChildren.all { affectedChild -> + if (!(affectedChild is PsiComment || affectedChild is KDoc)) return@all false val changeByChild = changesByElement.getChangeByChild(affectedChild) return@all if (changeByChild is ChangeInfoImpl) { - changeByChild.oldChild is PsiComment && changeByChild.newChild is PsiComment || - changeByChild.oldChild is KDoc && changeByChild.newChild is KDoc + val oldChild = changeByChild.oldChild + oldChild is PsiComment || oldChild is KDoc } else false } } + private fun isFormattingChange(changeSet: TreeChangeEvent): Boolean = + changeSet.changedElements.all { + changeSet.getChangesByElement(it).affectedChildren.all { c -> c is PsiWhiteSpace } + } + fun getInsideCodeBlockModificationScope(element: PsiElement): BlockModificationScopeElement? { val lambda = element.getTopmostParentOfType() if (lambda is KtLambdaExpression) { diff --git a/idea/testData/codeInsight/outOfBlock/Uncomment.kt b/idea/testData/codeInsight/outOfBlock/Uncomment.kt new file mode 100644 index 00000000000..4add173d291 --- /dev/null +++ b/idea/testData/codeInsight/outOfBlock/Uncomment.kt @@ -0,0 +1,6 @@ +// OUT_OF_CODE_BLOCK: FALSE +// TYPE: '\b\b' + +fun uncomment(): String { + //return "" +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/OutOfBlockModificationTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/OutOfBlockModificationTestGenerated.java index fd23d66fd9d..f321facd02e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/OutOfBlockModificationTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/OutOfBlockModificationTestGenerated.java @@ -348,6 +348,11 @@ public class OutOfBlockModificationTestGenerated extends AbstractOutOfBlockModif runTest("idea/testData/codeInsight/outOfBlock/StringInSuperConstroctorCall.kt"); } + @TestMetadata("Uncomment.kt") + public void testUncomment() throws Exception { + runTest("idea/testData/codeInsight/outOfBlock/Uncomment.kt"); + } + @TestMetadata("WholeFileChanged.kt") public void testWholeFileChanged() throws Exception { runTest("idea/testData/codeInsight/outOfBlock/WholeFileChanged.kt");