mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inspection view: do not execute huge read actions IDEA-157005
This commit is contained in:
+10
-8
@@ -24,12 +24,12 @@ import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.reference.RefManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class OfflineProblemDescriptor {
|
||||
@@ -91,14 +91,16 @@ public class OfflineProblemDescriptor {
|
||||
|
||||
@Nullable
|
||||
public RefEntity getRefElement(final RefManager refManager) {
|
||||
final RefEntity refElement = refManager.getReference(myType, myFQName);
|
||||
if (refElement instanceof RefElement) {
|
||||
final PsiElement element = ((RefElement)refElement).getElement();
|
||||
if (element != null && element.isValid()) {
|
||||
UIUtil.invokeLaterIfNeeded(() -> PsiDocumentManager.getInstance(element.getProject()).commitAllDocuments());
|
||||
return ReadAction.compute(() -> {
|
||||
final RefEntity refElement = refManager.getReference(myType, myFQName);
|
||||
if (refElement instanceof RefElement) {
|
||||
final PsiElement element = ((RefElement)refElement).getElement();
|
||||
if (element != null && element.isValid()) {
|
||||
UIUtil.invokeLaterIfNeeded(() -> PsiDocumentManager.getInstance(element.getProject()).commitAllDocuments());
|
||||
}
|
||||
}
|
||||
}
|
||||
return refElement;
|
||||
return refElement;
|
||||
});
|
||||
}
|
||||
|
||||
public boolean equals(final Object o) {
|
||||
|
||||
+32
-29
@@ -27,6 +27,7 @@ import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.reference.RefModule;
|
||||
import com.intellij.codeInspection.ui.*;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
@@ -73,7 +74,7 @@ public abstract class InspectionRVContentProvider {
|
||||
|
||||
@NotNull
|
||||
public RefElementNode createNode(@NotNull InspectionToolPresentation presentation) {
|
||||
return new RefElementNode(myEntity, presentation);
|
||||
return ReadAction.compute(() -> new RefElementNode(myEntity, presentation));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -203,7 +204,7 @@ public abstract class InspectionRVContentProvider {
|
||||
|
||||
if (moduleNode == null) {
|
||||
if (moduleName != null) {
|
||||
final Module module = ModuleManager.getInstance(myProject).findModuleByName(moduleName);
|
||||
final Module module = ReadAction.compute(() -> ModuleManager.getInstance(myProject).findModuleByName(moduleName));
|
||||
if (module != null) {
|
||||
moduleNode = new InspectionModuleNode(module);
|
||||
moduleNodes.put(moduleName, moduleNode);
|
||||
@@ -356,39 +357,41 @@ public abstract class InspectionRVContentProvider {
|
||||
|
||||
@SuppressWarnings({"ConstantConditions"}) //class cast suppression
|
||||
public static InspectionTreeNode merge(InspectionTreeNode child, InspectionTreeNode parent, boolean merge) {
|
||||
if (merge) {
|
||||
for (int i = 0; i < parent.getChildCount(); i++) {
|
||||
InspectionTreeNode current = (InspectionTreeNode)parent.getChildAt(i);
|
||||
if (child.getClass() != current.getClass()) {
|
||||
continue;
|
||||
}
|
||||
if (current instanceof InspectionPackageNode) {
|
||||
if (((InspectionPackageNode)current).getPackageName().compareTo(((InspectionPackageNode)child).getPackageName()) == 0) {
|
||||
processDepth(child, current);
|
||||
return current;
|
||||
return ReadAction.compute(() -> {
|
||||
if (merge) {
|
||||
for (int i = 0; i < parent.getChildCount(); i++) {
|
||||
InspectionTreeNode current = (InspectionTreeNode)parent.getChildAt(i);
|
||||
if (child.getClass() != current.getClass()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (current instanceof RefElementNode) {
|
||||
if (InspectionResultsViewComparator.getInstance().compare(current, child) == 0) {
|
||||
processDepth(child, current);
|
||||
return current;
|
||||
if (current instanceof InspectionPackageNode) {
|
||||
if (((InspectionPackageNode)current).getPackageName().compareTo(((InspectionPackageNode)child).getPackageName()) == 0) {
|
||||
processDepth(child, current);
|
||||
return current;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (current instanceof InspectionNode) {
|
||||
if (((InspectionNode)current).getToolWrapper().getShortName().compareTo(((InspectionNode)child).getToolWrapper().getShortName()) == 0) {
|
||||
processDepth(child, current);
|
||||
return current;
|
||||
else if (current instanceof RefElementNode) {
|
||||
if (InspectionResultsViewComparator.getInstance().compare(current, child) == 0) {
|
||||
processDepth(child, current);
|
||||
return current;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (current instanceof InspectionModuleNode) {
|
||||
if (((InspectionModuleNode)current).getName().compareTo(((InspectionModuleNode)child).getName()) == 0) {
|
||||
processDepth(child, current);
|
||||
return current;
|
||||
else if (current instanceof InspectionNode) {
|
||||
if (((InspectionNode)current).getToolWrapper().getShortName().compareTo(((InspectionNode)child).getToolWrapper().getShortName()) == 0) {
|
||||
processDepth(child, current);
|
||||
return current;
|
||||
}
|
||||
}
|
||||
else if (current instanceof InspectionModuleNode) {
|
||||
if (((InspectionModuleNode)current).getName().compareTo(((InspectionModuleNode)child).getName()) == 0) {
|
||||
processDepth(child, current);
|
||||
return current;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return parent.insertByOrder(child, false);
|
||||
return parent.insertByOrder(child, false);
|
||||
});
|
||||
}
|
||||
|
||||
private static void processDepth(final InspectionTreeNode child, final InspectionTreeNode current) {
|
||||
|
||||
+7
-2
@@ -21,8 +21,12 @@
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.codeInspection.CommonProblemDescriptor;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.reference.RefModule;
|
||||
import com.intellij.codeInspection.reference.RefUtil;
|
||||
import com.intellij.codeInspection.ui.*;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -125,7 +129,8 @@ public class InspectionRVContentProviderImpl extends InspectionRVContentProvider
|
||||
final RefElementNode elemNode = addNodeToParent(container, presentation, pNode);
|
||||
for (CommonProblemDescriptor problem : problems) {
|
||||
assert problem != null;
|
||||
elemNode.insertByOrder(new ProblemDescriptionNode(refElement, problem, toolWrapper,presentation), true);
|
||||
elemNode
|
||||
.insertByOrder(ReadAction.compute(() -> new ProblemDescriptionNode(refElement, problem, toolWrapper, presentation)), true);
|
||||
if (problems.length == 1) {
|
||||
elemNode.setProblem(problems[0]);
|
||||
}
|
||||
|
||||
+3
-1
@@ -30,6 +30,7 @@ import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -71,7 +72,8 @@ class OfflineDescriptorResolveResult {
|
||||
@NotNull InspectionToolWrapper wrapper,
|
||||
@NotNull InspectionToolPresentation presentation) {
|
||||
final RefEntity element = descriptor.getRefElement(presentation.getContext().getRefManager());
|
||||
final CommonProblemDescriptor resolvedDescriptor = createDescriptor(element, descriptor, wrapper, presentation);
|
||||
final CommonProblemDescriptor resolvedDescriptor =
|
||||
ReadAction.compute(() -> createDescriptor(element, descriptor, wrapper, presentation));
|
||||
return new OfflineDescriptorResolveResult(element, resolvedDescriptor);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -26,6 +26,7 @@ import com.intellij.codeInspection.offline.OfflineProblemDescriptor;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.ui.*;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.util.containers.FactoryMap;
|
||||
@@ -190,7 +191,7 @@ public class OfflineInspectionRVContentProvider extends InspectionRVContentProvi
|
||||
for (OfflineProblemDescriptor descriptor : ((RefEntityContainer<OfflineProblemDescriptor>)container).getDescriptors()) {
|
||||
final OfflineDescriptorResolveResult resolveResult = myResolvedDescriptor.get(toolWrapper.getShortName())
|
||||
.computeIfAbsent(descriptor, d -> OfflineDescriptorResolveResult.resolve(d, toolWrapper, presentation));
|
||||
elemNode.insertByOrder(OfflineProblemDescriptorNode.create(descriptor, resolveResult, toolWrapper, presentation), true);
|
||||
elemNode.insertByOrder(ReadAction.compute(() -> OfflineProblemDescriptorNode.create(descriptor, resolveResult, toolWrapper, presentation)), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -759,14 +759,16 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(defaultToolWrapper.getShortName());
|
||||
for (ScopeToolState state : myProvider.getTools(currentTools)) {
|
||||
InspectionToolWrapper toolWrapper = state.getTool();
|
||||
ReadAction.run(() -> {
|
||||
if (myProvider.checkReportedProblems(myGlobalInspectionContext, toolWrapper)) {
|
||||
addTool(toolWrapper,
|
||||
profile.getErrorLevel(key, state.getScope(myProject), myProject),
|
||||
isGroupedBySeverity,
|
||||
singleInspectionRun);
|
||||
}
|
||||
});
|
||||
if (ReadAction.compute(() -> myProvider.checkReportedProblems(myGlobalInspectionContext, toolWrapper))) {
|
||||
//ReadAction.run(
|
||||
// () ->
|
||||
addTool(toolWrapper,
|
||||
profile.getErrorLevel(key, state.getScope(myProject), myProject),
|
||||
isGroupedBySeverity,
|
||||
singleInspectionRun)
|
||||
//)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.codeInspection.ui;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.vcs.FileStatus;
|
||||
import com.intellij.util.containers.FactoryMap;
|
||||
import com.intellij.util.ui.tree.TreeUtil;
|
||||
@@ -101,18 +102,20 @@ public abstract class InspectionTreeNode extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public InspectionTreeNode insertByOrder(InspectionTreeNode child, boolean allowDuplication) {
|
||||
if (!allowDuplication) {
|
||||
int index = getIndex(child);
|
||||
if (index != -1) {
|
||||
return ReadAction.compute(() -> {
|
||||
if (!allowDuplication) {
|
||||
int index = getIndex(child);
|
||||
if (index != -1) {
|
||||
return (InspectionTreeNode)getChildAt(index);
|
||||
}
|
||||
}
|
||||
int index = TreeUtil.indexedBinarySearch(this, child, InspectionResultsViewComparator.getInstance());
|
||||
if (!allowDuplication && index >= 0){
|
||||
return (InspectionTreeNode)getChildAt(index);
|
||||
}
|
||||
}
|
||||
int index = TreeUtil.indexedBinarySearch(this, child, InspectionResultsViewComparator.getInstance());
|
||||
if (!allowDuplication && index >= 0){
|
||||
return (InspectionTreeNode)getChildAt(index);
|
||||
}
|
||||
insert(child, Math.abs(index + 1));
|
||||
return child;
|
||||
insert(child, Math.abs(index + 1));
|
||||
return child;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user