default void profileChanged(Profile profile) {
}
- default void profileActivated(@Nullable Profile oldProfile, Profile profile) {
+ default void profileActivated(@Nullable Profile oldProfile, @Nullable Profile profile) {
}
default void profilesInitialized() {
internal val LOG = Logger.getInstance(BaseInspectionProfileManager::class.java)
abstract class BaseInspectionProfileManager(messageBus: MessageBus) : InspectionProfileManager {
- protected abstract val schemeManager: SchemeManager<InspectionProfile>
+ protected abstract val schemeManager: SchemeManager<InspectionProfileImpl>
protected val profileListeners: MutableList<ProfileChangeAdapter> = ContainerUtil.createLockFreeCopyOnWriteList<ProfileChangeAdapter>()
private val severityRegistrar = SeverityRegistrar(messageBus)
}
}
- fun addProfile(profile: Profile) {
- schemeManager.addScheme(profile as InspectionProfile)
+ fun addProfile(profile: InspectionProfileImpl) {
+ schemeManager.addScheme(profile)
}
override final fun deleteProfile(name: String) {
}
override fun updateProfile(profile: Profile) {
- schemeManager.addScheme(profile as InspectionProfile)
+ schemeManager.addScheme(profile as InspectionProfileImpl)
fireProfileChanged(profile)
}
}
-abstract class InspectionProfileProcessor : LazySchemeProcessor<InspectionProfile, InspectionProfileImpl>() {
- override final fun getState(scheme: InspectionProfile): SchemeState {
+abstract class InspectionProfileProcessor : LazySchemeProcessor<InspectionProfileImpl, InspectionProfileImpl>() {
+ override final fun getState(scheme: InspectionProfileImpl): SchemeState {
if (scheme is InspectionProfileImpl) {
return if (scheme.wasInitialized()) SchemeState.POSSIBLY_CHANGED else SchemeState.UNCHANGED
}
void fireProfileChanged(@Nullable Profile oldProfile, @NotNull Profile profile);
- void setRootProfile(@Nullable String profileName);
+ void setRootProfile(@Nullable String name);
@SuppressWarnings("unused")
@NotNull
}
}
- override val schemeManager: SchemeManager<InspectionProfile>
+ override val schemeManager: SchemeManager<InspectionProfileImpl>
private data class State(@field:com.intellij.util.xmlb.annotations.OptionTag("PROJECT_PROFILE") var projectProfile: String? = PROJECT_DEFAULT_PROFILE_NAME,
@field:com.intellij.util.xmlb.annotations.OptionTag("USE_PROJECT_PROFILE") var useProjectProfile: Boolean = true)
}
override fun onSchemeAdded(scheme: InspectionProfileImpl) {
- fireProfileChanged(scheme)
+ if (scheme.wasInitialized()) {
+ fireProfileChanged(scheme)
+ }
+ }
+
+ override fun onCurrentSchemeSwitched(oldScheme: InspectionProfileImpl?, newScheme: InspectionProfileImpl?) {
+ for (adapter in profileListeners) {
+ adapter.profileActivated(oldScheme, newScheme)
+ }
}
}, isUseOldFileNameSanitize = true)
}
}
}
+
+ if (newState.useProjectProfile) {
+ schemeManager.currentSchemeName = newState.projectProfile
+ }
}
@Synchronized override fun getState(): Element? {
val result = Element("settings")
- XmlSerializer.serializeInto(this.state, result, skipDefaultsSerializationFilter)
+ val state = this.state
+ state.projectProfile = schemeManager.currentSchemeName
+ XmlSerializer.serializeInto(state, result, skipDefaultsSerializationFilter)
if (!result.children.isEmpty()) {
result.addContent(Element("version").setAttribute("value", VERSION))
}
@Synchronized override fun getAvailableProfileNames(): Array<String> = schemeManager.allSchemeNames.toTypedArray()
val projectProfile: String?
- get() = state.projectProfile
+ get() = schemeManager.currentSchemeName
- @Synchronized override fun setRootProfile(newProfile: String?) {
- if (newProfile == state.projectProfile) {
- return
- }
-
- val oldProfile = state.projectProfile
- state.projectProfile = newProfile
- state.useProjectProfile = newProfile != null
- oldProfile?.let {
- for (adapter in profileListeners) {
- adapter.profileActivated(getProfile(oldProfile), newProfile?.let { getProfile(it) })
- }
+ @Synchronized override fun setRootProfile(name: String?) {
+ if (name != schemeManager.currentSchemeName) {
+ schemeManager.currentSchemeName = name
+ state.useProjectProfile = name != null
}
}
return applicationProfileManager.currentProfile as InspectionProfileImpl
}
- val currentName = state.projectProfile
- if (currentName == null || schemeManager.isEmpty) {
- state.projectProfile = PROJECT_DEFAULT_PROFILE_NAME
- val projectProfile = InspectionProfileImpl(PROJECT_DEFAULT_PROFILE_NAME, InspectionToolRegistrar.getInstance(), this, InspectionProfileImpl.getDefaultProfile(), null)
- projectProfile.copyFrom(applicationProfileManager.currentProfile)
- projectProfile.isProjectLevel = true
- projectProfile.setName(PROJECT_DEFAULT_PROFILE_NAME)
- schemeManager.addScheme(projectProfile)
- return projectProfile
- }
-
- var profile = schemeManager.findSchemeByName(currentName)
- if (profile == null) {
- profile = schemeManager.allSchemes.get(0)!!
- state.projectProfile = profile.name
+ var currentScheme = schemeManager.currentScheme
+ if (currentScheme == null) {
+ currentScheme = schemeManager.allSchemes.firstOrNull()
+ if (currentScheme == null) {
+ currentScheme = InspectionProfileImpl(PROJECT_DEFAULT_PROFILE_NAME, InspectionToolRegistrar.getInstance(), this,
+ InspectionProfileImpl.getDefaultProfile(), null)
+ currentScheme.copyFrom(applicationProfileManager.currentProfile)
+ currentScheme.isProjectLevel = true
+ currentScheme.setName(PROJECT_DEFAULT_PROFILE_NAME)
+ schemeManager.addScheme(currentScheme)
+ }
+ schemeManager.setCurrent(currentScheme, false)
}
- return profile as InspectionProfileImpl
+ return currentScheme
}
private fun fireProfilesInitialized() {
processor.onSchemeDeleted(it)
}
- val newScheme = readSchemeFromFile(event.file, false)?.let {
+ updateCurrentScheme(oldCurrentScheme, readSchemeFromFile(event.file, false)?.let {
processor.initScheme(it)
processor.onSchemeAdded(it)
it
- }
-
- updateCurrentScheme(oldCurrentScheme, newScheme)
+ })
}
is VFileCreateEvent -> {
}
}
- private fun updateCurrentScheme(oldCurrentScheme: T?, newCurrentScheme: T? = null) {
+ private fun updateCurrentScheme(oldScheme: T?, newScheme: T? = null) {
if (currentScheme != null) {
return
}
- if (oldCurrentScheme != currentScheme) {
- @Suppress("UNCHECKED_CAST")
- setCurrent(newCurrentScheme ?: schemes.firstOrNull())
+ if (oldScheme != currentScheme) {
+ val scheme = newScheme ?: schemes.firstOrNull()
+ currentPendingSchemeName = null
+ currentScheme = scheme
+ // must be equals by reference
+ if (oldScheme !== scheme) {
+ processor.onCurrentSchemeSwitched(oldScheme, scheme)
+ }
}
- else if (newCurrentScheme != null) {
- processPendingCurrentSchemeName(newCurrentScheme)
+ else if (newScheme != null) {
+ processPendingCurrentSchemeName(newScheme)
}
}
}
schemes.addAll(newSchemes)
if (oldCurrentScheme != newCurrentScheme) {
+ val newScheme: T?
if (newCurrentScheme != null) {
currentScheme = newCurrentScheme
+ newScheme = newCurrentScheme
}
else if (oldCurrentScheme != null && !schemes.contains(oldCurrentScheme)) {
- currentScheme = schemes.firstOrNull()
+ newScheme = schemes.firstOrNull()
+ currentScheme = newScheme
+ }
+ else {
+ newScheme = null
}
- if (oldCurrentScheme != currentScheme) {
- processor.onCurrentSchemeChanged(oldCurrentScheme)
+ if (oldCurrentScheme != newScheme) {
+ processor.onCurrentSchemeSwitched(oldCurrentScheme, newScheme)
}
}
}
val oldCurrent = currentScheme
currentScheme = scheme
- if (notify && oldCurrent != scheme) {
- processor.onCurrentSchemeChanged(oldCurrent)
+ if (notify && oldCurrent !== scheme) {
+ processor.onCurrentSchemeSwitched(oldCurrent, scheme)
}
}
open fun onSchemeDeleted(scheme: MUTABLE_SCHEME) {
}
- /**
- * Scheme switched.
- */
- open fun onCurrentSchemeChanged(oldScheme: Scheme?) {
+ open fun onCurrentSchemeSwitched(oldScheme: SCHEME?, newScheme: SCHEME?) {
}
open fun getState(scheme: SCHEME): SchemeState = SchemeState.POSSIBLY_CHANGED
}
@Override
- public void profileActivated(Profile oldProfile, Profile profile) {
+ public void profileActivated(Profile oldProfile, @Nullable Profile profile) {
stopDaemonAndRestartAllFiles("Profile activated");
}
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
-import com.intellij.profile.codeInspection.ProjectInspectionProfileManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.ArrayUtil;
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@NotNull PsiFile file, @NotNull final Editor editor) {
TextRange textRange = calculateRangeToProcess(editor);
- if (textRange == null || !ProjectInspectionProfileManager.getInstanceImpl(file.getProject()).isCurrentProfileInitialized()){
+ if (textRange == null){
return new ProgressableTextEditorHighlightingPass.EmptyPass(myProject, editor.getDocument());
}
TextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
import com.intellij.profile.Profile;
import com.intellij.profile.ProfileChangeAdapter;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
-import com.intellij.profile.codeInspection.ProjectInspectionProfileManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
}
@Override
- public void profileActivated(Profile oldProfile, Profile profile) {
+ public void profileActivated(Profile oldProfile, @Nullable Profile profile) {
myFileToolsCache.clear();
}
};
return null; //optimization
}
- if (!ProjectInspectionProfileManager.getInstanceImpl(file.getProject()).isCurrentProfileInitialized() ||
- myFileToolsCache.containsKey(file) && !myFileToolsCache.get(file)) {
+ if (myFileToolsCache.containsKey(file) && !myFileToolsCache.get(file)) {
return null;
}
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.extensions.Extensions;
-import com.intellij.openapi.options.Scheme;
import com.intellij.openapi.options.SchemeManager;
import com.intellij.openapi.options.SchemeManagerFactory;
import com.intellij.openapi.project.Project;
SeverityProvider,
PersistentStateComponent<Element> {
private final InspectionToolRegistrar myRegistrar;
- private final SchemeManager<InspectionProfile> mySchemeManager;
+ private final SchemeManager<InspectionProfileImpl> mySchemeManager;
private final AtomicBoolean myProfilesAreInitialized = new AtomicBoolean(false);
public static ApplicationInspectionProfileManager getInstanceImpl() {
}
@Override
- public void onCurrentSchemeChanged(@Nullable Scheme oldScheme) {
- Profile current = mySchemeManager.getCurrentScheme();
- if (current != null) {
- fireProfileChanged((Profile)oldScheme, current);
+ public void onCurrentSchemeSwitched(@Nullable InspectionProfileImpl oldScheme, @Nullable InspectionProfileImpl newScheme) {
+ if (newScheme != null) {
+ fireProfileChanged(oldScheme, newScheme);
}
onProfilesChanged();
}
@NotNull
@Override
- protected SchemeManager<InspectionProfile> getSchemeManager() {
+ protected SchemeManager<InspectionProfileImpl> getSchemeManager() {
return mySchemeManager;
}
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.editor.colors.ex.DefaultColorSchemesManager;
import com.intellij.openapi.editor.markup.TextAttributes;
-import com.intellij.openapi.options.*;
+import com.intellij.openapi.options.BaseSchemeProcessor;
+import com.intellij.openapi.options.SchemeManager;
+import com.intellij.openapi.options.SchemeManagerFactory;
+import com.intellij.openapi.options.SchemeState;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.util.text.StringUtil;
}
@Override
- public void onCurrentSchemeChanged(@Nullable Scheme oldScheme) {
+ public void onCurrentSchemeSwitched(@Nullable EditorColorsScheme oldScheme, @Nullable EditorColorsScheme newScheme) {
LafManager.getInstance().updateUI();
schemeChangedOrSwitched();
- fireChanges(mySchemeManager.getCurrentScheme());
+ fireChanges(newScheme);
}
@NotNull
}
@Override
- public void onCurrentSchemeChanged(@Nullable Scheme oldScheme) {
- Keymap keymap = mySchemeManager.getCurrentScheme();
+ public void onCurrentSchemeSwitched(@Nullable Keymap oldScheme, @Nullable Keymap newScheme) {
for (KeymapManagerListener listener : myListeners) {
- listener.activeKeymapChanged(keymap);
+ listener.activeKeymapChanged(newScheme);
}
}
};
@NotNull final Project project,
@NotNull final Collection<String> disabledInspections,
@NotNull Disposable parentDisposable) {
- InspectionToolWrapper[] wrapped =
- ContainerUtil.map2Array(tools, InspectionToolWrapper.class, new Function<InspectionProfileEntry, InspectionToolWrapper>() {
- @Override
- public InspectionToolWrapper fun(InspectionProfileEntry tool) {
- return InspectionToolRegistrar.wrapTool(tool);
- }
- });
+ InspectionToolWrapper[] wrapped = ContainerUtil.map2Array(tools, InspectionToolWrapper.class, InspectionToolRegistrar::wrapTool);
final InspectionProfileImpl profile = InspectionProfileImpl.createSimple(LightPlatformTestCase.PROFILE, project, wrapped);
profile.disableToolByDefault(new ArrayList<String>(disabledInspections), project);
myProject = project;
final ProfileChangeAdapter profileChangeAdapter = new ProfileChangeAdapter() {
@Override
- public void profileActivated(Profile oldProfile, Profile profile) {
+ public void profileActivated(Profile oldProfile, @Nullable Profile profile) {
dropAnnotationsCache();
}