IDEA-238791: refactor project errors collector

GitOrigin-RevId: d3409f5719db1de2feb780d699f89d5c54dc009b
This commit is contained in:
Sergey Malenkov
2020-07-28 23:15:11 +00:00
committed by intellij-monorepo-bot
parent ee42f69239
commit 4ccc9d206b
6 changed files with 24 additions and 19 deletions
@@ -1,10 +1,17 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.analysis.problemsView
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
interface ProblemsCollector : ProblemsListener {
companion object {
@JvmStatic
fun getInstance(project: Project) = project.getService(ProblemsCollector::class.java)!!
}
fun getProblemCount(): Int
fun getProblemFiles(): Collection<VirtualFile>
fun getFileProblemCount(file: VirtualFile): Int
fun getFileProblems(file: VirtualFile): Collection<Problem>
@@ -1,14 +1,7 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.analysis.problemsView
import com.intellij.openapi.project.Project
interface ProblemsListener {
companion object {
@JvmStatic
fun getInstance(project: Project) = project.getService(ProblemsListener::class.java)!!
}
fun problemAppeared(problem: Problem)
fun problemDisappeared(problem: Problem)
fun problemUpdated(problem: Problem)
@@ -1,7 +1,7 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.analysis.problemsView.toolWindow
import com.intellij.analysis.problemsView.ProblemsListener
import com.intellij.analysis.problemsView.ProblemsCollector
import com.intellij.analysis.problemsView.ProblemsProvider
import com.intellij.codeInsight.problems.WolfTheProblemSolverImpl
import com.intellij.lang.annotation.HighlightSeverity.ERROR
@@ -30,7 +30,7 @@ internal class HighlightingErrorsProvider(override val project: Project) : Probl
override fun problemsAppeared(file: VirtualFile) {
synchronized(watchers) {
watchers.computeIfAbsent(file) { file ->
HighlightingWatcher(this, ProblemsListener.getInstance(project), file, ERROR.myVal).also { watcher ->
HighlightingWatcher(this, ProblemsCollector.getInstance(project), file, ERROR.myVal).also { watcher ->
Disposer.register(this, watcher)
}
}
@@ -10,13 +10,17 @@ import com.intellij.openapi.vfs.VirtualFile
import com.intellij.ui.AppUIUtil
import java.util.concurrent.atomic.AtomicInteger
internal class ProjectErrorsCollector(val project: Project) : ProblemsCollector {
private class ProjectErrorsCollector(val project: Project) : ProblemsCollector {
private val fileProblems = mutableMapOf<VirtualFile, MutableSet<FileProblem>>()
private val otherProblems = mutableSetOf<Problem>()
private val problemCount = AtomicInteger()
override fun getProblemCount() = problemCount.get()
override fun getProblemFiles() = synchronized(fileProblems) {
fileProblems.keys.toSet()
}
override fun getFileProblemCount(file: VirtualFile) = synchronized(fileProblems) {
fileProblems[file]?.size ?: 0
}
@@ -67,17 +71,17 @@ internal class ProjectErrorsCollector(val project: Project) : ProblemsCollector
private fun notify(problem: Problem, state: SetUpdateState) {
when (state) {
SetUpdateState.ADDED -> {
getProjectErrors()?.addProblem(problem)
getProblemsListener()?.problemAppeared(problem)
val emptyBefore = problemCount.getAndIncrement() == 0
if (emptyBefore) updateToolWindowIcon()
}
SetUpdateState.REMOVED -> {
getProjectErrors()?.removeProblem(problem)
getProblemsListener()?.problemDisappeared(problem)
val emptyAfter = problemCount.decrementAndGet() == 0
if (emptyAfter) updateToolWindowIcon()
}
SetUpdateState.UPDATED -> {
getProjectErrors()?.updateProblem(problem)
getProblemsListener()?.problemUpdated(problem)
}
SetUpdateState.IGNORED -> {
}
@@ -94,7 +98,7 @@ internal class ProjectErrorsCollector(val project: Project) : ProblemsCollector
else -> Toolwindows.ToolWindowProblems
}
private fun getProjectErrors() = ProblemsView.getToolWindow(project)
private fun getProblemsListener() = ProblemsView.getToolWindow(project)
?.contentManagerIfCreated
?.contents
?.mapNotNull { it.component as? ProjectErrorsPanel }
@@ -3,11 +3,12 @@ package com.intellij.analysis.problemsView.toolWindow
import com.intellij.analysis.problemsView.FileProblem
import com.intellij.analysis.problemsView.Problem
import com.intellij.analysis.problemsView.ProblemsListener
import com.intellij.openapi.actionSystem.ToggleOptionAction.Option
import com.intellij.openapi.project.Project
internal class ProjectErrorsPanel(project: Project, state: ProblemsViewState)
: ProblemsViewPanel(project, state) {
: ProblemsViewPanel(project, state), ProblemsListener {
private val root = Root(this)
@@ -20,15 +21,15 @@ internal class ProjectErrorsPanel(project: Project, state: ProblemsViewState)
override fun getSortFoldersFirst(): Option? = null
override fun getSortBySeverity(): Option? = null
fun addProblem(problem: Problem) {
override fun problemAppeared(problem: Problem) {
if (problem is FileProblem) root.addProblems(problem.file, problem)
}
fun removeProblem(problem: Problem) {
override fun problemDisappeared(problem: Problem) {
if (problem is FileProblem) root.removeProblems(problem.file, problem)
}
fun updateProblem(problem: Problem) {
override fun problemUpdated(problem: Problem) {
if (problem is FileProblem) root.updateProblem(problem.file, problem)
}
}
@@ -945,7 +945,7 @@
serviceImplementation="com.intellij.codeInsight.template.TemplateBuilderFactoryImpl"/>
<projectService serviceImplementation="com.intellij.analysis.problemsView.toolWindow.HighlightingErrorsProvider"/>
<projectService serviceInterface="com.intellij.analysis.problemsView.ProblemsListener"
<projectService serviceInterface="com.intellij.analysis.problemsView.ProblemsCollector"
serviceImplementation="com.intellij.analysis.problemsView.toolWindow.ProjectErrorsCollector"/>
<projectViewPane implementation="com.intellij.ide.scopeView.ScopeViewPane"/>