From 6b66e8fc2c982808ec4f9dadc35e116010e135fd Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Mon, 24 Apr 2017 17:58:27 +0300 Subject: [PATCH] Do not use "InspectionToolRegistrar" in "InspectionProfileImpl" directly Use just "Supplier>" instead. Update corresponding unnecessary "InspectionToolRegistrar" inheritors. --- .../ex/InspectionProfileTest.java | 20 +++++++----------- .../codeInspection/ex/InspectionProfile.kt | 4 +--- .../ex/InspectionProfileImpl.java | 21 ++++++++++--------- .../ex/InspectionProfileModifiableModel.kt | 2 +- .../ex/InspectionToolRegistrar.java | 10 +++++++-- .../CommitMessageInspectionProfile.java | 10 ++++----- 6 files changed, 33 insertions(+), 34 deletions(-) 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 be00d8486bc0..51298fb07f41 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java @@ -39,6 +39,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.function.Supplier; import static com.intellij.testFramework.assertions.Assertions.assertThat; @@ -492,15 +493,8 @@ public class InspectionProfileTest extends LightIdeaTestCase { final List list = new ArrayList<>(); list.add(createTool("foo", true)); - InspectionToolRegistrar registrar = new InspectionToolRegistrar() { - @NotNull - @Override - public List createTools() { - return list; - } - }; - - InspectionProfileImpl profile = createProfile(registrar); + Supplier> toolSupplier = () -> list; + InspectionProfileImpl profile = createProfile(toolSupplier); List tools = profile.getAllTools(); assertEquals(1, tools.size()); @@ -523,7 +517,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { list.add(createTool("bar", true)); list.add(createTool("disabled", false)); - profile = createProfile(registrar); + profile = createProfile(toolSupplier); profile.readExternal(element); tools = profile.getAllTools(); @@ -548,9 +542,9 @@ public class InspectionProfileTest extends LightIdeaTestCase { return JDOMUtil.writeElement(profile.writeScheme()); } - private static InspectionProfileImpl createProfile(@NotNull InspectionToolRegistrar registrar) { - InspectionProfileImpl base = new InspectionProfileImpl("Base", registrar, (InspectionProfileImpl)null); - return new InspectionProfileImpl("Foo", registrar, base); + private static InspectionProfileImpl createProfile(@NotNull Supplier> toolSupplier) { + InspectionProfileImpl base = new InspectionProfileImpl("Base", toolSupplier, (InspectionProfileImpl)null); + return new InspectionProfileImpl("Foo", toolSupplier, base); } public void testGlobalInspectionContext() throws Exception { 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 c677216b4e44..d95cd8e84cb8 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfile.kt +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfile.kt @@ -134,9 +134,7 @@ abstract class NewInspectionProfile(name: String, private var profileManager: Ba } fun createSimple(name: String, project: Project, toolWrappers: List>): InspectionProfileImpl { - val profile = InspectionProfileImpl(name, object : InspectionToolRegistrar() { - override fun createTools() = toolWrappers - }, InspectionProfileManager.getInstance() as BaseInspectionProfileManager) + val profile = InspectionProfileImpl(name, { toolWrappers }, InspectionProfileManager.getInstance() as BaseInspectionProfileManager) for (toolWrapper in toolWrappers) { profile.enableTool(toolWrapper.shortName, 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 770633aee975..6fb80c43346c 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java @@ -50,6 +50,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import java.util.*; +import java.util.function.Supplier; /** * @author max @@ -63,7 +64,7 @@ public class InspectionProfileImpl extends NewInspectionProfile { @NonNls private static final String USED_LEVELS = "used_levels"; @TestOnly public static boolean INIT_INSPECTIONS = false; - protected final InspectionToolRegistrar myRegistrar; + @NotNull protected final Supplier> myToolSupplier; protected final Map myUninitializedSettings = new TreeMap<>(); protected Map myTools = new THashMap<>(); protected volatile Set myChangedToolNames; @@ -77,9 +78,9 @@ public class InspectionProfileImpl extends NewInspectionProfile { private SchemeDataHolder myDataHolder; public InspectionProfileImpl(@NotNull String profileName, - @NotNull InspectionToolRegistrar registrar, + @NotNull Supplier> toolSupplier, @NotNull BaseInspectionProfileManager profileManager) { - this(profileName, registrar, profileManager, InspectionProfileKt.getBASE_PROFILE(), null); + this(profileName, toolSupplier, profileManager, InspectionProfileKt.getBASE_PROFILE(), null); } public InspectionProfileImpl(@NotNull String profileName) { @@ -87,19 +88,19 @@ public class InspectionProfileImpl extends NewInspectionProfile { } public InspectionProfileImpl(@NotNull String profileName, - @NotNull InspectionToolRegistrar registrar, + @NotNull Supplier> toolSupplier, @Nullable InspectionProfileImpl baseProfile) { - this(profileName, registrar, (BaseInspectionProfileManager)InspectionProfileManager.getInstance(), baseProfile, null); + this(profileName, toolSupplier, (BaseInspectionProfileManager)InspectionProfileManager.getInstance(), baseProfile, null); } public InspectionProfileImpl(@NotNull String profileName, - @NotNull InspectionToolRegistrar registrar, + @NotNull Supplier> toolSupplier, @NotNull BaseInspectionProfileManager profileManager, @Nullable InspectionProfileImpl baseProfile, @Nullable SchemeDataHolder dataHolder) { super(profileName, profileManager); - myRegistrar = registrar; + myToolSupplier = toolSupplier; myBaseProfile = baseProfile; myDataHolder = dataHolder; if (dataHolder != null) { @@ -108,10 +109,10 @@ public class InspectionProfileImpl extends NewInspectionProfile { } public InspectionProfileImpl(@NotNull String profileName, - @NotNull InspectionToolRegistrar registrar, + @NotNull Supplier> toolSupplier, @NotNull BaseInspectionProfileManager profileManager, @Nullable SchemeDataHolder dataHolder) { - this(profileName, registrar, profileManager, InspectionProfileKt.getBASE_PROFILE(), dataHolder); + this(profileName, toolSupplier, profileManager, InspectionProfileKt.getBASE_PROFILE(), dataHolder); } private static boolean toolSettingsAreEqual(@NotNull String toolName, @NotNull InspectionProfileImpl profile1, @NotNull InspectionProfileImpl profile2) { @@ -471,7 +472,7 @@ public class InspectionProfileImpl extends NewInspectionProfile { @NotNull protected List createTools(@Nullable Project project) { - return myRegistrar.createTools(); + return myToolSupplier.get(); } @Override 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 047d54255f07..8fcedf1fe3d8 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileModifiableModel.kt +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileModifiableModel.kt @@ -22,7 +22,7 @@ import com.intellij.openapi.util.WriteExternalException import com.intellij.profile.codeInspection.ProjectInspectionProfileManager import com.intellij.util.Consumer -open class InspectionProfileModifiableModel(val source: InspectionProfileImpl) : InspectionProfileImpl(source.name, source.myRegistrar, source.profileManager, source.myBaseProfile, null), ModifiableModel { +open class InspectionProfileModifiableModel(val source: InspectionProfileImpl) : InspectionProfileImpl(source.name, source.myToolSupplier, source.profileManager, source.myBaseProfile, null), ModifiableModel { private var modified = false init { diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionToolRegistrar.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionToolRegistrar.java index f10a7658b99e..ba12a83e2d86 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionToolRegistrar.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionToolRegistrar.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. @@ -35,7 +35,7 @@ import java.util.function.Supplier; /** * @author max */ -public class InspectionToolRegistrar { +public class InspectionToolRegistrar implements Supplier> { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionToolRegistrar"); private final List> myInspectionToolFactories = ContainerUtil.createLockFreeCopyOnWriteList(); @@ -101,6 +101,12 @@ public class InspectionToolRegistrar { return ServiceManager.getService(InspectionToolRegistrar.class); } + @Override + @NotNull + public List get() { + return createTools(); + } + @NotNull public List createTools() { ensureInitialized(); diff --git a/platform/vcs-impl/src/com/intellij/vcs/commit/CommitMessageInspectionProfile.java b/platform/vcs-impl/src/com/intellij/vcs/commit/CommitMessageInspectionProfile.java index 274a786def7d..227a20df9b59 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/commit/CommitMessageInspectionProfile.java +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/CommitMessageInspectionProfile.java @@ -16,7 +16,6 @@ package com.intellij.vcs.commit; import com.intellij.codeInspection.ex.InspectionProfileImpl; -import com.intellij.codeInspection.ex.InspectionToolRegistrar; import com.intellij.codeInspection.ex.InspectionToolWrapper; import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; import com.intellij.openapi.components.PersistentStateComponent; @@ -30,6 +29,7 @@ import org.jdom.Element; import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.function.Supplier; import java.util.stream.Stream; import static com.intellij.codeInspection.InspectionProfileEntry.getShortName; @@ -42,13 +42,13 @@ public class CommitMessageInspectionProfile extends InspectionProfileImpl public static final String PROFILE_NAME = "Commit Dialog"; public static final InspectionProfileImpl DEFAULT = - new InspectionProfileImpl(PROFILE_NAME, new CommitMessageInspectionToolRegistrar(), (InspectionProfileImpl)null); + new InspectionProfileImpl(PROFILE_NAME, new CommitMessageInspectionToolSupplier(), (InspectionProfileImpl)null); @NotNull private final Project myProject; @NotNull private State myState = new State(); public CommitMessageInspectionProfile(@NotNull Project project) { - super(PROFILE_NAME, new CommitMessageInspectionToolRegistrar(), DEFAULT); + super(PROFILE_NAME, new CommitMessageInspectionToolSupplier(), DEFAULT); myProject = project; } @@ -111,10 +111,10 @@ public class CommitMessageInspectionProfile extends InspectionProfileImpl return result; } - private static class CommitMessageInspectionToolRegistrar extends InspectionToolRegistrar { + private static class CommitMessageInspectionToolSupplier implements Supplier> { @NotNull @Override - public List createTools() { + public List get() { return Stream.of(new SubjectBodySeparationInspection(), new SubjectLimitInspection(), new BodyLimitInspection(), new CommitMessageSpellCheckingInspection()) .map(LocalInspectionToolWrapper::new)