Exception analyzer doesn't show multiple attachments

This commit is contained in:
Natalia Ukhorskaya
2014-10-30 14:25:52 +03:00
parent 7bb4e538a6
commit c36fc42014
3 changed files with 34 additions and 12 deletions
@@ -73,8 +73,9 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils
import org.jetbrains.jet.codegen.StackValue
import org.jetbrains.jet.lang.types.Flexibility
import org.jetbrains.jet.lang.psi.JetElement
import org.jetbrains.jet.plugin.util.attachment.attachmentsByPsiFile
import org.jetbrains.jet.plugin.util.attachment.attachmentByPsiFile
import com.intellij.openapi.diagnostic.Attachment
import org.jetbrains.jet.plugin.util.attachment.mergeAttachments
private val RECEIVER_NAME = "\$receiver"
private val THIS_NAME = "this"
@@ -91,11 +92,11 @@ object KotlinEvaluationBuilder: EvaluatorBuilder {
}
if (codeFragment.getContext() !is JetElement) {
val attachments = (attachmentsByPsiFile(position.getFile()) +
attachmentsByPsiFile(codeFragment) +
listOf(Attachment("breakpoint.info", "line: ${position.getLine()}"))
).copyToArray()
logger.error("Trying to evaluate ${codeFragment.javaClass} with context ${codeFragment.getContext()?.javaClass}", *attachments)
val attachments = array(attachmentByPsiFile(position.getFile()),
attachmentByPsiFile(codeFragment),
Attachment("breakpoint.info", "line: ${position.getLine()}"))
logger.error("Trying to evaluate ${codeFragment.javaClass} with context ${codeFragment.getContext()?.javaClass}", mergeAttachments(*attachments))
throw EvaluateExceptionUtil.createEvaluateException("Couldn't evaluate kotlin expression in this context")
}
@@ -112,7 +112,7 @@ public class KotlinSignatureInJavaMarkerProvider implements LineMarkerProvider {
LOG.error(LogMessageEx.createEvent(
"Exception while collecting KotlinSignature markers",
ExceptionUtil.getThrowableText(error),
AttachmentPackage.attachmentsByPsiFile(psiFile)
AttachmentPackage.attachmentByPsiFileAsArray(psiFile)
));
}
}
@@ -20,16 +20,37 @@ import com.intellij.psi.PsiFile
import com.intellij.openapi.diagnostic.Attachment
import com.intellij.diagnostic.AttachmentFactory
public fun attachmentsByPsiFile(file: PsiFile?): Array<Attachment> {
if (file == null) return array()
public fun attachmentByPsiFileAsArray(file: PsiFile?): Array<Attachment> {
val attachment = attachmentByPsiFile(file)
if (attachment == null) {
return array()
}
return array(attachment)
}
public fun attachmentByPsiFile(file: PsiFile?): Attachment? {
if (file == null) return null
val virtualFile = file.getVirtualFile()
if (virtualFile != null) return array(AttachmentFactory.createAttachment(virtualFile))
if (virtualFile != null) return AttachmentFactory.createAttachment(virtualFile)
val text = try { file.getText() } catch(e: Exception) { null }
val name = try { file.getName() } catch(e: Exception) { null }
if (text != null && name != null) return array(Attachment(name, text))
if (text != null && name != null) return Attachment(name, text)
return array()
return null
}
public fun mergeAttachments(vararg attachments: Attachment?): Attachment {
val builder = StringBuilder()
attachments.forEach {
if (it != null) {
builder.append("\n----- START ${it.getPath()} -----\n")
builder.append(it.getDisplayText())
builder.append("\n----- END ${it.getPath()} -----\n")
}
}
return Attachment("message.txt", builder.toString())
}