Skip to content

Commit 3bb0a62

Browse files
AlexVanGogenintellij-monorepo-bot
authored andcommitted
[debugger] IDEA-392757 IJ-CR-219708 Review fixes
GitOrigin-RevId: d5eb58c3ac747bf9e2f2ffcd45e2e62fd70105a0
1 parent 8de725b commit 3bb0a62

4 files changed

Lines changed: 74 additions & 46 deletions

File tree

java/debugger/impl/resources/META-INF/java-debugger.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@
6868
<with attribute="implementationClass" implements="com.intellij.debugger.engine.dfaassist.DfaAssistProvider"/>
6969
</extensionPoint>
7070

71-
<extensionPoint qualifiedName="com.intellij.debugger.trickyLineBreakpointLocationProvider" beanClass="com.intellij.lang.LanguageExtensionPoint"
71+
<extensionPoint qualifiedName="com.intellij.debugger.specialLineBreakpointCaseProvider" beanClass="com.intellij.lang.LanguageExtensionPoint"
7272
dynamic="true">
73-
<with attribute="implementationClass" implements="com.intellij.debugger.ui.breakpoints.JvmTrickyLineBreakpointLocationProvider"/>
73+
<with attribute="implementationClass" implements="com.intellij.debugger.ui.breakpoints.JvmSpecialLineBreakpointCaseProvider"/>
7474
</extensionPoint>
7575

7676
<extensionPoint qualifiedName="com.intellij.debugger.extraDebugNodesProvider"

java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaBreakpointsUsageCollector.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import com.intellij.internal.statistic.eventLog.EventLogGroup
55
import com.intellij.internal.statistic.eventLog.events.EventFields
66
import com.intellij.internal.statistic.service.fus.collectors.CounterUsagesCollector
77
import com.intellij.internal.statistic.utils.getPluginInfo
8-
import com.intellij.openapi.application.readAction
98
import com.intellij.xdebugger.XDebuggerManager
109
import com.intellij.xdebugger.breakpoints.XLineBreakpoint
1110
import com.intellij.xdebugger.breakpoints.XBreakpointType
@@ -21,13 +20,13 @@ object JavaBreakpointsUsageCollector : CounterUsagesCollector() {
2120
RETURN,
2221
}
2322

24-
private val GROUP = EventLogGroup("debugger.breakpoints.usage.java", 2)
23+
private val GROUP = EventLogGroup("debugger.breakpoints.usage.java", 3)
2524
private val LINE_BREAKPOINT_KIND_FIELD = EventFields.Enum<LineBreakpointKind>("kind")
26-
private val LINE_BREAKPOINT_LOCATION_KIND_FIELD = EventFields.NullableEnum<TrickyLineBreakpointLocation>("location_kind")
25+
private val LINE_BREAKPOINT_SPECIAL_CASE_FIELD = EventFields.NullableEnum<SpecialLineBreakpointCase>("special_case")
2726
private val LINE_BREAKPOINT_ADDED = GROUP.registerEvent("line.breakpoint.added",
2827
EventFields.PluginInfo,
2928
LINE_BREAKPOINT_KIND_FIELD,
30-
LINE_BREAKPOINT_LOCATION_KIND_FIELD)
29+
LINE_BREAKPOINT_SPECIAL_CASE_FIELD)
3130

3231
@JvmStatic
3332
fun reportNewBreakpoint(breakpoint: Breakpoint<*>, type: XBreakpointType<*, *>) {
@@ -48,8 +47,13 @@ object JavaBreakpointsUsageCollector : CounterUsagesCollector() {
4847
val line = xBreakpoint.line
4948
val coroutineScope = (XDebuggerManager.getInstance(project) as XDebuggerManagerImpl).coroutineScope
5049
coroutineScope.launch {
51-
val location = readAction { getLineBreakpointLocation(project, fileUrl, line) }
52-
LINE_BREAKPOINT_ADDED.log(project, pluginInfo, kind, location)
50+
val specialCase = if (kind == LineBreakpointKind.LINE || kind == LineBreakpointKind.LINE_AND_LAMBDAS) {
51+
getSpecialLineBreakpointCase(project, fileUrl, line)
52+
}
53+
else {
54+
null
55+
}
56+
LINE_BREAKPOINT_ADDED.log(project, pluginInfo, kind, specialCase)
5357
}
5458
}
5559
}

java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointLocation.kt

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
package com.intellij.debugger.ui.breakpoints
3+
4+
import com.intellij.lang.LanguageExtension
5+
import com.intellij.openapi.application.readAction
6+
import com.intellij.openapi.project.Project
7+
import com.intellij.openapi.vfs.VirtualFileManager
8+
import com.intellij.psi.PsiFile
9+
import com.intellij.psi.PsiManager
10+
import com.intellij.util.concurrency.annotations.RequiresReadLock
11+
import org.jetbrains.annotations.ApiStatus
12+
13+
/**
14+
* A special case of a line breakpoint position where a breakpoint may hit
15+
* unexpectedly many times or never hit at all.
16+
*/
17+
@ApiStatus.Internal
18+
enum class SpecialLineBreakpointCase {
19+
/** The line starts with the `for`/`while` keyword of a loop statement. */
20+
LOOP_START,
21+
22+
/** The line starts with the closing brace of a loop body. */
23+
LOOP_END,
24+
25+
/** The line starts with the `try`, `catch` or `finally` keyword. */
26+
TRY_CATCH_FINALLY_START,
27+
28+
/** The line starts with the closing brace of a `try`, `catch` or `finally` block. */
29+
TRY_CATCH_FINALLY_END,
30+
31+
/** The line starts with the closing brace of the then-branch of an `if` statement. */
32+
IF_THEN_END,
33+
34+
/** The line starts with the closing brace of the else-branch of an `if` statement. */
35+
IF_ELSE_END,
36+
37+
/** The line starts with the closing brace of a `switch` branch. */
38+
SWITCH_CASE_END,
39+
}
40+
41+
@ApiStatus.Internal
42+
interface JvmSpecialLineBreakpointCaseProvider {
43+
/**
44+
* Classifies the given [line] whether it falls to a "special case"
45+
* when the breakpoint may (not) hit, counterintuitively to a user.
46+
*
47+
* Return `null` if the line does not fall to a "special case" in the file's language.
48+
*/
49+
@RequiresReadLock
50+
fun getSpecialCase(project: Project, file: PsiFile, line: Int): SpecialLineBreakpointCase?
51+
52+
companion object {
53+
internal val EP_NAME = LanguageExtension<JvmSpecialLineBreakpointCaseProvider>("com.intellij.debugger.specialLineBreakpointCaseProvider")
54+
}
55+
}
56+
57+
internal suspend fun getSpecialLineBreakpointCase(project: Project, fileUrl: String, line: Int): SpecialLineBreakpointCase? =
58+
readAction {
59+
val virtualFile = VirtualFileManager.getInstance().findFileByUrl(fileUrl) ?: return@readAction null
60+
val file = PsiManager.getInstance(project).findFile(virtualFile) ?: return@readAction null
61+
JvmSpecialLineBreakpointCaseProvider.EP_NAME.forLanguage(file.language)?.getSpecialCase(project, file, line)
62+
}

0 commit comments

Comments
 (0)