private void rerun() { myRerun = true; if (myScope.isValid()) { AnalysisUIOptions.getInstance(myProject).save(myGlobalInspectionContext.getUIOptions()); myGlobalInspectionContext.doInspections(myScope); } }
@Override public void invoke( @NotNull final Project project, final Editor editor, PsiFile file, DataContext dataContext) { final int offset = editor.getCaretModel().getOffset(); final PsiElement element = file.findElementAt(offset); final PsiMember member = PsiTreeUtil.getParentOfType(element, PsiMember.class); final String cannotRefactorMessage = getCannotRefactorMessage(member); if (cannotRefactorMessage != null) { String message = RefactoringBundle.getCannotRefactorMessage(cannotRefactorMessage); showErrorMessage(message, project, editor); return; } final AnalysisScope scope = new AnalysisScope(file); final Module module = ModuleUtilCore.findModuleForPsiElement(file); final BaseAnalysisActionDialog dlg = new BaseAnalysisActionDialog( RefactoringBundle.message( "replace.method.duplicates.scope.chooser.title", REFACTORING_NAME), RefactoringBundle.message("replace.method.duplicates.scope.chooser.message"), project, scope, module != null ? module.getName() : null, false, AnalysisUIOptions.getInstance(project), element); if (dlg.showAndGet()) { ProgressManager.getInstance() .run( new Task.Backgroundable(project, "Locate duplicates", true) { @Override public void run(@NotNull ProgressIndicator indicator) { indicator.setIndeterminate(true); invokeOnScope( project, member, dlg.getScope(AnalysisUIOptions.getInstance(project), scope, project, module)); } }); } }
public InspectionResultsView( @NotNull final Project project, final InspectionProfile inspectionProfile, @NotNull AnalysisScope scope, @NotNull GlobalInspectionContextImpl globalInspectionContext, @NotNull InspectionRVContentProvider provider) { setLayout(new BorderLayout()); myProject = project; myInspectionProfile = inspectionProfile; myScope = scope; myGlobalInspectionContext = globalInspectionContext; myProvider = provider; myTree = new InspectionTree(project, globalInspectionContext); initTreeListeners(); myOccurenceNavigator = initOccurenceNavigator(); myBrowser = new Browser(this); mySplitter = new OnePixelSplitter(false, AnalysisUIOptions.getInstance(myProject).SPLITTER_PROPORTION); mySplitter.setFirstComponent( ScrollPaneFactory.createScrollPane(myTree, SideBorder.LEFT | SideBorder.RIGHT)); mySplitter.setSecondComponent(myBrowser); mySplitter.addPropertyChangeListener( new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (Splitter.PROP_PROPORTION.equals(evt.getPropertyName())) { myGlobalInspectionContext.setSplitterProportion( ((Float) evt.getNewValue()).floatValue()); } } }); add(mySplitter, BorderLayout.CENTER); myBrowser.addClickListener( new Browser.ClickListener() { @Override public void referenceClicked(final Browser.ClickEvent e) { if (e.getEventType() == Browser.ClickEvent.REF_ELEMENT) { final RefElement refElement = e.getClickedElement(); final OpenFileDescriptor descriptor = getOpenFileDescriptor(refElement); if (descriptor != null) { FileEditorManager.getInstance(project).openTextEditor(descriptor, false); } } else if (e.getEventType() == Browser.ClickEvent.FILE_OFFSET) { final VirtualFile file = e.getFile(); final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, e.getStartOffset()); final Editor editor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true); if (editor != null) { final TextAttributes selectionAttributes = EditorColorsManager.getInstance() .getGlobalScheme() .getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); HighlightManager.getInstance(project) .addRangeHighlight( editor, e.getStartOffset(), e.getEndOffset(), selectionAttributes, true, null); } } } }); createActionsToolbar(); TreeUtil.selectFirstNode(myTree); }
private static void runInspection( @NotNull Project project, @NotNull InspectionToolWrapper toolWrapper, @Nullable VirtualFile virtualFile, PsiElement psiElement, PsiFile psiFile) { 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 FileFilterPanel fileFilterPanel = new FileFilterPanel(); fileFilterPanel.init(); final BaseAnalysisActionDialog dlg = new BaseAnalysisActionDialog( AnalysisScopeBundle.message( "specify.analysis.scope", InspectionsBundle.message("inspection.action.title")), AnalysisScopeBundle.message( "analysis.scope.title", InspectionsBundle.message("inspection.action.noun")), project, analysisScope, module != null ? module.getName() : null, true, AnalysisUIOptions.getInstance(project), psiElement) { @Override protected JComponent getAdditionalActionSettings(Project project) { return fileFilterPanel.getPanel(); } @Override public SearchScope getCustomScope() { return PsiSearchScopeUtil.union( fileFilterPanel.getSearchScope(), super.getCustomScope()); } }; AnalysisScope scope = analysisScope; dlg.show(); if (!dlg.isOK()) return; final AnalysisUIOptions uiOptions = AnalysisUIOptions.getInstance(project); scope = dlg.getScope(uiOptions, scope, project, module); RunInspectionIntention.rerunInspection(toolWrapper, managerEx, scope, psiFile); }