Safe reporting PSI elements in KEWA

This commit is contained in:
Vladimir Dolzhenko
2021-09-28 22:04:06 +02:00
committed by teamcity
parent 20871dd555
commit 5dc2442872
16 changed files with 63 additions and 52 deletions
@@ -42,7 +42,7 @@ class MainFunctionDetector {
this.getFunctionDescriptor = { function ->
bindingContext.get(BindingContext.FUNCTION, function)
?: throw throw KotlinExceptionWithAttachments("No descriptor resolved for $function")
.withAttachment("function.text", function.text)
.withPsiAttachment("function.text", function)
}
this.languageVersionSettings = languageVersionSettings
}
@@ -146,13 +146,13 @@ fun getEnclosingDescriptor(context: BindingContext, element: KtElement): Declara
val declaration =
element.getParentOfTypeCodeFragmentAware(KtNamedDeclaration::class.java)
?: throw KotlinExceptionWithAttachments("No parent KtNamedDeclaration for of type ${element.javaClass}")
.withAttachment("element.kt", element.text)
.withPsiAttachment("element.kt", element)
return if (declaration is KtFunctionLiteral) {
getEnclosingDescriptor(context, declaration)
} else {
context.get(DECLARATION_TO_DESCRIPTOR, declaration)
?: throw KotlinExceptionWithAttachments("No descriptor for named declaration of type ${declaration.javaClass}")
.withAttachment("declaration.kt", declaration.text)
.withPsiAttachment("declaration.kt", declaration)
}
}
@@ -626,8 +626,8 @@ class PSICallResolver(
}
if (allValueArguments.isEmpty()) {
throw KotlinExceptionWithAttachments("Can not find an external argument for 'set' method")
.withAttachment("callElement.kt", oldCall.callElement.text)
.withAttachment("file.kt", oldCall.callElement.takeIf { it.isValid }?.containingFile?.text ?: "<no file>")
.withPsiAttachment("callElement.kt", oldCall.callElement)
.withPsiAttachment("file.kt", oldCall.callElement.takeIf { it.isValid }?.containingFile)
}
allValueArguments.last()
} else {
@@ -24,6 +24,6 @@ class NoDescriptorForDeclarationException @JvmOverloads constructor(declaration:
+ (additionalDetails?.let { "\n---------------------------------------------------\n$it" } ?: "")
) {
init {
withAttachment("declaration.kt", declaration.getElementTextWithContext())
withPsiAttachment("declaration.kt", declaration)
}
}
@@ -252,7 +252,7 @@ public abstract class ExpressionTypingVisitorDispatcher extends KtVisitor<Kotlin
// This trows AssertionError in CLI and reports the error in the IDE
LOG.error(
new KotlinExceptionWithAttachments("Exception while analyzing expression" + location, e)
.withAttachment("expression.kt", expression.getText())
.withPsiAttachment("expression.kt", expression)
);
}
catch (AssertionError errorFromLogger) {
@@ -15,13 +15,6 @@ class KotlinFrontEndException(message: String, cause: Throwable) : KotlinExcepti
cause: Throwable,
element: PsiElement
) : this(getExceptionMessage("Front-end", message, cause, PsiDiagnosticUtils.atLocation(element)), cause) {
withAttachment(
"element.kt",
if (element.isValid) {
element.text
} else {
"PsiElement (invalid): " + element.toString()
}
)
withPsiAttachment("element.kt", element)
}
}