From 8b0161fdada57b6a03b8fae18d99187e30bf8068 Mon Sep 17 00:00:00 2001 From: peter Date: Sat, 25 Feb 2017 12:55:46 +0100 Subject: [PATCH] more diagnostics for EA-96901 - assert: FileTrees.withGreenStub --- .../dataFlow/ContractInferenceIndex.kt | 7 ++++++- .../src/com/intellij/psi/impl/source/FileTrees.java | 12 ++++++++++-- .../com/intellij/psi/impl/source/PsiFileImpl.java | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInferenceIndex.kt b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInferenceIndex.kt index 6956c06e5881..88da8b40a5f0 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInferenceIndex.kt +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInferenceIndex.kt @@ -24,6 +24,7 @@ import com.intellij.psi.impl.source.tree.JavaElementType import com.intellij.psi.impl.source.tree.JavaElementType.* import com.intellij.psi.impl.source.tree.LightTreeUtil import com.intellij.psi.impl.source.tree.RecursiveLighterASTNodeWalkingVisitor +import com.intellij.psi.util.PsiUtil import com.intellij.util.gist.GistManager import java.util.* @@ -96,6 +97,10 @@ fun getIndexedData(method: PsiMethodImpl): MethodData? = gist.getFileData(method private fun methodIndex(method: PsiMethodImpl): Int { val file = method.containingFile as PsiFileImpl - val stubTree = file.stubTree ?: file.calcStubTree() + val stubTree = try { + file.stubTree ?: file.calcStubTree() + } catch (e: RuntimeException) { + throw RuntimeException("While inferring contract for " + PsiUtil.getMemberQualifiedName(method), e) + } return stubTree.plainList.filter { it.stubType == JavaElementType.METHOD }.map { it.psi }.indexOf(method) } \ No newline at end of file diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/FileTrees.java b/platform/core-impl/src/com/intellij/psi/impl/source/FileTrees.java index 6c9c1cf68d97..69ea88e7d5a8 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/FileTrees.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/FileTrees.java @@ -15,6 +15,9 @@ */ package com.intellij.psi.impl.source; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.diagnostic.Attachment; +import com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments; import com.intellij.openapi.util.Getter; import com.intellij.psi.impl.source.tree.FileElement; import com.intellij.psi.stubs.PsiFileStubImpl; @@ -72,8 +75,13 @@ final class FileTrees { return new FileTrees(new SoftReference<>(stub), null, false, false); } - FileTrees withGreenStub(@NotNull StubTree stub) { - assert derefTreeElement() != null && astLoaded : this; + FileTrees withGreenStub(@NotNull StubTree stub, @NotNull PsiFileImpl file) { + if (derefTreeElement() == null || !astLoaded) { + Attachment[] attachments = ApplicationManager.getApplication().isInternal() + ? new Attachment[]{new Attachment(file.getName(), file.getText())} + : Attachment.EMPTY_ARRAY; + throw new RuntimeExceptionWithAttachments("No AST in file " + file + " of " + file.getClass() + "; " + this, attachments); + } return new FileTrees(new SoftReference<>(stub), myTreeElementPointer, true, useStrongRefs); } diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java b/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java index d3527709c708..05b4900ede1e 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java @@ -1093,7 +1093,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF throw new RuntimeException("Stub and PSI element type mismatch in " + getName(), e); } - updateTrees(myTrees.withGreenStub(tree)); + updateTrees(myTrees.withGreenStub(tree, this)); } return tree;