From 99d4866d69a87b4f7f01d2a778105f23a3a86cb0 Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Mon, 25 Dec 2017 16:29:59 +0300 Subject: [PATCH] do not store documents to allow late init of breakpoints highlighters --- .../impl/breakpoints/XLineBreakpointImpl.java | 16 +---- .../breakpoints/XLineBreakpointManager.java | 65 +++++++++---------- 2 files changed, 34 insertions(+), 47 deletions(-) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointImpl.java index d14c2e272514..a1292ab4380e 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointImpl.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.xdebugger.impl.breakpoints; @@ -141,7 +129,7 @@ public class XLineBreakpointImpl

extends XBreak } @Nullable - public Document getDocument() { + private Document getDocument() { VirtualFile file = getFile(); if (file == null) return null; return FileDocumentManager.getInstance().getDocument(file); diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java index 19dc6ba04807..f6da3f291432 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java @@ -18,7 +18,6 @@ import com.intellij.openapi.editor.event.*; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.editor.markup.MarkupEditorFilterFactory; -import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManager; @@ -36,27 +35,31 @@ import com.intellij.openapi.vfs.VirtualFileUrlChangeAdapter; import com.intellij.psi.PsiDocumentManager; import com.intellij.util.SmartList; import com.intellij.util.containers.BidirectionalMap; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.update.MergingUpdateQueue; import com.intellij.util.ui.update.Update; import com.intellij.xdebugger.XDebuggerManager; import com.intellij.xdebugger.breakpoints.SuspendPolicy; import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.intellij.xdebugger.breakpoints.XBreakpointManager; +import com.intellij.xdebugger.breakpoints.XLineBreakpoint; import com.intellij.xdebugger.impl.XSourcePositionImpl; import com.intellij.xdebugger.impl.ui.DebuggerUIUtil; import gnu.trove.TIntHashSet; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.awt.event.MouseEvent; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.stream.Stream; /** * @author nik */ public class XLineBreakpointManager { - private final BidirectionalMap myBreakpoints = new BidirectionalMap<>(); + private final BidirectionalMap myBreakpoints = new BidirectionalMap<>(); private final MergingUpdateQueue myBreakpointsUpdateQueue; private final Project myProject; private final XDependentBreakpointManager myDependentBreakpointManager; @@ -77,23 +80,17 @@ public class XLineBreakpointManager { VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileUrlChangeAdapter() { @Override protected void fileUrlChanged(String oldUrl, String newUrl) { - for (XLineBreakpointImpl breakpoint : myBreakpoints.keySet()) { - final String url = breakpoint.getFileUrl(); + breakpoints().forEach(breakpoint -> { + String url = breakpoint.getFileUrl(); if (FileUtil.startsWith(url, oldUrl)) { breakpoint.setFileUrl(newUrl + url.substring(oldUrl.length())); } - } + }); } @Override public void fileDeleted(@NotNull VirtualFileEvent event) { - List> toRemove = new SmartList<>(); - for (XLineBreakpointImpl breakpoint : myBreakpoints.keySet()) { - if (breakpoint.getFileUrl().equals(event.getFile().getUrl())) { - toRemove.add(breakpoint); - } - } - removeBreakpoints(toRemove); + removeBreakpoints(myBreakpoints.getKeysByValue(event.getFile().getUrl())); } }, project); } @@ -105,43 +102,45 @@ public class XLineBreakpointManager { void updateBreakpointsUI() { StartupManager.getInstance(myProject).runWhenProjectIsInitialized( - (DumbAwareRunnable)() -> myBreakpoints.keySet().forEach(XLineBreakpointImpl::updateUI)); + (DumbAwareRunnable)() -> breakpoints().forEach(XLineBreakpointImpl::updateUI)); } public void registerBreakpoint(XLineBreakpointImpl breakpoint, final boolean initUI) { if (initUI) { breakpoint.updateUI(); } - Document document = breakpoint.getDocument(); - if (document != null) { - myBreakpoints.put(breakpoint, document); - } + myBreakpoints.put(breakpoint, breakpoint.getFileUrl()); } public void unregisterBreakpoint(final XLineBreakpointImpl breakpoint) { - RangeHighlighter highlighter = breakpoint.getHighlighter(); - if (highlighter != null) { - myBreakpoints.remove(breakpoint); - } + myBreakpoints.remove(breakpoint); } @NotNull public Collection getDocumentBreakpoints(Document document) { - Collection breakpoints = myBreakpoints.getKeysByValue(document); - if (breakpoints == null) { - breakpoints = Collections.emptyList(); + VirtualFile file = FileDocumentManager.getInstance().getFile(document); + if (file != null) { + Collection breakpoints = myBreakpoints.getKeysByValue(file.getUrl()); + if (breakpoints != null) { + return breakpoints; + } } - return breakpoints; + return Collections.emptyList(); + } + + private Stream breakpoints() { + return myBreakpoints.keySet().stream(); } private void updateBreakpoints(@NotNull Document document) { - Collection breakpoints = myBreakpoints.getKeysByValue(document); - if (breakpoints == null) { + Collection breakpoints = getDocumentBreakpoints(document); + + if (breakpoints.isEmpty()) { return; } TIntHashSet lines = new TIntHashSet(); - List> toRemove = new SmartList<>(); + List toRemove = new SmartList<>(); for (XLineBreakpointImpl breakpoint : breakpoints) { breakpoint.updatePosition(); if (!breakpoint.isValid() || !lines.add(breakpoint.getLine())) { @@ -152,8 +151,8 @@ public class XLineBreakpointManager { removeBreakpoints(toRemove); } - private void removeBreakpoints(final List> toRemove) { - if (toRemove.isEmpty()) { + private void removeBreakpoints(@Nullable final List toRemove) { + if (ContainerUtil.isEmpty(toRemove)) { return; } @@ -189,7 +188,7 @@ public class XLineBreakpointManager { myBreakpointsUpdateQueue.queue(new Update("all breakpoints") { @Override public void run() { - myBreakpoints.keySet().forEach(XLineBreakpointImpl::updateUI); + breakpoints().forEach(XLineBreakpointImpl::updateUI); } }); } @@ -198,8 +197,8 @@ public class XLineBreakpointManager { @Override public void documentChanged(final DocumentEvent e) { final Document document = e.getDocument(); - Collection breakpoints = myBreakpoints.getKeysByValue(document); - if (breakpoints != null && !breakpoints.isEmpty()) { + Collection breakpoints = getDocumentBreakpoints(document); + if (!breakpoints.isEmpty()) { myBreakpointsUpdateQueue.queue(new Update(document) { @Override public void run() {