mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-17 14:05:23 +02:00
Cosmetics.
This commit is contained in:
parent
bf5f005736
commit
2bc250198d
6 changed files with 88 additions and 94 deletions
|
@ -6,9 +6,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.core.internal.tests;
|
package org.eclipse.cdt.core.internal.tests;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
|
@ -6,9 +6,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core;
|
package org.eclipse.cdt.internal.core;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
@ -38,7 +37,7 @@ public class PositionTracker implements IPositionConverter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undo the retirement to make this the head of a tracker chain again.
|
* Undoes the retirement to make this the head of a tracker chain again.
|
||||||
*/
|
*/
|
||||||
synchronized void revive() {
|
synchronized void revive() {
|
||||||
fFollowedBy = null;
|
fFollowedBy = null;
|
||||||
|
@ -47,6 +46,7 @@ public class PositionTracker implements IPositionConverter {
|
||||||
/**
|
/**
|
||||||
* Notifies the tracker of the insertion of characters.
|
* Notifies the tracker of the insertion of characters.
|
||||||
* It is assumed that character get inserted before the offset.
|
* It is assumed that character get inserted before the offset.
|
||||||
|
*
|
||||||
* @param offset offset of the character in front of which insertion occurs.
|
* @param offset offset of the character in front of which insertion occurs.
|
||||||
* @param count amount of characters inserted.
|
* @param count amount of characters inserted.
|
||||||
*/
|
*/
|
||||||
|
@ -63,6 +63,7 @@ public class PositionTracker implements IPositionConverter {
|
||||||
* Notifies the tracker of the removal of characters.
|
* Notifies the tracker of the removal of characters.
|
||||||
* delete(0,1) removes the first character,
|
* delete(0,1) removes the first character,
|
||||||
* for convenience delete(1,-1) does the same.
|
* for convenience delete(1,-1) does the same.
|
||||||
|
*
|
||||||
* @param offset offset of the first character deleted.
|
* @param offset offset of the first character deleted.
|
||||||
* @param count amount of characters deleted.
|
* @param count amount of characters deleted.
|
||||||
*/
|
*/
|
||||||
|
@ -71,8 +72,7 @@ public class PositionTracker implements IPositionConverter {
|
||||||
assert offset >= 0;
|
assert offset >= 0;
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
delete(offset + count, -count);
|
delete(offset + count, -count);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (count == 0 || offset < 0) {
|
if (count == 0 || offset < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,7 @@ public class PositionTracker implements IPositionConverter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the position in the original unmodified text.
|
* Calculates the position in the original unmodified text.
|
||||||
|
*
|
||||||
* @param currentOffset position in the modified text.
|
* @param currentOffset position in the modified text.
|
||||||
* @return position in the unmodified text.
|
* @return position in the unmodified text.
|
||||||
*/
|
*/
|
||||||
|
@ -100,6 +101,7 @@ public class PositionTracker implements IPositionConverter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the position in the modified text.
|
* Calculates the position in the modified text.
|
||||||
|
*
|
||||||
* @param historicOffset position in the unmodified text.
|
* @param historicOffset position in the unmodified text.
|
||||||
* @return position in the modified text.
|
* @return position in the modified text.
|
||||||
*/
|
*/
|
||||||
|
@ -117,7 +119,8 @@ public class PositionTracker implements IPositionConverter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes this tracker final. Future changes are tracked by the tracker
|
* Makes this tracker final. Future changes are tracked by the tracker
|
||||||
* supplied and will be taken into acoount when converting positions.
|
* supplied and will be taken into account when converting positions.
|
||||||
|
*
|
||||||
* @param inFavourOf tracker that tracks changes from now on.
|
* @param inFavourOf tracker that tracks changes from now on.
|
||||||
*/
|
*/
|
||||||
public synchronized void retire(PositionTracker inFavourOf) {
|
public synchronized void retire(PositionTracker inFavourOf) {
|
||||||
|
@ -173,7 +176,7 @@ public class PositionTracker implements IPositionConverter {
|
||||||
|
|
||||||
int historic= historicOffset(actual, true);
|
int historic= historicOffset(actual, true);
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
len= historicOffset(actual+len-1, false) - historic + 1;
|
len= historicOffset(actual + len - 1, false) - historic + 1;
|
||||||
}
|
}
|
||||||
assert len >= 0;
|
assert len >= 0;
|
||||||
return new Region(historic, len);
|
return new Region(historic, len);
|
||||||
|
@ -186,7 +189,7 @@ public class PositionTracker implements IPositionConverter {
|
||||||
|
|
||||||
int actual= currentOffset(historic, true);
|
int actual= currentOffset(historic, true);
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
len= currentOffset(historic+len-1, false) - actual + 1;
|
len= currentOffset(historic + len - 1, false) - actual + 1;
|
||||||
}
|
}
|
||||||
assert len >= 0;
|
assert len >= 0;
|
||||||
return new Region(actual, len);
|
return new Region(actual, len);
|
||||||
|
@ -194,15 +197,16 @@ public class PositionTracker implements IPositionConverter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nodes implementing a red black binary tree.
|
* Nodes implementing a red black binary tree.
|
||||||
|
*
|
||||||
* @author markus.schorn@windriver.com
|
* @author markus.schorn@windriver.com
|
||||||
*/
|
*/
|
||||||
private static class Node {
|
private static class Node {
|
||||||
private static final boolean RED = true;
|
private static final boolean RED = true;
|
||||||
private static final boolean BLACK = false;
|
private static final boolean BLACK = false;
|
||||||
|
|
||||||
private int fDeltaPos2; // sum of this and pos2 of parent yields pos2.
|
private int fDeltaPos2; // Sum of this and pos2 of parent yields pos2.
|
||||||
private int fPos1;
|
private int fPos1;
|
||||||
private int fChange; // lenght of text change (+ add, - remove)
|
private int fChange; // Length of text change (+ add, - remove)
|
||||||
|
|
||||||
private boolean fColor;
|
private boolean fColor;
|
||||||
private Node fLeft;
|
private Node fLeft;
|
||||||
|
@ -230,61 +234,61 @@ public class PositionTracker implements IPositionConverter {
|
||||||
return StrictMath.max(fLeft.depth(), fRight.depth()) + 1;
|
return StrictMath.max(fLeft.depth(), fRight.depth()) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// forward calculation
|
// Forward calculation.
|
||||||
int calculateCurrentOffset(int value1, int parentPos2, boolean nextOnDelete) {
|
int calculateCurrentOffset(int value1, int parentPos2, boolean nextOnDelete) {
|
||||||
int fPos2 = parentPos2 + fDeltaPos2;
|
int fPos2 = parentPos2 + fDeltaPos2;
|
||||||
int rel1 = value1 - fPos1;
|
int rel1 = value1 - fPos1;
|
||||||
|
|
||||||
// is value ahead of this change?
|
// Is value ahead of this change?
|
||||||
if (rel1 < 0) {
|
if (rel1 < 0) {
|
||||||
if (fLeft != null) {
|
if (fLeft != null) {
|
||||||
return fLeft.calculateCurrentOffset(value1, fPos2, nextOnDelete);
|
return fLeft.calculateCurrentOffset(value1, fPos2, nextOnDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
// value is directly ahead of this change.
|
// Value is directly ahead of this change.
|
||||||
return rel1 + fPos2;
|
return rel1 + fPos2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// is value deleted by this?
|
// Is value deleted by this?
|
||||||
if (rel1 < -fChange) {
|
if (rel1 < -fChange) {
|
||||||
return nextOnDelete ? fPos2 : fPos2-1;
|
return nextOnDelete ? fPos2 : fPos2 - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// value is after this change.
|
// Value is after this change.
|
||||||
if (fRight != null) {
|
if (fRight != null) {
|
||||||
return fRight.calculateCurrentOffset(value1, fPos2, nextOnDelete);
|
return fRight.calculateCurrentOffset(value1, fPos2, nextOnDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
// value is directly after this change.
|
// Value is directly after this change.
|
||||||
return rel1 + fPos2 + fChange;
|
return rel1 + fPos2 + fChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
// backward calculation
|
// Backward calculation.
|
||||||
int calculateOriginalOffset(int value2, int parentPos2, boolean nextOnDelete) {
|
int calculateOriginalOffset(int value2, int parentPos2, boolean nextOnDelete) {
|
||||||
int fPos2 = parentPos2 + fDeltaPos2;
|
int fPos2 = parentPos2 + fDeltaPos2;
|
||||||
int rel2 = value2 - fPos2;
|
int rel2 = value2 - fPos2;
|
||||||
|
|
||||||
// is value ahead of this change?
|
// Is value ahead of this change?
|
||||||
if (rel2 < 0) {
|
if (rel2 < 0) {
|
||||||
if (fLeft != null) {
|
if (fLeft != null) {
|
||||||
return fLeft.calculateOriginalOffset(value2, fPos2, nextOnDelete);
|
return fLeft.calculateOriginalOffset(value2, fPos2, nextOnDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
// value is directly ahead of this change.
|
// Value is directly ahead of this change.
|
||||||
return rel2 + fPos1;
|
return rel2 + fPos1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// is value added by this?
|
// Is value added by this?
|
||||||
if (rel2 < fChange) {
|
if (rel2 < fChange) {
|
||||||
return nextOnDelete ? fPos1 : fPos1-1;
|
return nextOnDelete ? fPos1 : fPos1 - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// offset is behind this change.
|
// Offset is behind this change.
|
||||||
if (fRight != null) {
|
if (fRight != null) {
|
||||||
return fRight.calculateOriginalOffset(value2, fPos2, nextOnDelete);
|
return fRight.calculateOriginalOffset(value2, fPos2, nextOnDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
// offset is directly behind this change.
|
// Offset is directly behind this change.
|
||||||
return rel2 + fPos1 - fChange;
|
return rel2 + fPos1 - fChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,48 +296,47 @@ public class PositionTracker implements IPositionConverter {
|
||||||
int rel2 = value2 - fPos2;
|
int rel2 = value2 - fPos2;
|
||||||
|
|
||||||
if (fParent != null) {
|
if (fParent != null) {
|
||||||
fParent.balance(); // this may change both the parent and fDeltaPos2;
|
fParent.balance(); // This may change both the parent and fDeltaPos2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// added ahead of this change?
|
// Added ahead of this change?
|
||||||
if (rel2 < 0) {
|
if (rel2 < 0) {
|
||||||
fDeltaPos2 += add; // advance
|
fDeltaPos2 += add; // Advance
|
||||||
if (fLeft != null) {
|
if (fLeft != null) {
|
||||||
int childPos2 = fPos2 + fLeft.fDeltaPos2;
|
int childPos2 = fPos2 + fLeft.fDeltaPos2;
|
||||||
fLeft.fDeltaPos2 -= add; // unadvance
|
fLeft.fDeltaPos2 -= add; // Unadvance
|
||||||
fLeft.addChars(value2, add, childPos2); // use modified parent pos
|
fLeft.addChars(value2, add, childPos2); // Use modified parent pos
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addLeft(rel2 + fPos1, rel2 - add, add); // modify delta pos
|
addLeft(rel2 + fPos1, rel2 - add, add); // Modify delta pos
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// added inside range of another change?
|
// Added inside range of another change?
|
||||||
int range2 = (fChange > 0) ? fChange : 0;
|
int range2 = fChange > 0 ? fChange : 0;
|
||||||
if (rel2 <= range2 && !isHolder()) {
|
if (rel2 <= range2 && !isHolder()) {
|
||||||
fChange += add;
|
fChange += add;
|
||||||
// insert in a deletion at the end
|
// Insert in a deletion at the end
|
||||||
if (fChange<=0) {
|
if (fChange <= 0) {
|
||||||
fPos1+= add;
|
fPos1 += add;
|
||||||
fDeltaPos2+= add;
|
fDeltaPos2 += add;
|
||||||
if (fLeft != null) {
|
if (fLeft != null) {
|
||||||
fLeft.fDeltaPos2 -= add;
|
fLeft.fDeltaPos2 -= add;
|
||||||
}
|
}
|
||||||
}
|
} else if (fRight != null) {
|
||||||
else if (fRight != null) {
|
|
||||||
fRight.fDeltaPos2 += add; // advance right branch
|
fRight.fDeltaPos2 += add; // advance right branch
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// added behind this change.
|
// Added behind this change.
|
||||||
if (fRight != null) {
|
if (fRight != null) {
|
||||||
fRight.addChars(value2, add, fPos2 + fRight.fDeltaPos2);
|
fRight.addChars(value2, add, fPos2 + fRight.fDeltaPos2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// added directly behind this change
|
// Added directly behind this change.
|
||||||
addRight(rel2 + fPos1 - fChange, rel2, add);
|
addRight(rel2 + fPos1 - fChange, rel2, add);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,16 +344,16 @@ public class PositionTracker implements IPositionConverter {
|
||||||
int relFirstChar2 = firstChar2 - fPos2;
|
int relFirstChar2 = firstChar2 - fPos2;
|
||||||
int relAfterLastChar2 = relFirstChar2 + remove;
|
int relAfterLastChar2 = relFirstChar2 + remove;
|
||||||
|
|
||||||
// no insertion - no balancing
|
// No insertion - no balancing
|
||||||
if (mustRemove && fParent != null) {
|
if (mustRemove && fParent != null) {
|
||||||
fParent.balance();
|
fParent.balance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ahead and no merge possible
|
// Ahead and no merge possible.
|
||||||
if (relAfterLastChar2 < 0) {
|
if (relAfterLastChar2 < 0) {
|
||||||
fDeltaPos2 -= remove; // advance
|
fDeltaPos2 -= remove; // Advance
|
||||||
if (fLeft != null) {
|
if (fLeft != null) {
|
||||||
fLeft.fDeltaPos2 += remove; // unadvance
|
fLeft.fDeltaPos2 += remove; // Unadvance
|
||||||
return fLeft.removeChars(firstChar2, remove, fPos2 - remove + fLeft.fDeltaPos2, mustRemove);
|
return fLeft.removeChars(firstChar2, remove, fPos2 - remove + fLeft.fDeltaPos2, mustRemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,7 +364,7 @@ public class PositionTracker implements IPositionConverter {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// behind and no merge possible
|
// Behind and no merge possible.
|
||||||
int range2 = (fChange > 0) ? fChange : 0;
|
int range2 = (fChange > 0) ? fChange : 0;
|
||||||
if (relFirstChar2 > range2 || isHolder()) {
|
if (relFirstChar2 > range2 || isHolder()) {
|
||||||
if (fRight != null) {
|
if (fRight != null) {
|
||||||
|
@ -386,7 +389,7 @@ public class PositionTracker implements IPositionConverter {
|
||||||
}
|
}
|
||||||
int delInside = remove - delAbove - delBelow;
|
int delInside = remove - delAbove - delBelow;
|
||||||
|
|
||||||
// delegate above to left children
|
// Delegate above to left children.
|
||||||
if (delAbove > 0 && fLeft != null) {
|
if (delAbove > 0 && fLeft != null) {
|
||||||
if (fLeft.removeChars(firstChar2, delAbove, fPos2 + fLeft.fDeltaPos2, false)) {
|
if (fLeft.removeChars(firstChar2, delAbove, fPos2 + fLeft.fDeltaPos2, false)) {
|
||||||
fDeltaPos2 -= delAbove;
|
fDeltaPos2 -= delAbove;
|
||||||
|
@ -395,14 +398,14 @@ public class PositionTracker implements IPositionConverter {
|
||||||
delAbove = 0;
|
delAbove = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// delegate below to right children
|
// Delegate below to right children.
|
||||||
if (delBelow > 0 && fRight != null) {
|
if (delBelow > 0 && fRight != null) {
|
||||||
if (fRight.removeChars(fPos2 + range2, delBelow, fPos2 + fRight.fDeltaPos2, false)) {
|
if (fRight.removeChars(fPos2 + range2, delBelow, fPos2 + fRight.fDeltaPos2, false)) {
|
||||||
delBelow = 0;
|
delBelow = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// do the adjustments in this node
|
// Do the adjustments in this node.
|
||||||
fChange -= delAbove + delInside + delBelow;
|
fChange -= delAbove + delInside + delBelow;
|
||||||
fDeltaPos2 -= delAbove;
|
fDeltaPos2 -= delAbove;
|
||||||
fPos1 -= delAbove;
|
fPos1 -= delAbove;
|
||||||
|
@ -485,7 +488,7 @@ public class PositionTracker implements IPositionConverter {
|
||||||
int aboveLeft = -root.fDeltaPos2 - left.fDeltaPos2;
|
int aboveLeft = -root.fDeltaPos2 - left.fDeltaPos2;
|
||||||
int leftRoot = left.fDeltaPos2;
|
int leftRoot = left.fDeltaPos2;
|
||||||
|
|
||||||
// put under old parent
|
// Put under old parent.
|
||||||
if (fParent.fLeft == this) {
|
if (fParent.fLeft == this) {
|
||||||
fParent.putLeft(left);
|
fParent.putLeft(left);
|
||||||
} else {
|
} else {
|
||||||
|
@ -493,7 +496,7 @@ public class PositionTracker implements IPositionConverter {
|
||||||
}
|
}
|
||||||
left.fDeltaPos2 += rootAbove;
|
left.fDeltaPos2 += rootAbove;
|
||||||
|
|
||||||
// change the right node
|
// Change the right node.
|
||||||
left.putRight(root);
|
left.putRight(root);
|
||||||
root.fDeltaPos2 += aboveLeft;
|
root.fDeltaPos2 += aboveLeft;
|
||||||
|
|
||||||
|
@ -515,7 +518,7 @@ public class PositionTracker implements IPositionConverter {
|
||||||
int parentRight = -root.fDeltaPos2 - right.fDeltaPos2;
|
int parentRight = -root.fDeltaPos2 - right.fDeltaPos2;
|
||||||
int rightRoot = right.fDeltaPos2;
|
int rightRoot = right.fDeltaPos2;
|
||||||
|
|
||||||
// put under old parent
|
// Put under old parent.
|
||||||
if (fParent.fRight == this) {
|
if (fParent.fRight == this) {
|
||||||
fParent.putRight(right);
|
fParent.putRight(right);
|
||||||
} else {
|
} else {
|
||||||
|
@ -523,11 +526,11 @@ public class PositionTracker implements IPositionConverter {
|
||||||
}
|
}
|
||||||
right.fDeltaPos2 += rootAbove;
|
right.fDeltaPos2 += rootAbove;
|
||||||
|
|
||||||
// change the left node
|
// Change the left node.
|
||||||
right.putLeft(root);
|
right.putLeft(root);
|
||||||
root.fDeltaPos2 += parentRight;
|
root.fDeltaPos2 += parentRight;
|
||||||
|
|
||||||
// change right of left node.
|
// Change right of left node.
|
||||||
root.putRight(rightLeft);
|
root.putRight(rightLeft);
|
||||||
if (rightLeft != null) {
|
if (rightLeft != null) {
|
||||||
rightLeft.fDeltaPos2 += rightRoot;
|
rightLeft.fDeltaPos2 += rightRoot;
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
* Copyright (c) 2006, 2014 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core;
|
package org.eclipse.cdt.internal.core;
|
||||||
|
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
import java.util.Deque;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.ListIterator;
|
|
||||||
|
|
||||||
import org.eclipse.jface.text.DocumentEvent;
|
import org.eclipse.jface.text.DocumentEvent;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
@ -26,7 +26,7 @@ class PositionTrackerChain implements IDocumentListener {
|
||||||
private static final int MAX_DEPTH = 100; // 100 saves
|
private static final int MAX_DEPTH = 100; // 100 saves
|
||||||
private static final long MAX_AGE = 24 * 60 * 60 * 1000; // one day
|
private static final long MAX_AGE = 24 * 60 * 60 * 1000; // one day
|
||||||
|
|
||||||
private LinkedList<PositionTracker> fTrackers= new LinkedList<PositionTracker>();
|
private Deque<PositionTracker> fTrackers= new ArrayDeque<>();
|
||||||
private PositionTracker fActiveTracker;
|
private PositionTracker fActiveTracker;
|
||||||
private IDocument fDocument;
|
private IDocument fDocument;
|
||||||
|
|
||||||
|
@ -35,13 +35,12 @@ class PositionTrackerChain implements IDocumentListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int createCheckpoint(long timestamp) {
|
public int createCheckpoint(long timestamp) {
|
||||||
// travel in time
|
// Travel in time.
|
||||||
while (fActiveTracker != null && fActiveTracker.getTimeStamp() >= timestamp) {
|
while (fActiveTracker != null && fActiveTracker.getTimeStamp() >= timestamp) {
|
||||||
fTrackers.removeLast();
|
fTrackers.removeLast();
|
||||||
if (fTrackers.isEmpty()) {
|
if (fTrackers.isEmpty()) {
|
||||||
fActiveTracker= null;
|
fActiveTracker= null;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
fActiveTracker= fTrackers.getLast();
|
fActiveTracker= fTrackers.getLast();
|
||||||
fActiveTracker.revive();
|
fActiveTracker.revive();
|
||||||
}
|
}
|
||||||
|
@ -76,7 +75,7 @@ class PositionTrackerChain implements IDocumentListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent)
|
* @see org.eclipse.jface.text.IPositionUpdater#update(DocumentEvent)
|
||||||
*/
|
*/
|
||||||
private void update(DocumentEvent event) {
|
private void update(DocumentEvent event) {
|
||||||
String text = event.getText();
|
String text = event.getText();
|
||||||
|
@ -93,19 +92,19 @@ class PositionTrackerChain implements IDocumentListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the nearest tracker created at or after the given time.
|
* Finds the nearest tracker created at or after the given time.
|
||||||
|
*
|
||||||
* @param timestamp in milliseconds.
|
* @param timestamp in milliseconds.
|
||||||
* @return the tracker nearest to the timestamp, <code>null</code> if all were created before.
|
* @return the tracker nearest to the timestamp, <code>null</code> if all were created before.
|
||||||
*/
|
*/
|
||||||
public PositionTracker findTrackerAtOrAfter(long timestamp) {
|
public PositionTracker findTrackerAtOrAfter(long timestamp) {
|
||||||
PositionTracker candidate= null;
|
PositionTracker candidate= null;
|
||||||
for (ListIterator<PositionTracker> iter = fTrackers.listIterator(fTrackers.size()); iter.hasPrevious();) {
|
for (Iterator<PositionTracker> iter = fTrackers.descendingIterator(); iter.hasNext();) {
|
||||||
PositionTracker tracker = iter.previous();
|
PositionTracker tracker = iter.next();
|
||||||
long trackerTimestamp= tracker.getTimeStamp();
|
long trackerTimestamp= tracker.getTimeStamp();
|
||||||
if (trackerTimestamp >= timestamp) {
|
if (trackerTimestamp >= timestamp) {
|
||||||
candidate= tracker;
|
candidate= tracker;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,13 +112,14 @@ class PositionTrackerChain implements IDocumentListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the tracker created at the given time.
|
* Finds the tracker created at the given time.
|
||||||
|
*
|
||||||
* @param timestamp in milliseconds.
|
* @param timestamp in milliseconds.
|
||||||
* @return the tracker at the timestamp, <code>null</code> if none created at the given time.
|
* @return the tracker at the timestamp, <code>null</code> if none created at the given time.
|
||||||
*/
|
*/
|
||||||
public PositionTracker findTrackerAt(long timestamp) {
|
public PositionTracker findTrackerAt(long timestamp) {
|
||||||
for (ListIterator<PositionTracker> iter = fTrackers.listIterator(fTrackers.size()); iter.hasPrevious();) {
|
for (Iterator<PositionTracker> iter = fTrackers.descendingIterator(); iter.hasNext();) {
|
||||||
PositionTracker tracker = iter.previous();
|
PositionTracker tracker = iter.next();
|
||||||
long trackerTimestamp= tracker.getTimeStamp();
|
long trackerTimestamp= tracker.getTimeStamp();
|
||||||
if (trackerTimestamp == timestamp) {
|
if (trackerTimestamp == timestamp) {
|
||||||
return tracker;
|
return tracker;
|
||||||
|
@ -132,7 +132,7 @@ class PositionTrackerChain implements IDocumentListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the tracker.
|
* Destroys the tracker.
|
||||||
*/
|
*/
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
stopTracking();
|
stopTracking();
|
||||||
|
@ -162,7 +162,7 @@ class PositionTrackerChain implements IDocumentListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void documentChanged(DocumentEvent event) {
|
public void documentChanged(DocumentEvent event) {
|
||||||
// react before updateing the document
|
// React before updating the document.
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDocument getCurrentDocument() {
|
public IDocument getCurrentDocument() {
|
||||||
|
@ -180,8 +180,8 @@ class PositionTrackerChain implements IDocumentListener {
|
||||||
public int getMemorySize() {
|
public int getMemorySize() {
|
||||||
int size= MEMORY_SIZE;
|
int size= MEMORY_SIZE;
|
||||||
for (PositionTracker tracker : fTrackers) {
|
for (PositionTracker tracker : fTrackers) {
|
||||||
size+= LINKED_LIST_ENTRY_SIZE;
|
size += LINKED_LIST_ENTRY_SIZE;
|
||||||
size+= tracker.getMemorySize();
|
size += tracker.getMemorySize();
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core;
|
package org.eclipse.cdt.internal.core;
|
||||||
|
|
||||||
|
@ -99,14 +99,19 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bufferContentAboutToBeReplaced(IFileBuffer buffer) {}
|
public void bufferContentAboutToBeReplaced(IFileBuffer buffer) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bufferContentReplaced(IFileBuffer buffer) {}
|
public void bufferContentReplaced(IFileBuffer buffer) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void underlyingFileMoved(IFileBuffer buffer, IPath path) {}
|
public void underlyingFileMoved(IFileBuffer buffer, IPath path) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void underlyingFileDeleted(IFileBuffer buffer) {}
|
public void underlyingFileDeleted(IFileBuffer buffer) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stateChangeFailed(IFileBuffer buffer) {}
|
public void stateChangeFailed(IFileBuffer buffer) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stateChanging(IFileBuffer buffer) {}
|
public void stateChanging(IFileBuffer buffer) {}
|
||||||
|
|
||||||
|
@ -194,9 +199,6 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized IPositionConverter findPositionConverter(IFile file, long timestamp) {
|
public synchronized IPositionConverter findPositionConverter(IFile file, long timestamp) {
|
||||||
PositionTrackerChain chain= fPositionTrackerMap.get(file.getFullPath());
|
PositionTrackerChain chain= fPositionTrackerMap.get(file.getFullPath());
|
||||||
|
@ -206,9 +208,6 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized IPositionConverter findPositionConverter(IPath externalLocation, long timestamp) {
|
public synchronized IPositionConverter findPositionConverter(IPath externalLocation, long timestamp) {
|
||||||
PositionTrackerChain chain= fPositionTrackerMap.get(externalLocation);
|
PositionTrackerChain chain= fPositionTrackerMap.get(externalLocation);
|
||||||
|
@ -218,9 +217,6 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized IPositionConverter findPositionConverter(ITranslationUnit tu, long timestamp) {
|
public synchronized IPositionConverter findPositionConverter(ITranslationUnit tu, long timestamp) {
|
||||||
IFile file= (IFile) tu.getResource();
|
IFile file= (IFile) tu.getResource();
|
||||||
|
@ -240,9 +236,6 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized IPositionConverter findPositionConverter(URI locationURI, long timestamp) {
|
public synchronized IPositionConverter findPositionConverter(URI locationURI, long timestamp) {
|
||||||
PositionTrackerChain chain= fPositionTrackerMap.get(locationURI);
|
PositionTrackerChain chain= fPositionTrackerMap.get(locationURI);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*******************************************************************************
|
||||||
* Copyright (c) 2014 BlackBerry Limited and others.
|
* Copyright (c) 2014 BlackBerry Limited and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core;
|
package org.eclipse.cdt.internal.core;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*******************************************************************************
|
||||||
* Copyright (c) 2014 BlackBerry Limited and others.
|
* Copyright (c) 2014 BlackBerry Limited and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core;
|
package org.eclipse.cdt.internal.core;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -17,7 +17,6 @@ import org.eclipse.cdt.core.ErrorParserManager;
|
||||||
import org.eclipse.cdt.core.IProblemMarkerFilter;
|
import org.eclipse.cdt.core.IProblemMarkerFilter;
|
||||||
import org.eclipse.cdt.core.ProblemMarkerInfo;
|
import org.eclipse.cdt.core.ProblemMarkerInfo;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
import org.eclipse.core.runtime.IExtensionRegistry;
|
import org.eclipse.core.runtime.IExtensionRegistry;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
|
Loading…
Add table
Reference in a new issue