mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Changed position trackers to use IRegion instead of Position.
This commit is contained in:
parent
8cd5946f7a
commit
8cf13ce26a
5 changed files with 35 additions and 28 deletions
|
@ -18,7 +18,8 @@ import junit.framework.TestCase;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.PositionTracker;
|
import org.eclipse.cdt.internal.core.PositionTracker;
|
||||||
import org.eclipse.jface.text.Position;
|
import org.eclipse.jface.text.IRegion;
|
||||||
|
import org.eclipse.jface.text.Region;
|
||||||
|
|
||||||
public class PositionTrackerTests extends TestCase {
|
public class PositionTrackerTests extends TestCase {
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
|
@ -260,13 +261,13 @@ public class PositionTrackerTests extends TestCase {
|
||||||
doubleCheck(pt, 2, 3);
|
doubleCheck(pt, 2, 3);
|
||||||
|
|
||||||
// ranges
|
// ranges
|
||||||
doubleRangeCheck(pt, new Position(0,2), new Position(0,3));
|
doubleRangeCheck(pt, new Region(0,2), new Region(0,3));
|
||||||
backwdRangeCheck(pt, new Position(0,1), new Position(0,2));
|
backwdRangeCheck(pt, new Region(0,1), new Region(0,2));
|
||||||
doubleRangeCheck(pt, new Position(0,1), new Position(0,1));
|
doubleRangeCheck(pt, new Region(0,1), new Region(0,1));
|
||||||
backwdRangeCheck(pt, new Position(1,0), new Position(1,1));
|
backwdRangeCheck(pt, new Region(1,0), new Region(1,1));
|
||||||
backwdRangeCheck(pt, new Position(1,0), new Position(1,0));
|
backwdRangeCheck(pt, new Region(1,0), new Region(1,0));
|
||||||
doubleRangeCheck(pt, new Position(1,1), new Position(2,1));
|
doubleRangeCheck(pt, new Region(1,1), new Region(2,1));
|
||||||
doubleRangeCheck(pt, new Position(1,0), new Position(2,0));
|
doubleRangeCheck(pt, new Region(1,0), new Region(2,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeletion() {
|
public void testDeletion() {
|
||||||
|
@ -282,13 +283,13 @@ public class PositionTrackerTests extends TestCase {
|
||||||
doubleCheck(pt, 3, 2);
|
doubleCheck(pt, 3, 2);
|
||||||
|
|
||||||
// ranges
|
// ranges
|
||||||
doubleRangeCheck(pt, new Position(0,3), new Position(0,2));
|
doubleRangeCheck(pt, new Region(0,3), new Region(0,2));
|
||||||
fwdRangeCheck (pt, new Position(0,2), new Position(0,1));
|
fwdRangeCheck (pt, new Region(0,2), new Region(0,1));
|
||||||
doubleRangeCheck(pt, new Position(0,1), new Position(0,1));
|
doubleRangeCheck(pt, new Region(0,1), new Region(0,1));
|
||||||
fwdRangeCheck (pt, new Position(1,1), new Position(1,0));
|
fwdRangeCheck (pt, new Region(1,1), new Region(1,0));
|
||||||
fwdRangeCheck (pt, new Position(1,0), new Position(1,0));
|
fwdRangeCheck (pt, new Region(1,0), new Region(1,0));
|
||||||
doubleRangeCheck(pt, new Position(2,1), new Position(1,1));
|
doubleRangeCheck(pt, new Region(2,1), new Region(1,1));
|
||||||
doubleRangeCheck(pt, new Position(2,0), new Position(1,0));
|
doubleRangeCheck(pt, new Region(2,0), new Region(1,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testReplace() {
|
public void testReplace() {
|
||||||
|
@ -342,16 +343,16 @@ public class PositionTrackerTests extends TestCase {
|
||||||
assertEquals(orig, pt.historicOffset(mapped));
|
assertEquals(orig, pt.historicOffset(mapped));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doubleRangeCheck(PositionTracker pt, Position orig, Position mapped) {
|
private void doubleRangeCheck(PositionTracker pt, IRegion orig, IRegion mapped) {
|
||||||
fwdRangeCheck(pt, orig, mapped);
|
fwdRangeCheck(pt, orig, mapped);
|
||||||
backwdRangeCheck(pt, orig, mapped);
|
backwdRangeCheck(pt, orig, mapped);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fwdRangeCheck(PositionTracker pt, Position orig, Position mapped) {
|
private void fwdRangeCheck(PositionTracker pt, IRegion orig, IRegion mapped) {
|
||||||
assertEquals(mapped, pt.historicToActual(orig));
|
assertEquals(mapped, pt.historicToActual(orig));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void backwdRangeCheck(PositionTracker pt, Position orig, Position mapped) {
|
private void backwdRangeCheck(PositionTracker pt, IRegion orig, IRegion mapped) {
|
||||||
assertEquals(orig, pt.actualToHistoric(mapped));
|
assertEquals(orig, pt.actualToHistoric(mapped));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.core;
|
package org.eclipse.cdt.core;
|
||||||
|
|
||||||
import org.eclipse.jface.text.Position;
|
import org.eclipse.jface.text.IRegion;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows for converting character ranges of files previously stored on disk to the
|
* Allows for converting character ranges of files previously stored on disk to the
|
||||||
|
@ -37,6 +38,8 @@ import org.eclipse.jface.text.Position;
|
||||||
* work or that it will remain the same. Please do not use this API without
|
* work or that it will remain the same. Please do not use this API without
|
||||||
* consulting with the CDT team.
|
* consulting with the CDT team.
|
||||||
* </p>
|
* </p>
|
||||||
|
*
|
||||||
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface IPositionConverter {
|
public interface IPositionConverter {
|
||||||
|
@ -47,7 +50,7 @@ public interface IPositionConverter {
|
||||||
* @return a range suitable for the version of the file for which the converter
|
* @return a range suitable for the version of the file for which the converter
|
||||||
* was obtained.
|
* was obtained.
|
||||||
*/
|
*/
|
||||||
Position actualToHistoric(Position actualPosition);
|
IRegion actualToHistoric(IRegion actualPosition);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a historic character range to the range where the underlying text
|
* Converts a historic character range to the range where the underlying text
|
||||||
|
@ -56,5 +59,5 @@ public interface IPositionConverter {
|
||||||
* the converter was obtained.
|
* the converter was obtained.
|
||||||
* @return a range suitable for the current text buffer of the file.
|
* @return a range suitable for the current text buffer of the file.
|
||||||
*/
|
*/
|
||||||
Position historicToActual(Position historicPosition);
|
IRegion historicToActual(IRegion historicPosition);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.eclipse.core.runtime.IPath;
|
||||||
* work or that it will remain the same. Please do not use this API without
|
* work or that it will remain the same. Please do not use this API without
|
||||||
* consulting with the CDT team.
|
* consulting with the CDT team.
|
||||||
* </p>
|
* </p>
|
||||||
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public interface IPositionTrackerManager {
|
public interface IPositionTrackerManager {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,7 +14,8 @@ package org.eclipse.cdt.internal.core;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.IPositionConverter;
|
import org.eclipse.cdt.core.IPositionConverter;
|
||||||
import org.eclipse.jface.text.Position;
|
import org.eclipse.jface.text.IRegion;
|
||||||
|
import org.eclipse.jface.text.Region;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks changes made to a text buffer, to afterwards recalculate positions.
|
* Tracks changes made to a text buffer, to afterwards recalculate positions.
|
||||||
|
@ -165,7 +166,7 @@ public class PositionTracker implements IPositionConverter {
|
||||||
return fAboveRoot.countNodes();
|
return fAboveRoot.countNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized Position actualToHistoric(Position actualPosition) {
|
public synchronized IRegion actualToHistoric(IRegion actualPosition) {
|
||||||
int actual= actualPosition.getOffset();
|
int actual= actualPosition.getOffset();
|
||||||
int len= actualPosition.getLength();
|
int len= actualPosition.getLength();
|
||||||
|
|
||||||
|
@ -174,10 +175,10 @@ public class PositionTracker implements IPositionConverter {
|
||||||
len= historicOffset(actual+len-1, false) - historic + 1;
|
len= historicOffset(actual+len-1, false) - historic + 1;
|
||||||
}
|
}
|
||||||
assert len >= 0;
|
assert len >= 0;
|
||||||
return new Position(historic, len);
|
return new Region(historic, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized Position historicToActual(Position historicPosition) {
|
public synchronized IRegion historicToActual(IRegion historicPosition) {
|
||||||
int historic= historicPosition.getOffset();
|
int historic= historicPosition.getOffset();
|
||||||
int len= historicPosition.getLength();
|
int len= historicPosition.getLength();
|
||||||
|
|
||||||
|
@ -186,7 +187,7 @@ public class PositionTracker implements IPositionConverter {
|
||||||
len= currentOffset(historic+len-1, false) - actual + 1;
|
len= currentOffset(historic+len-1, false) - actual + 1;
|
||||||
}
|
}
|
||||||
assert len >= 0;
|
assert len >= 0;
|
||||||
return new Position(actual, len);
|
return new Region(actual, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,7 +25,8 @@ import org.eclipse.jface.action.IMenuManager;
|
||||||
import org.eclipse.jface.action.IToolBarManager;
|
import org.eclipse.jface.action.IToolBarManager;
|
||||||
import org.eclipse.jface.action.MenuManager;
|
import org.eclipse.jface.action.MenuManager;
|
||||||
import org.eclipse.jface.action.Separator;
|
import org.eclipse.jface.action.Separator;
|
||||||
import org.eclipse.jface.text.Position;
|
import org.eclipse.jface.text.IRegion;
|
||||||
|
import org.eclipse.jface.text.Region;
|
||||||
import org.eclipse.jface.util.LocalSelectionTransfer;
|
import org.eclipse.jface.util.LocalSelectionTransfer;
|
||||||
import org.eclipse.jface.viewers.IOpenListener;
|
import org.eclipse.jface.viewers.IOpenListener;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
@ -698,7 +699,7 @@ public class IBViewPart extends ViewPart
|
||||||
}
|
}
|
||||||
if (editor instanceof ITextEditor) {
|
if (editor instanceof ITextEditor) {
|
||||||
ITextEditor te= (ITextEditor) editor;
|
ITextEditor te= (ITextEditor) editor;
|
||||||
Position pos= new Position(node.getDirectiveCharacterOffset(),
|
IRegion pos= new Region(node.getDirectiveCharacterOffset(),
|
||||||
node.getDirectiveName().length() + 2);
|
node.getDirectiveName().length() + 2);
|
||||||
if (filebufferKey != null) {
|
if (filebufferKey != null) {
|
||||||
IPositionConverter pc= CCorePlugin.getPositionTrackerManager().findPositionConverter(filebufferKey, timestamp);
|
IPositionConverter pc= CCorePlugin.getPositionTrackerManager().findPositionConverter(filebufferKey, timestamp);
|
||||||
|
|
Loading…
Add table
Reference in a new issue