2 * Copyright 2000-2016 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.profile.codeInspection
18 import com.intellij.codeInsight.daemon.impl.SeverityRegistrar
19 import com.intellij.codeInspection.InspectionProfile
20 import com.intellij.codeInspection.ex.InspectionProfileImpl
21 import com.intellij.openapi.Disposable
22 import com.intellij.openapi.diagnostic.Logger
23 import com.intellij.openapi.options.LazySchemeProcessor
24 import com.intellij.openapi.options.SchemeManager
25 import com.intellij.openapi.options.SchemeState
26 import com.intellij.openapi.project.Project
27 import com.intellij.profile.Profile
28 import com.intellij.profile.ProfileChangeAdapter
29 import com.intellij.util.containers.ContainerUtil
30 import com.intellij.util.messages.MessageBus
33 internal val LOG = Logger.getInstance(BaseInspectionProfileManager::class.java)
35 abstract class BaseInspectionProfileManager(messageBus: MessageBus) : InspectionProjectProfileManager() {
36 protected abstract val schemeManager: SchemeManager<InspectionProfileImpl>
38 protected val profileListeners: MutableList<ProfileChangeAdapter> = ContainerUtil.createLockFreeCopyOnWriteList<ProfileChangeAdapter>()
39 private val severityRegistrar = SeverityRegistrar(messageBus)
41 override final fun getSeverityRegistrar() = severityRegistrar
43 override final fun getOwnSeverityRegistrar() = severityRegistrar
45 override final fun addProfileChangeListener(listener: ProfileChangeAdapter, parentDisposable: Disposable) {
46 ContainerUtil.add(listener, profileListeners, parentDisposable)
49 @Suppress("OverridingDeprecatedMember")
50 override final fun addProfileChangeListener(listener: ProfileChangeAdapter) {
51 profileListeners.add(listener)
54 @Suppress("OverridingDeprecatedMember")
55 override final fun removeProfileChangeListener(listener: ProfileChangeAdapter) {
56 profileListeners.remove(listener)
59 internal fun cleanupSchemes(project: Project) {
60 for (profile in schemeManager.allSchemes) {
61 profile.cleanup(project)
65 override final fun fireProfileChanged(profile: Profile?) {
66 if (profile is InspectionProfileImpl) {
67 profile.profileChanged()
69 for (adapter in profileListeners) {
70 adapter.profileChanged(profile)
74 override final fun fireProfileChanged(oldProfile: Profile?, profile: Profile) {
75 for (adapter in profileListeners) {
76 adapter.profileActivated(oldProfile, profile)
80 fun addProfile(profile: InspectionProfileImpl) {
81 schemeManager.addScheme(profile)
84 override final fun deleteProfile(name: String) {
85 schemeManager.removeScheme(name)?.let {
90 fun deleteProfile(profile: InspectionProfileImpl) {
91 schemeManager.removeScheme(profile)
92 schemeRemoved(profile)
95 open protected fun schemeRemoved(scheme: InspectionProfile) {
98 override fun updateProfile(profile: Profile) {
99 schemeManager.addScheme(profile as InspectionProfileImpl)
100 fireProfileChanged(profile)
104 abstract class InspectionProfileProcessor : LazySchemeProcessor<InspectionProfileImpl, InspectionProfileImpl>() {
105 override final fun getState(scheme: InspectionProfileImpl): SchemeState {
106 if (scheme is InspectionProfileImpl) {
107 return if (scheme.wasInitialized()) SchemeState.POSSIBLY_CHANGED else SchemeState.UNCHANGED
110 return SchemeState.NON_PERSISTENT