mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
speed up save — track inspection scheme state
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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<Tools> getAllEnabledInspectionTools(Project project);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
+1
-1
@@ -329,7 +329,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
|
||||
protected List<Tools> getUsedTools() {
|
||||
InspectionProfileImpl profile = getCurrentProfile();
|
||||
List<Tools> tools = profile.getAllEnabledInspectionTools(myProject);
|
||||
Set<InspectionToolWrapper> dependentTools = new LinkedHashSet<>();
|
||||
Set<InspectionToolWrapper<?, ?>> dependentTools = new LinkedHashSet<>();
|
||||
for (Tools tool : tools) {
|
||||
profile.collectDependentInspections(tool.getTool(), dependentTools, getProject());
|
||||
}
|
||||
|
||||
@@ -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<InspectionToolWrapper<*, *>>): 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
|
||||
}
|
||||
+42
-63
@@ -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<? super InspectionProfileImpl> dataHolder) {
|
||||
this(profileName, registrar, profileManager, getBaseProfile(), dataHolder);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static InspectionProfileImpl createSimple(@NotNull String name,
|
||||
@NotNull Project project,
|
||||
@NotNull List<InspectionToolWrapper> toolWrappers) {
|
||||
InspectionProfileImpl profile = new InspectionProfileImpl(name, new InspectionToolRegistrar() {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<InspectionToolWrapper> 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<InspectionToolWrapper> dependentEntries,
|
||||
@NotNull Set<InspectionToolWrapper<?, ?>> 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<String> 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<String> 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<HighlightDisplayKey> 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);
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -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
|
||||
|
||||
-5
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+1
-2
@@ -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)
|
||||
|
||||
+3
-5
@@ -98,8 +98,7 @@ class ProjectInspectionProfileManager(val project: Project,
|
||||
name: String,
|
||||
attributeProvider: Function<String, String?>,
|
||||
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
|
||||
|
||||
@@ -342,7 +342,7 @@ class SchemeManagerImpl<T : Scheme, MUTABLE_SCHEME : T>(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
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
+3
-4
@@ -136,12 +136,11 @@ public class RunInspectionIntention implements IntentionAction, HighPriorityActi
|
||||
@NotNull InspectionManagerEx managerEx,
|
||||
@Nullable PsiElement psiElement) {
|
||||
InspectionProfileImpl rootProfile = InspectionProfileManager.getInstance().getCurrentProfile();
|
||||
LinkedHashSet<InspectionToolWrapper> allWrappers = new LinkedHashSet<>();
|
||||
LinkedHashSet<InspectionToolWrapper<?, ?>> allWrappers = new LinkedHashSet<>();
|
||||
allWrappers.add(toolWrapper);
|
||||
rootProfile.collectDependentInspections(toolWrapper, allWrappers, managerEx.getProject());
|
||||
List<InspectionToolWrapper> toolWrappers = allWrappers.size() == 1 ? Collections.singletonList(allWrappers.iterator().next()) : new ArrayList<>(allWrappers);
|
||||
InspectionProfileImpl model = InspectionProfileImpl.createSimple(toolWrapper.getDisplayName(), managerEx.getProject(),
|
||||
toolWrappers);
|
||||
List<InspectionToolWrapper<?, ?>> 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) {
|
||||
|
||||
+7
-22
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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",
|
||||
|
||||
@@ -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<InspectionProfileEntry>,
|
||||
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<InspectionToolWrapper<*, *>> = 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<Tools> {
|
||||
for (tool in toolWrappers) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user