inspections: do not create InspectionsResultView instance if not need (leakage of GlobalInspectionContextImpl#myView fixed)

This commit is contained in:
Dmitry Batkovich
2016-02-24 21:09:31 +03:00
parent 33b48db6da
commit fb6e7de787
5 changed files with 38 additions and 26 deletions
@@ -92,7 +92,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
}
}
AnalysisScope getCurrentScope() {
public AnalysisScope getCurrentScope() {
return myCurrentScope;
}
@@ -222,7 +222,7 @@ public class ViewOfflineResultsAction extends AnAction {
context.setExternalProfile(inspectionProfile);
context.setCurrentScope(scope);
context.initializeTools(new ArrayList<Tools>(), new ArrayList<Tools>(), new ArrayList<Tools>());
final InspectionResultsView view = new InspectionResultsView(project, inspectionProfile, scope, context,
final InspectionResultsView view = new InspectionResultsView(context,
new OfflineInspectionRVContentProvider(resMap, project));
((RefManagerImpl)context.getRefManager()).startOfflineView();
view.update();
@@ -110,7 +110,7 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
}
public synchronized void addView(@NotNull InspectionResultsView view, @NotNull String title) {
if (myContent != null) return;
LOG.assertTrue(myContent == null, "GlobalInspectionContext is busy under other view now");
myContentManager.getValue().addContentManagerListener(new ContentManagerAdapter() {
@Override
public void contentRemoved(ContentManagerEvent event) {
@@ -314,8 +314,9 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
@Override
protected void launchInspections(@NotNull final AnalysisScope scope) {
myUIOptions = AnalysisUIOptions.getInstance(getProject()).copy();
myView = new InspectionResultsView(getProject(), getCurrentProfile(), scope, this, new InspectionRVContentProviderImpl(getProject()));
if (!ApplicationManager.getApplication().isUnitTestMode()) {
myUIOptions = AnalysisUIOptions.getInstance(getProject()).copy();
}
super.launchInspections(scope);
}
@@ -333,15 +334,23 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
public void run() {
LOG.info("Code inspection finished");
if (myView != null) {
if (!myView.update() && !getUIOptions().SHOW_ONLY_DIFF) {
NOTIFICATION_GROUP.createNotification(InspectionsBundle.message("inspection.no.problems.message", scope.getFileCount(), scope.getDisplayName()), MessageType.INFO).notify(getProject());
close(true);
}
else {
addView(myView);
final InspectionResultsView view;
if (myView == null) {
view = new InspectionResultsView(GlobalInspectionContextImpl.this,
new InspectionRVContentProviderImpl(getProject()));
} else {
view = null;
}
if (!(myView == null ? view : myView).update() && !getUIOptions().SHOW_ONLY_DIFF) {
NOTIFICATION_GROUP.createNotification(InspectionsBundle.message("inspection.no.problems.message", scope.getFileCount(), scope.getDisplayName()), MessageType.INFO).notify(getProject());
close(true);
if (view != null) {
Disposer.dispose(view);
}
}
else if (view != null) {
addView(view);
}
}
});
}
@@ -223,14 +223,19 @@ public class DefaultInspectionToolPresentation implements ProblemDescriptionsPro
}
final GlobalInspectionContextImpl context = getContext();
if (!(refElement instanceof RefElement)) {
return;
}
if (myToolWrapper instanceof LocalInspectionToolWrapper) {
final InspectionResultsView view = context.getView();
if (view == null || !(refElement instanceof RefElement)) {
return;
}
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
InspectionResultsView view = context.getView();
if (view == null) {
view = new InspectionResultsView(context,
new InspectionRVContentProviderImpl(context.getProject()));
context.addView(view);
}
if (!isDisposed()) {
final InspectionNode toolNode;
synchronized (myToolLock) {
@@ -259,7 +264,6 @@ public class DefaultInspectionToolPresentation implements ProblemDescriptionsPro
view.getProvider().appendToolNodeContent(context, toolNode,
(InspectionTreeNode)toolNode.getParent(), context.getUIOptions().SHOW_STRUCTURE,
contents, problems, (DefaultTreeModel)view.getTree().getModel());
context.addView(view);
}
}
});
@@ -94,6 +94,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
private final ConcurrentMap<HighlightDisplayLevel, ConcurrentMap<String, InspectionGroupNode>> myGroups = ContainerUtil.newConcurrentMap();
private final OccurenceNavigator myOccurenceNavigator;
private volatile InspectionProfile myInspectionProfile;
@NotNull
private final AnalysisScope myScope;
@NonNls
private static final String HELP_ID = "reference.toolWindows.inspections";
@@ -111,20 +112,16 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
private AnAction myExcludeAction;
private Editor myPreviewEditor;
public InspectionResultsView(@NotNull final Project project,
final InspectionProfile inspectionProfile,
@NotNull AnalysisScope scope,
@NotNull GlobalInspectionContextImpl globalInspectionContext,
public InspectionResultsView(@NotNull GlobalInspectionContextImpl globalInspectionContext,
@NotNull InspectionRVContentProvider provider) {
setLayout(new BorderLayout());
myProject = project;
myInspectionProfile = inspectionProfile;
myScope = scope;
myProject = globalInspectionContext.getProject();
myInspectionProfile = globalInspectionContext.getCurrentProfile();
myScope = globalInspectionContext.getCurrentScope();
myGlobalInspectionContext = globalInspectionContext;
myProvider = provider;
myTree = new InspectionTree(project, globalInspectionContext);
myTree = new InspectionTree(myProject, globalInspectionContext);
initTreeListeners();
myOccurenceNavigator = initOccurenceNavigator();
@@ -144,6 +141,8 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
TreeUtil.selectFirstNode(myTree);
}
private void initTreeListeners() {
myTree.getSelectionModel().addTreeSelectionListener(e -> {
syncRightPanel();