Workaround copied kotlin element happened to be outside the KtFile

Can be reproduced after revert with
IdeLightClassTestGenerated$Local.testDollarsInNameLocal test.
This commit is contained in:
Nikolay Krasko
2019-07-31 19:58:47 +03:00
committed by Nikolay Krasko
parent 5614afed14
commit 83e422fc3b
2 changed files with 8 additions and 4 deletions
@@ -35,9 +35,12 @@ open class KtLightClassForLocalDeclaration(
KotlinClassInnerStuffCache(
this,
with(KotlinModificationTrackerService.getInstance(classOrObject.project)) {
listOf(
outOfBlockModificationTracker, fileModificationTracker(classOrObject.containingKtFile)
)
val file = classOrObject.containingFile
if (file is KtFile) {
listOf(outOfBlockModificationTracker, fileModificationTracker(file))
} else {
listOf(outOfBlockModificationTracker)
}
}
)
@@ -67,7 +67,8 @@ public class KtElementImplStub<T extends StubElement<?>> extends StubBasedPsiEle
@Override
public KtFile getContainingKtFile() {
PsiFile file = getContainingFile();
if(!(file instanceof KtFile)) {
if (!(file instanceof KtFile)) {
// KtElementImpl.copy() might be the reason for this exception
String fileString = file.isValid() ? file.getText() : "";
throw new IllegalStateException("KtElement not inside KtFile: " + file + fileString +
"for element " + this + " of type " + this.getClass() + " node = " + getNode());