summaryrefslogtreecommitdiff
path: root/platform/analysis-impl/src/com/intellij/codeInspection/ex
diff options
context:
space:
mode:
Diffstat (limited to 'platform/analysis-impl/src/com/intellij/codeInspection/ex')
-rw-r--r--platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java50
-rw-r--r--platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java52
2 files changed, 79 insertions, 23 deletions
diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java
index d8dc5d00656a..0a1861e8000e 100644
--- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java
+++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java
@@ -39,9 +39,13 @@ import com.intellij.profile.codeInspection.InspectionProfileManager;
import com.intellij.profile.codeInspection.SeverityProvider;
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.Function;
import com.intellij.util.containers.ContainerUtil;
+import com.intellij.util.graph.CachingSemiGraph;
+import com.intellij.util.graph.DFSTBuilder;
+import com.intellij.util.graph.GraphGenerator;
import gnu.trove.THashMap;
import org.jdom.Document;
import org.jdom.Element;
@@ -85,7 +89,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
private final ExternalInfo myExternalInfo = new ExternalInfo();
@TestOnly
public static boolean INIT_INSPECTIONS = false;
- private List<NamedScope> myScopes = Collections.emptyList();
+ private String[] myScopesOrder = null;
@Override
public void setModified(final boolean modified) {
@@ -509,6 +513,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
catch (ProcessCanceledException e) {
return false;
}
+ final Map<String, List<String>> dependencies = new HashMap<String, List<String>>();
for (InspectionToolWrapper toolWrapper : tools) {
final String shortName = toolWrapper.getShortName();
HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
@@ -536,7 +541,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
final Element element = myDeinstalledInspectionsSettings.remove(toolWrapper.getShortName());
if (element != null) {
try {
- toolsList.readExternal(element, this);
+ toolsList.readExternal(element, this, dependencies);
}
catch (InvalidDataException e) {
LOG.error("Can't read settings for " + toolWrapper, e);
@@ -544,12 +549,39 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
myTools.put(toolWrapper.getShortName(), toolsList);
}
+ final GraphGenerator<String> graphGenerator = GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph<String>() {
+ @Override
+ public Collection<String> getNodes() {
+ return dependencies.keySet();
+ }
+
+ @Override
+ public Iterator<String> getIn(String n) {
+ return dependencies.get(n).iterator();
+ }
+ }));
+
+ DFSTBuilder<String> builder = new DFSTBuilder<String>(graphGenerator);
+ if (builder.isAcyclic()) {
+ final List<String> scopes = builder.getSortedNodes();
+ myScopesOrder = ArrayUtil.toStringArray(scopes);
+ }
+
if (mySource != null) {
copyToolsConfigurations(mySource, project);
}
return true;
}
+ @Nullable
+ public String[] getScopesOrder() {
+ return myScopesOrder;
+ }
+
+ public void setScopesOrder(String[] scopesOrder) {
+ myScopesOrder = scopesOrder;
+ }
+
@NotNull
private List<InspectionToolWrapper> createTools(Project project) {
if (mySource != null) {
@@ -907,13 +939,13 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
return getTools(toolWrapper.getShortName(), project).prependTool(scope, toolWrapper, enabled, level);
}
- public void setErrorLevel(@NotNull HighlightDisplayKey key, @NotNull HighlightDisplayLevel level, int scopeIdx, Project project) {
- getTools(key.toString(), project).setLevel(level, scopeIdx, project);
+ public void setErrorLevel(@NotNull HighlightDisplayKey key, @NotNull HighlightDisplayLevel level, String scopeName, Project project) {
+ getTools(key.toString(), project).setLevel(level, scopeName, project);
}
- public void setErrorLevel(@NotNull List<HighlightDisplayKey> keys, @NotNull HighlightDisplayLevel level, int scopeIdx, Project project) {
+ public void setErrorLevel(@NotNull List<HighlightDisplayKey> keys, @NotNull HighlightDisplayLevel level, String scopeName, Project project) {
for (HighlightDisplayKey key : keys) {
- getTools(key.toString(), project).setLevel(level, scopeIdx, project);
+ setErrorLevel(key, level, scopeName, project);
}
}
@@ -944,10 +976,4 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
return super.equals(o) && ((InspectionProfileImpl)o).getProfileManager() == getProfileManager();
}
- /**
- * @return list of used scopes for all inspections
- */
- public List<NamedScope> getUsedScopes() {
- return myScopes;
- }
}
diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java
index b28dad40f094..267c0ee67fc3 100644
--- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java
+++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/ToolsImpl.java
@@ -46,6 +46,7 @@ import org.jetbrains.annotations.TestOnly;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
public class ToolsImpl implements Tools {
@NonNls private static final String ENABLED_BY_DEFAULT_ATTRIBUTE = "enabled_by_default";
@@ -170,7 +171,7 @@ public class ToolsImpl implements Tools {
}
}
- void readExternal(@NotNull Element toolElement, @NotNull InspectionProfile profile) throws InvalidDataException {
+ void readExternal(@NotNull Element toolElement, @NotNull InspectionProfile profile, Map<String, List<String>> dependencies) throws InvalidDataException {
final String levelName = toolElement.getAttributeValue(LEVEL_ATTRIBUTE);
final ProfileManager profileManager = profile.getProfileManager();
final SeverityRegistrar registrar = ((SeverityProvider)profileManager).getOwnSeverityRegistrar();
@@ -187,6 +188,7 @@ public class ToolsImpl implements Tools {
final InspectionToolWrapper toolWrapper = myDefaultState.getTool();
final List scopeElements = toolElement.getChildren(ProfileEx.SCOPE);
+ final List<String> scopeNames = new ArrayList<String>();
for (Object sO : scopeElements) {
final Element scopeElement = (Element)sO;
final String scopeName = scopeElement.getAttributeValue(ProfileEx.NAME);
@@ -216,6 +218,20 @@ public class ToolsImpl implements Tools {
else {
addTool(scopeName, copyToolWrapper, enabledInScope != null && Boolean.parseBoolean(enabledInScope), scopeLevel);
}
+
+ scopeNames.add(scopeName);
+ }
+
+ for (int i = 0; i < scopeNames.size(); i++) {
+ String scopeName = scopeNames.get(i);
+ List<String> order = dependencies.get(scopeName);
+ if (order == null) {
+ order = new ArrayList<String>();
+ dependencies.put(scopeName, order);
+ }
+ for (int j = i + 1; j < scopeNames.size(); j++) {
+ order.add(scopeNames.get(j));
+ }
}
// check if unknown children exists
@@ -445,22 +461,36 @@ public class ToolsImpl implements Tools {
}
- public void setLevel(@NotNull HighlightDisplayLevel level, int idx, Project project) {
- if (myTools != null && myTools.size() > idx && idx >= 0) {
- final ScopeToolState scopeToolState = myTools.get(idx);
- myTools.remove(idx);
+ public void setLevel(@NotNull HighlightDisplayLevel level, @Nullable String scopeName, Project project) {
+ if (scopeName == null) {
+ myDefaultState.setLevel(level);
+ } else {
+ if (myTools == null) {
+ return;
+ }
+ ScopeToolState scopeToolState = null;
+ int index = -1;
+ for (int i = 0; i < myTools.size(); i++) {
+ ScopeToolState tool = myTools.get(i);
+ if (scopeName.equals(tool.getScopeName())) {
+ scopeToolState = tool;
+ myTools.remove(tool);
+ index = i;
+ break;
+ }
+ }
+ if (index < 0) {
+ throw new IllegalStateException("Scope " + scopeName + " not found");
+ }
+ final InspectionToolWrapper toolWrapper = scopeToolState.getTool();
final NamedScope scope = scopeToolState.getScope(project);
- InspectionToolWrapper toolWrapper = scopeToolState.getTool();
if (scope != null) {
- myTools.add(idx, new ScopeToolState(scope, toolWrapper, scopeToolState.isEnabled(), level));
+ myTools.add(index, new ScopeToolState(scope, toolWrapper, scopeToolState.isEnabled(), level));
}
else {
- myTools.add(idx, new ScopeToolState(scopeToolState.getScopeName(), toolWrapper, scopeToolState.isEnabled(), level));
+ myTools.add(index, new ScopeToolState(scopeToolState.getScopeName(), toolWrapper, scopeToolState.isEnabled(), level));
}
}
- else if (idx == -1) {
- myDefaultState.setLevel(level);
- }
}
public void setDefaultState(@NotNull InspectionToolWrapper toolWrapper, boolean enabled, @NotNull HighlightDisplayLevel level) {