FieldWatchpoints: reload breakpoint type if property changed
This commit is contained in:
@@ -48,7 +48,10 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult
|
|||||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
|
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.JetCallableDeclaration
|
||||||
|
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||||
|
import org.jetbrains.kotlin.psi.JetParameter
|
||||||
|
import org.jetbrains.kotlin.psi.JetProperty
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import javax.swing.Icon
|
import javax.swing.Icon
|
||||||
|
|
||||||
@@ -66,23 +69,7 @@ class KotlinFieldBreakpoint(
|
|||||||
METHOD
|
METHOD
|
||||||
}
|
}
|
||||||
|
|
||||||
private val breakpointType: BreakpointType
|
private var breakpointType: BreakpointType = BreakpointType.FIELD
|
||||||
|
|
||||||
init {
|
|
||||||
val element = getField()!!
|
|
||||||
val bindingContext = element.analyzeAndGetResult().bindingContext
|
|
||||||
var descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element)
|
|
||||||
if (descriptor is ValueParameterDescriptor) {
|
|
||||||
descriptor = bindingContext.get(BindingContext.VALUE_PARAMETER_AS_PROPERTY, descriptor)
|
|
||||||
}
|
|
||||||
|
|
||||||
breakpointType = if (bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, descriptor as PropertyDescriptor)) {
|
|
||||||
BreakpointType.FIELD
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
BreakpointType.METHOD
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isValid(): Boolean {
|
override fun isValid(): Boolean {
|
||||||
if (!BreakpointWithHighlighter.isPositionValid(getXBreakpoint().getSourcePosition())) return false
|
if (!BreakpointWithHighlighter.isPositionValid(getXBreakpoint().getSourcePosition())) return false
|
||||||
@@ -134,6 +121,10 @@ class KotlinFieldBreakpoint(
|
|||||||
override fun createRequestForPreparedClass(debugProcess: DebugProcessImpl?, refType: ReferenceType?) {
|
override fun createRequestForPreparedClass(debugProcess: DebugProcessImpl?, refType: ReferenceType?) {
|
||||||
if (debugProcess == null || refType == null) return
|
if (debugProcess == null || refType == null) return
|
||||||
|
|
||||||
|
val property = getProperty(getSourcePosition()) ?: return
|
||||||
|
|
||||||
|
breakpointType = computeBreakpointType(property)
|
||||||
|
|
||||||
val vm = debugProcess.getVirtualMachineProxy()
|
val vm = debugProcess.getVirtualMachineProxy()
|
||||||
try {
|
try {
|
||||||
if (getProperties().WATCH_INITIALIZATION) {
|
if (getProperties().WATCH_INITIALIZATION) {
|
||||||
@@ -197,6 +188,23 @@ class KotlinFieldBreakpoint(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun computeBreakpointType(property: JetCallableDeclaration): BreakpointType {
|
||||||
|
return runReadAction {
|
||||||
|
val bindingContext = property.analyzeAndGetResult().bindingContext
|
||||||
|
var descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, property)
|
||||||
|
if (descriptor is ValueParameterDescriptor) {
|
||||||
|
descriptor = bindingContext.get(BindingContext.VALUE_PARAMETER_AS_PROPERTY, descriptor)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, descriptor as PropertyDescriptor)) {
|
||||||
|
BreakpointType.FIELD
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
BreakpointType.METHOD
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun createMethodBreakpoint(debugProcess: DebugProcessImpl, refType: ReferenceType, accessor: Method) {
|
private fun createMethodBreakpoint(debugProcess: DebugProcessImpl, refType: ReferenceType, accessor: Method) {
|
||||||
val manager = debugProcess.getRequestsManager()
|
val manager = debugProcess.getRequestsManager()
|
||||||
val line = accessor.allLineLocations().firstOrNull()
|
val line = accessor.allLineLocations().firstOrNull()
|
||||||
|
|||||||
Reference in New Issue
Block a user