diff --git a/platform/core-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java b/platform/core-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java index 496a24dbec73..48c3b125978a 100644 --- a/platform/core-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java @@ -7,6 +7,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.ex.MarkupIterator; import com.intellij.openapi.editor.ex.RangeMarkerEx; import com.intellij.openapi.util.Getter; +import com.intellij.openapi.util.StaticGetter; import com.intellij.util.IncorrectOperationException; import com.intellij.util.Processor; import com.intellij.util.SmartList; @@ -164,8 +165,8 @@ abstract class IntervalTreeImpl extends RedBlackTree implements IntervalTr } } - protected Getter createGetter(@NotNull E interval) { - return new WeakReferencedGetter<>(interval, myIntervalTree.myReferenceQueue); + private Getter createGetter(@NotNull E interval) { + return myIntervalTree.keepIntervalsOnWeakReferences() ? new WeakReferencedGetter<>(interval, myIntervalTree.myReferenceQueue) : new StaticGetter<>(interval); } private static class WeakReferencedGetter extends WeakReference implements Getter { @@ -393,6 +394,10 @@ abstract class IntervalTreeImpl extends RedBlackTree implements IntervalTr } } + protected boolean keepIntervalsOnWeakReferences() { + return true; + } + @NotNull protected abstract IntervalNode createNewNode(@NotNull T key, int start, int end, boolean greedyToLeft, boolean greedyToRight, boolean stickingToRight, int layer); diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/RangeHighlighterImpl.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/RangeHighlighterImpl.java index 6a544f8eee96..e4dda02d41ad 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/RangeHighlighterImpl.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/RangeHighlighterImpl.java @@ -12,7 +12,6 @@ import com.intellij.openapi.editor.ex.MarkupModelEx; import com.intellij.openapi.editor.ex.RangeHighlighterEx; import com.intellij.openapi.editor.markup.*; import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.Getter; import com.intellij.openapi.util.Key; import com.intellij.util.BitUtil; import com.intellij.util.Consumer; @@ -27,7 +26,7 @@ import java.awt.*; * Implementation of the markup element for the editor and document. * @author max */ -class RangeHighlighterImpl extends RangeMarkerImpl implements RangeHighlighterEx, Getter { +class RangeHighlighterImpl extends RangeMarkerImpl implements RangeHighlighterEx { @SuppressWarnings({"InspectionUsingGrayColors", "UseJBColor"}) private static final Color NULL_COLOR = new Color(0, 0, 0); // must be new instance to work as a sentinel private static final Key VISIBLE_IF_FOLDED = Key.create("visible.folded"); @@ -443,11 +442,6 @@ class RangeHighlighterImpl extends RangeMarkerImpl implements RangeHighlighterEx getMarkupModel().removeHighlighter(this); } - @Override - public RangeHighlighterImpl get() { - return this; - } - @Override public int getLayer() { RangeHighlighterTree.RHNode node = (RangeHighlighterTree.RHNode)(Object)myNode; diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/RangeHighlighterTree.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/RangeHighlighterTree.java index 339e7b228ab3..5fa04679f408 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/RangeHighlighterTree.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/RangeHighlighterTree.java @@ -30,6 +30,11 @@ class RangeHighlighterTree extends RangeMarkerTree { myMarkupModel = markupModel; } + @Override + protected boolean keepIntervalsOnWeakReferences() { + return false; + } + @NotNull MarkupIterator overlappingIterator(@NotNull TextRangeInterval rangeInterval, boolean onlyRenderedInGutter) { MarkupIterator iterator = @@ -84,13 +89,6 @@ class RangeHighlighterTree extends RangeMarkerTree { myLayer = layer; } - //range highlighters are strongly referenced - @Override - protected Getter createGetter(@NotNull RangeHighlighterEx interval) { - //noinspection unchecked - return (Getter)interval; - } - private void recalculateRenderFlags() { boolean renderedInGutter = false; for (Getter getter : intervals) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/ErrorStripeMarkerImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/ErrorStripeMarkerImpl.java index c7941c97f53d..4dd140edcf68 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/ErrorStripeMarkerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/ErrorStripeMarkerImpl.java @@ -3,10 +3,9 @@ package com.intellij.openapi.editor.impl; import com.intellij.openapi.editor.ex.DocumentEx; import com.intellij.openapi.editor.ex.RangeHighlighterEx; -import com.intellij.openapi.util.Getter; import org.jetbrains.annotations.NotNull; -class ErrorStripeMarkerImpl extends RangeMarkerImpl implements Getter { +class ErrorStripeMarkerImpl extends RangeMarkerImpl { private final RangeHighlighterEx myHighlighter; @@ -20,11 +19,6 @@ class ErrorStripeMarkerImpl extends RangeMarkerImpl implements Getter { +class ErrorStripeRangeMarkerTree extends HardReferencingRangeMarkerTree { ErrorStripeRangeMarkerTree(@NotNull Document document) { super(document); @@ -44,9 +43,5 @@ class ErrorStripeRangeMarkerTree extends RangeMarkerTree myLayer = layer; } - @Override - protected Getter createGetter(@NotNull ErrorStripeMarkerImpl interval) { - return interval; - } } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldRegionImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldRegionImpl.java index 37b95329f04c..f5d879499d13 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldRegionImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldRegionImpl.java @@ -12,7 +12,7 @@ import com.intellij.util.DocumentUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class FoldRegionImpl extends RangeMarkerWithGetterImpl implements FoldRegion { +public class FoldRegionImpl extends RangeMarkerImpl implements FoldRegion { private static final Key MUTE_INNER_HIGHLIGHTERS = Key.create("mute.inner.highlighters"); private static final Key SHOW_GUTTER_MARK_FOR_SINGLE_LINE = Key.create("show.gutter.mark.for.single.line"); @@ -30,7 +30,7 @@ public class FoldRegionImpl extends RangeMarkerWithGetterImpl implements FoldReg @NotNull String placeholder, @Nullable FoldingGroup group, boolean shouldNeverExpand) { - super(editor.getDocument(), startOffset, endOffset,false); + super(editor.getDocument(), startOffset, endOffset,false, true); myGroup = group; myShouldNeverExpand = shouldNeverExpand; myIsExpanded = true; diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java index 564cca59a37f..6dcb6bf6f678 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java @@ -716,14 +716,14 @@ public class FoldingModelImpl extends InlayModel.SimpleAdapter @NotNull @Override - protected Node createNewNode(@NotNull FoldRegionImpl key, + protected RMNode createNewNode(@NotNull FoldRegionImpl key, int start, int end, boolean greedyToLeft, boolean greedyToRight, boolean stickingToRight, int layer) { - return new Node(this, key, start, end, greedyToLeft, greedyToRight, stickingToRight) { + return new RMNode(this, key, start, end, greedyToLeft, greedyToRight, stickingToRight) { @Override void onRemoved() { for (Getter getter : intervals) { @@ -766,7 +766,7 @@ public class FoldingModelImpl extends InlayModel.SimpleAdapter if (oldLength > 0 /* document change can cause regions to become equal*/) { for (Object o : affected) { //noinspection unchecked - Node node = (Node)o; + RMNode node = (RMNode)o; FoldRegionImpl region = getRegion(node); // region with the largest metric value is kept when several regions become identical after document change // we want the largest collapsed region to survive diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/HardReferencingRangeMarkerTree.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/HardReferencingRangeMarkerTree.java index 8f846e1b983b..7829f44706a1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/HardReferencingRangeMarkerTree.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/HardReferencingRangeMarkerTree.java @@ -2,46 +2,19 @@ package com.intellij.openapi.editor.impl; import com.intellij.openapi.editor.Document; -import com.intellij.openapi.util.Getter; import org.jetbrains.annotations.NotNull; /** * {@link RangeMarkerTree} with intervals which are not collected when no one holds a reference to them. - * - * @see RangeMarkerWithGetterImpl */ -class HardReferencingRangeMarkerTree extends RangeMarkerTree { +class HardReferencingRangeMarkerTree extends RangeMarkerTree { HardReferencingRangeMarkerTree(@NotNull Document document) { super(document); } - @NotNull @Override - protected Node createNewNode(@NotNull T key, - int start, - int end, - boolean greedyToLeft, - boolean greedyToRight, - boolean stickingToRight, - int layer) { - return new Node<>(this, key, start, end, greedyToLeft, greedyToRight, stickingToRight); + protected boolean keepIntervalsOnWeakReferences() { + return false; } - static class Node extends RMNode { - Node(@NotNull RangeMarkerTree rangeMarkerTree, - @NotNull T key, - int start, - int end, - boolean greedyToLeft, - boolean greedyToRight, - boolean stickingToRight) { - super(rangeMarkerTree, key, start, end, greedyToLeft, greedyToRight, stickingToRight); - } - - @Override - protected Getter createGetter(@NotNull T interval) { - //noinspection unchecked - return (Getter) interval; - } - } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/InlayImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/InlayImpl.java index 560ab39887d5..9f7cc8f1af08 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/InlayImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/InlayImpl.java @@ -15,7 +15,7 @@ import javax.swing.*; import java.awt.*; import java.util.Objects; -abstract class InlayImpl> extends RangeMarkerWithGetterImpl implements Inlay { +abstract class InlayImpl> extends RangeMarkerImpl implements Inlay { static final Key OFFSET_BEFORE_DISPOSAL = Key.create("inlay.offset.before.disposal"); @NotNull @@ -28,7 +28,7 @@ abstract class InlayImpl> createNewNode(@NotNull InlineInlayImpl key, int start, int end, + protected RMNode> createNewNode(@NotNull InlineInlayImpl key, int start, int end, boolean greedyToLeft, boolean greedyToRight, boolean stickingToRight, int layer) { - return new Node>(this, key, start, end, greedyToLeft, greedyToRight, stickingToRight) { + return new RMNode>(this, key, start, end, greedyToLeft, greedyToRight, stickingToRight) { @Override void addIntervalsFrom(@NotNull IntervalNode> otherNode) { super.addIntervalsFrom(otherNode); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkerTreeWithPartialSums.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkerTreeWithPartialSums.java index bc0554f53c99..9dfaaa059862 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkerTreeWithPartialSums.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/MarkerTreeWithPartialSums.java @@ -13,7 +13,7 @@ import java.util.function.IntSupplier; * Only 'non-greedy' markers with zero length are supported (for such markers start offset is always equal to end offset). * Not thread safe - cannot be used from multiple threads simultaneously. */ -class MarkerTreeWithPartialSums extends HardReferencingRangeMarkerTree { +class MarkerTreeWithPartialSums extends HardReferencingRangeMarkerTree { MarkerTreeWithPartialSums(@NotNull Document document) { super(document); } @@ -53,13 +53,13 @@ class MarkerTreeWithPartialSums createNewNode(@NotNull T key, - int start, - int end, - boolean greedyToLeft, - boolean greedyToRight, - boolean stickingToRight, - int layer) { + protected RMNode createNewNode(@NotNull T key, + int start, + int end, + boolean greedyToLeft, + boolean greedyToRight, + boolean stickingToRight, + int layer) { assert start == end; assert !greedyToLeft; assert !greedyToRight; @@ -72,7 +72,7 @@ class MarkerTreeWithPartialSums)node).recalculateSubTreeSum(); } - static class Node extends HardReferencingRangeMarkerTree.Node { + static class Node extends RMNode { private int subtreeSum; Node(@NotNull RangeMarkerTree rangeMarkerTree, diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeMarkerWithGetterImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeMarkerWithGetterImpl.java deleted file mode 100644 index 18d5d3416ef8..000000000000 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeMarkerWithGetterImpl.java +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2000-2018 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.openapi.editor.impl; - -import com.intellij.openapi.editor.ex.DocumentEx; -import com.intellij.openapi.util.Getter; -import org.jetbrains.annotations.NotNull; - -/** - * @see HardReferencingRangeMarkerTree - */ -class RangeMarkerWithGetterImpl extends RangeMarkerImpl implements Getter { - RangeMarkerWithGetterImpl(@NotNull DocumentEx document, int start, int end, boolean register) { - super(document, start, end, register, true); - } - - @Override - public final RangeMarkerWithGetterImpl get() { - return this; - } -} diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/MarkerTreeWithPartialSumsTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/MarkerTreeWithPartialSumsTest.java index 339242ff6db0..8379b38acce5 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/MarkerTreeWithPartialSumsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/MarkerTreeWithPartialSumsTest.java @@ -187,7 +187,7 @@ public class MarkerTreeWithPartialSumsTest extends AbstractEditorTest { return result; } - private class MyRange extends RangeMarkerWithGetterImpl implements IntSupplier { + private class MyRange extends RangeMarkerImpl implements IntSupplier { private int myValue; MyRange(int offset, int value) { @@ -195,7 +195,7 @@ public class MarkerTreeWithPartialSumsTest extends AbstractEditorTest { } MyRange(int offset, int value, boolean stickToRight) { - super(myDocument, offset, offset, false); + super(myDocument, offset, offset, false, true); myValue = value; myTree.addInterval(this, offset, offset, false, false, stickToRight, 0); }