mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract InspectionProfileModifiableModel
introduce modifyAndCommitProjectProfile use only and only modifyProfile and do not directly create modifiable model
This commit is contained in:
+3
-6
@@ -18,10 +18,7 @@ package com.intellij.codeInspection;
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInsight.daemon.impl.RemoveSuppressWarningAction;
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionContextBase;
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.*;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -303,8 +300,8 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool {
|
||||
}
|
||||
|
||||
protected InspectionToolWrapper[] getInspectionTools(PsiElement psiElement, @NotNull InspectionManager manager) {
|
||||
return InspectionProjectProfileManager.getInstance(manager.getProject()).getCurrentProfile().getModifiableModel()
|
||||
.getInspectionTools(psiElement);
|
||||
// todo for what we create modifiable model here?
|
||||
return new InspectionProfileModifiableModel(InspectionProjectProfileManager.getInstance(manager.getProject()).getCurrentProfile()).getInspectionTools(psiElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -84,8 +84,8 @@ public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public InspectionProfileImpl getModifiableModel() {
|
||||
return new InspectionProfileImpl("test") {
|
||||
public InspectionProfileModifiableModel getModifiableModel() {
|
||||
return new InspectionProfileModifiableModel(this) {
|
||||
@Override
|
||||
@NotNull
|
||||
public InspectionToolWrapper[] getInspectionTools(PsiElement element) {
|
||||
|
||||
@@ -215,8 +215,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
"</profile>");
|
||||
InspectionProfileImpl profile = createProfile(new InspectionProfileImpl("foo"));
|
||||
profile.readExternal(element);
|
||||
InspectionProfileImpl model = profile.getModifiableModel();
|
||||
model.commit();
|
||||
profile.getModifiableModel().commit();
|
||||
assertThat(profile.writeScheme()).isEqualTo(element);
|
||||
|
||||
|
||||
@@ -239,8 +238,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
" </inspection_tool>\n" +
|
||||
"</profile>");
|
||||
profile.readExternal(unusedProfile);
|
||||
model = profile.getModifiableModel();
|
||||
model.commit();
|
||||
profile.getModifiableModel().commit();
|
||||
assertEquals("<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"ToConvert\" />\n" +
|
||||
" <inspection_tool class=\"UNUSED_SYMBOL\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\">\n" +
|
||||
@@ -262,13 +260,13 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
//make them default
|
||||
profile = createProfile(new InspectionProfileImpl("foo"));
|
||||
profile.readExternal(unusedProfile);
|
||||
model = profile.getModifiableModel();
|
||||
InspectionToolWrapper toolWrapper = model.getInspectionTool("unused", getProject());
|
||||
UnusedDeclarationInspectionBase tool = (UnusedDeclarationInspectionBase)toolWrapper.getTool();
|
||||
tool.ADD_NONJAVA_TO_ENTRIES = true;
|
||||
UnusedSymbolLocalInspectionBase inspectionTool = tool.getSharedLocalInspectionTool();
|
||||
inspectionTool.setParameterVisibility(PsiModifier.PUBLIC);
|
||||
model.commit();
|
||||
profile.modifyProfile(it -> {
|
||||
InspectionToolWrapper toolWrapper = it.getInspectionTool("unused", getProject());
|
||||
UnusedDeclarationInspectionBase tool = (UnusedDeclarationInspectionBase)toolWrapper.getTool();
|
||||
tool.ADD_NONJAVA_TO_ENTRIES = true;
|
||||
UnusedSymbolLocalInspectionBase inspectionTool = tool.getSharedLocalInspectionTool();
|
||||
inspectionTool.setParameterVisibility(PsiModifier.PUBLIC);
|
||||
});
|
||||
String mergedText = "<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"ToConvert\" />\n" +
|
||||
" <inspection_tool class=\"UNUSED_SYMBOL\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\">\n" +
|
||||
@@ -297,8 +295,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
Element mergedElement = JDOMUtil.loadDocument(mergedText).getRootElement();
|
||||
profile = createProfile(new InspectionProfileImpl("foo"));
|
||||
profile.readExternal(mergedElement);
|
||||
model = profile.getModifiableModel();
|
||||
model.commit();
|
||||
profile.getModifiableModel().commit();
|
||||
assertThat(profile.writeScheme()).isEqualTo(mergedElement);
|
||||
|
||||
assertThat(importedProfile.writeScheme()).isEqualTo(mergedElement);
|
||||
@@ -320,13 +317,13 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
" <option name=\"ADD_NONJAVA_TO_ENTRIES\" value=\"false\" />\n" +
|
||||
" </inspection_tool>\n" +
|
||||
"</profile>").getRootElement());
|
||||
InspectionProfileImpl model = profile.getModifiableModel();
|
||||
InspectionToolWrapper toolWrapper = model.getInspectionTool("unused", getProject());
|
||||
UnusedDeclarationInspectionBase tool = (UnusedDeclarationInspectionBase)toolWrapper.getTool();
|
||||
UnusedSymbolLocalInspectionBase inspectionTool = tool.getSharedLocalInspectionTool();
|
||||
inspectionTool.setClassVisibility(PsiModifier.PUBLIC);
|
||||
inspectionTool.CLASS = false;
|
||||
model.commit();
|
||||
profile.modifyProfile(it -> {
|
||||
InspectionToolWrapper toolWrapper = it.getInspectionTool("unused", getProject());
|
||||
UnusedDeclarationInspectionBase tool = (UnusedDeclarationInspectionBase)toolWrapper.getTool();
|
||||
UnusedSymbolLocalInspectionBase inspectionTool = tool.getSharedLocalInspectionTool();
|
||||
inspectionTool.setClassVisibility(PsiModifier.PUBLIC);
|
||||
inspectionTool.CLASS = false;
|
||||
});
|
||||
String mergedText = "<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"ToConvert\" />\n" +
|
||||
" <inspection_tool class=\"unused\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"true\">\n" +
|
||||
@@ -506,10 +503,10 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
assertTrue(profile.isToolEnabled(HighlightDisplayKey.find("foo")));
|
||||
assertTrue(profile.getToolDefaultState("foo", getProject()).isEnabled());
|
||||
|
||||
InspectionProfileImpl model = profile.getModifiableModel();
|
||||
model.lockProfile(true);
|
||||
model.initInspectionTools(getProject()); // todo commit should take care of initialization
|
||||
model.commit();
|
||||
profile.modifyProfile(it -> {
|
||||
it.lockProfile(true);
|
||||
it.initInspectionTools(getProject()); // todo commit should take care of initialization
|
||||
});
|
||||
|
||||
assertEquals("<profile version=\"1.0\" is_locked=\"true\">\n" +
|
||||
" <option name=\"myName\" value=\"Foo\" />\n" +
|
||||
@@ -563,13 +560,12 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
}
|
||||
|
||||
public void testInspectionsInitialization() throws Exception {
|
||||
|
||||
InspectionProfileImpl foo = new InspectionProfileImpl("foo");
|
||||
assertEquals(0, countInitializedTools(foo));
|
||||
foo.initInspectionTools(getProject());
|
||||
assertEquals(0, countInitializedTools(foo));
|
||||
|
||||
InspectionProfileImpl model = foo.getModifiableModel();
|
||||
InspectionProfileModifiableModel model = foo.getModifiableModel();
|
||||
assertEquals(0, countInitializedTools(model));
|
||||
model.commit();
|
||||
assertEquals(0, countInitializedTools(model));
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.xmlb.annotations.Transient;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -35,11 +34,6 @@ import java.util.List;
|
||||
* Date: Dec 7, 2004
|
||||
*/
|
||||
public interface InspectionProfile extends Comparable {
|
||||
@Transient
|
||||
boolean isProjectLevel();
|
||||
|
||||
void setProjectLevel(boolean isProjectLevel);
|
||||
|
||||
void setName(@NotNull String name);
|
||||
|
||||
@NotNull
|
||||
@@ -65,8 +59,6 @@ public interface InspectionProfile extends Comparable {
|
||||
<T extends InspectionProfileEntry>
|
||||
T getUnwrappedTool(@NotNull Key<T> shortNameKey, @NotNull PsiElement element);
|
||||
|
||||
void modifyProfile(@NotNull Consumer<ModifiableModel> modelConsumer);
|
||||
|
||||
/**
|
||||
* Allows a plugin to modify the settings of the inspection tool with the specified ID programmatically, without going through
|
||||
* the settings dialog.
|
||||
@@ -88,12 +80,6 @@ public interface InspectionProfile extends Comparable {
|
||||
|
||||
void cleanup(@NotNull Project project);
|
||||
|
||||
/**
|
||||
* @see #modifyProfile(com.intellij.util.Consumer)
|
||||
*/
|
||||
@NotNull
|
||||
ModifiableModel getModifiableModel();
|
||||
|
||||
boolean isToolEnabled(@Nullable HighlightDisplayKey key, PsiElement element);
|
||||
|
||||
boolean isToolEnabled(@Nullable HighlightDisplayKey key);
|
||||
|
||||
@@ -30,9 +30,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
* Date: 15-Feb-2006
|
||||
*/
|
||||
public interface ModifiableModel extends InspectionProfile {
|
||||
|
||||
InspectionProfile getParentProfile();
|
||||
|
||||
void enableTool(@NotNull String inspectionTool, NamedScope namedScope, Project project);
|
||||
|
||||
void setErrorLevel(HighlightDisplayKey key, @NotNull HighlightDisplayLevel level, Project project);
|
||||
@@ -46,16 +43,6 @@ public interface ModifiableModel extends InspectionProfile {
|
||||
@Override
|
||||
boolean isToolEnabled(@Nullable HighlightDisplayKey key, @Nullable PsiElement element);
|
||||
|
||||
boolean isChanged();
|
||||
|
||||
void setModified(final boolean toolsSettingsChanged);
|
||||
|
||||
boolean isProperSetting(@NotNull String toolId);
|
||||
|
||||
void resetToBase(@Nullable Project project);
|
||||
|
||||
void resetToEmpty(Project project);
|
||||
|
||||
@Override
|
||||
InspectionProfileEntry getUnwrappedTool(@NotNull String shortName, @NotNull PsiElement element);
|
||||
|
||||
@@ -67,10 +54,6 @@ public interface ModifiableModel extends InspectionProfile {
|
||||
*/
|
||||
void setSingleTool(@NotNull String toolShortName);
|
||||
|
||||
boolean isProfileLocked();
|
||||
|
||||
void lockProfile(boolean isLocked);
|
||||
|
||||
void disableTool(@NotNull String toolId, @NotNull PsiElement element);
|
||||
|
||||
void disableTool(@NotNull String inspectionTool, @Nullable Project project);
|
||||
|
||||
+3
-6
@@ -17,7 +17,6 @@ package com.intellij.codeInsight.daemon;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -89,9 +88,7 @@ public class InspectionProfileConvertor {
|
||||
|
||||
public void storeEditorHighlightingProfile(@NotNull Element element, @NotNull InspectionProfileImpl editorProfile) {
|
||||
if (retrieveOldSettings(element)) {
|
||||
InspectionProfileImpl editorProfileModel = editorProfile.getModifiableModel();
|
||||
fillErrorLevels(editorProfileModel);
|
||||
editorProfileModel.commit();
|
||||
editorProfile.modifyProfile(it -> fillErrorLevels(it));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,8 +119,8 @@ public class InspectionProfileConvertor {
|
||||
}
|
||||
|
||||
protected void fillErrorLevels(final InspectionProfileImpl profile) {
|
||||
InspectionToolWrapper[] toolWrappers = profile.getInspectionTools(null);
|
||||
LOG.assertTrue(toolWrappers != null, "Profile was not correctly init");
|
||||
//noinspection ConstantConditions
|
||||
LOG.assertTrue(profile.getInspectionTools(null) != null, "Profile was not correctly init");
|
||||
//fill error levels
|
||||
for (final String shortName : myDisplayLevelMap.keySet()) {
|
||||
//key <-> short name
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.ex
|
||||
|
||||
import com.intellij.codeInspection.ModifiableModel
|
||||
import com.intellij.codeInspection.InspectionProfile
|
||||
import com.intellij.configurationStore.SerializableScheme
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.PathMacroManager
|
||||
@@ -24,13 +24,13 @@ import com.intellij.profile.codeInspection.BaseInspectionProfileManager
|
||||
import com.intellij.profile.codeInspection.ProjectInspectionProfileManager
|
||||
import com.intellij.util.xmlb.annotations.Transient
|
||||
|
||||
abstract class NewInspectionProfile(name: String, private var profileManager: BaseInspectionProfileManager) : ProfileEx(name), ModifiableModel, SerializableScheme {
|
||||
abstract class NewInspectionProfile(name: String, private var profileManager: BaseInspectionProfileManager) : ProfileEx(name), InspectionProfile, SerializableScheme {
|
||||
private var isProjectLevel: Boolean = false
|
||||
|
||||
@Transient
|
||||
override fun isProjectLevel() = isProjectLevel
|
||||
fun isProjectLevel() = isProjectLevel
|
||||
|
||||
override fun setProjectLevel(value: Boolean) {
|
||||
fun setProjectLevel(value: Boolean) {
|
||||
isProjectLevel = value
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ abstract class NewInspectionProfile(name: String, private var profileManager: Ba
|
||||
protected val pathMacroManager: PathMacroManager
|
||||
get() {
|
||||
val profileManager = profileManager
|
||||
return PathMacroManager.getInstance(
|
||||
if (profileManager is ProjectInspectionProfileManager) profileManager.project else ApplicationManager.getApplication())
|
||||
return PathMacroManager.getInstance((profileManager as? ProjectInspectionProfileManager)?.project ?: ApplicationManager.getApplication())
|
||||
}
|
||||
}
|
||||
+27
-133
@@ -19,7 +19,6 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInspection.InspectionEP;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.codeInspection.ModifiableModel;
|
||||
import com.intellij.configurationStore.SchemeDataHolder;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -35,7 +34,6 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScope;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.graph.CachingSemiGraph;
|
||||
import com.intellij.util.graph.DFSTBuilder;
|
||||
import com.intellij.util.graph.GraphGenerator;
|
||||
@@ -58,42 +56,29 @@ import java.util.*;
|
||||
public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
@NonNls static final String INSPECTION_TOOL_TAG = "inspection_tool";
|
||||
@NonNls static final String CLASS_TAG = "class";
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionProfileImpl");
|
||||
protected static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionProfileImpl");
|
||||
@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;
|
||||
private final InspectionToolRegistrar myRegistrar;
|
||||
@NotNull
|
||||
private final Map<String, Element> myUninitializedSettings = new TreeMap<>();
|
||||
protected InspectionProfileImpl mySource;
|
||||
private Map<String, ToolsImpl> myTools = new THashMap<>();
|
||||
private volatile Set<String> myChangedToolNames;
|
||||
protected final InspectionToolRegistrar myRegistrar;
|
||||
protected final Map<String, Element> myUninitializedSettings = new TreeMap<>();
|
||||
protected Map<String, ToolsImpl> myTools = new THashMap<>();
|
||||
protected volatile Set<String> myChangedToolNames;
|
||||
@Attribute("is_locked")
|
||||
private boolean myLockedProfile;
|
||||
private final InspectionProfileImpl myBaseProfile;
|
||||
protected boolean myLockedProfile;
|
||||
protected final InspectionProfileImpl myBaseProfile;
|
||||
private volatile String myToolShortName = null;
|
||||
private String[] myScopesOrder;
|
||||
private String myDescription;
|
||||
private boolean myModified;
|
||||
private volatile boolean myInitialized;
|
||||
|
||||
private final Object myLock = new Object();
|
||||
|
||||
private SchemeDataHolder<? super InspectionProfileImpl> myDataHolder;
|
||||
|
||||
InspectionProfileImpl(@NotNull InspectionProfileImpl inspectionProfile) {
|
||||
this(inspectionProfile.getName(), inspectionProfile.myRegistrar, inspectionProfile.getProfileManager(), inspectionProfile.myBaseProfile, null);
|
||||
myUninitializedSettings.putAll(inspectionProfile.myUninitializedSettings);
|
||||
|
||||
setProjectLevel(inspectionProfile.isProjectLevel());
|
||||
myLockedProfile = inspectionProfile.myLockedProfile;
|
||||
mySource = inspectionProfile;
|
||||
copyFrom(inspectionProfile);
|
||||
}
|
||||
|
||||
public InspectionProfileImpl(@NotNull String profileName,
|
||||
@NotNull InspectionToolRegistrar registrar,
|
||||
@NotNull BaseInspectionProfileManager profileManager) {
|
||||
@@ -157,7 +142,7 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static InspectionToolWrapper copyToolSettings(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
protected static InspectionToolWrapper copyToolSettings(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
final InspectionToolWrapper inspectionTool = toolWrapper.createCopy();
|
||||
if (toolWrapper.isInitialized()) {
|
||||
Element config = new Element("config");
|
||||
@@ -172,42 +157,6 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
return InspectionProfileImplHolder.DEFAULT_PROFILE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setModified(final boolean modified) {
|
||||
myModified = modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectionProfileImpl getParentProfile() {
|
||||
return mySource;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"SimplifiableIfStatement"})
|
||||
public boolean isChanged() {
|
||||
if (mySource != null && mySource.myLockedProfile != myLockedProfile) return true;
|
||||
return myModified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProperSetting(@NotNull String toolId) {
|
||||
if (myBaseProfile != null) {
|
||||
final Tools tools = myBaseProfile.getTools(toolId, null);
|
||||
final Tools currentTools = myTools.get(toolId);
|
||||
return !Comparing.equal(tools, currentTools);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetToBase(@Nullable Project project) {
|
||||
initInspectionTools(project);
|
||||
|
||||
copyToolsConfigurations(myBaseProfile, project);
|
||||
myChangedToolNames = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetToEmpty(Project project) {
|
||||
initInspectionTools(project);
|
||||
final InspectionToolWrapper[] profileEntries = getInspectionTools(null);
|
||||
@@ -408,11 +357,11 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
return (T) getUnwrappedTool(shortNameKey.toString(), element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modifyProfile(@NotNull Consumer<ModifiableModel> modelConsumer) {
|
||||
InspectionProfileImpl model = getModifiableModel();
|
||||
modelConsumer.consume(model);
|
||||
model.commit();
|
||||
public void modifyProfile(@NotNull Consumer<InspectionProfileModifiableModel> modelConsumer) {
|
||||
InspectionProfileModifiableModelKt.edit(this, it -> {
|
||||
modelConsumer.consume(it);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -464,7 +413,6 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
return myToolShortName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSingleTool(@NotNull final String toolShortName) {
|
||||
myToolShortName = toolShortName;
|
||||
}
|
||||
@@ -483,13 +431,11 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
getProfileManager().fireProfileChanged(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public boolean isProfileLocked() {
|
||||
return myLockedProfile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lockProfile(boolean isLocked) {
|
||||
myLockedProfile = isLocked;
|
||||
}
|
||||
@@ -518,7 +464,6 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableTool(@NotNull String toolId, @NotNull PsiElement element) {
|
||||
getTools(toolId, element.getProject()).disableTool(element);
|
||||
}
|
||||
@@ -557,6 +502,11 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected List<InspectionToolWrapper> createTools(@Nullable Project project) {
|
||||
return myRegistrar.createTools();
|
||||
}
|
||||
|
||||
private void initialize(@Nullable Project project) {
|
||||
SchemeDataHolder<? super InspectionProfileImpl> dataHolder = myDataHolder;
|
||||
if (dataHolder != null) {
|
||||
@@ -575,12 +525,7 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
|
||||
final List<InspectionToolWrapper> tools;
|
||||
try {
|
||||
if (mySource == null) {
|
||||
tools = myRegistrar.createTools();
|
||||
}
|
||||
else {
|
||||
tools = ContainerUtil.map(mySource.getDefaultStates(project), ScopeToolState::getTool);
|
||||
}
|
||||
tools = createTools(project);
|
||||
}
|
||||
catch (ProcessCanceledException ignored) {
|
||||
return;
|
||||
@@ -606,9 +551,7 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
myScopesOrder = ArrayUtil.toStringArray(builder.getSortedNodes());
|
||||
}
|
||||
|
||||
if (mySource != null) {
|
||||
copyToolsConfigurations(mySource, project);
|
||||
}
|
||||
copyToolsConfigurations(project);
|
||||
|
||||
myInitialized = true;
|
||||
if (dataHolder != null) {
|
||||
@@ -617,6 +560,9 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
}
|
||||
}
|
||||
|
||||
protected void copyToolsConfigurations(@Nullable Project project) {
|
||||
}
|
||||
|
||||
public void addTool(@Nullable Project project, @NotNull InspectionToolWrapper toolWrapper, @NotNull Map<String, List<String>> dependencies) {
|
||||
final String shortName = toolWrapper.getShortName();
|
||||
HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
|
||||
@@ -707,41 +653,10 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
return tools.getLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public InspectionProfileImpl getModifiableModel() {
|
||||
return new InspectionProfileImpl(this);
|
||||
}
|
||||
|
||||
private void copyToolsConfigurations(@NotNull InspectionProfileImpl profile, @Nullable Project project) {
|
||||
try {
|
||||
for (ToolsImpl toolList : profile.myTools.values()) {
|
||||
final ToolsImpl tools = myTools.get(toolList.getShortName());
|
||||
final ScopeToolState defaultState = toolList.getDefaultState();
|
||||
tools.setDefaultState(copyToolSettings(defaultState.getTool()), defaultState.isEnabled(), defaultState.getLevel());
|
||||
tools.removeAllScopes();
|
||||
final List<ScopeToolState> nonDefaultToolStates = toolList.getNonDefaultTools();
|
||||
if (nonDefaultToolStates != null) {
|
||||
for (ScopeToolState state : nonDefaultToolStates) {
|
||||
final InspectionToolWrapper toolWrapper = copyToolSettings(state.getTool());
|
||||
final NamedScope scope = state.getScope(project);
|
||||
if (scope != null) {
|
||||
tools.addTool(scope, toolWrapper, state.isEnabled(), state.getLevel());
|
||||
}
|
||||
else {
|
||||
tools.addTool(state.getScopeName(), toolWrapper, state.isEnabled(), state.getLevel());
|
||||
}
|
||||
}
|
||||
}
|
||||
tools.setEnabled(toolList.isEnabled());
|
||||
}
|
||||
}
|
||||
catch (WriteExternalException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (InvalidDataException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
@TestOnly
|
||||
public InspectionProfileModifiableModel getModifiableModel() {
|
||||
return new InspectionProfileModifiableModel(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -765,7 +680,6 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableTool(@NotNull String inspectionTool, NamedScope namedScope, Project project) {
|
||||
getTools(inspectionTool, project).enableTool(namedScope, project);
|
||||
}
|
||||
@@ -782,7 +696,6 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableTool(@NotNull String inspectionTool, @Nullable Project project) {
|
||||
ToolsImpl tools = getTools(inspectionTool, project);
|
||||
tools.setEnabled(false);
|
||||
@@ -791,7 +704,6 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setErrorLevel(@NotNull HighlightDisplayKey key, @NotNull HighlightDisplayLevel level, Project project) {
|
||||
getTools(key.toString(), project).setLevel(level);
|
||||
}
|
||||
@@ -819,24 +731,6 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
return false;
|
||||
}
|
||||
|
||||
//invoke when isChanged() == true
|
||||
public void commit() {
|
||||
LOG.assertTrue(mySource != null);
|
||||
mySource.commit(this);
|
||||
getProfileManager().updateProfile(mySource);
|
||||
mySource = null;
|
||||
}
|
||||
|
||||
private void commit(@NotNull InspectionProfileImpl model) {
|
||||
setName(model.getName());
|
||||
setDescription(model.getDescription());
|
||||
setProjectLevel(model.isProjectLevel());
|
||||
myLockedProfile = model.myLockedProfile;
|
||||
myChangedToolNames = model.myChangedToolNames;
|
||||
myTools = model.myTools;
|
||||
setProfileManager(model.getProfileManager());
|
||||
}
|
||||
|
||||
@Tag
|
||||
public String getDescription() {
|
||||
return myDescription;
|
||||
@@ -1012,7 +906,7 @@ public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
return mySource == null ? getName() : getName() + " (copy)";
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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.ex
|
||||
|
||||
import com.intellij.codeInspection.ModifiableModel
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Comparing
|
||||
import com.intellij.openapi.util.InvalidDataException
|
||||
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 {
|
||||
private var modified = false
|
||||
|
||||
init {
|
||||
myUninitializedSettings.putAll(source.myUninitializedSettings)
|
||||
isProjectLevel = source.isProjectLevel
|
||||
myLockedProfile = source.myLockedProfile
|
||||
copyFrom(source)
|
||||
}
|
||||
|
||||
fun isChanged() = modified || source.myLockedProfile != myLockedProfile
|
||||
|
||||
fun setModified(value: Boolean) {
|
||||
modified = value
|
||||
}
|
||||
|
||||
override fun copyToolsConfigurations(project: Project?) {
|
||||
copyToolsConfigurations(source, project)
|
||||
}
|
||||
|
||||
override fun createTools(project: Project?) = source.getDefaultStates(project).map { it.tool }
|
||||
|
||||
private fun copyToolsConfigurations(profile: InspectionProfileImpl, project: Project?) {
|
||||
try {
|
||||
for (toolList in profile.myTools.values) {
|
||||
val tools = myTools[toolList.shortName]!!
|
||||
val defaultState = toolList.defaultState
|
||||
tools.setDefaultState(copyToolSettings(defaultState.tool), defaultState.isEnabled, defaultState.level)
|
||||
tools.removeAllScopes()
|
||||
val nonDefaultToolStates = toolList.nonDefaultTools
|
||||
if (nonDefaultToolStates != null) {
|
||||
for (state in nonDefaultToolStates) {
|
||||
val toolWrapper = copyToolSettings(state.tool)
|
||||
val scope = state.getScope(project)
|
||||
if (scope == null) {
|
||||
tools.addTool(state.scopeName, toolWrapper, state.isEnabled, state.level)
|
||||
}
|
||||
else {
|
||||
tools.addTool(scope, toolWrapper, state.isEnabled, state.level)
|
||||
}
|
||||
}
|
||||
}
|
||||
tools.isEnabled = toolList.isEnabled
|
||||
}
|
||||
}
|
||||
catch (e: WriteExternalException) {
|
||||
LOG.error(e)
|
||||
}
|
||||
catch (e: InvalidDataException) {
|
||||
LOG.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
fun isProperSetting(toolId: String): Boolean {
|
||||
if (myBaseProfile != null) {
|
||||
val tools = myBaseProfile.getTools(toolId, null)
|
||||
val currentTools = myTools[toolId]
|
||||
return !Comparing.equal<Tools>(tools, currentTools)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun resetToBase(project: Project?) {
|
||||
initInspectionTools(project)
|
||||
|
||||
copyToolsConfigurations(myBaseProfile, project)
|
||||
myChangedToolNames = null
|
||||
}
|
||||
|
||||
//invoke when isChanged() == true
|
||||
fun commit() {
|
||||
source.commit(this)
|
||||
profileManager.updateProfile(source)
|
||||
modified = false
|
||||
}
|
||||
|
||||
private fun InspectionProfileImpl.commit(model: InspectionProfileImpl) {
|
||||
name = model.name
|
||||
description = model.description
|
||||
isProjectLevel = model.isProjectLevel
|
||||
myLockedProfile = model.myLockedProfile
|
||||
myChangedToolNames = model.myChangedToolNames
|
||||
myTools = model.myTools
|
||||
profileManager = model.profileManager
|
||||
}
|
||||
|
||||
override fun toString() = "$name (copy)"
|
||||
}
|
||||
|
||||
fun modifyAndCommitProjectProfile(project: Project, action: Consumer<ModifiableModel>) {
|
||||
ProjectInspectionProfileManager.getInstance(project).currentProfile.edit { action.consume(this) }
|
||||
}
|
||||
|
||||
inline fun InspectionProfileImpl.edit(task: InspectionProfileModifiableModel.() -> Unit) {
|
||||
val model = InspectionProfileModifiableModel(this)
|
||||
model.task()
|
||||
model.commit()
|
||||
}
|
||||
+6
-5
@@ -24,6 +24,7 @@ import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionManagerEx;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileModifiableModel;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.options.ex.SingleConfigurableEditor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -99,7 +100,7 @@ public class CodeInspectionAction extends BaseAnalysisAction {
|
||||
protected JComponent getAdditionalActionSettings(@NotNull final Project project, final BaseAnalysisActionDialog dialog) {
|
||||
final AdditionalPanel panel = new AdditionalPanel();
|
||||
final InspectionManagerEx manager = (InspectionManagerEx)InspectionManager.getInstance(project);
|
||||
final ProfilesComboBox profiles = (ProfilesComboBox)panel.myBrowseProfilesCombo.getComboBox();
|
||||
final ProfilesComboBox<InspectionProfileImpl> profiles = (ProfilesComboBox<InspectionProfileImpl>)panel.myBrowseProfilesCombo.getComboBox();
|
||||
final InspectionProfileManager profileManager = InspectionProfileManager.getInstance();
|
||||
final ProjectInspectionProfileManager projectProfileManager = ProjectInspectionProfileManager.getInstance(project);
|
||||
reloadProfiles(profiles, profileManager, projectProfileManager, manager);
|
||||
@@ -142,7 +143,7 @@ public class CodeInspectionAction extends BaseAnalysisAction {
|
||||
}
|
||||
|
||||
protected static class ExternalProfilesComboboxAwareInspectionToolsConfigurable extends InspectionToolsConfigurable {
|
||||
private final ProfilesComboBox myProfilesCombo;
|
||||
private final ProfilesComboBox<InspectionProfileImpl> myProfilesCombo;
|
||||
|
||||
public ExternalProfilesComboboxAwareInspectionToolsConfigurable(@NotNull ProjectInspectionProfileManager projectProfileManager, ProfilesComboBox profilesCombo) {
|
||||
super(projectProfileManager);
|
||||
@@ -155,9 +156,9 @@ public class CodeInspectionAction extends BaseAnalysisAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addProfile(InspectionProfileImpl model) {
|
||||
protected void addProfile(InspectionProfileModifiableModel model) {
|
||||
super.addProfile(model);
|
||||
myProfilesCombo.addProfile(model.getParentProfile());
|
||||
myProfilesCombo.addProfile(model.getSource());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -173,7 +174,7 @@ public class CodeInspectionAction extends BaseAnalysisAction {
|
||||
}
|
||||
|
||||
|
||||
private void reloadProfiles(ProfilesComboBox profilesCombo,
|
||||
private void reloadProfiles(ProfilesComboBox<InspectionProfileImpl> profilesCombo,
|
||||
InspectionProfileManager inspectionProfileManager,
|
||||
InspectionProjectProfileManager inspectionProjectProfileManager,
|
||||
InspectionManagerEx inspectionManager) {
|
||||
|
||||
@@ -44,10 +44,10 @@ public class Descriptor {
|
||||
private final NamedScope myScope;
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.Descriptor");
|
||||
private final ScopeToolState myState;
|
||||
private final InspectionProfileImpl myInspectionProfile;
|
||||
private final InspectionProfileModifiableModel myInspectionProfile;
|
||||
private final String myScopeName;
|
||||
|
||||
public Descriptor(@NotNull ScopeToolState state, @NotNull InspectionProfileImpl inspectionProfile, @NotNull Project project) {
|
||||
public Descriptor(@NotNull ScopeToolState state, @NotNull InspectionProfileModifiableModel inspectionProfile, @NotNull Project project) {
|
||||
myState = state;
|
||||
myInspectionProfile = inspectionProfile;
|
||||
InspectionToolWrapper tool = state.getTool();
|
||||
@@ -120,7 +120,7 @@ public class Descriptor {
|
||||
return myToolWrapper.loadDescription();
|
||||
}
|
||||
|
||||
public InspectionProfileImpl getInspectionProfile() {
|
||||
public InspectionProfileModifiableModel getInspectionProfile() {
|
||||
return myInspectionProfile;
|
||||
}
|
||||
|
||||
|
||||
+5
-13
@@ -13,21 +13,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.InspectionProfile;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.IntentionAndQuickFixAction;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.profile.codeInspection.ProjectInspectionProfileManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.Consumer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -67,14 +66,7 @@ public class DisableInspectionToolAction extends IntentionAndQuickFixAction impl
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, final PsiFile file, @Nullable Editor editor) {
|
||||
modifyAndCommitProjectProfile(modifiableModel -> modifiableModel.disableTool(myToolId, file), project);
|
||||
DaemonCodeAnalyzer.getInstance(project).restart();
|
||||
}
|
||||
|
||||
public static void modifyAndCommitProjectProfile(Consumer<ModifiableModel> action, Project project) {
|
||||
InspectionProfileImpl model = ProjectInspectionProfileManager.getInstance(project).getCurrentProfile().getModifiableModel();
|
||||
action.consume(model);
|
||||
model.commit();
|
||||
InspectionProfileModifiableModelKt.modifyAndCommitProjectProfile(project, it -> it.disableTool(myToolId, file));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+9
-16
@@ -16,13 +16,12 @@
|
||||
package com.intellij.codeInspection.ui.actions;
|
||||
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInspection.InspectionProfile;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.actions.RunInspectionIntention;
|
||||
import com.intellij.codeInspection.ex.DisableInspectionToolAction;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileModifiableModelKt;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
@@ -31,7 +30,6 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -87,28 +85,23 @@ public abstract class KeyAwareInspectionViewAction extends InspectionViewActionB
|
||||
@Override
|
||||
protected void actionPerformed(@NotNull InspectionResultsView view, @NotNull HighlightDisplayKey key) {
|
||||
if (view.isSingleInspectionRun()) {
|
||||
InspectionProfileImpl model = view.getCurrentProfile().getModifiableModel();
|
||||
model.disableTool(key.toString(), view.getProject());
|
||||
model.commit();
|
||||
view.getCurrentProfile().modifyProfile(it -> it.disableTool(key.toString(), view.getProject()));
|
||||
view.updateCurrentProfile();
|
||||
}
|
||||
else {
|
||||
final RefEntity[] selectedElements = view.getTree().getSelectedElements();
|
||||
final Set<PsiElement> files = new HashSet<>();
|
||||
final Project project = view.getProject();
|
||||
final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(project);
|
||||
for (RefEntity selectedElement : selectedElements) {
|
||||
if (selectedElement instanceof RefElement) {
|
||||
final PsiElement element = ((RefElement)selectedElement).getElement();
|
||||
files.add(element);
|
||||
files.add(((RefElement)selectedElement).getElement());
|
||||
}
|
||||
}
|
||||
InspectionProfileImpl model = profileManager.getCurrentProfile().getModifiableModel();
|
||||
for (PsiElement element : files) {
|
||||
model.disableTool(key.toString(), element);
|
||||
}
|
||||
model.commit();
|
||||
DaemonCodeAnalyzer.getInstance(project).restart();
|
||||
|
||||
InspectionProfileModifiableModelKt.modifyAndCommitProjectProfile(view.getProject(), it -> {
|
||||
for (PsiElement element : files) {
|
||||
it.disableTool(key.toString(), element);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -16,6 +16,7 @@
|
||||
package com.intellij.profile.codeInspection.ui;
|
||||
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileModifiableModel;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.application.ApplicationNamesInfo;
|
||||
@@ -103,7 +104,7 @@ public abstract class AdvancedSettingsAction extends DumbAwareAction {
|
||||
|
||||
@Override
|
||||
public void actionPerformed() {
|
||||
final InspectionProfileImpl inspectionProfile = getInspectionProfile();
|
||||
InspectionProfileModifiableModel inspectionProfile = getInspectionProfile();
|
||||
if (inspectionProfile == null) {
|
||||
return;
|
||||
}
|
||||
@@ -179,7 +180,7 @@ public abstract class AdvancedSettingsAction extends DumbAwareAction {
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract InspectionProfileImpl getInspectionProfile();
|
||||
protected abstract InspectionProfileModifiableModel getInspectionProfile();
|
||||
|
||||
protected abstract void postProcessModification();
|
||||
|
||||
|
||||
+29
-40
@@ -99,7 +99,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
new InspectionConfigTreeNode.Group(InspectionsBundle.message("inspection.root.node.title"));
|
||||
private final Alarm myAlarm = new Alarm();
|
||||
private final ProjectInspectionProfileManager myProjectProfileManager;
|
||||
private InspectionProfileImpl myProfile;
|
||||
private InspectionProfileModifiableModel myProfile;
|
||||
private JEditorPane myBrowser;
|
||||
private JPanel myOptionsPanel;
|
||||
private JPanel myInspectionProfilePanel = null;
|
||||
@@ -122,7 +122,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
};
|
||||
|
||||
public SingleInspectionProfilePanel(@NotNull ProjectInspectionProfileManager projectProfileManager,
|
||||
@NotNull InspectionProfileImpl profile) {
|
||||
@NotNull InspectionProfileModifiableModel profile) {
|
||||
super(new BorderLayout());
|
||||
myProjectProfileManager = projectProfileManager;
|
||||
myProfile = profile;
|
||||
@@ -409,13 +409,18 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
}
|
||||
|
||||
private void initToolStates() {
|
||||
final InspectionProfileImpl profile = myProfile;
|
||||
if (profile == null) return;
|
||||
InspectionProfileModifiableModel profile = myProfile;
|
||||
if (profile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
myInitialToolDescriptors.clear();
|
||||
final Project project = myProjectProfileManager.getProject();
|
||||
for (final ScopeToolState state : profile.getDefaultStates(myProjectProfileManager.getProject())) {
|
||||
if (!accept(state.getTool())) continue;
|
||||
final ToolDescriptors descriptors = ToolDescriptors.fromScopeToolState(state, profile, project);
|
||||
if (!accept(state.getTool())) {
|
||||
continue;
|
||||
}
|
||||
ToolDescriptors descriptors = ToolDescriptors.fromScopeToolState(state, profile, project);
|
||||
myInitialToolDescriptors.put(descriptors.getDefaultDescriptor().getKey(), descriptors);
|
||||
}
|
||||
myInitialScopesOrder = myProfile.getScopesOrder();
|
||||
@@ -505,7 +510,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
|
||||
actions.add(new AdvancedSettingsAction(myProjectProfileManager.getProject(), myRoot) {
|
||||
@Override
|
||||
protected InspectionProfileImpl getInspectionProfile() {
|
||||
protected InspectionProfileModifiableModel getInspectionProfile() {
|
||||
return myProfile;
|
||||
}
|
||||
|
||||
@@ -604,16 +609,13 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
}
|
||||
|
||||
if (!myIsInRestore) {
|
||||
InspectionProfileImpl selected = myProfile;
|
||||
InspectionProfileModifiableModel selected = myProfile;
|
||||
if (selected != null) {
|
||||
InspectionProfileImpl baseProfile = selected.getParentProfile();
|
||||
if (baseProfile != null) {
|
||||
getExpandedNodes(baseProfile).setSelectionPaths(myTreeTable.getTree().getSelectionPaths());
|
||||
}
|
||||
InspectionProfileImpl baseProfile = selected.getSource();
|
||||
getExpandedNodes(baseProfile).setSelectionPaths(myTreeTable.getTree().getSelectionPaths());
|
||||
getExpandedNodes(selected).setSelectionPaths(myTreeTable.getTree().getSelectionPaths());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@@ -652,23 +654,17 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
|
||||
@Override
|
||||
public void treeCollapsed(TreeExpansionEvent event) {
|
||||
InspectionProfileImpl selected = myProfile;
|
||||
final InspectionProfileImpl parentProfile = selected.getParentProfile();
|
||||
if (parentProfile != null) {
|
||||
getExpandedNodes(parentProfile).saveVisibleState(myTreeTable.getTree());
|
||||
}
|
||||
InspectionProfileModifiableModel selected = myProfile;
|
||||
getExpandedNodes(selected.getSource()).saveVisibleState(myTreeTable.getTree());
|
||||
getExpandedNodes(selected).saveVisibleState(myTreeTable.getTree());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void treeExpanded(TreeExpansionEvent event) {
|
||||
InspectionProfileImpl selected = myProfile;
|
||||
InspectionProfileModifiableModel selected = myProfile;
|
||||
if (selected != null) {
|
||||
final InspectionConfigTreeNode node = (InspectionConfigTreeNode)event.getPath().getLastPathComponent();
|
||||
final InspectionProfileImpl parentProfile = selected.getParentProfile();
|
||||
if (parentProfile != null) {
|
||||
getExpandedNodes(parentProfile).expandNode(node);
|
||||
}
|
||||
getExpandedNodes(selected.getSource()).expandNode(node);
|
||||
getExpandedNodes(selected).expandNode(node);
|
||||
}
|
||||
}
|
||||
@@ -1007,16 +1003,11 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
myOptionsPanel.repaint();
|
||||
}
|
||||
|
||||
private boolean setSelectedProfileModified(boolean modified) {
|
||||
myProfile.setModified(modified);
|
||||
return modified;
|
||||
}
|
||||
|
||||
public InspectionProfileImpl getProfile() {
|
||||
public InspectionProfileModifiableModel getProfile() {
|
||||
return myProfile;
|
||||
}
|
||||
|
||||
private void setProfile(InspectionProfileImpl modifiableModel) {
|
||||
private void setProfile(InspectionProfileModifiableModel modifiableModel) {
|
||||
if (myProfile == modifiableModel) {
|
||||
return;
|
||||
}
|
||||
@@ -1095,8 +1086,8 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
if (myTreeTable == null) return false;
|
||||
if (myModified) return true;
|
||||
if (myProfile.isChanged()) return true;
|
||||
if (myProfile.getParentProfile().isProjectLevel() != myProfile.isProjectLevel()) return true;
|
||||
if (!Comparing.strEqual(myProfile.getParentProfile().getName(), myProfile.getName())) return true;
|
||||
if (myProfile.getSource().isProjectLevel() != myProfile.isProjectLevel()) return true;
|
||||
if (!Comparing.strEqual(myProfile.getSource().getName(), myProfile.getName())) return true;
|
||||
if (!Comparing.equal(myInitialScopesOrder, myProfile.getScopesOrder())) return true;
|
||||
return descriptorsAreChanged();
|
||||
}
|
||||
@@ -1108,8 +1099,8 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
final String filter = myProfileFilter.getFilter();
|
||||
myProfileFilter.reset();
|
||||
myProfileFilter.setSelectedItem(filter);
|
||||
myProfile.setName(myProfile.getParentProfile().getName());
|
||||
myProfile.setProjectLevel(myProfile.getParentProfile().isProjectLevel());
|
||||
myProfile.setName(myProfile.getSource().getName());
|
||||
myProfile.setProjectLevel(myProfile.getSource().isProjectLevel());
|
||||
}
|
||||
|
||||
public void apply() {
|
||||
@@ -1117,14 +1108,14 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
if (!modified) {
|
||||
return;
|
||||
}
|
||||
final InspectionProfileImpl selectedProfile = getProfile();
|
||||
InspectionProfileModifiableModel selectedProfile = myProfile;
|
||||
|
||||
BaseInspectionProfileManager profileManager = selectedProfile.isProjectLevel() ? myProjectProfileManager : (BaseInspectionProfileManager)InspectionProfileManager.getInstance();
|
||||
InspectionProfileImpl parentProfile = selectedProfile.getParentProfile();
|
||||
InspectionProfileImpl source = selectedProfile.getSource();
|
||||
|
||||
// delete by instance, only if from another profile manager or has another name (otherwise will be replaced and we don't need to explicitly delete it)
|
||||
if (parentProfile.getProfileManager() != profileManager || !parentProfile.getName().equals(selectedProfile.getName())) {
|
||||
parentProfile.getProfileManager().deleteProfile(parentProfile);
|
||||
if (source.getProfileManager() != profileManager || !source.getName().equals(selectedProfile.getName())) {
|
||||
source.getProfileManager().deleteProfile(source);
|
||||
}
|
||||
|
||||
if (selectedProfile.getProfileManager() != profileManager) {
|
||||
@@ -1133,8 +1124,6 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
}
|
||||
|
||||
selectedProfile.commit();
|
||||
myProfile = parentProfile.getModifiableModel();
|
||||
setSelectedProfileModified(false);
|
||||
myModified = false;
|
||||
myRoot.dropCache();
|
||||
initToolStates();
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
package com.intellij.profile.codeInspection.ui;
|
||||
|
||||
import com.intellij.codeInspection.ex.Descriptor;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileModifiableModel;
|
||||
import com.intellij.codeInspection.ex.ScopeToolState;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -42,11 +41,10 @@ public class ToolDescriptors {
|
||||
}
|
||||
|
||||
public static ToolDescriptors fromScopeToolState(final ScopeToolState state,
|
||||
final InspectionProfileImpl profile,
|
||||
@NotNull InspectionProfileModifiableModel profile,
|
||||
final Project project) {
|
||||
final InspectionToolWrapper toolWrapper = state.getTool();
|
||||
final List<ScopeToolState> nonDefaultTools = profile.getNonDefaultTools(toolWrapper.getShortName(), project);
|
||||
final ArrayList<Descriptor> descriptors = new ArrayList<>(nonDefaultTools.size());
|
||||
List<ScopeToolState> nonDefaultTools = profile.getNonDefaultTools(state.getTool().getShortName(), project);
|
||||
ArrayList<Descriptor> descriptors = new ArrayList<>(nonDefaultTools.size());
|
||||
for (final ScopeToolState nonDefaultToolState : nonDefaultTools) {
|
||||
descriptors.add(new Descriptor(nonDefaultToolState, profile, project));
|
||||
}
|
||||
|
||||
+28
-36
@@ -19,6 +19,7 @@ package com.intellij.profile.codeInspection.ui.header;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
|
||||
import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileModifiableModel;
|
||||
import com.intellij.codeInspection.ex.InspectionToolRegistrar;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
@@ -42,7 +43,6 @@ import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.profile.codeInspection.BaseInspectionProfileManager;
|
||||
import com.intellij.profile.codeInspection.InspectionProfileManager;
|
||||
@@ -51,6 +51,7 @@ import com.intellij.profile.codeInspection.ui.ErrorsConfigurable;
|
||||
import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jdom.Element;
|
||||
@@ -82,7 +83,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
|
||||
protected final BaseInspectionProfileManager myApplicationProfileManager;
|
||||
protected final ProjectInspectionProfileManager myProjectProfileManager;
|
||||
private final List<SingleInspectionProfilePanel> myPanels = new ArrayList<>();
|
||||
private final List<InspectionProfileImpl> myDeletedProfiles = new ArrayList<>();
|
||||
private final List<InspectionProfileModifiableModel> myDeletedProfiles = new SmartList<>();
|
||||
protected ProfilesChooser myProfiles;
|
||||
private JPanel myProfilePanelHolder;
|
||||
private AuxiliaryRightPanel myAuxiliaryRightPanel;
|
||||
@@ -142,16 +143,15 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
|
||||
inspectionProfile.copyFrom(selectedProfile);
|
||||
inspectionProfile.setName(profileDefaultName);
|
||||
inspectionProfile.initInspectionTools(project);
|
||||
inspectionProfile.setModified(true);
|
||||
inspectionProfile.setProjectLevel(isProjectLevel);
|
||||
|
||||
final InspectionProfileImpl modifiableModel = inspectionProfile.getModifiableModel();
|
||||
InspectionProfileModifiableModel modifiableModel = new InspectionProfileModifiableModel(inspectionProfile);
|
||||
modifiableModel.setModified(true);
|
||||
addProfile(modifiableModel);
|
||||
return modifiableModel;
|
||||
}
|
||||
|
||||
protected void addProfile(InspectionProfileImpl model) {
|
||||
protected void addProfile(InspectionProfileModifiableModel model) {
|
||||
final SingleInspectionProfilePanel panel = createPanel(model);
|
||||
myPanels.add(panel);
|
||||
myProfiles.getProfilesComboBox().addProfile(model);
|
||||
@@ -204,7 +204,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
|
||||
myAuxiliaryRightPanel = new AuxiliaryRightPanel(new AuxiliaryRightPanel.DescriptionSaveListener() {
|
||||
@Override
|
||||
public void saveDescription(@NotNull String description) {
|
||||
final InspectionProfileImpl inspectionProfile = getSelectedObject();
|
||||
InspectionProfileModifiableModel inspectionProfile = getSelectedObject();
|
||||
if (!Comparing.strEqual(description, inspectionProfile.getDescription())) {
|
||||
inspectionProfile.setDescription(description);
|
||||
inspectionProfile.setModified(true);
|
||||
@@ -303,7 +303,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
final InspectionProfileImpl selectedProfile = myProfiles.getProfilesComboBox().getSelectedProfile();
|
||||
InspectionProfileModifiableModel selectedProfile = myProfiles.getProfilesComboBox().getSelectedProfile();
|
||||
myProfiles.getProfilesComboBox().removeProfile(selectedProfile);
|
||||
myPanels.remove(getProfilePanel(selectedProfile));
|
||||
myDeletedProfiles.add(selectedProfile);
|
||||
@@ -364,8 +364,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
|
||||
if (file != null) {
|
||||
final InspectionProfileImpl profile;
|
||||
try {
|
||||
Element rootElement = JDOMUtil.load(VfsUtilCore.virtualToIoFile(file));
|
||||
profile = importInspectionProfile(rootElement, myApplicationProfileManager, getProject(), wholePanel);
|
||||
profile = importInspectionProfile(JDOMUtil.load(file.getInputStream()), myApplicationProfileManager, getProject(), wholePanel);
|
||||
final SingleInspectionProfilePanel existed = getProfilePanel(profile);
|
||||
if (existed != null) {
|
||||
if (Messages.showOkCancelDialog(wholePanel, "Profile with name \'" +
|
||||
@@ -377,13 +376,10 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
|
||||
myProfiles.getProfilesComboBox().removeProfile(existed.getProfile());
|
||||
myPanels.remove(existed);
|
||||
}
|
||||
InspectionProfileImpl model = profile.getModifiableModel();
|
||||
InspectionProfileModifiableModel model = new InspectionProfileModifiableModel(profile);
|
||||
model.setModified(true);
|
||||
addProfile(model);
|
||||
selectProfile(model);
|
||||
|
||||
//TODO myDeletedProfiles ? really need this
|
||||
myDeletedProfiles.remove(profile);
|
||||
}
|
||||
catch (JDOMException e) {
|
||||
LOG.error(e);
|
||||
@@ -421,23 +417,22 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
|
||||
public static InspectionProfileImpl importInspectionProfile(@NotNull Element rootElement,
|
||||
@NotNull BaseInspectionProfileManager profileManager,
|
||||
@NotNull Project project,
|
||||
@Nullable JPanel anchorPanel)
|
||||
throws JDOMException, IOException, InvalidDataException {
|
||||
@Nullable JPanel anchorPanel) {
|
||||
final boolean unitTestMode = ApplicationManager.getApplication().isUnitTestMode();
|
||||
if (!unitTestMode) {
|
||||
LOG.assertTrue(anchorPanel != null);
|
||||
}
|
||||
InspectionProfileImpl profile =
|
||||
new InspectionProfileImpl("TempProfile", InspectionToolRegistrar.getInstance(), profileManager);
|
||||
if (Comparing.strEqual(rootElement.getName(), "component")) {//import right from .idea/inspectProfiles/xxx.xml
|
||||
if (Comparing.strEqual(rootElement.getName(), "component")) {
|
||||
//import right from .idea/inspectProfiles/xxx.xml
|
||||
rootElement = rootElement.getChildren().get(0);
|
||||
}
|
||||
final Set<String> levels = new HashSet<>();
|
||||
for (Object o : rootElement.getChildren("inspection_tool")) {
|
||||
final Element inspectElement = (Element)o;
|
||||
for (Element inspectElement : rootElement.getChildren("inspection_tool")) {
|
||||
addLevelIfNotNull(levels, inspectElement);
|
||||
for (Object s : inspectElement.getChildren("scope")) {
|
||||
addLevelIfNotNull(levels, ((Element)s));
|
||||
for (Element s : inspectElement.getChildren("scope")) {
|
||||
addLevelIfNotNull(levels, s);
|
||||
}
|
||||
}
|
||||
for (Iterator<String> iterator = levels.iterator(); iterator.hasNext(); ) {
|
||||
@@ -471,7 +466,6 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
|
||||
profile.setProjectLevel(false);
|
||||
profile.initInspectionTools(project);
|
||||
return profile;
|
||||
|
||||
}
|
||||
|
||||
private static void addLevelIfNotNull(Set<String> levels, Element inspectElement) {
|
||||
@@ -499,9 +493,16 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
|
||||
@Override
|
||||
public void apply() {
|
||||
SingleInspectionProfilePanel selectedPanel = getSelectedPanel();
|
||||
for (InspectionProfileImpl profile : myDeletedProfiles) {
|
||||
deleteProfile(profile);
|
||||
for (InspectionProfileModifiableModel profile : myDeletedProfiles) {
|
||||
// getParentProfile here is original scheme
|
||||
if (profile.getProfileManager() == myApplicationProfileManager) {
|
||||
myApplicationProfileManager.deleteProfile(profile.getSource());
|
||||
}
|
||||
else {
|
||||
myProjectProfileManager.deleteProfile(profile.getName());
|
||||
}
|
||||
}
|
||||
|
||||
myDeletedProfiles.clear();
|
||||
|
||||
for (SingleInspectionProfilePanel panel : myPanels) {
|
||||
@@ -514,15 +515,6 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
|
||||
|
||||
protected abstract void applyRootProfile(@NotNull String name, boolean isProjectLevel);
|
||||
|
||||
private void deleteProfile(@NotNull InspectionProfileImpl profile) {
|
||||
if (profile.getProfileManager() == myApplicationProfileManager) {
|
||||
myApplicationProfileManager.deleteProfile(profile.getName());
|
||||
}
|
||||
else {
|
||||
myProjectProfileManager.deleteProfile(profile.getName());
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean acceptTool(InspectionToolWrapper entry) {
|
||||
return true;
|
||||
}
|
||||
@@ -536,9 +528,9 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
|
||||
myDeletedProfiles.clear();
|
||||
disposeUIResources();
|
||||
final Collection<InspectionProfileImpl> profiles = getProfiles();
|
||||
final List<InspectionProfileImpl> modifiableProfiles = new ArrayList<>(profiles.size());
|
||||
final List<InspectionProfileModifiableModel> modifiableProfiles = new ArrayList<>(profiles.size());
|
||||
for (InspectionProfileImpl profile : profiles) {
|
||||
InspectionProfileImpl inspectionProfile = profile.getModifiableModel();
|
||||
InspectionProfileModifiableModel inspectionProfile = new InspectionProfileModifiableModel(profile);
|
||||
modifiableProfiles.add(inspectionProfile);
|
||||
myPanels.add(createPanel(inspectionProfile));
|
||||
}
|
||||
@@ -556,7 +548,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
|
||||
}
|
||||
}
|
||||
|
||||
private SingleInspectionProfilePanel createPanel(InspectionProfileImpl profile) {
|
||||
private SingleInspectionProfilePanel createPanel(InspectionProfileModifiableModel profile) {
|
||||
return new SingleInspectionProfilePanel(myProjectProfileManager, profile) {
|
||||
@Override
|
||||
protected boolean accept(InspectionToolWrapper entry) {
|
||||
@@ -647,7 +639,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InspectionProfileImpl getSelectedObject() {
|
||||
public InspectionProfileModifiableModel getSelectedObject() {
|
||||
return myProfiles.getProfilesComboBox().getSelectedProfile();
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -16,6 +16,7 @@
|
||||
package com.intellij.profile.codeInspection.ui.header;
|
||||
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileModifiableModel;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.wm.IdeFocusManager;
|
||||
@@ -32,7 +33,7 @@ public abstract class ProfilesChooser extends JPanel {
|
||||
private static final String COMBO_CARD = "combo.card";
|
||||
private static final String EDIT_CARD = "edit.card";
|
||||
|
||||
private final ProfilesComboBox myProfilesComboBox;
|
||||
private final ProfilesComboBox<InspectionProfileModifiableModel> myProfilesComboBox;
|
||||
private final CardLayout myCardLayout;
|
||||
private final ValidatedTextField mySubmitNameComponent;
|
||||
private final SaveInputComponentValidator.Wrapper mySaveListener;
|
||||
@@ -46,7 +47,7 @@ public abstract class ProfilesChooser extends JPanel {
|
||||
myCardLayout = new CardLayout();
|
||||
myComboBoxPanel.setLayout(myCardLayout);
|
||||
setBorder(IdeBorderFactory.createEmptyBorder(JBUI.insets(4, 0, 6, 0)));
|
||||
myProfilesComboBox = new ProfilesComboBox() {
|
||||
myProfilesComboBox = new ProfilesComboBox<InspectionProfileModifiableModel>() {
|
||||
@Override
|
||||
protected void onProfileChosen(InspectionProfileImpl inspectionProfile) {
|
||||
ProfilesChooser.this.onProfileChosen(inspectionProfile);
|
||||
@@ -66,7 +67,7 @@ public abstract class ProfilesChooser extends JPanel {
|
||||
showComboBoxCard();
|
||||
}
|
||||
|
||||
ProfilesComboBox getProfilesComboBox() {
|
||||
ProfilesComboBox<InspectionProfileModifiableModel> getProfilesComboBox() {
|
||||
return myProfilesComboBox;
|
||||
}
|
||||
|
||||
|
||||
+13
-13
@@ -36,17 +36,17 @@ import java.util.List;
|
||||
/**
|
||||
* @author Dmitry Batkovich
|
||||
*/
|
||||
public abstract class ProfilesComboBox extends ComboBox<InspectionProfileImpl> {
|
||||
public abstract class ProfilesComboBox<T extends InspectionProfileImpl> extends ComboBox<T> {
|
||||
private static final String PROJECT_LEVEL_SEPARATOR_TEXT = "Project Level";
|
||||
private static final String GLOBAL_LEVEL_SEPARATOR_TEXT = "Global Level";
|
||||
|
||||
private SortedComboBoxModel<InspectionProfileImpl> myComboModel;
|
||||
private InspectionProfileImpl myFirstGlobalProfile;
|
||||
private SortedComboBoxModel<T> myComboModel;
|
||||
private T myFirstGlobalProfile;
|
||||
|
||||
public ProfilesComboBox() {
|
||||
final Comparator<InspectionProfileImpl> comparator =
|
||||
Comparator.comparing(InspectionProfileImpl::isProjectLevel).reversed().thenComparing(InspectionProfileImpl::getDisplayName);
|
||||
myComboModel = new SortedComboBoxModel<>(comparator);
|
||||
myComboModel = new SortedComboBoxModel<>(Comparator.comparing(T::isProjectLevel)
|
||||
.reversed()
|
||||
.thenComparing(InspectionProfileImpl::getDisplayName));
|
||||
setModel(myComboModel);
|
||||
//noinspection GtkPreferredJComboBoxRenderer
|
||||
setRenderer(new ListCellRenderer<InspectionProfileImpl>() {
|
||||
@@ -117,9 +117,9 @@ public abstract class ProfilesComboBox extends ComboBox<InspectionProfileImpl> {
|
||||
setSelectedItem(inspectionProfile);
|
||||
}
|
||||
|
||||
public void reset(final Collection<InspectionProfileImpl> profiles) {
|
||||
public void reset(final Collection<T> profiles) {
|
||||
myComboModel.clear();
|
||||
for (InspectionProfileImpl profile : profiles) {
|
||||
for (T profile : profiles) {
|
||||
myComboModel.add(profile);
|
||||
}
|
||||
findFirstGlobalProfile();
|
||||
@@ -127,32 +127,32 @@ public abstract class ProfilesComboBox extends ComboBox<InspectionProfileImpl> {
|
||||
resort();
|
||||
}
|
||||
|
||||
void removeProfile(InspectionProfileImpl profile) {
|
||||
void removeProfile(T profile) {
|
||||
myComboModel.remove(profile);
|
||||
if (!profile.isProjectLevel() && profile == myFirstGlobalProfile) {
|
||||
findFirstGlobalProfile();
|
||||
}
|
||||
}
|
||||
|
||||
public void addProfile(InspectionProfileImpl inspectionProfile) {
|
||||
public void addProfile(T inspectionProfile) {
|
||||
myComboModel.add(inspectionProfile);
|
||||
if (!inspectionProfile.isProjectLevel()) {
|
||||
findFirstGlobalProfile();
|
||||
}
|
||||
}
|
||||
|
||||
InspectionProfileImpl getSelectedProfile() {
|
||||
T getSelectedProfile() {
|
||||
return myComboModel.getSelectedItem();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
List<InspectionProfileImpl> getProfiles() {
|
||||
List<T> getProfiles() {
|
||||
return myComboModel.getItems();
|
||||
}
|
||||
|
||||
private void findFirstGlobalProfile() {
|
||||
myFirstGlobalProfile = null;
|
||||
for (InspectionProfileImpl profile : getProfiles()) {
|
||||
for (T profile : getProfiles()) {
|
||||
if (!profile.isProjectLevel()) {
|
||||
myFirstGlobalProfile = profile;
|
||||
break;
|
||||
|
||||
+3
-3
@@ -19,7 +19,7 @@ import com.intellij.codeInspection.InspectionProfile;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.ProblemHighlightType;
|
||||
import com.intellij.codeInspection.QuickFix;
|
||||
import com.intellij.codeInspection.ex.DisableInspectionToolAction;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileModifiableModelKt;
|
||||
import com.intellij.codeInspection.ex.UnfairLocalInspectionTool;
|
||||
import com.intellij.lang.properties.*;
|
||||
import com.intellij.lang.properties.ResourceBundle;
|
||||
@@ -134,8 +134,8 @@ public class IncompletePropertyInspection extends LocalInspectionTool implements
|
||||
final TreeSet<String> suffixesToIgnore = new TreeSet<>(ContainerUtil.map(allFilesWithoutTranslation,
|
||||
PropertiesUtil::getSuffix));
|
||||
if (new IncompletePropertyInspectionOptionsPanel(suffixesToIgnore).showDialogAndGet(project)) {
|
||||
DisableInspectionToolAction.modifyAndCommitProjectProfile(
|
||||
modifiableModel -> ((IncompletePropertyInspection)modifiableModel.getInspectionTool(TOOL_KEY, element).getTool()).addSuffixes(suffixesToIgnore), project);
|
||||
InspectionProfileModifiableModelKt.modifyAndCommitProjectProfile(project,
|
||||
it -> ((IncompletePropertyInspection)it.getInspectionTool(TOOL_KEY, element).getTool()).addSuffixes(suffixesToIgnore));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ import com.intellij.codeInspection.LocalInspectionToolSession;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileModifiableModelKt;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.ui.CheckBox;
|
||||
@@ -252,10 +252,8 @@ public class PyChainedComparisonsInspection extends PyInspection {
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiFile file = descriptor.getStartElement().getContainingFile();
|
||||
InspectionProjectProfileManager.getInstance(project).getInspectionProfile().modifyProfile(model -> {
|
||||
final PyChainedComparisonsInspection tool = (PyChainedComparisonsInspection)model.getUnwrappedTool(INSPECTION_SHORT_NAME, file);
|
||||
tool.ignoreConstantInTheMiddle = true;
|
||||
});
|
||||
InspectionProfileModifiableModelKt.modifyAndCommitProjectProfile(project, it ->
|
||||
((PyChainedComparisonsInspection)it.getUnwrappedTool(INSPECTION_SHORT_NAME, file)).ignoreConstantInTheMiddle = true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,11 @@ package com.jetbrains.python.inspections;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.LocalInspectionToolSession;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileModifiableModelKt;
|
||||
import com.intellij.codeInspection.ui.ListEditForm;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.lang.ASTNode;
|
||||
@@ -26,7 +30,6 @@ import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.PopupChooserBuilder;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -283,25 +286,16 @@ public class PyPep8NamingInspection extends PyInspection {
|
||||
@Override
|
||||
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
|
||||
final JBList list = new JBList(getBaseClassNames());
|
||||
final Runnable updateBlackList = () -> {
|
||||
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
|
||||
profile.modifyProfile(model -> {
|
||||
final PyPep8NamingInspection inspection = (PyPep8NamingInspection)model
|
||||
.getUnwrappedTool(PyPep8NamingInspection.class.getSimpleName(), descriptor.getPsiElement());
|
||||
DataManager.getInstance().getDataContextFromFocus().doWhenDone((Consumer<DataContext>)dataContext -> new PopupChooserBuilder(list)
|
||||
.setTitle("Ignore base class")
|
||||
.setItemChoosenCallback(() -> InspectionProfileModifiableModelKt.modifyAndCommitProjectProfile(project, it -> {
|
||||
PyPep8NamingInspection inspection =
|
||||
(PyPep8NamingInspection)it.getUnwrappedTool(PyPep8NamingInspection.class.getSimpleName(), descriptor.getPsiElement());
|
||||
addIfNotNull(inspection.ignoredBaseClasses, (String)list.getSelectedValue());
|
||||
});
|
||||
};
|
||||
DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() {
|
||||
@Override
|
||||
public void consume(DataContext dataContext) {
|
||||
new PopupChooserBuilder(list)
|
||||
.setTitle("Ignore base class")
|
||||
.setItemChoosenCallback(updateBlackList)
|
||||
.setFilteringEnabled(o -> (String)o)
|
||||
.createPopup()
|
||||
.showInBestPositionFor(dataContext);
|
||||
}
|
||||
});
|
||||
}))
|
||||
.setFilteringEnabled(o -> (String)o)
|
||||
.createPopup()
|
||||
.showInBestPositionFor(dataContext));
|
||||
}
|
||||
|
||||
public List<String> getBaseClassNames() {
|
||||
@@ -327,7 +321,7 @@ public class PyPep8NamingInspection extends PyInspection {
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiFile file = descriptor.getStartElement().getContainingFile();
|
||||
InspectionProjectProfileManager.getInstance(project).getCurrentProfile().modifyProfile(model -> {
|
||||
InspectionProfileModifiableModelKt.modifyAndCommitProjectProfile(project, model -> {
|
||||
PyPep8NamingInspection tool = (PyPep8NamingInspection)model.getUnwrappedTool(INSPECTION_SHORT_NAME, file);
|
||||
if (!tool.ignoredErrors.contains(myCode)) {
|
||||
tool.ignoredErrors.add(myCode);
|
||||
|
||||
@@ -18,9 +18,9 @@ package com.jetbrains.python.inspections;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.intellij.codeInsight.intention.LowPriorityAction;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileModifiableModelKt;
|
||||
import com.intellij.codeInspection.ui.ListEditForm;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
@@ -138,10 +138,9 @@ public class PyShadowingBuiltinsInspection extends PyInspection {
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
if (element != null) {
|
||||
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
|
||||
profile.modifyProfile(model -> {
|
||||
InspectionProfileModifiableModelKt.modifyAndCommitProjectProfile(project, it -> {
|
||||
final String toolName = PyShadowingBuiltinsInspection.class.getSimpleName();
|
||||
final PyShadowingBuiltinsInspection inspection = (PyShadowingBuiltinsInspection)model.getUnwrappedTool(toolName, element);
|
||||
final PyShadowingBuiltinsInspection inspection = (PyShadowingBuiltinsInspection)it.getUnwrappedTool(toolName, element);
|
||||
if (inspection != null) {
|
||||
if (!inspection.ignoredNames.contains(myName)) {
|
||||
inspection.ignoredNames.add(myName);
|
||||
|
||||
+2
-4
@@ -16,11 +16,10 @@
|
||||
package com.jetbrains.python.inspections.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.intention.LowPriorityAction;
|
||||
import com.intellij.codeInspection.InspectionProfile;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileModifiableModelKt;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.QualifiedName;
|
||||
import com.jetbrains.python.inspections.unresolvedReference.PyUnresolvedReferencesInspection;
|
||||
@@ -60,8 +59,7 @@ public class AddIgnoredIdentifierQuickFix implements LocalQuickFix, LowPriorityA
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement context = descriptor.getPsiElement();
|
||||
InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
|
||||
profile.modifyProfile(model -> {
|
||||
InspectionProfileModifiableModelKt.modifyAndCommitProjectProfile(project, model -> {
|
||||
PyUnresolvedReferencesInspection inspection =
|
||||
(PyUnresolvedReferencesInspection)model.getUnwrappedTool(PyUnresolvedReferencesInspection.class.getSimpleName(), context);
|
||||
String name = myIdentifier.toString();
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.InspectionProfile;
|
||||
import com.intellij.codeInspection.ex.CustomEditInspectionToolsSettingsAction;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileModifiableModelKt;
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.execution.process.ProcessOutput;
|
||||
import com.intellij.lang.annotation.Annotation;
|
||||
@@ -271,7 +272,7 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator<Pep8ExternalAnnotat
|
||||
problemElement = file.findElementAt(Math.max(0, offset - 1));
|
||||
}
|
||||
|
||||
if (ignoreDueToSettings(project, problem, problemElement) || ignoredDueToProblemSuppressors(project, problem, file, problemElement)) {
|
||||
if (ignoreDueToSettings(project, problem, problemElement) || ignoredDueToProblemSuppressors(problem, file, problemElement)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -331,8 +332,7 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator<Pep8ExternalAnnotat
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean ignoredDueToProblemSuppressors(@NotNull Project project,
|
||||
@NotNull Problem problem,
|
||||
private static boolean ignoredDueToProblemSuppressors(@NotNull Problem problem,
|
||||
@NotNull PsiFile file,
|
||||
@Nullable PsiElement element) {
|
||||
final Pep8ProblemSuppressor[] suppressors = Pep8ProblemSuppressor.EP_NAME.getExtensions();
|
||||
@@ -445,8 +445,8 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator<Pep8ExternalAnnotat
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, final PsiFile file) throws IncorrectOperationException {
|
||||
InspectionProjectProfileManager.getInstance(project).getCurrentProfile().modifyProfile(model -> {
|
||||
PyPep8Inspection tool = (PyPep8Inspection)model.getUnwrappedTool(PyPep8Inspection.INSPECTION_SHORT_NAME, file);
|
||||
InspectionProfileModifiableModelKt.modifyAndCommitProjectProfile(project, it -> {
|
||||
PyPep8Inspection tool = (PyPep8Inspection)it.getUnwrappedTool(PyPep8Inspection.INSPECTION_SHORT_NAME, file);
|
||||
if (!tool.ignoredErrors.contains(myCode)) {
|
||||
tool.ignoredErrors.add(myCode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user