import com.intellij.openapi.wm.ToolWindowId;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.psi.*;
+ import com.intellij.psi.search.GlobalSearchScopesCore;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.scope.packageSet.NamedScope;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashMap;
import com.intellij.util.containers.HashSet;
- import com.intellij.util.ui.UIUtil;
import gnu.trove.THashSet;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
private final NotNullLazyValue<ContentManager> myContentManager;
private volatile InspectionResultsView myView;
+ private volatile String myOutputPath;
private Content myContent;
private volatile boolean myViewClosed = true;
private long myInspectionStartedTimestamp;
setCurrentScope(scope);
final Runnable action = () -> {
- DefaultInspectionToolPresentation.setOutputPath(outputPath);
+ myOutputPath = outputPath;
try {
performInspectionsWithProgress(scope, runGlobalToolsOnly, isOfflineInspections);
exportResults(inspectionsResults, outputPath);
}
finally {
- DefaultInspectionToolPresentation.setOutputPath(null);
+ myOutputPath = null;
}
};
if (isOfflineInspections) {
}
}
- public void ignoreElement(@NotNull InspectionProfileEntry tool, @NotNull PsiElement element) {
+ public void resolveElement(@NotNull InspectionProfileEntry tool, @NotNull PsiElement element) {
final RefElement refElement = getRefManager().getReference(element);
+ if (refElement == null) return;
final Tools tools = getTools().get(tool.getShortName());
if (tools != null){
for (ScopeToolState state : tools.getTools()) {
InspectionToolWrapper toolWrapper = state.getTool();
- ignoreElementRecursively(toolWrapper, refElement);
+ InspectionToolPresentation presentation = getPresentationOrNull(toolWrapper);
+ if (presentation != null) {
+ resolveElementRecursively(presentation, refElement);
+ }
}
}
}
return myView;
}
- private void ignoreElementRecursively(@NotNull InspectionToolWrapper toolWrapper, final RefEntity refElement) {
- if (refElement != null) {
- InspectionToolPresentation presentation = getPresentation(toolWrapper);
- presentation.ignoreCurrentElement(refElement);
- final List<RefEntity> children = refElement.getChildren();
- for (RefEntity child : children) {
- ignoreElementRecursively(toolWrapper, child);
- }
+ public String getOutputPath() {
+ return myOutputPath;
+ }
+
+ private static void resolveElementRecursively(@NotNull InspectionToolPresentation presentation, @NotNull RefEntity refElement) {
+ presentation.suppressProblem(refElement);
+ final List<RefEntity> children = refElement.getChildren();
+ for (RefEntity child : children) {
+ resolveElementRecursively(presentation, child);
}
}
@Override
protected void notifyInspectionsFinished(@NotNull final AnalysisScope scope) {
if (ApplicationManager.getApplication().isUnitTestMode()) return;
- UIUtil.invokeLaterIfNeeded(() -> {
- long elapsed = System.currentTimeMillis() - myInspectionStartedTimestamp;
- LOG.info("Code inspection finished. Took "+elapsed+"ms");
- if (getProject().isDisposed()) return;
-
- InspectionResultsView view = myView == null ? new InspectionResultsView(this, createContentProvider()) : null;
- if (!(myView == null ? view : myView).hasProblems()) {
- NOTIFICATION_GROUP.createNotification(InspectionsBundle.message("inspection.no.problems.message",
- scope.getFileCount(),
- scope.getShortenName()),
- MessageType.INFO).notify(getProject());
- close(true);
- if (view != null) {
- Disposer.dispose(view);
- }
+ LOG.assertTrue(ApplicationManager.getApplication().isDispatchThread());
+ long elapsed = System.currentTimeMillis() - myInspectionStartedTimestamp;
+ LOG.info("Code inspection finished. Took " + elapsed + "ms");
+ if (getProject().isDisposed()) return;
+
+ InspectionResultsView view = myView == null ? new InspectionResultsView(this, createContentProvider()) : null;
+ if (!(myView == null ? view : myView).hasProblems()) {
+ NOTIFICATION_GROUP.createNotification(InspectionsBundle.message("inspection.no.problems.message",
+ scope.getFileCount(),
+ scope.getShortenName()),
+ MessageType.INFO).notify(getProject());
+ close(true);
+ if (view != null) {
+ Disposer.dispose(view);
}
- else if (view != null && !view.isDisposed() && getCurrentScope() != null) {
- addView(view);
- view.update();
- }
- if (myView != null) {
- myView.setUpdating(false);
- }
- });
+ }
+ else if (view != null && !view.isDisposed() && getCurrentScope() != null) {
+ addView(view);
+ view.update();
+ }
+ if (myView != null) {
+ myView.setUpdating(false);
+ }
}
@Override
}
private void inspectFile(@NotNull final PsiFile file,
- @NotNull final TextRange range,
- @NotNull final InspectionManager inspectionManager,
- @NotNull List<Tools> localTools,
- @NotNull List<Tools> globalSimpleTools,
- @NotNull final Map<String, InspectionToolWrapper> wrappersMap) {
+ @NotNull final TextRange range,
+ @NotNull final InspectionManager inspectionManager,
+ @NotNull List<Tools> localTools,
+ @NotNull List<Tools> globalSimpleTools,
+ @NotNull final Map<String, InspectionToolWrapper> wrappersMap) {
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file);
if (document == null) return;
final boolean canBeExternalUsages = !(scope.getScopeType() == AnalysisScope.PROJECT && scope.isIncludeTestSource());
for (Tools tools : globalTools) {
for (ScopeToolState state : tools.getTools()) {
+ if (!state.isEnabled()) continue;
+ NamedScope stateScope = state.getScope(getProject());
+ if (stateScope == null) continue;
+ AnalysisScope scopeForState = new AnalysisScope(GlobalSearchScopesCore.filterScope(getProject(), stateScope), getProject());
final InspectionToolWrapper toolWrapper = state.getTool();
final GlobalInspectionTool tool = (GlobalInspectionTool)toolWrapper.getTool();
final InspectionToolPresentation toolPresentation = getPresentation(toolWrapper);
}
}
ApplicationManager.getApplication().runReadAction(() -> {
- tool.runInspection(scope, inspectionManager, this, toolPresentation);
+ tool.runInspection(scopeForState, inspectionManager, this, toolPresentation);
//skip phase when we are sure that scope already contains everything, unused declaration though needs to proceed with its suspicious code
if ((canBeExternalUsages || tool.getAdditionalJobs(this) != null) &&
tool.queryExternalUsagesRequests(inspectionManager, this, toolPresentation)) {
myViewClosed = true;
myView = null;
((InspectionManagerEx)InspectionManager.getInstance(getProject())).closeRunningContext(this);
- for (Tools tools : getTools().values()) {
- for (ScopeToolState state : tools.getTools()) {
- InspectionToolWrapper toolWrapper = state.getTool();
- getPresentation(toolWrapper).finalCleanup();
- }
- }
+ myPresentationMap.clear();
super.close(noSuspiciousCodeFound);
}
}
private final ConcurrentMap<InspectionToolWrapper, InspectionToolPresentation> myPresentationMap = ContainerUtil.newConcurrentMap();
+
+ @Nullable
+ public InspectionToolPresentation getPresentationOrNull(@NotNull InspectionToolWrapper toolWrapper) {
+ return myPresentationMap.get(toolWrapper);
+ }
@NotNull
public InspectionToolPresentation getPresentation(@NotNull InspectionToolWrapper toolWrapper) {
InspectionToolPresentation presentation = myPresentationMap.get(toolWrapper);
}, ModalityState.defaultModalityState());
return;
}
-
+
Runnable runnable = () -> {
if (!FileModificationService.getInstance().preparePsiElementsForWrite(files)) return;
- CleanupInspectionIntention.applyFixesNoSort(getProject(), "Code Cleanup", descriptors, null);
+ CleanupInspectionIntention.applyFixesNoSort(getProject(), "Code Cleanup", descriptors, null, false);
if (postRunnable != null) {
postRunnable.run();
}
import com.intellij.util.OpenSourceUtil;
import com.intellij.util.concurrency.AppExecutorUtil;
import com.intellij.util.containers.ContainerUtil;
- import com.intellij.util.containers.FactoryMap;
import com.intellij.util.containers.HashSet;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.tree.TreeUtil;
- import gnu.trove.THashSet;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
private final ExclusionHandler<InspectionTreeNode> myExclusionHandler;
private EditorEx myPreviewEditor;
private InspectionTreeLoadingProgressAware myLoadingProgressPreview;
- private final ExcludedInspectionTreeNodesManager myExcludedInspectionTreeNodesManager;
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
- private final Map<String, Set<Object>> mySuppressedNodes = FactoryMap.createMap(key -> new THashSet<>());
private final InspectionViewSuppressActionHolder mySuppressActionHolder = new InspectionViewSuppressActionHolder();
private final Object myTreeStructureUpdateLock = new Object();
myScope = globalInspectionContext.getCurrentScope();
myGlobalInspectionContext = globalInspectionContext;
myProvider = provider;
- myExcludedInspectionTreeNodesManager = new ExcludedInspectionTreeNodesManager(provider instanceof OfflineInspectionRVContentProvider,
- isSingleInspectionRun());
-
myTree = new InspectionTree(globalInspectionContext, this);
initTreeListeners();
@Override
public boolean isNodeExcluded(@NotNull InspectionTreeNode node) {
- return node.isExcluded(myExcludedInspectionTreeNodesManager);
+ return node.isExcluded();
}
@Override
public void excludeNode(@NotNull InspectionTreeNode node) {
- node.excludeElement(myExcludedInspectionTreeNodesManager);
+ node.excludeElement();
}
@Override
public void includeNode(@NotNull InspectionTreeNode node) {
- node.amnestyElement(myExcludedInspectionTreeNodesManager);
+ node.amnestyElement();
}
@Override
@Override
@Nullable
protected Navigatable createDescriptorForNode(DefaultMutableTreeNode node) {
- if (node instanceof InspectionTreeNode && ((InspectionTreeNode)node).isExcluded(myExcludedInspectionTreeNodesManager)) {
+ if (node instanceof InspectionTreeNode && ((InspectionTreeNode)node).isExcluded()) {
return null;
}
if (node instanceof RefElementNode) {
}
}
if (previewEditor != null) {
- ProblemPreviewEditorPresentation.setupFoldingsForNonProblemRanges(previewEditor, this);
+ ProblemPreviewEditorPresentation.setupFoldingsAndHighlightProblems(previewEditor, this);
}
mySplitter.setSecondComponent(editorPanel);
}
return mySuppressActionHolder;
}
- public Set<Object> getSuppressedNodes(String toolId) {
- return mySuppressedNodes.get(toolId);
- }
-
- @NotNull
- public ExcludedInspectionTreeNodesManager getExcludedManager() {
- return myExcludedInspectionTreeNodesManager;
- }
-
@Nullable
public String getCurrentProfileName() {
return myInspectionProfile == null ? null : myInspectionProfile.getDisplayName();
}
final InspectionNode toolNode = presentation.getToolNode();
LOG.assertTrue(toolNode != null);
- final Map<RefEntity, CommonProblemDescriptor[]> problems = new HashMap<>();
+ final Map<RefEntity, CommonProblemDescriptor[]> problems = new HashMap<>(1);
problems.put(refElement, descriptors);
final Map<String, Set<RefEntity>> contents = new HashMap<>();
final String groupName = refElement.getRefManager().getGroupName((RefElement)refElement);
uiOptions.SHOW_STRUCTURE,
true,
contents,
- problems);
+ problems::get);
}
}
}));
boolean singleInspectionRun = isSingleInspectionRun();
for (Tools currentTools : tools) {
InspectionToolWrapper defaultToolWrapper = currentTools.getDefaultState().getTool();
- if (myGlobalInspectionContext.getUIOptions().FILTER_RESOLVED_ITEMS &&
- myExcludedInspectionTreeNodesManager.containsInspectionNode(defaultToolWrapper)) {
- continue;
- }
final HighlightDisplayKey key = HighlightDisplayKey.find(defaultToolWrapper.getShortName());
for (ScopeToolState state : myProvider.getTools(currentTools)) {
InspectionToolWrapper toolWrapper = state.getTool();