diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java index be7dee7d7199..2a4c24924f3a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java @@ -84,7 +84,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { } private static InspectionProfileImpl createProfile() { - return new InspectionProfileImpl(PROFILE, InspectionToolRegistrar.getInstance(), InspectionProfileImpl.getBaseProfile()); + return createProfile(InspectionProfileKt.getBASE_PROFILE()); } private static InspectionProfileImpl createProfile(@NotNull InspectionProfileImpl base) { @@ -100,8 +100,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { try { //normally on open project profile wrappers are init for both managers updateProfile(profileManager, localProfile); - InspectionProfileImpl profile = new InspectionProfileImpl(PROFILE, InspectionToolRegistrar.getInstance(), projectProfileManager, - InspectionProfileImpl.getBaseProfile(), null); + InspectionProfileImpl profile = new InspectionProfileImpl(PROFILE, InspectionToolRegistrar.getInstance(), projectProfileManager, null); updateProfile(projectProfileManager, profile); projectProfileManager.setRootProfile(profile.getName()); @@ -550,7 +549,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { } private static InspectionProfileImpl createProfile(@NotNull InspectionToolRegistrar registrar) { - InspectionProfileImpl base = new InspectionProfileImpl("Base", registrar); + InspectionProfileImpl base = new InspectionProfileImpl("Base", registrar, (InspectionProfileImpl)null); return new InspectionProfileImpl("Foo", registrar, base); } @@ -589,7 +588,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { } public void testDoNotInstantiateOnSave() throws Exception { - InspectionProfileImpl profile = new InspectionProfileImpl("profile", InspectionToolRegistrar.getInstance(), InspectionProfileImpl.getBaseProfile()); + InspectionProfileImpl profile = new InspectionProfileImpl("profile", InspectionToolRegistrar.getInstance(), InspectionProfileKt.getBASE_PROFILE()); assertEquals(0, countInitializedTools(profile)); InspectionToolWrapper[] toolWrappers = profile.getInspectionTools(null); assertTrue(toolWrappers.length > 0); diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionSchemeTest.kt b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionSchemeTest.kt index 752c2920558d..69a67666220e 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionSchemeTest.kt +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionSchemeTest.kt @@ -17,8 +17,9 @@ package com.intellij.codeInspection.ex import com.intellij.configurationStore.SchemeManagerFactoryBase import com.intellij.openapi.application.ApplicationManager -import com.intellij.testFramework.rules.InMemoryFsRule +import com.intellij.openapi.options.SchemeState import com.intellij.testFramework.ProjectRule +import com.intellij.testFramework.rules.InMemoryFsRule import com.intellij.testFramework.runInInitMode import com.intellij.util.io.readText import com.intellij.util.io.write @@ -53,12 +54,15 @@ class InspectionSchemeTest { assertThat(profileManager.profiles).hasSize(1) val scheme = profileManager.profiles.first() + assertThat(scheme.schemeState).isEqualTo(SchemeState.UNCHANGED) assertThat(scheme.name).isEqualTo("Bar") runInInitMode { scheme.initInspectionTools(null) } schemeManagerFactory.save() + assertThat(scheme.schemeState).isEqualTo(SchemeState.UNCHANGED) + assertThat(schemeFile.readText()).isEqualTo(schemeData) profileManager.profiles diff --git a/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfile.java b/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfile.java index d9968db36ede..2a05ae09933c 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfile.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfile.java @@ -75,8 +75,6 @@ public interface InspectionProfile extends Comparable { @NotNull InspectionToolWrapper[] getInspectionTools(@Nullable PsiElement element); - void cleanup(@NotNull Project project); - boolean isToolEnabled(@Nullable HighlightDisplayKey key, PsiElement element); boolean isToolEnabled(@Nullable HighlightDisplayKey key); @@ -84,7 +82,7 @@ public interface InspectionProfile extends Comparable { boolean isExecutable(Project project); /** - * @see {@link ModifiableModel#setSingleTool(String)} + * @see {@link InspectionProfileImpl#setSingleTool(String)} * * @return tool short name when inspection profile corresponds to synthetic profile for single inspection run */ @@ -94,8 +92,6 @@ public interface InspectionProfile extends Comparable { @NotNull String getDisplayName(); - void scopesChanged(); - @NotNull List getAllEnabledInspectionTools(Project project); } diff --git a/platform/analysis-api/src/com/intellij/codeInspection/ModifiableModel.java b/platform/analysis-api/src/com/intellij/codeInspection/ModifiableModel.java index 54181b862648..f12623fad0e2 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/ModifiableModel.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/ModifiableModel.java @@ -15,8 +15,6 @@ */ package com.intellij.codeInspection; -import com.intellij.codeHighlighting.HighlightDisplayLevel; -import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.search.scope.packageSet.NamedScope; @@ -26,13 +24,6 @@ import org.jetbrains.annotations.Nullable; public interface ModifiableModel extends InspectionProfile { void enableTool(@NotNull String inspectionTool, NamedScope namedScope, Project project); - void setErrorLevel(HighlightDisplayKey key, @NotNull HighlightDisplayLevel level, Project project); - - /** - * @see InspectionProfile#getSingleTool() - */ - void setSingleTool(@NotNull String toolShortName); - void disableTool(@NotNull String toolId, @NotNull PsiElement element); void disableTool(@NotNull String inspectionTool, @Nullable Project project); diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java index 0475043d95e9..1b0837a49172 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java @@ -329,7 +329,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G protected List getUsedTools() { InspectionProfileImpl profile = getCurrentProfile(); List tools = profile.getAllEnabledInspectionTools(myProject); - Set dependentTools = new LinkedHashSet<>(); + Set> dependentTools = new LinkedHashSet<>(); for (Tools tool : tools) { profile.collectDependentInspections(tool.getTool(), dependentTools, getProject()); } diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfile.kt b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfile.kt index daa91cf11a6e..969791048515 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfile.kt +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfile.kt @@ -19,14 +19,26 @@ import com.intellij.codeInspection.InspectionProfile import com.intellij.configurationStore.SerializableScheme import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.PathMacroManager +import com.intellij.openapi.options.SchemeState +import com.intellij.openapi.project.Project import com.intellij.profile.ProfileEx import com.intellij.profile.codeInspection.BaseInspectionProfileManager +import com.intellij.profile.codeInspection.InspectionProfileManager import com.intellij.profile.codeInspection.ProjectInspectionProfileManager import com.intellij.util.xmlb.annotations.Transient +const val DEFAULT_PROFILE_NAME = "Default" +val BASE_PROFILE by lazy { InspectionProfileImpl(DEFAULT_PROFILE_NAME) } + abstract class NewInspectionProfile(name: String, private var profileManager: BaseInspectionProfileManager) : ProfileEx(name), InspectionProfile, SerializableScheme { private var isProjectLevel: Boolean = false + @JvmField + @Transient + internal var schemeState: SchemeState? = null + + override fun getSchemeState() = schemeState + @Transient fun isProjectLevel() = isProjectLevel @@ -46,4 +58,18 @@ abstract class NewInspectionProfile(name: String, private var profileManager: Ba val profileManager = profileManager return PathMacroManager.getInstance((profileManager as? ProjectInspectionProfileManager)?.project ?: ApplicationManager.getApplication()) } + + override fun toString() = name + + override fun equals(other: Any?) = super.equals(other) && (other as NewInspectionProfile).profileManager === profileManager +} + +fun createSimple(name: String, project: Project, toolWrappers: List>): InspectionProfileImpl { + val profile = InspectionProfileImpl(name, object : InspectionToolRegistrar() { + override fun createTools() = toolWrappers + }, InspectionProfileManager.getInstance() as BaseInspectionProfileManager) + for (toolWrapper in toolWrappers) { + profile.enableTool(toolWrapper.shortName, project) + } + return profile } \ No newline at end of file diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java index 0595f94534aa..9140a1847240 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java @@ -23,9 +23,11 @@ import com.intellij.configurationStore.SchemeDataHolder; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.options.SchemeState; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.*; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.profile.codeInspection.BaseInspectionProfileManager; import com.intellij.profile.codeInspection.InspectionProfileManager; import com.intellij.profile.codeInspection.ProjectInspectionProfileManager; @@ -60,7 +62,6 @@ public class InspectionProfileImpl extends NewInspectionProfile { @NonNls private static final String VALID_VERSION = "1.0"; @NonNls private static final String VERSION_TAG = "version"; @NonNls private static final String USED_LEVELS = "used_levels"; - public static final String DEFAULT_PROFILE_NAME = "Default"; @TestOnly public static boolean INIT_INSPECTIONS = false; protected final InspectionToolRegistrar myRegistrar; @@ -70,7 +71,7 @@ public class InspectionProfileImpl extends NewInspectionProfile { @Attribute("is_locked") protected boolean myLockedProfile; protected final InspectionProfileImpl myBaseProfile; - private volatile String myToolShortName = null; + private volatile String myToolShortName; private String[] myScopesOrder; private String myDescription; private volatile boolean myInitialized; @@ -82,15 +83,11 @@ public class InspectionProfileImpl extends NewInspectionProfile { public InspectionProfileImpl(@NotNull String profileName, @NotNull InspectionToolRegistrar registrar, @NotNull BaseInspectionProfileManager profileManager) { - this(profileName, registrar, profileManager, getBaseProfile(), null); + this(profileName, registrar, profileManager, InspectionProfileKt.getBASE_PROFILE(), null); } - public InspectionProfileImpl(@NotNull @NonNls String profileName) { - this(profileName, InspectionToolRegistrar.getInstance()); - } - - public InspectionProfileImpl(@NotNull String profileName, @NotNull InspectionToolRegistrar registrar) { - this(profileName, registrar, (BaseInspectionProfileManager)InspectionProfileManager.getInstance(), null, null); + public InspectionProfileImpl(@NotNull String profileName) { + this(profileName, InspectionToolRegistrar.getInstance(), (BaseInspectionProfileManager)InspectionProfileManager.getInstance(), null, null); } public InspectionProfileImpl(@NotNull String profileName, @@ -109,30 +106,16 @@ public class InspectionProfileImpl extends NewInspectionProfile { myRegistrar = registrar; myBaseProfile = baseProfile; myDataHolder = dataHolder; + if (dataHolder != null) { + schemeState = SchemeState.UNCHANGED; + } } public InspectionProfileImpl(@NotNull String profileName, @NotNull InspectionToolRegistrar registrar, @NotNull BaseInspectionProfileManager profileManager, @Nullable SchemeDataHolder dataHolder) { - this(profileName, registrar, profileManager, getBaseProfile(), dataHolder); - } - - @NotNull - public static InspectionProfileImpl createSimple(@NotNull String name, - @NotNull Project project, - @NotNull List toolWrappers) { - InspectionProfileImpl profile = new InspectionProfileImpl(name, new InspectionToolRegistrar() { - @NotNull - @Override - public List createTools() { - return toolWrappers; - } - }, (BaseInspectionProfileManager)InspectionProfileManager.getInstance()); - for (InspectionToolWrapper toolWrapper : toolWrappers) { - profile.enableTool(toolWrapper.getShortName(), project); - } - return profile; + this(profileName, registrar, profileManager, InspectionProfileKt.getBASE_PROFILE(), dataHolder); } private static boolean toolSettingsAreEqual(@NotNull String toolName, @NotNull InspectionProfileImpl profile1, @NotNull InspectionProfileImpl profile2) { @@ -152,19 +135,6 @@ public class InspectionProfileImpl extends NewInspectionProfile { return inspectionTool; } - @NotNull - public static InspectionProfileImpl getBaseProfile() { - return InspectionProfileImplHolder.DEFAULT_PROFILE; - } - - public void resetToEmpty(Project project) { - initInspectionTools(project); - final InspectionToolWrapper[] profileEntries = getInspectionTools(null); - for (InspectionToolWrapper toolWrapper : profileEntries) { - disableTool(toolWrapper.getShortName(), project); - } - } - @Override public HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey inspectionToolKey, PsiElement element) { Project project = element == null ? null : element.getProject(); @@ -233,6 +203,11 @@ public class InspectionProfileImpl extends NewInspectionProfile { @Override @NotNull public Element writeScheme() { + return writeScheme(true); + } + + @NotNull + public Element writeScheme(boolean setSchemeStateToUnchanged) { if (myDataHolder != null) { return myDataHolder.read(); } @@ -244,6 +219,10 @@ public class InspectionProfileImpl extends NewInspectionProfile { if (isProjectLevel() && ProjectKt.isDirectoryBased(((ProjectInspectionProfileManager)getProfileManager()).getProject())) { return new Element("component").setAttribute("name", "InspectionProjectProfileManager").addContent(element); } + + if (setSchemeStateToUnchanged) { + schemeState = SchemeState.UNCHANGED; + } return element; } @@ -320,13 +299,12 @@ public class InspectionProfileImpl extends NewInspectionProfile { } public void collectDependentInspections(@NotNull InspectionToolWrapper toolWrapper, - @NotNull Set dependentEntries, + @NotNull Set> dependentEntries, Project project) { String mainToolId = toolWrapper.getMainToolId(); if (mainToolId != null) { InspectionToolWrapper dependentEntryWrapper = getInspectionTool(mainToolId, project); - if (dependentEntryWrapper == null) { LOG.error("Can't find main tool: '" + mainToolId+"' which was specified in "+toolWrapper); return; @@ -423,11 +401,15 @@ public class InspectionProfileImpl extends NewInspectionProfile { return getName(); } - @Override public void scopesChanged() { - for (ScopeToolState toolState : getAllTools(null)) { - toolState.scopesChanged(); + if (!myInitialized) { + return; } + + for (ToolsImpl tools : myTools.values()) { + tools.scopesChanged(); + } + getProfileManager().fireProfileChanged(this); } @@ -438,6 +420,7 @@ public class InspectionProfileImpl extends NewInspectionProfile { public void lockProfile(boolean isLocked) { myLockedProfile = isLocked; + schemeState = SchemeState.POSSIBLY_CHANGED; } @Override @@ -472,6 +455,7 @@ public class InspectionProfileImpl extends NewInspectionProfile { for (String toolId : toolIds) { getTools(toolId, project).setDefaultEnabled(false); } + schemeState = SchemeState.POSSIBLY_CHANGED; } @NotNull @@ -483,6 +467,7 @@ public class InspectionProfileImpl extends NewInspectionProfile { for (final String toolId : toolIds) { getTools(toolId, project).setDefaultEnabled(true); } + schemeState = SchemeState.POSSIBLY_CHANGED; } public boolean wasInitialized() { @@ -645,6 +630,7 @@ public class InspectionProfileImpl extends NewInspectionProfile { public void setScopesOrder(String[] scopesOrder) { myScopesOrder = scopesOrder; + schemeState = SchemeState.POSSIBLY_CHANGED; } private HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key, @Nullable Project project) { @@ -659,7 +645,6 @@ public class InspectionProfileImpl extends NewInspectionProfile { return new InspectionProfileModifiableModel(this); } - @Override public void cleanup(@NotNull Project project) { if (!myInitialized) { return; @@ -678,10 +663,12 @@ public class InspectionProfileImpl extends NewInspectionProfile { if (tools.getNonDefaultTools() == null) { tools.getDefaultState().setEnabled(true); } + schemeState = SchemeState.POSSIBLY_CHANGED; } public void enableTool(@NotNull String inspectionTool, NamedScope namedScope, Project project) { getTools(inspectionTool, project).enableTool(namedScope, project); + schemeState = SchemeState.POSSIBLY_CHANGED; } public void enableTools(@NotNull List inspectionTools, NamedScope namedScope, Project project) { @@ -694,6 +681,7 @@ public class InspectionProfileImpl extends NewInspectionProfile { for (String inspectionTool : inspectionTools) { getTools(inspectionTool, project).disableTool(namedScope, project); } + schemeState = SchemeState.POSSIBLY_CHANGED; } public void disableTool(@NotNull String inspectionTool, @Nullable Project project) { @@ -702,10 +690,12 @@ public class InspectionProfileImpl extends NewInspectionProfile { if (tools.getNonDefaultTools() == null) { tools.getDefaultState().setEnabled(false); } + schemeState = SchemeState.POSSIBLY_CHANGED; } public void setErrorLevel(@NotNull HighlightDisplayKey key, @NotNull HighlightDisplayLevel level, Project project) { getTools(key.toString(), project).setLevel(level); + schemeState = SchemeState.POSSIBLY_CHANGED; } @Override @@ -736,8 +726,9 @@ public class InspectionProfileImpl extends NewInspectionProfile { return myDescription; } - public void setDescription(String description) { - myDescription = description; + public void setDescription(@Nullable String description) { + myDescription = StringUtil.nullize(description); + schemeState = SchemeState.POSSIBLY_CHANGED; } public void convert(@NotNull Element element, @NotNull Project project) { @@ -830,6 +821,7 @@ public class InspectionProfileImpl extends NewInspectionProfile { public void removeScope(@NotNull String toolId, @NotNull String scopeName, Project project) { getTools(toolId, project).removeScope(scopeName); + schemeState = SchemeState.POSSIBLY_CHANGED; } public void removeScopes(@NotNull List toolIds, @NotNull String scopeName, Project project) { @@ -865,6 +857,7 @@ public class InspectionProfileImpl extends NewInspectionProfile { public void profileChanged() { myChangedToolNames = null; + schemeState = SchemeState.POSSIBLY_CHANGED; } @NotNull @@ -884,6 +877,7 @@ public class InspectionProfileImpl extends NewInspectionProfile { public void setErrorLevel(@NotNull HighlightDisplayKey key, @NotNull HighlightDisplayLevel level, String scopeName, Project project) { getTools(key.toString(), project).setLevel(level, scopeName, project); + schemeState = SchemeState.POSSIBLY_CHANGED; } public void setErrorLevel(@NotNull List keys, @NotNull HighlightDisplayLevel level, String scopeName, Project project) { @@ -902,19 +896,4 @@ public class InspectionProfileImpl extends NewInspectionProfile { enableTool(entry.getShortName(), project); } } - - @Override - @NotNull - public String toString() { - return getName(); - } - - @Override - public boolean equals(Object o) { - return super.equals(o) && ((InspectionProfileImpl)o).getProfileManager() == getProfileManager(); - } - - private static class InspectionProfileImplHolder { - private static final InspectionProfileImpl DEFAULT_PROFILE = new InspectionProfileImpl(DEFAULT_PROFILE_NAME); - } } diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileModifiableModel.kt b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileModifiableModel.kt index 3b9cbb2f9dae..d048a06aa6df 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileModifiableModel.kt +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileModifiableModel.kt @@ -98,6 +98,13 @@ open class InspectionProfileModifiableModel(val source: InspectionProfileImpl) : modified = false } + fun resetToEmpty(project: Project) { + initInspectionTools(project) + for (toolWrapper in getInspectionTools(null)) { + disableTool(toolWrapper.shortName, project) + } + } + private fun InspectionProfileImpl.commit(model: InspectionProfileImpl) { name = model.name description = model.description diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapper.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapper.java index c4352c1c6be1..0212a8cf962b 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapper.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapper.java @@ -20,7 +20,6 @@ import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.psi.PsiElement; import gnu.trove.THashSet; @@ -81,10 +80,6 @@ public class InspectionProfileWrapper { return myProfile.getInspectionTool(shortName, element); } - public void cleanup(@NotNull Project project) { - myProfile.cleanup(project); - } - @NotNull public InspectionProfileImpl getInspectionProfile() { return myProfile; diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java index e3c5b24204ef..48abc015ce7e 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java @@ -134,6 +134,15 @@ public class ToolsImpl implements Tools { } } + public void scopesChanged() { + if (myTools != null) { + for (ScopeToolState tool : myTools) { + tool.scopesChanged(); + } + } + myDefaultState.scopesChanged(); + } + public void writeExternal(@NotNull Element inspectionElement) { if (myTools != null) { for (ScopeToolState state : myTools) { diff --git a/platform/analysis-impl/src/com/intellij/profile/codeInspection/BaseInspectionProfileManager.kt b/platform/analysis-impl/src/com/intellij/profile/codeInspection/BaseInspectionProfileManager.kt index a17c5301a851..1a4126dc26ce 100644 --- a/platform/analysis-impl/src/com/intellij/profile/codeInspection/BaseInspectionProfileManager.kt +++ b/platform/analysis-impl/src/com/intellij/profile/codeInspection/BaseInspectionProfileManager.kt @@ -16,7 +16,6 @@ package com.intellij.profile.codeInspection import com.intellij.codeInsight.daemon.impl.SeverityRegistrar -import com.intellij.codeInspection.InspectionProfile import com.intellij.codeInspection.ex.InspectionProfileImpl import com.intellij.configurationStore.LazySchemeProcessor import com.intellij.openapi.diagnostic.Logger @@ -59,7 +58,7 @@ abstract class BaseInspectionProfileManager(messageBus: MessageBus) : Inspectio } } - open protected fun schemeRemoved(scheme: InspectionProfile) { + open protected fun schemeRemoved(scheme: InspectionProfileImpl) { } abstract fun fireProfileChanged(profile: InspectionProfileImpl) diff --git a/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt b/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt index 76a230b7d532..025cef72ada2 100644 --- a/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt +++ b/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt @@ -98,8 +98,7 @@ class ProjectInspectionProfileManager(val project: Project, name: String, attributeProvider: Function, isBundled: Boolean): InspectionProfileImpl { - val profile = InspectionProfileImpl(name, InspectionToolRegistrar.getInstance(), this@ProjectInspectionProfileManager, - InspectionProfileImpl.getBaseProfile(), dataHolder) + val profile = InspectionProfileImpl(name, InspectionToolRegistrar.getInstance(), this@ProjectInspectionProfileManager, dataHolder) profile.isProjectLevel = true return profile } @@ -165,7 +164,7 @@ class ProjectInspectionProfileManager(val project: Project, fun isCurrentProfileInitialized() = currentProfile.wasInitialized() - override fun schemeRemoved(scheme: InspectionProfile) { + override fun schemeRemoved(scheme: InspectionProfileImpl) { scheme.cleanup(project) } @@ -293,8 +292,7 @@ class ProjectInspectionProfileManager(val project: Project, if (currentScheme == null) { currentScheme = schemeManager.allSchemes.firstOrNull() if (currentScheme == null) { - currentScheme = InspectionProfileImpl(PROJECT_DEFAULT_PROFILE_NAME, InspectionToolRegistrar.getInstance(), this, - InspectionProfileImpl.getBaseProfile(), null) + currentScheme = InspectionProfileImpl(PROJECT_DEFAULT_PROFILE_NAME, InspectionToolRegistrar.getInstance(), this) currentScheme.copyFrom(applicationProfileManager.currentProfile) currentScheme.isProjectLevel = true currentScheme.name = PROJECT_DEFAULT_PROFILE_NAME diff --git a/platform/configuration-store-impl/src/SchemeManagerImpl.kt b/platform/configuration-store-impl/src/SchemeManagerImpl.kt index 82d8c1d787a0..c93dd0de68de 100644 --- a/platform/configuration-store-impl/src/SchemeManagerImpl.kt +++ b/platform/configuration-store-impl/src/SchemeManagerImpl.kt @@ -342,7 +342,7 @@ class SchemeManagerImpl(val fileSpec: String, // todo check is bundled/read-only schemes correctly handled val iterator = schemes.iterator() for (scheme in iterator) { - if (processor.getState(scheme) == SchemeState.NON_PERSISTENT) { + if ((scheme as? SerializableScheme)?.schemeState ?: processor.getState(scheme) == SchemeState.NON_PERSISTENT) { continue } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/DaemonCodeAnalyzerSettingsImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/DaemonCodeAnalyzerSettingsImpl.java index 0f42f4d8b3de..44eb143c535b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/DaemonCodeAnalyzerSettingsImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/DaemonCodeAnalyzerSettingsImpl.java @@ -17,6 +17,7 @@ package com.intellij.codeInsight.daemon; import com.intellij.codeInspection.ex.ApplicationInspectionProfileManager; import com.intellij.codeInspection.ex.InspectionProfileImpl; +import com.intellij.codeInspection.ex.InspectionProfileKt; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; @@ -51,7 +52,7 @@ public class DaemonCodeAnalyzerSettingsImpl extends DaemonCodeAnalyzerSettings i public Element getState() { Element element = XmlSerializer.serialize(this, new SkipDefaultsSerializationFilter()); String profile = ApplicationInspectionProfileManager.getInstanceImpl().getRootProfileName(); - if (!InspectionProfileImpl.DEFAULT_PROFILE_NAME.equals(profile)) { + if (!InspectionProfileKt.DEFAULT_PROFILE_NAME.equals(profile)) { element.setAttribute("profile", profile); } return element; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java index b850e842f5a9..b4c9c7fb8ced 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java @@ -508,22 +508,19 @@ public class DaemonListeners implements Disposable { @Override public void profilesInitialized() { - inspectionProfilesInitialized(); + UIUtil.invokeLaterIfNeeded(() -> { + if (myProject.isDisposed()) return; + StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject); + myTogglePopupHintsPanel = new TogglePopupHintsPanel(myProject); + statusBar.addWidget(myTogglePopupHintsPanel, myProject); + updateStatusBar(); + + stopDaemonAndRestartAllFiles("Inspection profiles activated"); + }); } } private TogglePopupHintsPanel myTogglePopupHintsPanel; - private void inspectionProfilesInitialized() { - UIUtil.invokeLaterIfNeeded(() -> { - if (myProject.isDisposed()) return; - StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject); - myTogglePopupHintsPanel = new TogglePopupHintsPanel(myProject); - statusBar.addWidget(myTogglePopupHintsPanel, myProject); - updateStatusBar(); - - stopDaemonAndRestartAllFiles("Inspection profiles activated"); - }); - } public void updateStatusBar() { if (myTogglePopupHintsPanel != null) myTogglePopupHintsPanel.updateStatus(); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionIntention.java b/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionIntention.java index a5d3d175d5d8..a86981af0762 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionIntention.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionIntention.java @@ -136,12 +136,11 @@ public class RunInspectionIntention implements IntentionAction, HighPriorityActi @NotNull InspectionManagerEx managerEx, @Nullable PsiElement psiElement) { InspectionProfileImpl rootProfile = InspectionProfileManager.getInstance().getCurrentProfile(); - LinkedHashSet allWrappers = new LinkedHashSet<>(); + LinkedHashSet> allWrappers = new LinkedHashSet<>(); allWrappers.add(toolWrapper); rootProfile.collectDependentInspections(toolWrapper, allWrappers, managerEx.getProject()); - List toolWrappers = allWrappers.size() == 1 ? Collections.singletonList(allWrappers.iterator().next()) : new ArrayList<>(allWrappers); - InspectionProfileImpl model = InspectionProfileImpl.createSimple(toolWrapper.getDisplayName(), managerEx.getProject(), - toolWrappers); + List> toolWrappers = allWrappers.size() == 1 ? Collections.singletonList(allWrappers.iterator().next()) : new ArrayList<>(allWrappers); + InspectionProfileImpl model = InspectionProfileKt.createSimple(toolWrapper.getDisplayName(), managerEx.getProject(), toolWrappers); try { Element element = new Element("toCopy"); for (InspectionToolWrapper wrapper : toolWrappers) { diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/ApplicationInspectionProfileManager.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/ApplicationInspectionProfileManager.java index b2e179be8374..1a1cd66847d9 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/ApplicationInspectionProfileManager.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/ApplicationInspectionProfileManager.java @@ -21,7 +21,6 @@ import com.intellij.codeInsight.daemon.impl.DaemonListeners; import com.intellij.codeInsight.daemon.impl.HighlightInfoType; import com.intellij.codeInsight.daemon.impl.SeveritiesProvider; import com.intellij.codeInsight.daemon.impl.SeverityRegistrar; -import com.intellij.codeInsight.daemon.impl.analysis.HighlightingSettingsPerFile; import com.intellij.codeInspection.InspectionsBundle; import com.intellij.configurationStore.BundledSchemeEP; import com.intellij.configurationStore.SchemeDataHolder; @@ -41,9 +40,9 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.ui.Messages; import com.intellij.profile.codeInspection.*; +import com.intellij.ui.AppUIUtil; import com.intellij.util.ObjectUtils; import com.intellij.util.messages.MessageBus; -import com.intellij.util.ui.UIUtil; import org.jdom.Element; import org.jdom.JDOMException; import org.jetbrains.annotations.NotNull; @@ -118,11 +117,6 @@ public class ApplicationInspectionProfileManager extends BaseInspectionProfileMa return mySchemeManager; } - @NotNull - private InspectionProfileImpl createSampleProfile(@NotNull String name, InspectionProfileImpl baseProfile) { - return new InspectionProfileImpl(name, InspectionToolRegistrar.getInstance(), this, baseProfile, null); - } - // It should be public to be available from Upsource public static void registerProvidedSeverities() { for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) { @@ -159,7 +153,7 @@ public class ApplicationInspectionProfileManager extends BaseInspectionProfileMa mySchemeManager.loadSchemes(); if (mySchemeManager.isEmpty()) { - mySchemeManager.addScheme(createSampleProfile(InspectionProfileImpl.DEFAULT_PROFILE_NAME, InspectionProfileImpl.getBaseProfile())); + mySchemeManager.addScheme(new InspectionProfileImpl(InspectionProfileKt.DEFAULT_PROFILE_NAME, InspectionToolRegistrar.getInstance(), this)); } } @@ -239,16 +233,16 @@ public class ApplicationInspectionProfileManager extends BaseInspectionProfileMa } // use default as base, not random custom profile - InspectionProfileImpl result = mySchemeManager.findSchemeByName(InspectionProfileImpl.DEFAULT_PROFILE_NAME); + InspectionProfileImpl result = mySchemeManager.findSchemeByName(InspectionProfileKt.DEFAULT_PROFILE_NAME); if (result == null) { - return createSampleProfile(InspectionProfileImpl.DEFAULT_PROFILE_NAME, null); + return new InspectionProfileImpl(InspectionProfileKt.DEFAULT_PROFILE_NAME, InspectionToolRegistrar.getInstance(), this, null, null); } return result; } @NotNull public String getRootProfileName() { - return ObjectUtils.chooseNotNull(mySchemeManager.getCurrentSchemeName(), InspectionProfileImpl.DEFAULT_PROFILE_NAME); + return ObjectUtils.chooseNotNull(mySchemeManager.getCurrentSchemeName(), InspectionProfileKt.DEFAULT_PROFILE_NAME); } @Override @@ -261,17 +255,8 @@ public class ApplicationInspectionProfileManager extends BaseInspectionProfileMa } public static void onProfilesChanged() { - //cleanup caches blindly for all projects in case ide profile was modified - for (final Project project : ProjectManager.getInstance().getOpenProjects()) { - //noinspection EmptySynchronizedStatement - synchronized (HighlightingSettingsPerFile.getInstance(project)) { - } - - UIUtil.invokeLaterIfNeeded(() -> { - if (!project.isDisposed()) { - DaemonListeners.getInstance(project).updateStatusBar(); - } - }); + for (Project project : ProjectManager.getInstance().getOpenProjects()) { + AppUIUtil.invokeLaterIfProjectAlive(project, () -> DaemonListeners.getInstance(project).updateStatusBar()); } } } diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java index 1098b26cd45f..ca3fd0737f29 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java @@ -366,7 +366,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable LOG.assertTrue(panel != null); InspectionProfileImpl profile = getSelectedObject(); LOG.assertTrue(true); - Element element = profile.writeScheme(); + Element element = profile.writeScheme(false); File file = new File(FileUtil.toSystemDependentName(dir.getPath()), sanitizeFileName(profile.getName()) + ".xml"); if (file.isFile() && Messages.showOkCancelDialog(wholePanel, "File \'" + file + "\' already exist. Do you want to overwrite it?", "Warning", diff --git a/platform/testFramework/src/com/intellij/testFramework/inspections.kt b/platform/testFramework/src/com/intellij/testFramework/inspections.kt index 1cb636669136..1c9ce96c12d5 100644 --- a/platform/testFramework/src/com/intellij/testFramework/inspections.kt +++ b/platform/testFramework/src/com/intellij/testFramework/inspections.kt @@ -26,6 +26,7 @@ import com.intellij.openapi.util.Disposer import com.intellij.profile.codeInspection.ProjectInspectionProfileManager import com.intellij.testFramework.fixtures.impl.GlobalInspectionContextForTests import com.intellij.util.ReflectionUtil +import com.intellij.util.containers.mapSmart import gnu.trove.THashMap import org.jetbrains.annotations.TestOnly import java.util.* @@ -34,13 +35,13 @@ fun configureInspections(tools: Array, project: Project, parentDisposable: Disposable): InspectionProfileImpl { runInInitMode { - val profile = InspectionProfileImpl.createSimple(UUID.randomUUID().toString(), project, tools.map { InspectionToolRegistrar.wrapTool(it) }) + val profile = createSimple(UUID.randomUUID().toString(), project, tools.mapSmart { InspectionToolRegistrar.wrapTool(it) }) val profileManager = ProjectInspectionProfileManager.getInstance(project) // we don't restore old project profile because in tests it must be in any case null - app default profile Disposer.register(parentDisposable, Disposable { profileManager.deleteProfile(profile) profileManager.setCurrentProfile(null) - clearAllToolsIn(InspectionProfileImpl.getBaseProfile()) + clearAllToolsIn(BASE_PROFILE) }) profileManager.addProfile(profile) @@ -56,7 +57,7 @@ fun createGlobalContextForTool(scope: AnalysisScope, project: Project, toolWrappers: List> = emptyList()): GlobalInspectionContextForTests { runInInitMode { - val profile = InspectionProfileImpl.createSimple("test", project, toolWrappers) + val profile = createSimple("test", project, toolWrappers) val context = object : GlobalInspectionContextForTests(project, (InspectionManagerEx.getInstance(project) as InspectionManagerEx).contentManager) { override fun getUsedTools(): List { for (tool in toolWrappers) { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/SuppressForTestsScopeFix.java b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/SuppressForTestsScopeFix.java index 557d3ecee7c1..92c66bfe3c6e 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/SuppressForTestsScopeFix.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/SuppressForTestsScopeFix.java @@ -84,8 +84,7 @@ public class SuppressForTestsScopeFix extends InspectionGadgetsFix { } private void addRemoveTestsScope(Project project, boolean add) { - final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(project); - final InspectionProfileImpl profile = profileManager.getCurrentProfile(); + final InspectionProfileImpl profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile(); final String shortName = myInspection.getShortName(); final InspectionToolWrapper tool = profile.getInspectionTool(shortName, project); if (tool == null) {