Make changes in super call lambda not cause out-of-block modification (KT-13474)

#KT-13474 Fixed
This commit is contained in:
Nikolay Krasko
2016-08-26 21:17:39 +03:00
parent 64d511566e
commit 52dd02fe08
9 changed files with 77 additions and 7 deletions
@@ -68,7 +68,13 @@ class KotlinCodeBlockModificationListener(
}
private fun isInsideCodeBlock(element: PsiElement): Boolean {
//TODO: other types
val lambda = KtPsiUtil.getTopmostParentOfTypes(element, KtLambdaExpression::class.java)
if (lambda is KtLambdaExpression) {
if (KtPsiUtil.getTopmostParentOfTypes(lambda, KtSuperTypeCallEntry::class.java) != null) {
return true
}
}
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
@@ -60,12 +60,15 @@ class ResolveElementCache(
private fun modificationStamp(resolveElement: KtElement): Long? {
val file = resolveElement.containingFile
return if (!file.isPhysical) // for non-physical file we don't get OUT_OF_CODE_BLOCK_MODIFICATION_COUNT increased and must reset data on any modification of the file
file.modificationStamp
else if (resolveElement is KtDeclaration && KotlinCodeBlockModificationListener.isBlockDeclaration(resolveElement))
resolveElement.getModificationStamp()
else
null
return when {
// for non-physical file we don't get OUT_OF_CODE_BLOCK_MODIFICATION_COUNT increased and must reset
// data on any modification of the file
!file.isPhysical -> file.modificationStamp
resolveElement is KtDeclaration && KotlinCodeBlockModificationListener.isBlockDeclaration(resolveElement) -> resolveElement.getModificationStamp()
resolveElement is KtSuperTypeList -> resolveElement.modificationStamp
else -> null
}
}
}