mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
IDEA-130330 Inspection settings: severity of disabled scope is reported as for enabled
This commit is contained in:
+1
-1
@@ -765,7 +765,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
public ScopeToolState fun(InspectionConfigTreeNode node) {
|
||||
return node.getDefaultDescriptor().getState();
|
||||
}
|
||||
}));
|
||||
}), false);
|
||||
severityLevelChooser.setChosen(severity);
|
||||
|
||||
final ScopesChooser scopesChooser = new ScopesChooser(ContainerUtil.map(nodes, new Function<InspectionConfigTreeNode, Descriptor>() {
|
||||
|
||||
+16
-21
@@ -84,17 +84,18 @@ public class InspectionsConfigTreeTable extends TreeTable {
|
||||
final int row = rowAtPoint(point);
|
||||
final Object maybeIcon = getModel().getValueAt(row, column);
|
||||
if (maybeIcon instanceof MultiScopeSeverityIcon) {
|
||||
final MultiScopeSeverityIcon icon = (MultiScopeSeverityIcon)maybeIcon;
|
||||
final LinkedHashMap<String, HighlightDisplayLevel> scopeToAverageSeverityMap =
|
||||
((MultiScopeSeverityIcon)maybeIcon).getScopeToAverageSeverityMap();
|
||||
icon.getScopeToAverageSeverityMap();
|
||||
final JComponent component;
|
||||
if (scopeToAverageSeverityMap.size() == 1) {
|
||||
if (scopeToAverageSeverityMap.size() == 1 && scopeToAverageSeverityMap.get(icon.getDefaultScopeName()) != null) {
|
||||
final HighlightDisplayLevel level = ContainerUtil.getFirstItem(scopeToAverageSeverityMap.values());
|
||||
final JLabel label = new JLabel();
|
||||
label.setIcon(level.getIcon());
|
||||
label.setText(SingleInspectionProfilePanel.renderSeverity(level.getSeverity()));
|
||||
component = label;
|
||||
} else {
|
||||
component = new ScopesAndSeveritiesHintTable(scopeToAverageSeverityMap);
|
||||
component = new ScopesAndSeveritiesHintTable(scopeToAverageSeverityMap, icon.getDefaultScopeName());
|
||||
}
|
||||
IdeTooltipManager.getInstance().show(
|
||||
new IdeTooltip(InspectionsConfigTreeTable.this, point, component), false);
|
||||
@@ -267,10 +268,6 @@ public class InspectionsConfigTreeTable extends TreeTable {
|
||||
private HighlightSeverity myPrimarySeverity;
|
||||
private final Map<String, HighlightSeverity> myOccurrences = new HashMap<String, HighlightSeverity>();
|
||||
|
||||
public void setSeverityToMixed() {
|
||||
myPrimarySeverity = ScopesAndSeveritiesTable.MIXED_FAKE_SEVERITY;
|
||||
}
|
||||
|
||||
public SeverityAndOccurrences incOccurrences(final String toolName, final HighlightSeverity severity) {
|
||||
if (myPrimarySeverity == null) {
|
||||
myPrimarySeverity = severity;
|
||||
@@ -296,7 +293,6 @@ public class InspectionsConfigTreeTable extends TreeTable {
|
||||
|
||||
private static class MultiColoredHighlightSeverityIconSink {
|
||||
|
||||
|
||||
private final Map<String, SeverityAndOccurrences> myScopeToAverageSeverityMap = new HashMap<String, SeverityAndOccurrences>();
|
||||
|
||||
private String myDefaultScopeName;
|
||||
@@ -331,27 +327,23 @@ public class InspectionsConfigTreeTable extends TreeTable {
|
||||
if (myScopeToAverageSeverityMap.size() == 1) {
|
||||
return result;
|
||||
}
|
||||
String[] scopesOrder = inspectionProfile.getScopesOrder();
|
||||
if (scopesOrder == null || scopesOrder.length == 0) {
|
||||
final ArrayList<String> scopesList = new ArrayList<String>(myScopeToAverageSeverityMap.keySet());
|
||||
scopesList.remove(myDefaultScopeName);
|
||||
ContainerUtil.sort(scopesList);
|
||||
scopesOrder = ArrayUtil.toStringArray(scopesList);
|
||||
}
|
||||
|
||||
final SeverityAndOccurrences defaultSeveritiesAndOccurrences = myScopeToAverageSeverityMap.get(myDefaultScopeName);
|
||||
final int allInspectionsCount = defaultSeveritiesAndOccurrences.getOccurrencesSize();
|
||||
final Map<String, HighlightSeverity> allScopes = defaultSeveritiesAndOccurrences.getOccurrences();
|
||||
String[] reversedScopesOrder = ArrayUtil.reverseArray(scopesOrder);
|
||||
for (String currentScope : reversedScopesOrder) {
|
||||
final SeverityAndOccurrences currentSeverityAndOccurrences = myScopeToAverageSeverityMap.get(currentScope);
|
||||
for (Map.Entry<String, SeverityAndOccurrences> e : myScopeToAverageSeverityMap.entrySet()) {
|
||||
final String scope = e.getKey();
|
||||
if (myDefaultScopeName.equals(scope)) {
|
||||
continue;
|
||||
}
|
||||
final SeverityAndOccurrences currentSeverityAndOccurrences = e.getValue();
|
||||
if (currentSeverityAndOccurrences == null) {
|
||||
continue;
|
||||
}
|
||||
final HighlightSeverity currentSeverity = currentSeverityAndOccurrences.getPrimarySeverity();
|
||||
if (currentSeverity == ScopesAndSeveritiesTable.MIXED_FAKE_SEVERITY ||
|
||||
currentSeverityAndOccurrences.getOccurrencesSize() == allInspectionsCount) {
|
||||
result.put(currentScope, currentSeverity);
|
||||
result.put(scope, currentSeverity);
|
||||
}
|
||||
else {
|
||||
Set<String> toolsToCheck = ContainerUtil.newHashSet(allScopes.keySet());
|
||||
@@ -362,7 +354,7 @@ public class InspectionsConfigTreeTable extends TreeTable {
|
||||
final HighlightSeverity currentToolSeverity = lowerScopeOccurrences.get(toolName);
|
||||
if (currentToolSeverity != null) {
|
||||
if (!currentSeverity.equals(currentToolSeverity)) {
|
||||
result.put(currentScope, ScopesAndSeveritiesTable.MIXED_FAKE_SEVERITY);
|
||||
result.put(scope, ScopesAndSeveritiesTable.MIXED_FAKE_SEVERITY);
|
||||
doContinue = true;
|
||||
break;
|
||||
}
|
||||
@@ -371,7 +363,7 @@ public class InspectionsConfigTreeTable extends TreeTable {
|
||||
if (doContinue) {
|
||||
continue;
|
||||
}
|
||||
result.put(currentScope, currentSeverity);
|
||||
result.put(scope, currentSeverity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,6 +381,9 @@ public class InspectionsConfigTreeTable extends TreeTable {
|
||||
}
|
||||
|
||||
private void putOne(final ScopeToolState state) {
|
||||
if (!state.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
final Icon icon = state.getLevel().getIcon();
|
||||
final String scopeName = state.getScopeName();
|
||||
if (icon instanceof HighlightDisplayLevel.SingleColorIconWithMask) {
|
||||
|
||||
+8
@@ -40,6 +40,8 @@ public class MultiScopeSeverityIcon implements Icon {
|
||||
|
||||
private final LinkedHashMap<String, HighlightDisplayLevel> myScopeToAverageSeverityMap;
|
||||
|
||||
private final String myDefaultScopeName;
|
||||
|
||||
public MultiScopeSeverityIcon(final Map<String, HighlightSeverity> scopeToAverageSeverityMap,
|
||||
final String defaultScopeName,
|
||||
final InspectionProfileImpl inspectionProfile) {
|
||||
@@ -59,12 +61,18 @@ public class MultiScopeSeverityIcon implements Icon {
|
||||
}
|
||||
myScopeToAverageSeverityMap.put(scopeName, level);
|
||||
}
|
||||
|
||||
myDefaultScopeName = defaultScopeName;
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, HighlightDisplayLevel> getScopeToAverageSeverityMap() {
|
||||
return myScopeToAverageSeverityMap;
|
||||
}
|
||||
|
||||
public String getDefaultScopeName() {
|
||||
return myDefaultScopeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintIcon(final Component c, final Graphics g, final int i, final int j) {
|
||||
final int iconWidth = getIconWidth();
|
||||
|
||||
+12
-4
@@ -19,6 +19,7 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
@@ -36,8 +37,9 @@ public class ScopesAndSeveritiesHintTable extends JBTable {
|
||||
private final static int SCOPE_COLUMN = 0;
|
||||
private final static int SEVERITY_COLUMN = 1;
|
||||
|
||||
public ScopesAndSeveritiesHintTable(final LinkedHashMap<String, HighlightDisplayLevel> scopeToAverageSeverityMap) {
|
||||
super(new MyModel(scopeToAverageSeverityMap));
|
||||
public ScopesAndSeveritiesHintTable(final LinkedHashMap<String, HighlightDisplayLevel> scopeToAverageSeverityMap,
|
||||
final @NotNull String defaultScopeName) {
|
||||
super(new MyModel(scopeToAverageSeverityMap, defaultScopeName));
|
||||
|
||||
getColumnModel().getColumn(SCOPE_COLUMN).setCellRenderer(new DefaultTableCellRenderer() {
|
||||
@Override
|
||||
@@ -90,10 +92,14 @@ public class ScopesAndSeveritiesHintTable extends JBTable {
|
||||
private final static class MyModel extends AbstractTableModel {
|
||||
|
||||
private final LinkedHashMap<String, HighlightDisplayLevel> myScopeToAverageSeverityMap;
|
||||
@NotNull
|
||||
private final String myDefaultScopeName;
|
||||
private final List<String> myScopes;
|
||||
|
||||
public MyModel(final LinkedHashMap<String, HighlightDisplayLevel> scopeToAverageSeverityMap) {
|
||||
public MyModel(final LinkedHashMap<String, HighlightDisplayLevel> scopeToAverageSeverityMap,
|
||||
final @NotNull String defaultScopeName) {
|
||||
myScopeToAverageSeverityMap = scopeToAverageSeverityMap;
|
||||
myDefaultScopeName = defaultScopeName;
|
||||
myScopes = new ArrayList<String>(myScopeToAverageSeverityMap.keySet());
|
||||
}
|
||||
|
||||
@@ -119,7 +125,9 @@ public class ScopesAndSeveritiesHintTable extends JBTable {
|
||||
@Override
|
||||
public Object getValueAt(final int rowIndex, final int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case SCOPE_COLUMN: return rowIndex < getRowCount() - 1 ? myScopes.get(rowIndex) : "Everywhere else";
|
||||
case SCOPE_COLUMN:
|
||||
final String scopeName = myScopes.get(rowIndex);
|
||||
return myDefaultScopeName.equals(scopeName) ? "Everywhere else" : scopeName;
|
||||
case SEVERITY_COLUMN: return myScopeToAverageSeverityMap.get(myScopes.get(rowIndex));
|
||||
default: throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
+15
-47
@@ -95,8 +95,7 @@ public class ScopesAndSeveritiesTable extends JBTable {
|
||||
public void valueChanged(final ListSelectionEvent e) {
|
||||
final int idx = getSelectionModel().getMinSelectionIndex();
|
||||
if (idx >= 0) {
|
||||
final ExistedScopesStatesAndNonExistNames scopeToolState = ((MyTableModel)getModel()).getScopeToolState(idx);
|
||||
final List<ScopeToolState> existedStates = scopeToolState.getExistedStates();
|
||||
final List<ScopeToolState> existedStates = ((MyTableModel)getModel()).getScopeToolState(idx);
|
||||
if (existedStates.size() == 1) {
|
||||
tableSettings.onScopeChosen(existedStates.get(0));
|
||||
}
|
||||
@@ -166,9 +165,13 @@ public class ScopesAndSeveritiesTable extends JBTable {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HighlightSeverity getSeverity(final List<ScopeToolState> scopeToolStates) {
|
||||
public static HighlightSeverity getSeverity(final List<ScopeToolState> scopeToolStates, boolean onlyEnabled) {
|
||||
HighlightSeverity previousValue = null;
|
||||
onlyEnabled = onlyEnabled && scopeToolStates.size() != 1;
|
||||
for (final ScopeToolState scopeToolState : scopeToolStates) {
|
||||
if (onlyEnabled && !scopeToolState.isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
final HighlightSeverity currentValue = scopeToolState.getLevel().getSeverity();
|
||||
if (previousValue == null) {
|
||||
previousValue = currentValue;
|
||||
@@ -206,14 +209,7 @@ public class ScopesAndSeveritiesTable extends JBTable {
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(final int rowIndex, final int columnIndex) {
|
||||
if (columnIndex == SCOPE_NAME_COLUMN) {
|
||||
return false;
|
||||
} else if (columnIndex == SCOPE_ENABLED_COLUMN) {
|
||||
return true;
|
||||
}
|
||||
assert columnIndex == SEVERITY_COLUMN;
|
||||
final ExistedScopesStatesAndNonExistNames scopeToolState = getScopeToolState(rowIndex);
|
||||
return scopeToolState.getNonExistNames().isEmpty();
|
||||
return columnIndex != SCOPE_NAME_COLUMN;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -264,27 +260,24 @@ public class ScopesAndSeveritiesTable extends JBTable {
|
||||
}
|
||||
|
||||
private NamedScope getScope(final int rowIndex) {
|
||||
return getScopeToolState(rowIndex).getExistedStates().get(0).getScope(myProject);
|
||||
return getScopeToolState(rowIndex).get(0).getScope(myProject);
|
||||
}
|
||||
|
||||
private String getScopeName(final int rowIndex) {
|
||||
return getScopeToolState(rowIndex).getExistedStates().get(0).getScopeName();
|
||||
return getScopeToolState(rowIndex).get(0).getScopeName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private SeverityState getSeverityState(final int rowIndex) {
|
||||
final ExistedScopesStatesAndNonExistNames existedScopesStatesAndNonExistNames = getScopeToolState(rowIndex);
|
||||
if (!existedScopesStatesAndNonExistNames.getNonExistNames().isEmpty()) {
|
||||
return new SeverityState(MIXED_FAKE_SEVERITY, false);
|
||||
}
|
||||
return new SeverityState(getSeverity(existedScopesStatesAndNonExistNames.getExistedStates()), true);
|
||||
final List<ScopeToolState> existedScopesStatesAndNonExistNames = getScopeToolState(rowIndex);
|
||||
return new SeverityState(getSeverity(existedScopesStatesAndNonExistNames, true), true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Boolean isEnabled(final int rowIndex) {
|
||||
Boolean previousValue = null;
|
||||
final ExistedScopesStatesAndNonExistNames existedScopesStatesAndNonExistNames = getScopeToolState(rowIndex);
|
||||
for (final ScopeToolState scopeToolState : existedScopesStatesAndNonExistNames.getExistedStates()) {
|
||||
final List<ScopeToolState> existedScopesStatesAndNonExistNames = getScopeToolState(rowIndex);
|
||||
for (final ScopeToolState scopeToolState : existedScopesStatesAndNonExistNames) {
|
||||
final boolean currentValue = scopeToolState.isEnabled();
|
||||
if (previousValue == null) {
|
||||
previousValue = currentValue;
|
||||
@@ -292,24 +285,18 @@ public class ScopesAndSeveritiesTable extends JBTable {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (!existedScopesStatesAndNonExistNames.getNonExistNames().isEmpty() && !Boolean.FALSE.equals(previousValue)) {
|
||||
return null;
|
||||
}
|
||||
return previousValue;
|
||||
}
|
||||
|
||||
private ExistedScopesStatesAndNonExistNames getScopeToolState(final int rowIndex) {
|
||||
final List<String> nonExistNames = new SmartList<String>();
|
||||
private List<ScopeToolState> getScopeToolState(final int rowIndex) {
|
||||
final List<ScopeToolState> existedStates = new SmartList<ScopeToolState>();
|
||||
for (final String keyName : myKeyNames) {
|
||||
final ScopeToolState scopeToolState = getScopeToolState(keyName, rowIndex);
|
||||
if (scopeToolState != null) {
|
||||
existedStates.add(scopeToolState);
|
||||
} else {
|
||||
nonExistNames.add(keyName);
|
||||
}
|
||||
}
|
||||
return new ExistedScopesStatesAndNonExistNames(existedStates, nonExistNames);
|
||||
return existedStates;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -432,23 +419,4 @@ public class ScopesAndSeveritiesTable extends JBTable {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ExistedScopesStatesAndNonExistNames {
|
||||
|
||||
private final List<ScopeToolState> myExistedStates;
|
||||
private final List<String> myNonExistNames;
|
||||
|
||||
public ExistedScopesStatesAndNonExistNames(final List<ScopeToolState> existedStates, final List<String> nonExistNames) {
|
||||
myExistedStates = existedStates;
|
||||
myNonExistNames = nonExistNames;
|
||||
}
|
||||
|
||||
public List<ScopeToolState> getExistedStates() {
|
||||
return myExistedStates;
|
||||
}
|
||||
|
||||
public List<String> getNonExistNames() {
|
||||
return myNonExistNames;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user