use of com.intellij.codeInspection.ex.InspectionManagerEx in project android by JetBrains.
the class AndroidTestCase method doGlobalInspectionTest.
/**
* Given an inspection and a path to a directory that contains an "expected.xml" file, run the
* inspection on the current test project and verify that its output matches that of the
* expected file.
*/
protected final void doGlobalInspectionTest(@NotNull GlobalInspectionToolWrapper wrapper, @NotNull String globalTestDir, @NotNull AnalysisScope scope) {
myFixture.enableInspections(wrapper.getTool());
scope.invalidate();
InspectionManagerEx inspectionManager = (InspectionManagerEx) InspectionManager.getInstance(getProject());
GlobalInspectionContextForTests globalContext = CodeInsightTestFixtureImpl.createGlobalContextForTool(scope, getProject(), inspectionManager, wrapper);
InspectionTestUtil.runTool(wrapper, scope, globalContext);
InspectionTestUtil.compareToolResults(globalContext, wrapper, false, getTestDataPath() + globalTestDir);
}
use of com.intellij.codeInspection.ex.InspectionManagerEx in project intellij-community by JetBrains.
the class SuppressActionSequentialTask method suppress.
private void suppress(@NotNull final PsiElement element, @Nullable final CommonProblemDescriptor descriptor, @NotNull final SuppressIntentionAction action, @NotNull final RefEntity refEntity, InspectionToolWrapper wrapper, @NotNull final SuppressableInspectionTreeNode node) {
if (action instanceof SuppressIntentionActionFromFix && !(descriptor instanceof ProblemDescriptor)) {
LOG.info("local suppression fix for specific problem descriptor: " + wrapper.getTool().getClass().getName());
}
final Project project = element.getProject();
ApplicationManager.getApplication().runWriteAction(() -> {
PsiDocumentManager.getInstance(project).commitAllDocuments();
try {
PsiElement container = null;
if (action instanceof SuppressIntentionActionFromFix) {
container = ((SuppressIntentionActionFromFix) action).getContainer(element);
}
if (container == null) {
container = element;
}
if (action.isAvailable(project, null, element)) {
action.invoke(project, null, element);
}
final Set<GlobalInspectionContextImpl> globalInspectionContexts = ((InspectionManagerEx) InspectionManager.getInstance(element.getProject())).getRunningContexts();
for (GlobalInspectionContextImpl context : globalInspectionContexts) {
context.ignoreElement(wrapper.getTool(), container);
if (descriptor != null) {
context.getPresentation(wrapper).ignoreCurrentElementProblem(refEntity, descriptor);
}
}
final RefElement containerRef = refEntity.getRefManager().getReference(container);
final Set<Object> suppressedNodes = myContext.getView().getSuppressedNodes(wrapper.getShortName());
if (containerRef != null) {
Queue<RefEntity> toIgnoreInView = new Queue<>(1);
toIgnoreInView.addLast(containerRef);
while (!toIgnoreInView.isEmpty()) {
final RefEntity entity = toIgnoreInView.pullFirst();
if (node instanceof ProblemDescriptionNode) {
final CommonProblemDescriptor[] descriptors = myContext.getPresentation(wrapper).getIgnoredElements().get(entity);
if (descriptors != null) {
Collections.addAll(suppressedNodes, descriptors);
}
} else {
suppressedNodes.add(entity);
}
final List<RefEntity> children = entity.getChildren();
for (RefEntity child : children) {
toIgnoreInView.addLast(child);
}
}
}
if (node instanceof ProblemDescriptionNode) {
suppressedNodes.add(descriptor);
}
} catch (IncorrectOperationException e1) {
LOG.error(e1);
}
});
node.removeSuppressActionFromAvailable(mySuppressAction);
}
use of com.intellij.codeInspection.ex.InspectionManagerEx in project intellij-community by JetBrains.
the class CodeInspectionAction method getAdditionalActionSettings.
@Override
protected JComponent getAdditionalActionSettings(@NotNull final Project project, final BaseAnalysisActionDialog dialog) {
final AdditionalPanel panel = new AdditionalPanel();
final InspectionManagerEx manager = (InspectionManagerEx) InspectionManager.getInstance(project);
final SchemesCombo<InspectionProfileImpl> profiles = (SchemesCombo<InspectionProfileImpl>) panel.myBrowseProfilesCombo.getComboBox();
final InspectionProfileManager profileManager = InspectionProfileManager.getInstance();
final ProjectInspectionProfileManager projectProfileManager = ProjectInspectionProfileManager.getInstance(project);
panel.myBrowseProfilesCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final ExternalProfilesComboboxAwareInspectionToolsConfigurable errorConfigurable = createConfigurable(projectProfileManager, profiles);
final MySingleConfigurableEditor editor = new MySingleConfigurableEditor(project, errorConfigurable, manager);
if (editor.showAndGet()) {
reloadProfiles(profiles, profileManager, projectProfileManager, project);
if (errorConfigurable.mySelectedName != null) {
final InspectionProfileImpl profile = (errorConfigurable.mySelectedIsProjectProfile ? projectProfileManager : profileManager).getProfile(errorConfigurable.mySelectedName);
profiles.selectScheme(profile);
}
} else {
//if profile was disabled and cancel after apply was pressed
final InspectionProfile profile = profiles.getSelectedScheme();
final boolean canExecute = profile != null && profile.isExecutable(project);
dialog.setOKActionEnabled(canExecute);
}
}
});
profiles.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
myExternalProfile = profiles.getSelectedScheme();
final boolean canExecute = myExternalProfile != null && myExternalProfile.isExecutable(project);
dialog.setOKActionEnabled(canExecute);
if (canExecute) {
PropertiesComponent.getInstance(project).setValue(LAST_SELECTED_PROFILE_PROP, (myExternalProfile.isProjectLevel() ? 'p' : 'a') + myExternalProfile.getName());
manager.setProfile(myExternalProfile.getName());
}
}
});
reloadProfiles(profiles, profileManager, projectProfileManager, project);
return panel.myAdditionalPanel;
}
use of com.intellij.codeInspection.ex.InspectionManagerEx in project intellij-community by JetBrains.
the class CodeInspectionOnEditorAction method analyze.
protected static void analyze(Project project, PsiFile psiFile) {
FileDocumentManager.getInstance().saveAllDocuments();
final InspectionManagerEx inspectionManagerEx = (InspectionManagerEx) InspectionManager.getInstance(project);
final AnalysisScope scope = new AnalysisScope(psiFile);
final GlobalInspectionContextImpl inspectionContext = inspectionManagerEx.createNewGlobalContext(false);
inspectionContext.setCurrentScope(scope);
inspectionContext.setExternalProfile(InspectionProjectProfileManager.getInstance(project).getCurrentProfile());
inspectionContext.doInspections(scope);
}
use of com.intellij.codeInspection.ex.InspectionManagerEx 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