Minor: Clean up jvm-debugger-core module

This commit is contained in:
Yan Zhulanow
2020-02-07 03:07:32 +09:00
parent 3e05f7c2ab
commit 8a3e63aaf6
24 changed files with 110 additions and 121 deletions
@@ -62,7 +62,7 @@ class InlineCallableUsagesSearcher(private val myDebugProcess: DebugProcess) {
try { try {
ProgressManager.getInstance().runProcess(task, EmptyProgressIndicator()) ProgressManager.getInstance().runProcess(task, EmptyProgressIndicator())
} catch (e: InterruptedException) { } catch (e: InterruptedException) {
isSuccess = false; isSuccess = false
} }
} }
@@ -62,7 +62,7 @@ class KotlinAlternativeSourceNotificationProvider(private val myProject: Project
val alternativeKtFiles = findFilesWithExactPackage( val alternativeKtFiles = findFilesWithExactPackage(
packageFqName, packageFqName,
GlobalSearchScope.allScope(myProject), GlobalSearchScope.allScope(myProject),
myProject myProject,
).filterTo(HashSet()) { it.name == fileName } ).filterTo(HashSet()) { it.name == fileName }
FILE_PROCESSED_KEY.set(file, true) FILE_PROCESSED_KEY.set(file, true)
@@ -88,7 +88,7 @@ class KotlinAlternativeSourceNotificationProvider(private val myProject: Project
alternatives: Collection<KtFile>, alternatives: Collection<KtFile>,
project: Project, project: Project,
file: VirtualFile, file: VirtualFile,
locationDeclName: String? locationDeclName: String?,
) : EditorNotificationPanel() { ) : EditorNotificationPanel() {
private class ComboBoxFileElement(val ktFile: KtFile) { private class ComboBoxFileElement(val ktFile: KtFile) {
private val label: String by lazy(LazyThreadSafetyMode.NONE) { private val label: String by lazy(LazyThreadSafetyMode.NONE) {
@@ -110,7 +110,7 @@ class KotlinAlternativeSourceNotificationProvider(private val myProject: Project
val items = alternatives.map { ComboBoxFileElement(it) } val items = alternatives.map { ComboBoxFileElement(it) }
myLinksPanel.add( myLinksPanel.add(
ComboBox<ComboBoxFileElement>(items.toTypedArray()).apply { ComboBox(items.toTypedArray()).apply {
addActionListener { addActionListener {
val context = DebuggerManagerEx.getInstanceEx(project).context val context = DebuggerManagerEx.getInstanceEx(project).context
val session = context.debuggerSession val session = context.debuggerSession
@@ -119,25 +119,28 @@ class KotlinAlternativeSourceNotificationProvider(private val myProject: Project
when { when {
session != null && vFile != null -> session != null && vFile != null ->
session.process.managerThread.schedule(object : DebuggerCommandImpl() { session.process.managerThread.schedule(
override fun action() { object : DebuggerCommandImpl() {
if (!StringUtil.isEmpty(locationDeclName)) { override fun action() {
DebuggerUtilsEx.setAlternativeSourceUrl(locationDeclName, vFile.url, project) if (!StringUtil.isEmpty(locationDeclName)) {
} DebuggerUtilsEx.setAlternativeSourceUrl(locationDeclName, vFile.url, project)
}
DebuggerUIUtil.invokeLater { DebuggerUIUtil.invokeLater {
FileEditorManager.getInstance(project).closeFile(file) FileEditorManager.getInstance(project).closeFile(file)
session.refresh(true) session.refresh(true)
}
} }
} },
}) )
else -> { else -> {
FileEditorManager.getInstance(project).closeFile(file) FileEditorManager.getInstance(project).closeFile(file)
ktFile.navigate(true) ktFile.navigate(true)
} }
} }
} }
}) },
)
createActionLabel(KotlinDebuggerCoreBundle.message("alternative.sources.notification.disable")) { createActionLabel(KotlinDebuggerCoreBundle.message("alternative.sources.notification.disable")) {
DebuggerSettings.getInstance().SHOW_ALTERNATIVE_SOURCE = false DebuggerSettings.getInstance().SHOW_ALTERNATIVE_SOURCE = false
@@ -17,12 +17,12 @@ import com.intellij.xdebugger.settings.DebuggerSettingsCategory
import com.intellij.xdebugger.settings.XDebuggerSettings import com.intellij.xdebugger.settings.XDebuggerSettings
import org.jetbrains.kotlin.idea.debugger.stepping.KotlinSteppingConfigurableUi import org.jetbrains.kotlin.idea.debugger.stepping.KotlinSteppingConfigurableUi
@State(name = "KotlinDebuggerSettings", storages = arrayOf(Storage("kotlin_debug.xml"))) @State(name = "KotlinDebuggerSettings", storages = [Storage("kotlin_debug.xml")])
class KotlinDebuggerSettings : XDebuggerSettings<KotlinDebuggerSettings>("kotlin_debugger"), Getter<KotlinDebuggerSettings> { class KotlinDebuggerSettings : XDebuggerSettings<KotlinDebuggerSettings>("kotlin_debugger"), Getter<KotlinDebuggerSettings> {
var DEBUG_RENDER_DELEGATED_PROPERTIES: Boolean = false var renderDelegatedProperties: Boolean = false
var DEBUG_DISABLE_KOTLIN_INTERNAL_CLASSES: Boolean = true var disableKotlinInternalClasses: Boolean = true
var DEBUG_IS_FILTER_FOR_STDLIB_ALREADY_ADDED: Boolean = false var isFilterForStdlibAlreadyAdded: Boolean = false
var DEBUG_DISABLE_COROUTINE_AGENT: Boolean = false var debugDisableCoroutineAgent: Boolean = false
companion object { companion object {
fun getInstance(): KotlinDebuggerSettings { fun getInstance(): KotlinDebuggerSettings {
@@ -29,21 +29,21 @@ public class KotlinDelegatedPropertyRendererConfigurableUi implements Configurab
@Override @Override
public void reset(@NotNull KotlinDebuggerSettings settings) { public void reset(@NotNull KotlinDebuggerSettings settings) {
boolean flag = settings.getDEBUG_RENDER_DELEGATED_PROPERTIES(); boolean flag = settings.getRenderDelegatedProperties();
renderDelegatedProperties.setSelected(flag); renderDelegatedProperties.setSelected(flag);
disableCoroutineAgent.setSelected(settings.getDEBUG_DISABLE_COROUTINE_AGENT()); disableCoroutineAgent.setSelected(settings.getDebugDisableCoroutineAgent());
} }
@Override @Override
public boolean isModified(@NotNull KotlinDebuggerSettings settings) { public boolean isModified(@NotNull KotlinDebuggerSettings settings) {
return settings.getDEBUG_RENDER_DELEGATED_PROPERTIES() != renderDelegatedProperties.isSelected() return settings.getRenderDelegatedProperties() != renderDelegatedProperties.isSelected()
|| settings.getDEBUG_DISABLE_COROUTINE_AGENT() != disableCoroutineAgent.isSelected(); || settings.getDebugDisableCoroutineAgent() != disableCoroutineAgent.isSelected();
} }
@Override @Override
public void apply(@NotNull KotlinDebuggerSettings settings) { public void apply(@NotNull KotlinDebuggerSettings settings) {
settings.setDEBUG_RENDER_DELEGATED_PROPERTIES(renderDelegatedProperties.isSelected()); settings.setRenderDelegatedProperties(renderDelegatedProperties.isSelected());
settings.setDEBUG_DISABLE_COROUTINE_AGENT(disableCoroutineAgent.isSelected()); settings.setDebugDisableCoroutineAgent(disableCoroutineAgent.isSelected());
} }
@NotNull @NotNull
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.psi.KtFile
import java.awt.Color import java.awt.Color
import java.util.* import java.util.*
@Suppress("ComponentNotRegistered")
class InspectBreakpointApplicabilityAction : AnAction() { class InspectBreakpointApplicabilityAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) { override fun actionPerformed(e: AnActionEvent) {
val data = e.getData() ?: return val data = e.getData() ?: return
@@ -68,7 +68,7 @@ class KotlinFieldBreakpoint(
} }
} }
fun getField(): KtCallableDeclaration? { private fun getField(): KtCallableDeclaration? {
val sourcePosition = sourcePosition val sourcePosition = sourcePosition
return getProperty(sourcePosition) return getProperty(sourcePosition)
} }
@@ -115,7 +115,7 @@ class KotlinFieldBreakpoint(
val vm = debugProcess.virtualMachineProxy val vm = debugProcess.virtualMachineProxy
try { try {
if (properties.WATCH_INITIALIZATION) { if (properties.watchInitialization) {
val sourcePosition = sourcePosition val sourcePosition = sourcePosition
if (sourcePosition != null) { if (sourcePosition != null) {
debugProcess.positionManager debugProcess.positionManager
@@ -136,14 +136,14 @@ class KotlinFieldBreakpoint(
val field = refType.fieldByName(getFieldName()) val field = refType.fieldByName(getFieldName())
if (field != null) { if (field != null) {
val manager = debugProcess.requestsManager val manager = debugProcess.requestsManager
if (properties.WATCH_MODIFICATION && vm.canWatchFieldModification()) { if (properties.watchModification && vm.canWatchFieldModification()) {
val request = manager.createModificationWatchpointRequest(this, field) val request = manager.createModificationWatchpointRequest(this, field)
debugProcess.requestsManager.enableRequest(request) debugProcess.requestsManager.enableRequest(request)
if (LOG.isDebugEnabled) { if (LOG.isDebugEnabled) {
LOG.debug("Modification request added") LOG.debug("Modification request added")
} }
} }
if (properties.WATCH_ACCESS && vm.canWatchFieldAccess()) { if (properties.watchAccess && vm.canWatchFieldAccess()) {
val request = manager.createAccessWatchpointRequest(this, field) val request = manager.createAccessWatchpointRequest(this, field)
debugProcess.requestsManager.enableRequest(request) debugProcess.requestsManager.enableRequest(request)
if (LOG.isDebugEnabled) { if (LOG.isDebugEnabled) {
@@ -155,14 +155,14 @@ class KotlinFieldBreakpoint(
BreakpointType.METHOD -> { BreakpointType.METHOD -> {
val fieldName = getFieldName() val fieldName = getFieldName()
if (properties.WATCH_ACCESS) { if (properties.watchAccess) {
val getter = refType.methodsByName(JvmAbi.getterName(fieldName)).firstOrNull() val getter = refType.methodsByName(JvmAbi.getterName(fieldName)).firstOrNull()
if (getter != null) { if (getter != null) {
createMethodBreakpoint(debugProcess, refType, getter) createMethodBreakpoint(debugProcess, refType, getter)
} }
} }
if (properties.WATCH_MODIFICATION) { if (properties.watchModification) {
val setter = refType.methodsByName(JvmAbi.setterName(fieldName)).firstOrNull() val setter = refType.methodsByName(JvmAbi.setterName(fieldName)).firstOrNull()
if (setter != null) { if (setter != null) {
createMethodBreakpoint(debugProcess, refType, setter) createMethodBreakpoint(debugProcess, refType, setter)
@@ -219,7 +219,7 @@ class KotlinFieldBreakpoint(
} }
} }
inline private fun <reified T : EventRequest> findRequest( private inline fun <reified T : EventRequest> findRequest(
debugProcess: DebugProcessImpl, debugProcess: DebugProcessImpl,
requestClass: Class<T>, requestClass: Class<T>,
requestor: Requestor requestor: Requestor
@@ -321,17 +321,17 @@ class KotlinFieldBreakpoint(
@TestOnly @TestOnly
fun setWatchAccess(value: Boolean) { fun setWatchAccess(value: Boolean) {
properties.WATCH_ACCESS = value properties.watchAccess = value
} }
@TestOnly @TestOnly
fun setWatchModification(value: Boolean) { fun setWatchModification(value: Boolean) {
properties.WATCH_MODIFICATION = value properties.watchModification = value
} }
@TestOnly @TestOnly
fun setWatchInitialization(value: Boolean) { fun setWatchInitialization(value: Boolean) {
properties.WATCH_INITIALIZATION = value properties.watchInitialization = value
} }
override fun getDisabledIcon(isMuted: Boolean): Icon { override fun getDisabledIcon(isMuted: Boolean): Icon {
@@ -57,20 +57,20 @@ class KotlinFieldBreakpointPropertiesPanel : XBreakpointCustomPropertiesPanel<XL
} }
override fun loadFrom(breakpoint: XLineBreakpoint<KotlinPropertyBreakpointProperties>) { override fun loadFrom(breakpoint: XLineBreakpoint<KotlinPropertyBreakpointProperties>) {
myWatchInitializationCheckBox.isSelected = breakpoint.properties.WATCH_INITIALIZATION myWatchInitializationCheckBox.isSelected = breakpoint.properties.watchInitialization
myWatchAccessCheckBox.isSelected = breakpoint.properties.WATCH_ACCESS myWatchAccessCheckBox.isSelected = breakpoint.properties.watchAccess
myWatchModificationCheckBox.isSelected = breakpoint.properties.WATCH_MODIFICATION myWatchModificationCheckBox.isSelected = breakpoint.properties.watchModification
} }
override fun saveTo(breakpoint: XLineBreakpoint<KotlinPropertyBreakpointProperties>) { override fun saveTo(breakpoint: XLineBreakpoint<KotlinPropertyBreakpointProperties>) {
var changed = breakpoint.properties.WATCH_ACCESS != myWatchAccessCheckBox.isSelected var changed = breakpoint.properties.watchAccess != myWatchAccessCheckBox.isSelected
breakpoint.properties.WATCH_ACCESS = myWatchAccessCheckBox.isSelected breakpoint.properties.watchAccess = myWatchAccessCheckBox.isSelected
changed = breakpoint.properties.WATCH_MODIFICATION != myWatchModificationCheckBox.isSelected || changed changed = breakpoint.properties.watchModification != myWatchModificationCheckBox.isSelected || changed
breakpoint.properties.WATCH_MODIFICATION = myWatchModificationCheckBox.isSelected breakpoint.properties.watchModification = myWatchModificationCheckBox.isSelected
changed = breakpoint.properties.WATCH_INITIALIZATION != myWatchInitializationCheckBox.isSelected || changed changed = breakpoint.properties.watchInitialization != myWatchInitializationCheckBox.isSelected || changed
breakpoint.properties.WATCH_INITIALIZATION = myWatchInitializationCheckBox.isSelected breakpoint.properties.watchInitialization = myWatchInitializationCheckBox.isSelected
if (changed) { if (changed) {
(breakpoint as XBreakpointBase<*, *, *>).fireBreakpointChanged() (breakpoint as XBreakpointBase<*, *, *>).fireBreakpointChanged()
@@ -22,6 +22,7 @@ import com.intellij.xdebugger.breakpoints.XBreakpoint
import com.intellij.xdebugger.breakpoints.XLineBreakpoint import com.intellij.xdebugger.breakpoints.XLineBreakpoint
import com.intellij.xdebugger.breakpoints.XLineBreakpointType import com.intellij.xdebugger.breakpoints.XLineBreakpointType
import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider
import org.jetbrains.kotlin.asJava.classes.KtLightClass import org.jetbrains.kotlin.asJava.classes.KtLightClass
import org.jetbrains.kotlin.asJava.classes.KtLightClassForFacade import org.jetbrains.kotlin.asJava.classes.KtLightClassForFacade
import org.jetbrains.kotlin.asJava.classes.KtLightClassForSourceDeclaration import org.jetbrains.kotlin.asJava.classes.KtLightClassForSourceDeclaration
@@ -32,6 +33,7 @@ import org.jetbrains.kotlin.psi.KtDeclarationContainer
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtParameter import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.kotlin.psi.KtProperty import org.jetbrains.kotlin.psi.KtProperty
import javax.swing.Icon
import javax.swing.JComponent import javax.swing.JComponent
class KotlinFieldBreakpointType : class KotlinFieldBreakpointType :
@@ -137,13 +139,13 @@ class KotlinFieldBreakpointType :
override fun isAddBreakpointButtonVisible() = true override fun isAddBreakpointButtonVisible() = true
override fun getMutedEnabledIcon() = AllIcons.Debugger.Db_muted_field_breakpoint override fun getMutedEnabledIcon(): Icon = AllIcons.Debugger.Db_muted_field_breakpoint
override fun getDisabledIcon() = AllIcons.Debugger.Db_disabled_field_breakpoint override fun getDisabledIcon(): Icon = AllIcons.Debugger.Db_disabled_field_breakpoint
override fun getEnabledIcon() = AllIcons.Debugger.Db_field_breakpoint override fun getEnabledIcon(): Icon = AllIcons.Debugger.Db_field_breakpoint
override fun getMutedDisabledIcon() = AllIcons.Debugger.Db_muted_disabled_field_breakpoint override fun getMutedDisabledIcon(): Icon = AllIcons.Debugger.Db_muted_disabled_field_breakpoint
override fun canBeHitInOtherPlaces() = true override fun canBeHitInOtherPlaces() = true
@@ -166,7 +168,7 @@ class KotlinFieldBreakpointType :
return kotlinBreakpoint?.description ?: super.getDisplayText(breakpoint) return kotlinBreakpoint?.description ?: super.getDisplayText(breakpoint)
} }
override fun getEditorsProvider() = null override fun getEditorsProvider(): XDebuggerEditorsProvider? = null
override fun createCustomRightPropertiesPanel(project: Project): XBreakpointCustomPropertiesPanel<XLineBreakpoint<KotlinPropertyBreakpointProperties>>? { override fun createCustomRightPropertiesPanel(project: Project): XBreakpointCustomPropertiesPanel<XLineBreakpoint<KotlinPropertyBreakpointProperties>>? {
return KotlinBreakpointFiltersPanel(project) return KotlinBreakpointFiltersPanel(project)
@@ -8,11 +8,9 @@ package org.jetbrains.kotlin.idea.debugger.breakpoints
import com.intellij.debugger.engine.DebugProcess import com.intellij.debugger.engine.DebugProcess
import com.intellij.debugger.impl.DebuggerUtilsEx import com.intellij.debugger.impl.DebuggerUtilsEx
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.xdebugger.XSourcePosition import com.intellij.xdebugger.XSourcePosition
import com.intellij.xdebugger.breakpoints.XBreakpoint import com.intellij.xdebugger.breakpoints.XBreakpoint
import com.intellij.xdebugger.breakpoints.XBreakpointProperties import com.intellij.xdebugger.breakpoints.XBreakpointProperties
import com.sun.jdi.AbsentInformationException
import com.sun.jdi.ReferenceType import com.sun.jdi.ReferenceType
import org.jetbrains.kotlin.codegen.inline.KOTLIN_STRATA_NAME import org.jetbrains.kotlin.codegen.inline.KOTLIN_STRATA_NAME
import org.jetbrains.kotlin.idea.debugger.isDexDebug import org.jetbrains.kotlin.idea.debugger.isDexDebug
@@ -12,18 +12,19 @@ class KotlinPropertyBreakpointProperties(
@Attribute var myFieldName: String = "", @Attribute var myFieldName: String = "",
@Attribute var myClassName: String = "" @Attribute var myClassName: String = ""
) : JavaBreakpointProperties<KotlinPropertyBreakpointProperties>() { ) : JavaBreakpointProperties<KotlinPropertyBreakpointProperties>() {
var WATCH_MODIFICATION: Boolean = true var watchModification: Boolean = true
var WATCH_ACCESS: Boolean = false var watchAccess: Boolean = false
var WATCH_INITIALIZATION: Boolean = false var watchInitialization: Boolean = false
override fun getState() = this override fun getState() = this
override fun loadState(state: KotlinPropertyBreakpointProperties) { override fun loadState(state: KotlinPropertyBreakpointProperties) {
super.loadState(state) super.loadState(state)
WATCH_MODIFICATION = state.WATCH_MODIFICATION watchModification = state.watchModification
WATCH_ACCESS = state.WATCH_ACCESS watchAccess = state.watchAccess
WATCH_INITIALIZATION = state.WATCH_INITIALIZATION watchInitialization = state.watchInitialization
myFieldName = state.myFieldName myFieldName = state.myFieldName
myClassName = state.myClassName myClassName = state.myClassName
} }
@@ -37,8 +37,6 @@ import java.util.*
interface KotlinBreakpointType interface KotlinBreakpointType
private val LOG = Logger.getInstance("BreakpointTypeUtilsKt")
class ApplicabilityResult(val isApplicable: Boolean, val shouldStop: Boolean) { class ApplicabilityResult(val isApplicable: Boolean, val shouldStop: Boolean) {
companion object { companion object {
@JvmStatic @JvmStatic
@@ -74,26 +72,29 @@ fun isBreakpointApplicable(file: VirtualFile, line: Int, project: Project, check
var isApplicable = false var isApplicable = false
val checked = HashSet<PsiElement>() val checked = HashSet<PsiElement>()
XDebuggerUtil.getInstance().iterateLine(project, document, line, fun(element: PsiElement): Boolean { XDebuggerUtil.getInstance().iterateLine(
if (element is PsiWhiteSpace || element.getParentOfType<PsiComment>(false) != null || !element.isValid) { project, document, line,
return true fun(element: PsiElement): Boolean {
} if (element is PsiWhiteSpace || element.getParentOfType<PsiComment>(false) != null || !element.isValid) {
return true
}
val parent = getTopmostParentOnLineOrSelf(element, document, line) val parent = getTopmostParentOnLineOrSelf(element, document, line)
if (!checked.add(parent)) { if (!checked.add(parent)) {
return true return true
} }
val result = checker(parent) val result = checker(parent)
if (result.shouldStop && !result.isApplicable) { if (result.shouldStop && !result.isApplicable) {
isApplicable = false isApplicable = false
return false return false
} }
isApplicable = isApplicable or result.isApplicable isApplicable = isApplicable or result.isApplicable
return !result.shouldStop return !result.shouldStop
}) },
)
return@runReadAction isApplicable return@runReadAction isApplicable
} }
@@ -117,7 +118,7 @@ private fun getTopmostParentOnLineOrSelf(element: PsiElement, document: Document
fun computeLineBreakpointVariants( fun computeLineBreakpointVariants(
project: Project, project: Project,
position: XSourcePosition, position: XSourcePosition,
kotlinBreakpointType: KotlinLineBreakpointType kotlinBreakpointType: KotlinLineBreakpointType,
): List<JavaLineBreakpointType.JavaBreakpointVariant> { ): List<JavaLineBreakpointType.JavaBreakpointVariant> {
val file = PsiManager.getInstance(project).findFile(position.file) as? KtFile ?: return emptyList() val file = PsiManager.getInstance(project).findFile(position.file) as? KtFile ?: return emptyList()
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.inline.InlineUtil import org.jetbrains.kotlin.resolve.inline.InlineUtil
import org.jetbrains.org.objectweb.asm.Type
import java.util.* import java.util.*
fun Location.isInKotlinSources(): Boolean { fun Location.isInKotlinSources(): Boolean {
@@ -221,15 +222,6 @@ fun isOnSuspendReturnOrReenter(location: Location): Boolean {
return firstLocation.safeLineNumber() == location.safeLineNumber() return firstLocation.safeLineNumber() == location.safeLineNumber()
} }
fun isLastLineLocationInMethod(location: Location): Boolean {
val knownLines = location.method().safeAllLineLocations().map { it.lineNumber() }.filter { it != -1 }
if (knownLines.isEmpty()) {
return false
}
return knownLines.max() == location.lineNumber()
}
fun isOneLineMethod(location: Location): Boolean { fun isOneLineMethod(location: Location): Boolean {
val allLineLocations = location.method().safeAllLineLocations() val allLineLocations = location.method().safeAllLineLocations()
val firstLine = allLineLocations.firstOrNull()?.lineNumber() val firstLine = allLineLocations.firstOrNull()?.lineNumber()
@@ -23,13 +23,13 @@ import org.jetbrains.kotlin.idea.debugger.KotlinDebuggerSettings
private const val KOTLIN_STDLIB_FILTER = "kotlin.*" private const val KOTLIN_STDLIB_FILTER = "kotlin.*"
fun addKotlinStdlibDebugFilterIfNeeded() { fun addKotlinStdlibDebugFilterIfNeeded() {
if (!KotlinDebuggerSettings.getInstance().DEBUG_IS_FILTER_FOR_STDLIB_ALREADY_ADDED) { if (!KotlinDebuggerSettings.getInstance().isFilterForStdlibAlreadyAdded) {
val settings = DebuggerSettings.getInstance()!! val settings = DebuggerSettings.getInstance()!!
val newFilters = (settings.steppingFilters + ClassFilter(KOTLIN_STDLIB_FILTER)) val newFilters = (settings.steppingFilters + ClassFilter(KOTLIN_STDLIB_FILTER))
settings.steppingFilters = newFilters settings.steppingFilters = newFilters
KotlinDebuggerSettings.getInstance().DEBUG_IS_FILTER_FOR_STDLIB_ALREADY_ADDED = true KotlinDebuggerSettings.getInstance().isFilterForStdlibAlreadyAdded = true
} }
} }
@@ -21,6 +21,6 @@ class KotlinDebuggerInternalClassesFilterProvider : DebuggerClassFilterProvider
} }
override fun getFilters(): List<ClassFilter>? { override fun getFilters(): List<ClassFilter>? {
return if (KotlinDebuggerSettings.getInstance().DEBUG_DISABLE_KOTLIN_INTERNAL_CLASSES) FILTERS else listOf() return if (KotlinDebuggerSettings.getInstance().disableKotlinInternalClasses) FILTERS else listOf()
} }
} }
@@ -91,36 +91,36 @@ class KotlinSyntheticTypeComponentProvider : SyntheticTypeComponentProvider {
return hasInterfaceWithImplementation(this) return hasInterfaceWithImplementation(this)
} }
private val LOAD_INSTRUCTIONS_WITH_INDEX = Opcodes.ILOAD.toByte()..Opcodes.ALOAD.toByte() private companion object {
private val LOAD_INSTRUCTIONS = (Opcodes.ALOAD + 1).toByte()..(Opcodes.IALOAD - 1).toByte() private val LOAD_INSTRUCTIONS_WITH_INDEX = Opcodes.ILOAD.toByte()..Opcodes.ALOAD.toByte()
private val LOAD_INSTRUCTIONS = (Opcodes.ALOAD + 1).toByte()..(Opcodes.IALOAD - 1).toByte()
private val RETURN_INSTRUCTIONS = Opcodes.IRETURN.toByte()..Opcodes.RETURN.toByte() private val RETURN_INSTRUCTIONS = Opcodes.IRETURN.toByte()..Opcodes.RETURN.toByte()
}
// Check that method contains only load and invokeStatic instructions. Note that if after load goes ldc instruction it could be checkParametersNotNull method invocation // Check that method contains only load and invokeStatic instructions. Note that if after load goes ldc instruction it could be checkParametersNotNull method invocation
private fun hasOnlyInvokeStatic(m: Method): Boolean { private fun hasOnlyInvokeStatic(m: Method): Boolean {
val bytecodes = m.bytecodes() val instructions = m.bytecodes()
var i = 0 var i = 0
var isALoad0BeforeStaticCall = false var isALoad0BeforeStaticCall = false
while (i < bytecodes.size) { while (i < instructions.size) {
val instr = bytecodes[i] when (val instr = instructions[i]) {
when { 42.toByte() /* ALOAD_0 */ -> {
instr == 42.toByte() /* ALOAD_0 */ -> {
i += 1 i += 1
isALoad0BeforeStaticCall = true isALoad0BeforeStaticCall = true
} }
instr in LOAD_INSTRUCTIONS_WITH_INDEX || instr in LOAD_INSTRUCTIONS -> { in LOAD_INSTRUCTIONS_WITH_INDEX, in LOAD_INSTRUCTIONS -> {
i += 1 i += 1
if (instr in LOAD_INSTRUCTIONS_WITH_INDEX) i += 1 if (instr in LOAD_INSTRUCTIONS_WITH_INDEX) i += 1
val nextInstr = bytecodes[i] val nextInstr = instructions[i]
if (nextInstr == Opcodes.LDC.toByte()) { if (nextInstr == Opcodes.LDC.toByte()) {
i += 2 i += 2
isALoad0BeforeStaticCall = false isALoad0BeforeStaticCall = false
} }
} }
instr == Opcodes.INVOKESTATIC.toByte() -> { Opcodes.INVOKESTATIC.toByte() -> {
i += 3 i += 3
if (isALoad0BeforeStaticCall && i == (bytecodes.size - 1)) { if (isALoad0BeforeStaticCall && i == (instructions.size - 1)) {
val nextInstr = bytecodes[i] val nextInstr = instructions[i]
return nextInstr in RETURN_INSTRUCTIONS return nextInstr in RETURN_INSTRUCTIONS
} }
} }
@@ -93,7 +93,7 @@ class KotlinClassWithDelegatedPropertyRenderer : ClassRenderer() {
val fieldDescriptor = nodeDescriptorFactory.getFieldDescriptor(builder.parentDescriptor, value, field) val fieldDescriptor = nodeDescriptorFactory.getFieldDescriptor(builder.parentDescriptor, value, field)
if (field.name().endsWith(JvmAbi.DELEGATED_PROPERTY_NAME_SUFFIX)) { if (field.name().endsWith(JvmAbi.DELEGATED_PROPERTY_NAME_SUFFIX)) {
val shouldRenderDelegatedProperty = KotlinDebuggerSettings.getInstance().DEBUG_RENDER_DELEGATED_PROPERTIES val shouldRenderDelegatedProperty = KotlinDebuggerSettings.getInstance().renderDelegatedProperties
if (shouldRenderDelegatedProperty && !ToggleKotlinVariablesState.getService().kotlinVariableView) { if (shouldRenderDelegatedProperty && !ToggleKotlinVariablesState.getService().kotlinVariableView) {
children.add(nodeManager.createNode(fieldDescriptor, context)) children.add(nodeManager.createNode(fieldDescriptor, context))
} }
@@ -225,10 +225,6 @@ open class KotlinStackFrame(stackFrameDescriptorImpl: StackFrameDescriptorImpl)
return name().startsWith(AsmUtil.LABELED_THIS_PARAMETER) return name().startsWith(AsmUtil.LABELED_THIS_PARAMETER)
} }
override fun hashCode(): Int {
return super.hashCode()
}
override fun equals(other: Any?) : Boolean { override fun equals(other: Any?) : Boolean {
val eq = super.equals(other) val eq = super.equals(other)
return other is KotlinStackFrame && eq return other is KotlinStackFrame && eq
@@ -17,7 +17,6 @@ import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiExpression import com.intellij.psi.PsiExpression
import com.intellij.util.IncorrectOperationException import com.intellij.util.IncorrectOperationException
import com.sun.jdi.* import com.sun.jdi.*
import org.jetbrains.org.objectweb.asm.Type as AsmType
class LabeledThisData(val label: String, val name: String, val value: Value?) : DescriptorData<ValueDescriptorImpl>() { class LabeledThisData(val label: String, val name: String, val value: Value?) : DescriptorData<ValueDescriptorImpl>() {
override fun createDescriptorImpl(project: Project): ValueDescriptorImpl { override fun createDescriptorImpl(project: Project): ValueDescriptorImpl {
@@ -25,7 +25,6 @@ import com.intellij.debugger.impl.DebuggerUtilsEx;
import com.intellij.debugger.jdi.StackFrameProxyImpl; import com.intellij.debugger.jdi.StackFrameProxyImpl;
import com.intellij.debugger.jdi.ThreadReferenceProxyImpl; import com.intellij.debugger.jdi.ThreadReferenceProxyImpl;
import com.intellij.debugger.settings.DebuggerSettings; import com.intellij.debugger.settings.DebuggerSettings;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.ui.classFilter.ClassFilter; import com.intellij.ui.classFilter.ClassFilter;
import com.intellij.ui.classFilter.DebuggerClassFilterProvider; import com.intellij.ui.classFilter.DebuggerClassFilterProvider;
import com.sun.jdi.Location; import com.sun.jdi.Location;
@@ -44,8 +43,6 @@ import org.jetbrains.kotlin.idea.debugger.SafeUtilKt;
import java.util.List; import java.util.List;
public class DebuggerSteppingHelper { public class DebuggerSteppingHelper {
private static final Logger LOG = Logger.getInstance(DebuggerSteppingHelper.class);
public static DebugProcessImpl.ResumeCommand createStepOverCommand( public static DebugProcessImpl.ResumeCommand createStepOverCommand(
SuspendContextImpl suspendContext, SuspendContextImpl suspendContext,
boolean ignoreBreakpoints, boolean ignoreBreakpoints,
@@ -29,18 +29,18 @@ public class KotlinSteppingConfigurableUi implements ConfigurableUi<KotlinDebugg
@Override @Override
public void reset(@NotNull KotlinDebuggerSettings settings) { public void reset(@NotNull KotlinDebuggerSettings settings) {
boolean flag = settings.getDEBUG_DISABLE_KOTLIN_INTERNAL_CLASSES(); boolean flag = settings.getDisableKotlinInternalClasses();
ignoreKotlinMethods.setSelected(flag); ignoreKotlinMethods.setSelected(flag);
} }
@Override @Override
public boolean isModified(@NotNull KotlinDebuggerSettings settings) { public boolean isModified(@NotNull KotlinDebuggerSettings settings) {
return settings.getDEBUG_DISABLE_KOTLIN_INTERNAL_CLASSES() != ignoreKotlinMethods.isSelected(); return settings.getDisableKotlinInternalClasses() != ignoreKotlinMethods.isSelected();
} }
@Override @Override
public void apply(@NotNull KotlinDebuggerSettings settings) { public void apply(@NotNull KotlinDebuggerSettings settings) {
settings.setDEBUG_DISABLE_KOTLIN_INTERNAL_CLASSES(ignoreKotlinMethods.isSelected()); settings.setDisableKotlinInternalClasses(ignoreKotlinMethods.isSelected());
} }
@NotNull @NotNull
@@ -27,7 +27,7 @@ class KotlinStepOverParamDefaultImplsMethodFilter(
val method = location.safeMethod() ?: return null val method = location.safeMethod() ?: return null
val name = method.name() val name = method.name()
assert(name.endsWith(JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX)); assert(name.endsWith(JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX))
val originalName = name.dropLast(JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX.length) val originalName = name.dropLast(JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX.length)
val signature = method.signature() val signature = method.signature()
val containingTypeName = location.declaringType().name() val containingTypeName = location.declaringType().name()
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
import org.jetbrains.kotlin.renderer.PropertyAccessorRenderingPolicy import org.jetbrains.kotlin.renderer.PropertyAccessorRenderingPolicy
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
import org.jetbrains.kotlin.resolve.inline.InlineUtil
import javax.swing.Icon import javax.swing.Icon
class KotlinMethodSmartStepTarget( class KotlinMethodSmartStepTarget(
@@ -33,7 +33,7 @@ class CoroutineDebuggerListener(val project: Project) : DebuggerListener {
): DebuggerConnection? { ): DebuggerConnection? {
val isExternalSystemRunConfiguration = configuration is ExternalSystemRunConfiguration val isExternalSystemRunConfiguration = configuration is ExternalSystemRunConfiguration
val isGradleConfiguration = gradleConfiguration(configuration.type.id) val isGradleConfiguration = gradleConfiguration(configuration.type.id)
val disableCoroutineAgent = KotlinDebuggerSettings.getInstance().DEBUG_DISABLE_COROUTINE_AGENT val disableCoroutineAgent = KotlinDebuggerSettings.getInstance().debugDisableCoroutineAgent
if (!disableCoroutineAgent && runnerSettings is DebuggingRunnerData && !isExternalSystemRunConfiguration && !isGradleConfiguration) if (!disableCoroutineAgent && runnerSettings is DebuggingRunnerData && !isExternalSystemRunConfiguration && !isGradleConfiguration)
return DebuggerConnection(project, configuration, params, runnerSettings) return DebuggerConnection(project, configuration, params, runnerSettings)
return null return null
@@ -27,9 +27,9 @@ internal val SettingsMutators: List<SettingsMutator<*>> = listOf(
DebuggerSettingsMutator(SKIP_CLASSLOADERS, DebuggerSettings::SKIP_CLASSLOADERS), DebuggerSettingsMutator(SKIP_CLASSLOADERS, DebuggerSettings::SKIP_CLASSLOADERS),
DebuggerSettingsMutator(TRACING_FILTERS_ENABLED, DebuggerSettings::TRACING_FILTERS_ENABLED), DebuggerSettingsMutator(TRACING_FILTERS_ENABLED, DebuggerSettings::TRACING_FILTERS_ENABLED),
DebuggerSettingsMutator(SKIP_GETTERS, DebuggerSettings::SKIP_GETTERS), DebuggerSettingsMutator(SKIP_GETTERS, DebuggerSettings::SKIP_GETTERS),
KotlinSettingsMutator(DISABLE_KOTLIN_INTERNAL_CLASSES, KotlinDebuggerSettings::DEBUG_DISABLE_KOTLIN_INTERNAL_CLASSES), KotlinSettingsMutator(DISABLE_KOTLIN_INTERNAL_CLASSES, KotlinDebuggerSettings::disableKotlinInternalClasses),
KotlinSettingsMutator(RENDER_DELEGATED_PROPERTIES, KotlinDebuggerSettings::DEBUG_RENDER_DELEGATED_PROPERTIES), KotlinSettingsMutator(RENDER_DELEGATED_PROPERTIES, KotlinDebuggerSettings::renderDelegatedProperties),
KotlinSettingsMutator(IS_FILTER_FOR_STDLIB_ALREADY_ADDED, KotlinDebuggerSettings::DEBUG_IS_FILTER_FOR_STDLIB_ALREADY_ADDED), KotlinSettingsMutator(IS_FILTER_FOR_STDLIB_ALREADY_ADDED, KotlinDebuggerSettings::isFilterForStdlibAlreadyAdded),
KotlinVariablesModeSettingsMutator, KotlinVariablesModeSettingsMutator,
JvmTargetSettingsMutator, JvmTargetSettingsMutator,
ForceRankingSettingsMutator ForceRankingSettingsMutator