Improve diagnostics in KtElementImplStub::getContainingKtFile
- If containing file is not a `PsiFileImpl`, `getNode()` will throw a CCE (which will prevent collecting the diagnostics) - Relates to #EA-209630
This commit is contained in:
@@ -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<T extends StubElement<?>> 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;
|
||||
}
|
||||
|
||||
@@ -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<T extends StubElement<?>> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user