mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[daemon] IJPL-206789 extract ErrorCountStorage to a separate file
GitOrigin-RevId: d5d089bb915044f88895e9f99ff26db711c5862f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fdab1bb2ba
commit
5258e96282
@@ -0,0 +1,44 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.daemon.impl
|
||||
|
||||
import com.intellij.codeInsight.multiverse.CodeInsightContext
|
||||
import com.intellij.lang.annotation.HighlightSeverity
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import kotlin.math.max
|
||||
|
||||
/**
|
||||
* Synchronized storage for error counts.
|
||||
* Stores a separate number for each severity and context combination.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
class ErrorCountStorage {
|
||||
private val errorCount = Object2IntOpenHashMap<HighlightKey>() // guarded by errorCount
|
||||
|
||||
fun getErrorCount(severity: HighlightSeverity, context: CodeInsightContext): Int {
|
||||
val contextHighlightKey = HighlightKey(severity, context)
|
||||
return synchronized(errorCount) {
|
||||
errorCount.getInt(contextHighlightKey)
|
||||
}
|
||||
}
|
||||
|
||||
fun incErrorCount(infoSeverity: HighlightSeverity, context: CodeInsightContext, delta: Int) {
|
||||
val highlightKey = HighlightKey(infoSeverity, context)
|
||||
synchronized(errorCount) {
|
||||
val oldVal = errorCount.getInt(highlightKey)
|
||||
val newVal = max(0, oldVal + delta)
|
||||
errorCount.put(highlightKey, newVal)
|
||||
}
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
synchronized(errorCount) {
|
||||
errorCount.clear()
|
||||
}
|
||||
}
|
||||
|
||||
private data class HighlightKey(
|
||||
val severity: HighlightSeverity,
|
||||
val context: CodeInsightContext?,
|
||||
)
|
||||
}
|
||||
+6
-18
@@ -49,11 +49,10 @@ import com.intellij.util.io.storage.HeavyProcessLatch
|
||||
import com.intellij.util.ui.EdtInvocationManager
|
||||
import com.intellij.util.ui.GridBag
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.annotations.Nls
|
||||
import java.awt.Container
|
||||
import java.util.Collections
|
||||
import java.util.*
|
||||
import java.util.concurrent.CancellationException
|
||||
|
||||
open class TrafficLightRenderer private constructor(
|
||||
@@ -64,7 +63,7 @@ open class TrafficLightRenderer private constructor(
|
||||
) : ErrorStripeRenderer, Disposable {
|
||||
private val daemonCodeAnalyzer: DaemonCodeAnalyzerImpl
|
||||
private val severityRegistrar: SeverityRegistrar
|
||||
private val errorCount = Object2IntOpenHashMap<HighlightKey>() // guarded by errorCount
|
||||
private val errorCount = ErrorCountStorage()
|
||||
@JvmField
|
||||
@ApiStatus.Internal
|
||||
protected val uiController: UIController
|
||||
@@ -167,8 +166,7 @@ open class TrafficLightRenderer private constructor(
|
||||
val context = getContext()
|
||||
for (severity in severities) {
|
||||
val severityIndex = severityRegistrar.getSeverityIdx(severity)
|
||||
val highlightKey = HighlightKey(severity, context)
|
||||
cachedErrors[severityIndex] = synchronized(errorCount) { errorCount.getInt(highlightKey) }
|
||||
cachedErrors[severityIndex] = errorCount.getErrorCount(severity, context)
|
||||
}
|
||||
return cachedErrors
|
||||
}
|
||||
@@ -177,20 +175,15 @@ open class TrafficLightRenderer private constructor(
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
synchronized(errorCount) {
|
||||
errorCount.clear()
|
||||
}
|
||||
errorCount.clear()
|
||||
}
|
||||
|
||||
private fun incErrorCount(highlighter: RangeHighlighter, delta: Int) {
|
||||
val info = HighlightInfo.fromRangeHighlighter(highlighter) ?: return
|
||||
val infoSeverity = info.severity
|
||||
if (infoSeverity > HighlightSeverity.TEXT_ATTRIBUTES) {
|
||||
val highlightKey = HighlightKey(infoSeverity, getContext(highlighter))
|
||||
synchronized(errorCount) {
|
||||
val oldVal = errorCount.getInt(highlightKey)
|
||||
errorCount.put(highlightKey, Math.max(0, oldVal + delta))
|
||||
}
|
||||
val context = getContext(highlighter)
|
||||
errorCount.incErrorCount(infoSeverity, context, delta)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -675,8 +668,3 @@ open class TrafficLightRenderer private constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data class HighlightKey(
|
||||
val severity: HighlightSeverity,
|
||||
val context: CodeInsightContext,
|
||||
)
|
||||
Reference in New Issue
Block a user