mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
trackInvalidation
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -35,5 +35,5 @@ public interface RangeMarkerEx extends RangeMarker, MutableInterval, Segment {
|
||||
long getId();
|
||||
|
||||
void trackInvalidation(boolean track);
|
||||
|
||||
boolean isTrackInvalidation();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public abstract class IntervalTreeImpl<T extends MutableInterval> extends RedBla
|
||||
private final ReferenceQueue<T> myReferenceQueue = new ReferenceQueue<T>();
|
||||
private int deadReferenceCount;
|
||||
|
||||
protected class IntervalNode extends Node<T> implements MutableInterval/*, Iterable<T>, Iterator<T>*/ {
|
||||
protected class IntervalNode extends Node<T> implements MutableInterval {
|
||||
private volatile int myStart;
|
||||
private volatile int myEnd;
|
||||
private volatile boolean isValid = true;
|
||||
@@ -181,11 +181,11 @@ public abstract class IntervalTreeImpl<T extends MutableInterval> extends RedBla
|
||||
return myEnd;
|
||||
}
|
||||
|
||||
public IntervalTreeImpl getTree() {
|
||||
public IntervalTreeImpl<T> getTree() {
|
||||
return IntervalTreeImpl.this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void pushDeltaFromRoot(IntervalNode node) {
|
||||
if (normalized) return;
|
||||
if (node != null) {
|
||||
@@ -437,7 +437,7 @@ public abstract class IntervalTreeImpl<T extends MutableInterval> extends RedBla
|
||||
}
|
||||
}
|
||||
|
||||
public IntervalNode addInterval(@NotNull T interval, int start, int end, boolean greedyToLeft, boolean greedyToRight, int layer) {
|
||||
public IntervalTreeImpl<T>.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<T extends MutableInterval> 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();
|
||||
|
||||
+1
-1
@@ -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();
|
||||
|
||||
+8
-8
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<RangeMarkerEx>.RMNode node = myNode;
|
||||
|
||||
if (node != null) {
|
||||
node.processAliveKeys(new Processor<RangeMarkerEx>() {
|
||||
@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<Boolean> TRACK_INVALIDATION_KEY = new Key<Boolean>("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);
|
||||
}
|
||||
|
||||
@@ -82,10 +82,10 @@ public class RangeMarkerTree<T extends RangeMarkerEx> extends IntervalTreeImpl<T
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntervalNode addInterval(@NotNull T interval, int start, int end, boolean greedyToLeft, boolean greedyToRight, int layer) {
|
||||
public RangeMarkerTree<T>.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<T>.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<T extends RangeMarkerEx> extends IntervalTreeImpl<T
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IntervalNode lookupNode(@NotNull T key) {
|
||||
return ((RangeMarkerImpl)key).myNode;
|
||||
protected RangeMarkerTree<T>.RMNode lookupNode(@NotNull T key) {
|
||||
return (RMNode)((RangeMarkerImpl)key).myNode;
|
||||
}
|
||||
|
||||
public class RMNode extends IntervalNode {
|
||||
@@ -131,7 +131,7 @@ public class RangeMarkerTree<T extends RangeMarkerEx> extends IntervalTreeImpl<T
|
||||
@Override
|
||||
public void addInterval(@NotNull T interval) {
|
||||
super.addInterval(interval);
|
||||
((RangeMarkerImpl)interval).myNode = this;
|
||||
((RangeMarkerImpl)interval).myNode = (RangeMarkerTree.RMNode)this;
|
||||
checkBelongsToTheTree(interval, true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user