Debugger: correct scope for runtime type calculation

This commit is contained in:
Natalia Ukhorskaya
2016-04-04 16:31:18 +03:00
parent e806341cdc
commit 0d4fa46cfa
6 changed files with 14 additions and 15 deletions
+1
View File
@@ -189,6 +189,7 @@ Issues fixed:
- [KT-6805](https://youtrack.jetbrains.com/issue/KT-6805) Convert Java expression to Kotlin when opening Evaluate Expression from Variables view
- Show error message when debug info for some local variable is corrupted
- Avoid 1s delay in completion in debugger fields if session is not stopped on a breakpoint
- Avoid cast to runtime type unavailable in current scope
### Java to Kotlin converter
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.resolve.jvm.AsmTypes
import org.jetbrains.org.objectweb.asm.Type
class FrameVisitor(context: EvaluationContextImpl) {
private val project = context.debugProcess.project
private val scope = context.debugProcess.searchScope
private val frame = context.frameProxy
companion object {
@@ -177,7 +177,6 @@ class FrameVisitor(context: EvaluationContextImpl) {
private fun isValueOfCorrectType(value: Value, asmType: Type?, shouldCheckType: Boolean): Boolean {
if (!shouldCheckType || asmType == null || value.asmType == asmType) return true
if (project == null) return false
if (asmType == OBJECT_TYPE) return true
@@ -185,8 +184,8 @@ class FrameVisitor(context: EvaluationContextImpl) {
return true
}
val thisDesc = value.asmType.getClassDescriptor(project)
val expDesc = asmType.getClassDescriptor(project)
val thisDesc = value.asmType.getClassDescriptor(scope)
val expDesc = asmType.getClassDescriptor(scope)
return thisDesc != null && expDesc != null && runReadAction { DescriptorUtils.isSubclass(thisDesc, expDesc) }
}
@@ -262,7 +262,7 @@ class KotlinCodeFragmentFactory: CodeFragmentFactory() {
}
private fun createKotlinProperty(project: Project, variableName: String, variableTypeName: String, value: Value): String? {
val actualClassDescriptor = value.asValue().asmType.getClassDescriptor(project)
val actualClassDescriptor = value.asValue().asmType.getClassDescriptor(GlobalSearchScope.allScope(project))
if (actualClassDescriptor != null && actualClassDescriptor.defaultType.arguments.isEmpty()) {
val renderedType = IdeDescriptorRenderers.SOURCE_CODE.renderType(actualClassDescriptor.defaultType.makeNullable())
return "val ${variableName.quoteIfNeeded()}: $renderedType = null"
@@ -187,7 +187,7 @@ class KotlinDebuggerCaches(private val project: Project) {
val value = frameVisitor.findValue(name, asmType = null, checkType = false, failIfNotFound = false)
if (value == null) return@all false
val thisDescriptor = value.asmType.getClassDescriptor(project)
val thisDescriptor = value.asmType.getClassDescriptor(context.debugProcess.searchScope)
val superClassDescriptor = jetType.constructor.declarationDescriptor as? ClassDescriptor
return@all thisDescriptor != null && superClassDescriptor != null && runReadAction { DescriptorUtils.isSubclass(thisDescriptor, superClassDescriptor) }
}
@@ -26,7 +26,6 @@ import com.intellij.diagnostic.LogMessageEx
import com.intellij.openapi.diagnostic.Attachment
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.CharsetToolkit
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiDocumentManager
@@ -552,7 +551,7 @@ private fun SuspendContext.getInvokePolicy(): Int {
return if (suspendPolicy == EventRequest.SUSPEND_EVENT_THREAD) ObjectReference.INVOKE_SINGLE_THREADED else 0
}
fun Type.getClassDescriptor(project: Project): ClassDescriptor? {
fun Type.getClassDescriptor(scope: GlobalSearchScope): ClassDescriptor? {
if (AsmUtil.isPrimitive(this)) return null
val jvmName = JvmClassName.byInternalName(internalName).fqNameForClassNameWithoutDollars
@@ -561,7 +560,7 @@ fun Type.getClassDescriptor(project: Project): ClassDescriptor? {
if (platformClasses.isNotEmpty()) return platformClasses.first()
return runReadAction {
val classes = JavaPsiFacade.getInstance(project).findClasses(jvmName.asString(), GlobalSearchScope.allScope(project))
val classes = JavaPsiFacade.getInstance(scope.project).findClasses(jvmName.asString(), scope)
if (classes.isEmpty()) null
else {
classes.first().getJavaClassDescriptor()
@@ -29,8 +29,8 @@ import com.intellij.debugger.ui.EditorEvaluationCommand
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.project.Project
import com.intellij.psi.CommonClassNames
import com.intellij.psi.search.GlobalSearchScope
import com.sun.jdi.ClassType
import com.sun.jdi.Value
import org.jetbrains.eval4j.jdi.asValue
@@ -73,16 +73,16 @@ abstract class KotlinRuntimeTypeEvaluator(
val value = evaluator.evaluate(evaluationContext)
if (value != null) {
return getCastableRuntimeType(project, value)
return getCastableRuntimeType(evaluationContext.debugProcess.searchScope, value)
}
throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.surrounded.expression.null"))
}
companion object {
private fun getCastableRuntimeType(project: Project, value: Value): KotlinType? {
private fun getCastableRuntimeType(scope: GlobalSearchScope, value: Value): KotlinType? {
val myValue = value.asValue()
var psiClass = myValue.asmType.getClassDescriptor(project)
var psiClass = myValue.asmType.getClassDescriptor(scope)
if (psiClass != null) {
return psiClass.defaultType
}
@@ -91,14 +91,14 @@ abstract class KotlinRuntimeTypeEvaluator(
if (type is ClassType) {
val superclass = type.superclass()
if (superclass != null && CommonClassNames.JAVA_LANG_OBJECT != superclass.name()) {
psiClass = AsmType.getType(superclass.signature()).getClassDescriptor(project)
psiClass = AsmType.getType(superclass.signature()).getClassDescriptor(scope)
if (psiClass != null) {
return psiClass.defaultType
}
}
for (interfaceType in type.interfaces()) {
psiClass = AsmType.getType(interfaceType.signature()).getClassDescriptor(project)
psiClass = AsmType.getType(interfaceType.signature()).getClassDescriptor(scope)
if (psiClass != null) {
return psiClass.defaultType
}