use of com.intellij.codeInspection.ex.InspectionToolWrapper in project intellij-community by JetBrains.
the class SuppressActionWrapper method getChildren.
@Override
@NotNull
public AnAction[] getChildren(@Nullable final AnActionEvent e) {
final InspectionResultsView view = getView(e);
if (view == null)
return AnAction.EMPTY_ARRAY;
final InspectionToolWrapper wrapper = view.getTree().getSelectedToolWrapper(true);
if (wrapper == null)
return AnAction.EMPTY_ARRAY;
final Set<SuppressIntentionAction> suppressActions = view.getSuppressActions(wrapper);
if (suppressActions.isEmpty())
return AnAction.EMPTY_ARRAY;
final AnAction[] actions = new AnAction[suppressActions.size() + 1];
int i = 0;
for (SuppressIntentionAction action : suppressActions) {
actions[i++] = new SuppressTreeAction(action);
}
actions[suppressActions.size()] = Separator.getInstance();
Arrays.sort(actions, new Comparator<AnAction>() {
@Override
public int compare(AnAction a1, AnAction a2) {
return getWeight(a1) - getWeight(a2);
}
public int getWeight(AnAction a) {
return a instanceof Separator ? 0 : ((SuppressTreeAction) a).isSuppressAll() ? 1 : -1;
}
});
return actions;
}
use of com.intellij.codeInspection.ex.InspectionToolWrapper in project intellij-community by JetBrains.
the class InspectionTree method getSelectedToolWrapper.
@Nullable
public InspectionToolWrapper getSelectedToolWrapper(boolean allowDummy) {
final TreePath[] paths = getSelectionPaths();
if (paths == null)
return null;
InspectionToolWrapper toolWrapper = null;
for (TreePath path : paths) {
Object[] nodes = path.getPath();
for (int j = nodes.length - 1; j >= 0; j--) {
Object node = nodes[j];
if (node instanceof InspectionGroupNode) {
return null;
}
if (node instanceof InspectionNode) {
InspectionToolWrapper wrapper = ((InspectionNode) node).getToolWrapper();
if (!allowDummy && getContext().getPresentation(wrapper).isDummy()) {
continue;
}
if (toolWrapper == null) {
toolWrapper = wrapper;
} else if (toolWrapper != wrapper) {
return null;
}
break;
}
}
}
return toolWrapper;
}
use of com.intellij.codeInspection.ex.InspectionToolWrapper in project intellij-community by JetBrains.
the class InspectionTree method getSelectedElements.
@NotNull
public RefEntity[] getSelectedElements() {
TreePath[] selectionPaths = getSelectionPaths();
if (selectionPaths != null) {
InspectionToolWrapper toolWrapper = getSelectedToolWrapper(true);
if (toolWrapper == null)
return RefEntity.EMPTY_ELEMENTS_ARRAY;
Set<RefEntity> result = new LinkedHashSet<>();
for (TreePath selectionPath : selectionPaths) {
final InspectionTreeNode node = (InspectionTreeNode) selectionPath.getLastPathComponent();
addElementsInNode(node, result);
}
return ArrayUtil.reverseArray(result.toArray(new RefEntity[result.size()]));
}
return RefEntity.EMPTY_ELEMENTS_ARRAY;
}
use of com.intellij.codeInspection.ex.InspectionToolWrapper in project intellij-community by JetBrains.
the class InspectionListCellRenderer method getListCellRendererComponent.
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean sel, boolean focus) {
final BorderLayout layout = new BorderLayout();
layout.setHgap(5);
final JPanel panel = new JPanel(layout);
panel.setOpaque(true);
final Color bg = sel ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground();
final Color fg = sel ? UIUtil.getListSelectionForeground() : UIUtil.getListForeground();
panel.setBackground(bg);
panel.setForeground(fg);
if (value instanceof InspectionToolWrapper) {
final InspectionToolWrapper toolWrapper = (InspectionToolWrapper) value;
final String inspectionName = " " + toolWrapper.getDisplayName();
final String groupName = StringUtil.join(toolWrapper.getGroupPath(), " | ");
final String matchingText = inspectionName + "|" + groupName;
Matcher matcher = MatcherHolder.getAssociatedMatcher(list);
List<TextRange> fragments = matcher == null ? null : ((MinusculeMatcher) matcher).matchingFragments(matchingText);
List<TextRange> adjustedFragments = new ArrayList<>();
if (fragments != null) {
adjustedFragments.addAll(fragments);
}
final int splitPoint = adjustRanges(adjustedFragments, inspectionName.length() + 1);
final SimpleColoredComponent c = new SimpleColoredComponent();
final boolean matchHighlighting = Registry.is("ide.highlight.match.in.selected.only") && !sel;
if (matchHighlighting) {
c.append(inspectionName, myPlain);
} else {
final List<TextRange> ranges = adjustedFragments.subList(0, splitPoint);
SpeedSearchUtil.appendColoredFragments(c, inspectionName, ranges, sel ? mySelected : myPlain, myHighlighted);
}
panel.add(c, BorderLayout.WEST);
final SimpleColoredComponent group = new SimpleColoredComponent();
if (matchHighlighting) {
group.append(groupName, SimpleTextAttributes.GRAYED_ATTRIBUTES);
} else {
final SimpleTextAttributes attributes = sel ? mySelected : SimpleTextAttributes.GRAYED_ATTRIBUTES;
final List<TextRange> ranges = adjustedFragments.subList(splitPoint, adjustedFragments.size());
SpeedSearchUtil.appendColoredFragments(group, groupName, ranges, attributes, myHighlighted);
}
final JPanel right = new JPanel(new BorderLayout());
right.setBackground(bg);
right.setForeground(fg);
right.add(group, BorderLayout.CENTER);
final JLabel icon = new JLabel(getIcon(toolWrapper));
icon.setBackground(bg);
icon.setForeground(fg);
right.add(icon, BorderLayout.EAST);
panel.add(right, BorderLayout.EAST);
} else {
// E.g. "..." item
return value == ChooseByNameBase.NON_PREFIX_SEPARATOR ? ChooseByNameBase.renderNonPrefixSeparatorComponent(UIUtil.getListBackground()) : super.getListCellRendererComponent(list, value, index, sel, focus);
}
return panel;
}
use of com.intellij.codeInspection.ex.InspectionToolWrapper in project intellij-community by JetBrains.
the class RunInspectionAction method runInspection.
public static void runInspection(@NotNull final Project project, @NotNull String shortName, @Nullable VirtualFile virtualFile, PsiElement psiElement, PsiFile psiFile) {
final PsiElement element = psiFile == null ? psiElement : psiFile;
final InspectionProfile currentProfile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
final InspectionToolWrapper toolWrapper = element != null ? currentProfile.getInspectionTool(shortName, element) : currentProfile.getInspectionTool(shortName, project);
LOGGER.assertTrue(toolWrapper != null, "Missed inspection: " + shortName);
final InspectionManagerEx managerEx = (InspectionManagerEx) InspectionManager.getInstance(project);
final Module module = virtualFile != null ? ModuleUtilCore.findModuleForFile(virtualFile, project) : null;
AnalysisScope analysisScope = null;
if (psiFile != null) {
analysisScope = new AnalysisScope(psiFile);
} else {
if (virtualFile != null && virtualFile.isDirectory()) {
final PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(virtualFile);
if (psiDirectory != null) {
analysisScope = new AnalysisScope(psiDirectory);
}
}
if (analysisScope == null && virtualFile != null) {
analysisScope = new AnalysisScope(project, Arrays.asList(virtualFile));
}
if (analysisScope == null) {
analysisScope = new AnalysisScope(project);
}
}
final AnalysisUIOptions options = AnalysisUIOptions.getInstance(project);
final FileFilterPanel fileFilterPanel = new FileFilterPanel();
fileFilterPanel.init(options);
final AnalysisScope initialAnalysisScope = analysisScope;
final BaseAnalysisActionDialog dialog = new BaseAnalysisActionDialog("Run '" + toolWrapper.getDisplayName() + "'", AnalysisScopeBundle.message("analysis.scope.title", InspectionsBundle.message("inspection.action.noun")), project, analysisScope, module != null ? module.getName() : null, true, options, psiElement) {
private InspectionToolWrapper myUpdatedSettingsToolWrapper;
@Nullable
@Override
protected JComponent getAdditionalActionSettings(Project project) {
final JPanel fileFilter = fileFilterPanel.getPanel();
if (toolWrapper.getTool().createOptionsPanel() != null) {
JPanel additionPanel = new JPanel();
additionPanel.setLayout(new BoxLayout(additionPanel, BoxLayout.Y_AXIS));
additionPanel.add(fileFilter);
//new InheritOptionsForToolPanel(toolWrapper.getShortName(), project);
myUpdatedSettingsToolWrapper = copyToolWithSettings(toolWrapper);
additionPanel.add(new TitledSeparator(IdeBundle.message("goto.inspection.action.choose.inherit.settings.from")));
JComponent optionsPanel = myUpdatedSettingsToolWrapper.getTool().createOptionsPanel();
LOGGER.assertTrue(optionsPanel != null);
if (UIUtil.hasScrollPane(optionsPanel)) {
additionPanel.add(optionsPanel);
} else {
additionPanel.add(ScrollPaneFactory.createScrollPane(optionsPanel, SideBorder.NONE));
}
return additionPanel;
} else {
return fileFilter;
}
}
@NotNull
@Override
public AnalysisScope getScope(@NotNull AnalysisUIOptions uiOptions, @NotNull AnalysisScope defaultScope, @NotNull Project project, Module module) {
final AnalysisScope scope = super.getScope(uiOptions, defaultScope, project, module);
final GlobalSearchScope filterScope = fileFilterPanel.getSearchScope();
if (filterScope == null) {
return scope;
}
scope.setFilter(filterScope);
return scope;
}
private AnalysisScope getScope() {
return getScope(options, initialAnalysisScope, project, module);
}
private InspectionToolWrapper getToolWrapper() {
return myUpdatedSettingsToolWrapper == null ? toolWrapper : myUpdatedSettingsToolWrapper;
}
@NotNull
@Override
protected Action[] createActions() {
final List<Action> actions = new ArrayList<>();
final boolean hasFixAll = toolWrapper.getTool() instanceof CleanupLocalInspectionTool;
actions.add(new AbstractAction(hasFixAll ? AnalysisScopeBundle.message("action.analyze.verb") : CommonBundle.getOkButtonText()) {
{
putValue(DEFAULT_ACTION, Boolean.TRUE);
}
@Override
public void actionPerformed(ActionEvent e) {
RunInspectionIntention.rerunInspection(getToolWrapper(), managerEx, getScope(), null);
close(DialogWrapper.OK_EXIT_CODE);
}
});
if (hasFixAll) {
actions.add(new AbstractAction("Fix All") {
@Override
public void actionPerformed(ActionEvent e) {
InspectionToolWrapper wrapper = getToolWrapper();
InspectionProfileImpl cleanupToolProfile = RunInspectionIntention.createProfile(wrapper, managerEx, null);
managerEx.createNewGlobalContext(false).codeCleanup(getScope(), cleanupToolProfile, "Cleanup by " + wrapper.getDisplayName(), null, false);
close(DialogWrapper.OK_EXIT_CODE);
}
});
}
actions.add(getCancelAction());
if (SystemInfo.isMac) {
Collections.reverse(actions);
}
return actions.toArray(new Action[actions.size()]);
}
};
dialog.showAndGet();
}
Aggregations