Assertions to catch EA-114080

This commit is contained in:
Nicolay Mitropolsky
2018-02-22 12:50:09 +03:00
parent 5a591be25f
commit 3a609a9472
5 changed files with 24 additions and 5 deletions
@@ -56,7 +56,11 @@ public class KtElementImpl extends ASTWrapperPsiElement implements KtElement {
@Override
public KtFile getContainingKtFile() {
PsiFile file = getContainingFile();
assert file instanceof KtFile : "KtElement not inside KtFile: " + file + (file == null ? "" : " " + file.getText());
if(!(file instanceof KtFile)) {
String fileString = (file != null && file.isValid()) ? file.getText() : "";
throw new IllegalStateException("KtElement not inside KtFile: " + file + fileString +
"for element " + this + " of type " + this.getClass() + " node = " + getNode());
}
return (KtFile) file;
}
@@ -67,7 +67,11 @@ public class KtElementImplStub<T extends StubElement<?>> extends StubBasedPsiEle
@Override
public KtFile getContainingKtFile() {
PsiFile file = getContainingFile();
assert file instanceof KtFile : "KtElement not inside KtFile: " + file + " " + (file.isValid() ? file.getText() : "<invalid>");
if(!(file instanceof KtFile)) {
String fileString = file.isValid() ? file.getText() : "";
throw new IllegalStateException("KtElement not inside KtFile: " + file + fileString +
"for element " + this + " of type " + this.getClass() + " node = " + getNode());
}
return (KtFile) file;
}
@@ -77,7 +77,11 @@ public class KtLambdaExpression extends LazyParseablePsiElement implements KtExp
@Override
public KtFile getContainingKtFile() {
PsiFile file = getContainingFile();
assert file instanceof KtFile : "KtElement not inside KtFile: " + file + " " + file.getText();
if(!(file instanceof KtFile)) {
String fileString = (file != null && file.isValid()) ? file.getText() : "";
throw new IllegalStateException("KtElement not inside KtFile: " + file + fileString +
"for element " + this + " of type " + this.getClass() + " node = " + getNode());
}
return (KtFile) file;
}
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.AbstractClassTypeConstructor
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeConstructor
import java.lang.IllegalStateException
/*
* This class introduces all attributes that are needed for synthetic classes/object so far.
@@ -151,7 +152,10 @@ class SyntheticClassOrObjectDescriptor(
override fun getPsiOrParent() = _parent.psiOrParent
override fun getParent() = _parent.psiOrParent
override fun getContainingKtFile() = _parent.containingKtFile
override fun getContainingKtFile() =
// in theory `containingKtFile` is `@NotNull` but in practice EA-114080
_parent.containingKtFile ?: throw IllegalStateException("containingKtFile was null for $_parent of ${_parent.javaClass}")
}
}
@@ -62,7 +62,10 @@ data class PlatformAnalysisSettings(val platform: TargetPlatform, val sdk: Sdk?,
class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
override fun getResolutionFacade(elements: List<KtElement>): ResolutionFacade {
return getFacadeToAnalyzeFiles(elements.map { it.containingKtFile })
return getFacadeToAnalyzeFiles(elements.map {
// in theory `containingKtFile` is `@NotNull` but in practice EA-114080
it.containingKtFile ?: throw IllegalStateException("containingKtFile was null for $it of ${it.javaClass}")
})
}
override fun getSuppressionCache(): KotlinSuppressCache = kotlinSuppressCache.value