From e3b1adc82b98d59e5cf63a0720f468f98f9cd812 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 13 Apr 2011 17:38:32 +0400 Subject: [PATCH] trackInvalidation --- .../injected/editor/RangeMarkerWindow.java | 5 +++ .../openapi/editor/ex/RangeMarkerEx.java | 2 +- .../openapi/editor/impl/IntervalTreeImpl.java | 10 +++--- .../impl/PersistentRangeHighlighterImpl.java | 2 +- .../editor/impl/PersistentRangeMarker.java | 16 ++++----- .../openapi/editor/impl/RangeMarkerImpl.java | 36 +++++++++++++------ .../openapi/editor/impl/RangeMarkerTree.java | 10 +++--- 7 files changed, 50 insertions(+), 31 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/injected/editor/RangeMarkerWindow.java b/platform/lang-impl/src/com/intellij/injected/editor/RangeMarkerWindow.java index 82e9098b5200..1bdb50f08bec 100644 --- a/platform/lang-impl/src/com/intellij/injected/editor/RangeMarkerWindow.java +++ b/platform/lang-impl/src/com/intellij/injected/editor/RangeMarkerWindow.java @@ -65,6 +65,11 @@ public class RangeMarkerWindow implements RangeMarkerEx { myHostMarker.trackInvalidation(track); } + @Override + public boolean isTrackInvalidation() { + return myHostMarker.isTrackInvalidation(); + } + ////////////////////////////delegates public void setGreedyToLeft(final boolean greedy) { myHostMarker.setGreedyToLeft(greedy); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/RangeMarkerEx.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/RangeMarkerEx.java index 190d6c6c28bb..413a9b6ccdc1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/RangeMarkerEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/RangeMarkerEx.java @@ -35,5 +35,5 @@ public interface RangeMarkerEx extends RangeMarker, MutableInterval, Segment { long getId(); void trackInvalidation(boolean track); - + boolean isTrackInvalidation(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java index a120b780dbb9..a314c8201b4e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java @@ -45,7 +45,7 @@ public abstract class IntervalTreeImpl extends RedBla private final ReferenceQueue myReferenceQueue = new ReferenceQueue(); private int deadReferenceCount; - protected class IntervalNode extends Node implements MutableInterval/*, Iterable, Iterator*/ { + protected class IntervalNode extends Node implements MutableInterval { private volatile int myStart; private volatile int myEnd; private volatile boolean isValid = true; @@ -181,11 +181,11 @@ public abstract class IntervalTreeImpl extends RedBla return myEnd; } - public IntervalTreeImpl getTree() { + public IntervalTreeImpl getTree() { return IntervalTreeImpl.this; } - } + private void pushDeltaFromRoot(IntervalNode node) { if (normalized) return; if (node != null) { @@ -437,7 +437,7 @@ public abstract class IntervalTreeImpl extends RedBla } } - public IntervalNode addInterval(@NotNull T interval, int start, int end, boolean greedyToLeft, boolean greedyToRight, int layer) { + public IntervalTreeImpl.IntervalNode addInterval(@NotNull T interval, int start, int end, boolean greedyToLeft, boolean greedyToRight, int layer) { try { l.writeLock().lock(); checkMax(true); @@ -502,7 +502,7 @@ public abstract class IntervalTreeImpl extends RedBla int maxRightStart = r.second; if (!root.isValid()) { allValid.set(false); - if (assertInvalid) assert false : (T)root; + if (assertInvalid) assert false : root; return Trinity.create(Math.min(minLeftStart, minRightStart), Math.max(maxLeftStart, maxRightStart), Math.max(maxRightEnd, maxLeftEnd)); } IntervalNode parent = root.getParent(); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/PersistentRangeHighlighterImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/PersistentRangeHighlighterImpl.java index 55b3bb8c3d9a..c74afce3ccff 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/PersistentRangeHighlighterImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/PersistentRangeHighlighterImpl.java @@ -45,7 +45,7 @@ class PersistentRangeHighlighterImpl extends RangeHighlighterImpl implements Ran if (PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, this)) { setLine(event.translateLineViaDiff(getLine())); if (getLine() < 0 || getLine() >= getDocument().getLineCount()) { - invalidate(); + invalidate(e); } else { DocumentEx document = getDocument(); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/PersistentRangeMarker.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/PersistentRangeMarker.java index 1c7d4a464300..61f9a3e365c2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/PersistentRangeMarker.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/PersistentRangeMarker.java @@ -36,23 +36,23 @@ class PersistentRangeMarker extends RangeMarkerImpl { PersistentRangeMarker(DocumentEx document, int startOffset, int endOffset, boolean register) { super(document, startOffset, endOffset, register); - storeLinesAndCols(); + storeLinesAndCols(null); } - private void storeLinesAndCols() { + private void storeLinesAndCols(DocumentEvent e) { // document might have been changed already if (getStartOffset() < myDocument.getTextLength()) { myStartLine = myDocument.getLineNumber(getStartOffset()); myStartColumn = getStartOffset() - myDocument.getLineStartOffset(myStartLine); if (myStartColumn < 0) { - invalidate(); + invalidate(e); } } if (getEndOffset() < myDocument.getTextLength()) { myEndLine = myDocument.getLineNumber(getEndOffset()); myEndColumn = getEndOffset() - myDocument.getLineStartOffset(myEndLine); if (myEndColumn < 0) { - invalidate(); + invalidate(e); } } } @@ -63,7 +63,7 @@ class PersistentRangeMarker extends RangeMarkerImpl { if (PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, this)){ myStartLine = event.translateLineViaDiffStrict(myStartLine); if (myStartLine < 0 || myStartLine >= getDocument().getLineCount()){ - invalidate(); + invalidate(e); } else{ setIntervalStart(getDocument().getLineStartOffset(myStartLine) + myStartColumn); @@ -71,7 +71,7 @@ class PersistentRangeMarker extends RangeMarkerImpl { myEndLine = event.translateLineViaDiffStrict(myEndLine); if (myEndLine < 0 || myEndLine >= getDocument().getLineCount()){ - invalidate(); + invalidate(e); } else{ setIntervalEnd(getDocument().getLineStartOffset(myEndLine) + myEndColumn); @@ -80,11 +80,11 @@ class PersistentRangeMarker extends RangeMarkerImpl { else { super.changedUpdateImpl(e); if (isValid()){ - storeLinesAndCols(); + storeLinesAndCols(e); } } if (getEndOffset() < getStartOffset() || getEndOffset() > getDocument().getTextLength()) { - invalidate(); + invalidate(e); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeMarkerImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeMarkerImpl.java index 2f52d3a489e9..c00edb2180d8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeMarkerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeMarkerImpl.java @@ -19,7 +19,9 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.editor.ex.DocumentEx; import com.intellij.openapi.editor.ex.RangeMarkerEx; +import com.intellij.openapi.util.Key; import com.intellij.openapi.util.UserDataHolderBase; +import com.intellij.util.Processor; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -30,7 +32,6 @@ public class RangeMarkerImpl extends UserDataHolderBase implements RangeMarkerEx protected final DocumentEx myDocument; RangeMarkerTree.RMNode myNode; - private boolean myTrackInvalidation; private final long myId; //private static long counter; @@ -91,8 +92,21 @@ public class RangeMarkerImpl extends UserDataHolderBase implements RangeMarkerEx return intervalEnd() + (node == null ? 0 : node.computeDeltaUpToRoot()); } - public void invalidate() { + public void invalidate(final DocumentEvent e) { setValid(false); + RangeMarkerTree.RMNode node = myNode; + + if (node != null) { + node.processAliveKeys(new Processor() { + @Override + public boolean process(RangeMarkerEx markerEx) { + if (markerEx.isTrackInvalidation()) { + LOG.error("Range marker invalidated: "+markerEx +"; say thanks to the "+e); + } + return true; + } + }); + } } @NotNull @@ -133,7 +147,7 @@ public class RangeMarkerImpl extends UserDataHolderBase implements RangeMarkerEx if (intervalStart() > intervalEnd() || intervalStart() < 0 || intervalEnd() > docLength - e.getNewLength() + e.getOldLength()) { LOG.error("RangeMarker" + (isGreedyToLeft() ? "[" : "(") + oldStart + ", " + oldEnd + (isGreedyToRight() ? "]" : ")") + " is invalid before update. Event = " + e + ". Doc length=" + docLength + "; "+getClass()); - invalidate(); + invalidate(e); return; } changedUpdateImpl(e); @@ -143,7 +157,7 @@ public class RangeMarkerImpl extends UserDataHolderBase implements RangeMarkerEx "old doc length=" + docLength + "; real doc length = "+myDocument.getTextLength()+ "; "+getClass()+"." + " Before update: '"+markerBefore+"'; After update: '"+this+"'"); - invalidate(); + invalidate(e); } } @@ -192,7 +206,7 @@ public class RangeMarkerImpl extends UserDataHolderBase implements RangeMarkerEx return; } - invalidate(); + invalidate(e); } private void processIfOnePoint(DocumentEvent e) { @@ -200,7 +214,7 @@ public class RangeMarkerImpl extends UserDataHolderBase implements RangeMarkerEx int oldLength = e.getOldLength(); int oldEnd = offset + oldLength; if (offset < intervalStart() && intervalStart() < oldEnd) { - invalidate(); + invalidate(e); return; } @@ -237,17 +251,17 @@ public class RangeMarkerImpl extends UserDataHolderBase implements RangeMarkerEx return node != null && node.isValid(); } + private static final Key TRACK_INVALIDATION_KEY = new Key("TRACK_INVALIDATION_KEY"); @Override public void trackInvalidation(boolean track) { - myTrackInvalidation = track; + putUserData(TRACK_INVALIDATION_KEY, track ? Boolean.TRUE : null); + } + public boolean isTrackInvalidation() { + return getUserData(TRACK_INVALIDATION_KEY) == Boolean.TRUE; } @Override public boolean setValid(boolean value) { - if (!value && myTrackInvalidation) { - LOG.error("Range marker invalidated"); - } - RangeMarkerTree.RMNode node = myNode; return node == null || node.setValid(value); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeMarkerTree.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeMarkerTree.java index 5a15cb0e0fa2..a5ba44e06006 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeMarkerTree.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeMarkerTree.java @@ -82,10 +82,10 @@ public class RangeMarkerTree extends IntervalTreeImpl.RMNode addInterval(@NotNull T interval, int start, int end, boolean greedyToLeft, boolean greedyToRight, int layer) { RangeMarkerImpl marker = (RangeMarkerImpl)interval; marker.setValid(true); - RMNode node = (RMNode)super.addInterval(interval, start, end, greedyToLeft, greedyToRight, layer); + RangeMarkerTree.RMNode node = (RMNode)super.addInterval(interval, start, end, greedyToLeft, greedyToRight, layer); ((RangeMarkerImpl)interval).myNode = node; checkBelongsToTheTree(interval, true); @@ -106,8 +106,8 @@ public class RangeMarkerTree extends IntervalTreeImpl.RMNode lookupNode(@NotNull T key) { + return (RMNode)((RangeMarkerImpl)key).myNode; } public class RMNode extends IntervalNode { @@ -131,7 +131,7 @@ public class RangeMarkerTree extends IntervalTreeImpl