Implement modification stamp for ScriptInitializer
This should influence ResolveElementCache to correctly update caches because it rely on modifications stamps of the declaration Before this change file.modificationStamp was used for script initializers in file, so they all became outdated after some change in file
This commit is contained in:
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
|
||||
interface KtAnonymousInitializer : KtDeclaration, KtStatementExpression {
|
||||
val containingDeclaration: KtDeclaration
|
||||
@@ -57,4 +58,15 @@ class KtScriptInitializer(node: ASTNode) : KtDeclarationImpl(node), KtAnonymousI
|
||||
get() = getParentOfType<KtScript>(true).sure { "Should only be present in script" }
|
||||
|
||||
override fun <R, D> accept(visitor: KtVisitor<R, D>, data: D) = visitor.visitScriptInitializer(this, data)
|
||||
|
||||
private val modificationStamp = AtomicLong()
|
||||
|
||||
override fun subtreeChanged() {
|
||||
super.subtreeChanged()
|
||||
modificationStamp.getAndIncrement()
|
||||
}
|
||||
|
||||
fun getModificationStamp(): Long {
|
||||
return modificationStamp.get()
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ fun KtElement.getModificationStamp(): Long {
|
||||
is KtFile -> this.modificationStamp
|
||||
is KtDeclarationStub<*> -> this.modificationStamp
|
||||
is KtSuperTypeList -> this.modificationStamp
|
||||
is KtScriptInitializer -> this.getModificationStamp()
|
||||
else -> (parent as KtElement).getModificationStamp()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user