Send source code in exceptions as attachments, not text (common cases)

#KT-17678 In Progress
This commit is contained in:
Dmitry Jemerov
2017-12-29 12:42:11 +01:00
parent 817dadc120
commit 25ea53457e
10 changed files with 88 additions and 137 deletions
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.asJava.builder
@@ -34,6 +23,7 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.debugText.getDebugText
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
interface LightClassDataHolder {
val javaFileStub: PsiJavaFileStub
@@ -107,7 +97,10 @@ fun PsiJavaFileStub.findDelegate(classOrObject: KtClassOrObject): PsiClass {
}
val stubFileText = DebugUtil.stubTreeToString(this)
throw IllegalStateException("Couldn't get delegate for ${classOrObject.getDebugText()}\nin $ktFileText\nstub: \n$stubFileText")
throw KotlinExceptionWithAttachments("Couldn't get delegate for class")
.withAttachment(classOrObject.name ?: "unnamed class or object", classOrObject.getDebugText())
.withAttachment("file.kt", ktFileText)
.withAttachment("stub text", stubFileText)
}
fun PsiJavaFileStub.findDelegate(classFqName: FqName): PsiClass {