Add more investigation info to getFilesForElements
Relates to #EA-209630
This commit is contained in:
@@ -60,9 +60,9 @@ public class KtElementImpl extends ASTWrapperPsiElement implements KtElement {
|
|||||||
public KtFile getContainingKtFile() {
|
public KtFile getContainingKtFile() {
|
||||||
PsiFile file = getContainingFile();
|
PsiFile file = getContainingFile();
|
||||||
if(!(file instanceof KtFile)) {
|
if(!(file instanceof KtFile)) {
|
||||||
String fileString = (file != null && file.isValid()) ? file.getText() : "";
|
String fileString = (file != null && file.isValid()) ? (" " + file.getText()) : "";
|
||||||
throw new IllegalStateException("KtElement not inside KtFile: " + file + fileString +
|
throw new IllegalStateException("KtElement not inside KtFile: " + file + fileString +
|
||||||
"for element " + this + " of type " + this.getClass() + " node = " + getNode());
|
" for element " + this + " of type " + this.getClass() + " node = " + getNode());
|
||||||
}
|
}
|
||||||
return (KtFile) file;
|
return (KtFile) file;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,9 +69,9 @@ public class KtElementImplStub<T extends StubElement<?>> extends StubBasedPsiEle
|
|||||||
PsiFile file = getContainingFile();
|
PsiFile file = getContainingFile();
|
||||||
if (!(file instanceof KtFile)) {
|
if (!(file instanceof KtFile)) {
|
||||||
// KtElementImpl.copy() might be the reason for this exception
|
// KtElementImpl.copy() might be the reason for this exception
|
||||||
String fileString = file.isValid() ? file.getText() : "";
|
String fileString = file.isValid() ? (" " + file.getText()) : "";
|
||||||
throw new IllegalStateException("KtElement not inside KtFile: " + file + fileString +
|
throw new IllegalStateException("KtElement not inside KtFile: " + file + fileString +
|
||||||
"for element " + this + " of type " + this.getClass() + " node = " + getNode());
|
" for element " + this + " of type " + this.getClass() + " node = " + getNode());
|
||||||
}
|
}
|
||||||
return (KtFile) file;
|
return (KtFile) file;
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-3
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.caches.resolve
|
package org.jetbrains.kotlin.idea.caches.resolve
|
||||||
|
|
||||||
|
import com.intellij.openapi.diagnostic.ControlFlowException
|
||||||
import com.intellij.openapi.diagnostic.Logger
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.projectRoots.Sdk
|
import com.intellij.openapi.projectRoots.Sdk
|
||||||
@@ -59,6 +60,7 @@ import org.jetbrains.kotlin.psi.psiUtil.contains
|
|||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.diagnostics.KotlinSuppressCache
|
import org.jetbrains.kotlin.resolve.diagnostics.KotlinSuppressCache
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
|
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.sumByLong
|
import org.jetbrains.kotlin.utils.addToStdlib.sumByLong
|
||||||
|
|
||||||
@@ -120,9 +122,15 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
|
|||||||
|
|
||||||
private fun getFilesForElements(elements: List<KtElement>): List<KtFile> {
|
private fun getFilesForElements(elements: List<KtElement>): List<KtFile> {
|
||||||
return elements.map {
|
return elements.map {
|
||||||
// in theory `containingKtFile` is `@NotNull` but in practice EA-114080
|
try {
|
||||||
@Suppress("USELESS_ELVIS")
|
// in theory `containingKtFile` is `@NotNull` but in practice EA-114080
|
||||||
it.containingKtFile ?: throw IllegalStateException("containingKtFile was null for $it of ${it.javaClass}")
|
@Suppress("USELESS_ELVIS")
|
||||||
|
it.containingKtFile ?: throw IllegalStateException("containingKtFile was null for $it of ${it.javaClass}")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (e is ControlFlowException) throw e
|
||||||
|
throw KotlinExceptionWithAttachments("Couldn't get containingKtFile for ktElement")
|
||||||
|
.withAttachment("element.kt", it.text)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user