more diagnostics for EA-96901 - assert: FileTrees.withGreenStub

This commit is contained in:
peter
2017-02-25 12:55:46 +01:00
parent bfa51a87c6
commit 8b0161fdad
3 changed files with 17 additions and 4 deletions
@@ -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)
}
@@ -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);
}
@@ -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;