Assertions to catch EA-114080
This commit is contained in:
@@ -56,7 +56,11 @@ public class KtElementImpl extends ASTWrapperPsiElement implements KtElement {
|
|||||||
@Override
|
@Override
|
||||||
public KtFile getContainingKtFile() {
|
public KtFile getContainingKtFile() {
|
||||||
PsiFile file = getContainingFile();
|
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;
|
return (KtFile) file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,11 @@ public class KtElementImplStub<T extends StubElement<?>> extends StubBasedPsiEle
|
|||||||
@Override
|
@Override
|
||||||
public KtFile getContainingKtFile() {
|
public KtFile getContainingKtFile() {
|
||||||
PsiFile file = getContainingFile();
|
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;
|
return (KtFile) file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,11 @@ public class KtLambdaExpression extends LazyParseablePsiElement implements KtExp
|
|||||||
@Override
|
@Override
|
||||||
public KtFile getContainingKtFile() {
|
public KtFile getContainingKtFile() {
|
||||||
PsiFile file = getContainingFile();
|
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;
|
return (KtFile) file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
|||||||
import org.jetbrains.kotlin.types.AbstractClassTypeConstructor
|
import org.jetbrains.kotlin.types.AbstractClassTypeConstructor
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.TypeConstructor
|
import org.jetbrains.kotlin.types.TypeConstructor
|
||||||
|
import java.lang.IllegalStateException
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This class introduces all attributes that are needed for synthetic classes/object so far.
|
* 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 getPsiOrParent() = _parent.psiOrParent
|
||||||
override fun getParent() = _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}")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -62,7 +62,10 @@ data class PlatformAnalysisSettings(val platform: TargetPlatform, val sdk: Sdk?,
|
|||||||
|
|
||||||
class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
|
class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
|
||||||
override fun getResolutionFacade(elements: List<KtElement>): ResolutionFacade {
|
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
|
override fun getSuppressionCache(): KotlinSuppressCache = kotlinSuppressCache.value
|
||||||
|
|||||||
Reference in New Issue
Block a user