mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Do not use "InspectionToolRegistrar" in "InspectionProfileImpl" directly
Use just "Supplier<List<InspectionToolWrapper>>" instead. Update corresponding unnecessary "InspectionToolRegistrar" inheritors.
This commit is contained in:
@@ -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<InspectionToolWrapper> list = new ArrayList<>();
|
||||
list.add(createTool("foo", true));
|
||||
|
||||
InspectionToolRegistrar registrar = new InspectionToolRegistrar() {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<InspectionToolWrapper> createTools() {
|
||||
return list;
|
||||
}
|
||||
};
|
||||
|
||||
InspectionProfileImpl profile = createProfile(registrar);
|
||||
Supplier<List<InspectionToolWrapper>> toolSupplier = () -> list;
|
||||
InspectionProfileImpl profile = createProfile(toolSupplier);
|
||||
|
||||
List<ScopeToolState> 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<List<InspectionToolWrapper>> toolSupplier) {
|
||||
InspectionProfileImpl base = new InspectionProfileImpl("Base", toolSupplier, (InspectionProfileImpl)null);
|
||||
return new InspectionProfileImpl("Foo", toolSupplier, base);
|
||||
}
|
||||
|
||||
public void testGlobalInspectionContext() throws Exception {
|
||||
|
||||
@@ -134,9 +134,7 @@ abstract class NewInspectionProfile(name: String, private var profileManager: Ba
|
||||
}
|
||||
|
||||
fun createSimple(name: String, project: Project, toolWrappers: List<InspectionToolWrapper<*, *>>): 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)
|
||||
}
|
||||
|
||||
+11
-10
@@ -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<List<InspectionToolWrapper>> myToolSupplier;
|
||||
protected final Map<String, Element> myUninitializedSettings = new TreeMap<>();
|
||||
protected Map<String, ToolsImpl> myTools = new THashMap<>();
|
||||
protected volatile Set<String> myChangedToolNames;
|
||||
@@ -77,9 +78,9 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
private SchemeDataHolder<? super InspectionProfileImpl> myDataHolder;
|
||||
|
||||
public InspectionProfileImpl(@NotNull String profileName,
|
||||
@NotNull InspectionToolRegistrar registrar,
|
||||
@NotNull Supplier<List<InspectionToolWrapper>> 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<List<InspectionToolWrapper>> 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<List<InspectionToolWrapper>> toolSupplier,
|
||||
@NotNull BaseInspectionProfileManager profileManager,
|
||||
@Nullable InspectionProfileImpl baseProfile,
|
||||
@Nullable SchemeDataHolder<? super InspectionProfileImpl> 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<List<InspectionToolWrapper>> toolSupplier,
|
||||
@NotNull BaseInspectionProfileManager profileManager,
|
||||
@Nullable SchemeDataHolder<? super InspectionProfileImpl> 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<InspectionToolWrapper> createTools(@Nullable Project project) {
|
||||
return myRegistrar.createTools();
|
||||
return myToolSupplier.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
+8
-2
@@ -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<List<InspectionToolWrapper>> {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionToolRegistrar");
|
||||
|
||||
private final List<Supplier<InspectionToolWrapper>> myInspectionToolFactories = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
@@ -101,6 +101,12 @@ public class InspectionToolRegistrar {
|
||||
return ServiceManager.getService(InspectionToolRegistrar.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<InspectionToolWrapper> get() {
|
||||
return createTools();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<InspectionToolWrapper> createTools() {
|
||||
ensureInitialized();
|
||||
|
||||
@@ -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<List<InspectionToolWrapper>> {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<InspectionToolWrapper> createTools() {
|
||||
public List<InspectionToolWrapper> get() {
|
||||
return Stream.of(new SubjectBodySeparationInspection(), new SubjectLimitInspection(), new BodyLimitInspection(),
|
||||
new CommitMessageSpellCheckingInspection())
|
||||
.map(LocalInspectionToolWrapper::new)
|
||||
|
||||
Reference in New Issue
Block a user