diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/GlobalInspectionContextTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/GlobalInspectionContextTest.java index 21b7de17de96..c7bb69e76b93 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/GlobalInspectionContextTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/GlobalInspectionContextTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,20 +23,17 @@ import com.intellij.codeInspection.ex.*; import com.intellij.codeInspection.ui.InspectionToolPresentation; import com.intellij.codeInspection.visibility.VisibilityInspection; import com.intellij.psi.PsiFile; +import com.intellij.testFramework.InspectionsKt; import com.intellij.util.ui.UIUtil; import java.util.ArrayList; import java.util.Arrays; -/** - * @author Dmitry Avdeev - * Date: 5/24/12 - */ public class GlobalInspectionContextTest extends CodeInsightTestCase { public void testProblemDuplication() throws Exception { String shortName = new VisibilityInspection().getShortName(); InspectionProfileImpl profile = new InspectionProfileImpl("Foo"); - ProjectInspectionManagerTestKt.disableAllTools(profile, getProject()); + InspectionsKt.disableAllTools(profile); profile.enableTool(shortName, getProject()); GlobalInspectionContextImpl context = ((InspectionManagerEx)InspectionManager.getInstance(getProject())).createNewGlobalContext(false); 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 0f52e4b60871..37f8c5b264ea 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java @@ -28,6 +28,7 @@ import com.intellij.profile.codeInspection.InspectionProfileManager; import com.intellij.profile.codeInspection.ProjectInspectionProfileManager; import com.intellij.profile.codeInspection.ui.header.InspectionProfileSchemesPanel; import com.intellij.psi.PsiModifier; +import com.intellij.testFramework.InspectionsKt; import com.intellij.testFramework.LightIdeaTestCase; import com.intellij.util.JdomKt; import com.intellij.util.SmartList; @@ -43,10 +44,6 @@ import java.util.function.Supplier; import static com.intellij.testFramework.assertions.Assertions.assertThat; -/** - * @author Anna.Kozlova - * Date: 18-Aug-2006 - */ public class InspectionProfileTest extends LightIdeaTestCase { private static final String PROFILE = "ToConvert"; @@ -549,7 +546,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { public void testGlobalInspectionContext() throws Exception { InspectionProfileImpl profile = new InspectionProfileImpl("Foo"); - ProjectInspectionManagerTestKt.disableAllTools(profile, getProject()); + InspectionsKt.disableAllTools(profile); profile.enableTool(new UnusedDeclarationInspectionBase(true).getShortName(), getProject()); GlobalInspectionContextImpl context = ((InspectionManagerEx)InspectionManager.getInstance(getProject())).createNewGlobalContext(false); @@ -590,13 +587,8 @@ public class InspectionProfileTest extends LightIdeaTestCase { assertNotNull(toolWrapper); String id = toolWrapper.getShortName(); System.out.println(id); - if (profile.isToolEnabled(HighlightDisplayKey.findById(id))) { - profile.disableTool(id, getProject()); - } - else { - profile.enableTool(id, getProject()); - } - assertEquals(0, countInitializedTools(profile)); + profile.setToolEnabled(id, !profile.isToolEnabled(HighlightDisplayKey.findById(id))); + assertThat(countInitializedTools(profile)).isEqualTo(0); profile.writeScheme(); List initializedTools = getInitializedTools(profile); if (initializedTools.size() > 0) { @@ -653,6 +645,5 @@ public class InspectionProfileTest extends LightIdeaTestCase { @SuppressWarnings("InspectionDescriptionNotFoundInspection") public static class TestTool extends LocalInspectionTool { - } } diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ex/ProjectInspectionManagerTest.kt b/java/java-tests/testSrc/com/intellij/codeInspection/ex/ProjectInspectionManagerTest.kt index 44274146a2a8..6f575c97f8c3 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ex/ProjectInspectionManagerTest.kt +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ex/ProjectInspectionManagerTest.kt @@ -19,7 +19,6 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel import com.intellij.configurationStore.PROJECT_CONFIG_DIR import com.intellij.configurationStore.StoreAwareProjectManager import com.intellij.ide.highlighter.ProjectFileType -import com.intellij.openapi.project.Project import com.intellij.openapi.project.ProjectManager import com.intellij.profile.codeInspection.ProjectInspectionProfileManager import com.intellij.project.stateStore @@ -129,7 +128,7 @@ class ProjectInspectionManagerTest { // cause to use app profile val currentProfile = projectInspectionProfileManager.currentProfile assertThat(currentProfile.isProjectLevel).isTrue() - currentProfile.disableTool("Convert2Diamond", project) + currentProfile.setToolEnabled("Convert2Diamond", false) project.saveStore() @@ -175,7 +174,7 @@ class ProjectInspectionManagerTest { val currentProfile = projectInspectionProfileManager.currentProfile assertThat(currentProfile.isProjectLevel).isTrue() - currentProfile.disableTool("Convert2Diamond", project) + currentProfile.setToolEnabled("Convert2Diamond", false) currentProfile.profileChanged() project.saveStore() @@ -196,17 +195,11 @@ class ProjectInspectionManagerTest { """.trimIndent() assertThat(projectFile.readText()).isEqualTo(expected) - currentProfile.disableAllTools(project) + currentProfile.disableAllTools() currentProfile.profileChanged() project.saveStore() assertThat(projectFile.readText()).isNotEqualTo(expected) assertThat(projectFile.parent.resolve(".inspectionProfiles")).doesNotExist() } } -} - -fun InspectionProfileImpl.disableAllTools(project: Project?) { - for (entry in getInspectionTools(null)) { - disableTool(entry.shortName, project) - } } \ No newline at end of file diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java index 0913d54f14f7..628faa89a311 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java @@ -152,7 +152,7 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase { protected void disableInspectionTool(@NotNull String shortName){ InspectionProfileImpl profile = InspectionProjectProfileManager.getInstance(getProject()).getCurrentProfile(); if (profile.getInspectionTool(shortName, getProject()) != null) { - profile.disableTool(shortName, getProject()); + profile.setToolEnabled(shortName, false); } } diff --git a/platform/analysis-api/src/com/intellij/codeInspection/ModifiableModel.java b/platform/analysis-api/src/com/intellij/codeInspection/ModifiableModel.java deleted file mode 100644 index 2ed7044d5a54..000000000000 --- a/platform/analysis-api/src/com/intellij/codeInspection/ModifiableModel.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.codeInspection; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiElement; -import com.intellij.psi.search.scope.packageSet.NamedScope; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public interface ModifiableModel extends InspectionProfile { - void enableTool(@NotNull String toolShortName, NamedScope namedScope, Project project); - - void disableTool(@NotNull String toolShortName, @NotNull PsiElement element); - - void disableTool(@NotNull String toolShortName, @Nullable Project project); -} 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 6fb80c43346c..165028a02d5e 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java @@ -52,13 +52,10 @@ import org.jetbrains.annotations.TestOnly; import java.util.*; import java.util.function.Supplier; -/** - * @author max - */ public class InspectionProfileImpl extends NewInspectionProfile { @NonNls static final String INSPECTION_TOOL_TAG = "inspection_tool"; @NonNls static final String CLASS_TAG = "class"; - protected static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionProfileImpl"); + protected static final Logger LOG = Logger.getInstance(InspectionProfileImpl.class); @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"; @@ -144,6 +141,7 @@ public class InspectionProfileImpl extends NewInspectionProfile { return level; } + @Override public void readExternal(@NotNull Element element) { mySerializer.readExternal(this, element); @@ -447,10 +445,6 @@ public class InspectionProfileImpl extends NewInspectionProfile { return result; } - public void disableTool(@NotNull String toolShortName, @NotNull PsiElement element) { - getTools(toolShortName, element.getProject()).disableTool(element); - } - public void disableToolByDefault(@NotNull Collection toolShortNames, @Nullable Project project) { for (String toolId : toolShortNames) { getTools(toolId, project).setDefaultEnabled(false); @@ -662,11 +656,6 @@ public class InspectionProfileImpl extends NewInspectionProfile { schemeState = SchemeState.POSSIBLY_CHANGED; } - @Deprecated - public void disableTool(@NotNull String inspectionTool, @Nullable Project project) { - setToolEnabled(inspectionTool, false, project); - } - public void setErrorLevel(@NotNull HighlightDisplayKey key, @NotNull HighlightDisplayLevel level, Project project) { getTools(key.toString(), project).setLevel(level); schemeState = SchemeState.POSSIBLY_CHANGED; 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 8fcedf1fe3d8..528d2ce83077 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileModifiableModel.kt +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileModifiableModel.kt @@ -15,14 +15,14 @@ */ package com.intellij.codeInspection.ex -import com.intellij.codeInspection.ModifiableModel import com.intellij.openapi.project.Project import com.intellij.openapi.util.InvalidDataException import com.intellij.openapi.util.WriteExternalException import com.intellij.profile.codeInspection.ProjectInspectionProfileManager +import com.intellij.psi.PsiElement import com.intellij.util.Consumer -open class InspectionProfileModifiableModel(val source: InspectionProfileImpl) : InspectionProfileImpl(source.name, source.myToolSupplier, source.profileManager, source.myBaseProfile, null), ModifiableModel { +open class InspectionProfileModifiableModel(val source: InspectionProfileImpl) : InspectionProfileImpl(source.name, source.myToolSupplier, source.profileManager, source.myBaseProfile, null) { private var modified = false init { @@ -114,10 +114,14 @@ open class InspectionProfileModifiableModel(val source: InspectionProfileImpl) : profileManager = model.profileManager } + fun disableTool(toolShortName: String, element: PsiElement) { + getTools(toolShortName, element.project).disableTool(element) + } + override fun toString() = "$name (copy)" } -fun modifyAndCommitProjectProfile(project: Project, action: Consumer) { +fun modifyAndCommitProjectProfile(project: Project, action: Consumer) { ProjectInspectionProfileManager.getInstance(project).currentProfile.edit { action.consume(this) } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/KeyAwareInspectionViewAction.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/KeyAwareInspectionViewAction.java index e2727dd97c1d..65e975b65a1a 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/KeyAwareInspectionViewAction.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/actions/KeyAwareInspectionViewAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,7 +85,7 @@ public abstract class KeyAwareInspectionViewAction extends InspectionViewActionB @Override protected void actionPerformed(@NotNull InspectionResultsView view, @NotNull HighlightDisplayKey key) { if (view.isSingleInspectionRun()) { - view.getCurrentProfile().modifyProfile(it -> it.disableTool(key.toString(), view.getProject())); + view.getCurrentProfile().modifyProfile(it -> it.setToolEnabled(key.toString(), false)); view.updateCurrentProfile(); } else { diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/InspectionsConfigTreeTable.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/InspectionsConfigTreeTable.java index 9b973a642c69..768508a9fea2 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/InspectionsConfigTreeTable.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/inspectionsTree/InspectionsConfigTreeTable.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -244,12 +244,7 @@ public class InspectionsConfigTreeTable extends TreeTable { @NotNull InspectionProfileImpl profile, @NotNull String toolId, @NotNull Project project) { - if (newState) { - profile.enableTool(toolId, project); - } - else { - profile.disableTool(toolId, project); - } + profile.setToolEnabled(toolId, newState); for (ScopeToolState scopeToolState : profile.getTools(toolId, project).getTools()) { scopeToolState.setEnabled(newState); } diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 61d44519186d..104418041f87 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -39,7 +39,6 @@ import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.codeInspection.InspectionToolProvider; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.ex.InspectionManagerEx; -import com.intellij.codeInspection.ex.InspectionProfileImpl; import com.intellij.codeInspection.ex.InspectionToolWrapper; import com.intellij.facet.Facet; import com.intellij.facet.FacetManager; @@ -96,7 +95,6 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.readOnlyHandler.ReadonlyStatusHandlerImpl; import com.intellij.openapi.vfs.*; -import com.intellij.profile.codeInspection.InspectionProjectProfileManager; import com.intellij.psi.*; import com.intellij.psi.impl.DebugUtil; import com.intellij.psi.impl.PsiManagerEx; @@ -368,10 +366,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @Override public void disableInspections(@NotNull InspectionProfileEntry... inspections) { - InspectionProfileImpl profile = InspectionProjectProfileManager.getInstance(getProject()).getCurrentProfile(); - for (InspectionProfileEntry inspection : inspections) { - profile.disableTool(inspection.getShortName(), getProject()); - } + InspectionsKt.disableInspections(getProject(), inspections); } @Override diff --git a/platform/testFramework/src/com/intellij/testFramework/inspections.kt b/platform/testFramework/src/com/intellij/testFramework/inspections.kt index 21a93c46fb01..ae3530e07273 100644 --- a/platform/testFramework/src/com/intellij/testFramework/inspections.kt +++ b/platform/testFramework/src/com/intellij/testFramework/inspections.kt @@ -23,6 +23,7 @@ import com.intellij.codeInspection.ex.* import com.intellij.openapi.Disposable import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer +import com.intellij.profile.codeInspection.InspectionProjectProfileManager import com.intellij.profile.codeInspection.ProjectInspectionProfileManager import com.intellij.testFramework.fixtures.impl.GlobalInspectionContextForTests import com.intellij.util.ReflectionUtil @@ -112,7 +113,7 @@ fun enableInspectionTool(project: Project, toolWrapper: InspectionToolWrapper<*, } profile.enableTool(shortName, project) } - Disposer.register(disposable, Disposable { profile.disableTool(shortName, project) }) + Disposer.register(disposable, Disposable { profile.setToolEnabled(shortName, false) }) } inline fun runInInitMode(runnable: () -> T): T { @@ -124,4 +125,17 @@ inline fun runInInitMode(runnable: () -> T): T { finally { InspectionProfileImpl.INIT_INSPECTIONS = old } +} + +fun disableInspections(project: Project, vararg inspections: InspectionProfileEntry) { + val profile = InspectionProjectProfileManager.getInstance(project).currentProfile + for (inspection in inspections) { + profile.setToolEnabled(inspection.shortName, false) + } +} + +fun InspectionProfileImpl.disableAllTools() { + for (entry in getInspectionTools(null)) { + setToolEnabled(entry.shortName, false) + } } \ No newline at end of file