summaryrefslogtreecommitdiff
path: root/platform/analysis-impl/src/com/intellij/codeInspection
diff options
context:
space:
mode:
Diffstat (limited to 'platform/analysis-impl/src/com/intellij/codeInspection')
-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
-rw-r--r--platform/analysis-impl/src/com/intellij/codeInspection/reference/RefManagerImpl.java5
-rw-r--r--platform/analysis-impl/src/com/intellij/codeInspection/ui/ConventionOptionsPanel.java54
4 files changed, 90 insertions, 71 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) {
diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/reference/RefManagerImpl.java b/platform/analysis-impl/src/com/intellij/codeInspection/reference/RefManagerImpl.java
index 0fbd048f4929..f31e44e96e2c 100644
--- a/platform/analysis-impl/src/com/intellij/codeInspection/reference/RefManagerImpl.java
+++ b/platform/analysis-impl/src/com/intellij/codeInspection/reference/RefManagerImpl.java
@@ -149,6 +149,7 @@ public class RefManagerImpl extends RefManager {
}
}
+ @Nullable
@Override
public AnalysisScope getScope() {
return myScope;
@@ -304,7 +305,9 @@ public class RefManagerImpl extends RefManager {
if (!myDeclarationsFound) {
long before = System.currentTimeMillis();
final AnalysisScope scope = getScope();
- scope.accept(myProjectIterator);
+ if (scope != null) {
+ scope.accept(myProjectIterator);
+ }
myDeclarationsFound = true;
LOG.info("Total duration of processing project usages:" + (System.currentTimeMillis() - before));
diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ui/ConventionOptionsPanel.java b/platform/analysis-impl/src/com/intellij/codeInspection/ui/ConventionOptionsPanel.java
index 0afe259bd018..ba9125f3808a 100644
--- a/platform/analysis-impl/src/com/intellij/codeInspection/ui/ConventionOptionsPanel.java
+++ b/platform/analysis-impl/src/com/intellij/codeInspection/ui/ConventionOptionsPanel.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
@@ -18,6 +18,7 @@ package com.intellij.codeInspection.ui;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.ui.DocumentAdapter;
+import com.intellij.util.ReflectionUtil;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -28,7 +29,6 @@ import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
import javax.swing.text.InternationalFormatter;
import java.awt.*;
-import java.lang.reflect.Field;
import java.text.NumberFormat;
import java.util.regex.Pattern;
@@ -150,58 +150,18 @@ public class ConventionOptionsPanel extends JPanel {
}
private static void setPropertyIntegerValue(InspectionProfileEntry owner, String property, Integer value) {
- try {
- final Field field = getField(owner.getClass(), property);
- field.setAccessible(true);
- field.setInt(owner, value.intValue());
- } catch (Exception e) {
- LOG.error(e);
- }
+ setPropertyValue(owner, property, value);
}
private static Integer getPropertyIntegerValue(InspectionProfileEntry owner, String property) {
- try {
- final Field field = getField(owner.getClass(), property);
- field.setAccessible(true);
- return Integer.valueOf(field.getInt(owner));
- } catch (Exception e) {
- LOG.error(e);
- return 0;
- }
+ return (Integer)getPropertyValue(owner, property);
}
- private static void setPropertyValue(InspectionProfileEntry owner, String property, Object value) {
- try {
- final Field field = getField(owner.getClass(), property);
- field.setAccessible(true);
- field.set(owner, value);
- } catch (Exception e) {
- LOG.error(e);
- }
+ private static void setPropertyValue(@NotNull InspectionProfileEntry owner, String property, Object value) {
+ ReflectionUtil.setField(owner.getClass(), owner, null, property, value);
}
private static Object getPropertyValue(InspectionProfileEntry owner, String property) {
- try {
- final Field field = getField(owner.getClass(), property);
- field.setAccessible(true);
- return field.get(owner);
- }
- catch (Exception e) {
- LOG.error(e);
- return null;
- }
- }
-
- private static Field getField(Class clazz, String fieldName) throws NoSuchFieldException {
- try {
- return clazz.getDeclaredField(fieldName);
- } catch (NoSuchFieldException e) {
- Class superClass = clazz.getSuperclass();
- if (superClass == null) {
- throw e;
- } else {
- return getField(superClass, fieldName);
- }
- }
+ return ReflectionUtil.getField(owner.getClass(), owner, null, property);
}
}