diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtElementImplStub.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtElementImplStub.java index f8dd426e95c..bd255f9512f 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtElementImplStub.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtElementImplStub.java @@ -20,6 +20,7 @@ import com.intellij.extapi.psi.StubBasedPsiElementBase; import com.intellij.lang.ASTNode; import com.intellij.lang.Language; import com.intellij.psi.*; +import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.psi.stubs.IStubElementType; import com.intellij.psi.stubs.StubElement; import com.intellij.util.IncorrectOperationException; @@ -70,8 +71,12 @@ public class KtElementImplStub> extends StubBasedPsiEle 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()); + // getNode() will fail if getContainingFile() returns not PsiFileImpl instance + String nodeString = (file instanceof PsiFileImpl ? (" node = " + getNode()) : ""); + + throw new IllegalStateException("KtElement not inside KtFile: " + + file + fileString + " of type " + file.getClass() + + " for element " + this + " of type " + this.getClass() + nodeString); } return (KtFile) file; } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtElementImplStub.java.203 b/compiler/psi/src/org/jetbrains/kotlin/psi/KtElementImplStub.java.203 index 1ccc116d1e0..f802e8d3341 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtElementImplStub.java.203 +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtElementImplStub.java.203 @@ -9,6 +9,7 @@ import com.intellij.extapi.psi.StubBasedPsiElementBase; import com.intellij.lang.ASTNode; import com.intellij.lang.Language; import com.intellij.psi.*; +import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.psi.stubs.IStubElementType; import com.intellij.psi.stubs.StubElement; import com.intellij.util.IncorrectOperationException; @@ -59,8 +60,12 @@ public class KtElementImplStub> extends StubBasedPsiEle 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()); + // getNode() will fail if getContainingFile() returns not PsiFileImpl instance + String nodeString = (file instanceof PsiFileImpl ? (" node = " + getNode()) : ""); + + throw new IllegalStateException("KtElement not inside KtFile: " + + file + fileString + " of type " + file.getClass() + + " for element " + this + " of type " + this.getClass() + nodeString); } return (KtFile) file; }