aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Christiaens2010-09-28 07:20:25 (EDT)
committerKnut Wannheden2011-04-28 05:18:04 (EDT)
commita576ca2625b61e218318b5b2f1bcbd056cda3595 (patch)
tree7cfe7b74e71d06c4da8bb1a0c2a84995a5b51577
parent654a171df2cfef18e6042f7d37158970f811d304 (diff)
downloadorg.eclipse.xtext-a576ca2625b61e218318b5b2f1bcbd056cda3595.zip
org.eclipse.xtext-a576ca2625b61e218318b5b2f1bcbd056cda3595.tar.gz
org.eclipse.xtext-a576ca2625b61e218318b5b2f1bcbd056cda3595.tar.bz2
Another refactoring.
-rw-r--r--plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/FastDamagerRepairer.java27
1 files changed, 15 insertions, 12 deletions
diff --git a/plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/FastDamagerRepairer.java b/plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/FastDamagerRepairer.java
index 8d20108..9385740 100644
--- a/plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/FastDamagerRepairer.java
+++ b/plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/FastDamagerRepairer.java
@@ -154,15 +154,14 @@ public class FastDamagerRepairer extends AbstractDamagerRepairer {
}
int tokenStartsAt = 0;
+ int nextTokenStartsAt = 0;
int tokenInfoIdx = 0;
- int regionOffset = 0;
- int regionLength = e.fDocument.getLength();
TokenSource source = createLexer(e.fDocument.get());
CommonToken token = (CommonToken) source.nextToken();
ListIterator<TokenInfo> tokenInfosIt = tokenInfos.listIterator();
- TokenInfo tokenInfo = tokenInfosIt.next();
+ TokenInfo tokenInfo = null;
// find start idx
while (true) {
@@ -176,20 +175,21 @@ public class FastDamagerRepairer extends AbstractDamagerRepairer {
tokenInfo = tokenInfosIt.next();
- if (tokenInfo.type != token.getType() || getTokenLength(token) != tokenInfo.length)
+ if (tokenCorrespondsToTokenInfo(token, tokenInfo))
break;
- if (tokenStartsAt + tokenInfo.length > e.fOffset)
+ nextTokenStartsAt = tokenStartsAt + tokenInfo.length;
+
+ if (nextTokenStartsAt > e.fOffset)
break;
-
+
tokenInfoIdx++;
- tokenStartsAt += tokenInfo.length;
+ tokenStartsAt = nextTokenStartsAt;
token = (CommonToken) source.nextToken();
}
- regionLength -= tokenStartsAt;
- regionOffset = tokenStartsAt;
-
+ int regionOffset = tokenStartsAt;
+ int regionLength = e.fDocument.getLength() - tokenStartsAt;
int lengthDiff = e.fText.length() - e.fLength;
LinkedList<TokenInfo> tokenInfosCopy = new LinkedList<TokenInfo>(tokenInfos);
@@ -215,8 +215,7 @@ public class FastDamagerRepairer extends AbstractDamagerRepairer {
assert tokenInfo == tokenInfoCopy;
if (token.getStartIndex() >= e.fOffset + e.fText.length()) {
- if (tokenStartsAt + lengthDiff == token.getStartIndex() && tokenInfo.type == token.getType()
- && getTokenLength(token) == tokenInfo.length) {
+ if (tokenStartsAt + lengthDiff == token.getStartIndex() && tokenCorrespondsToTokenInfo(token, tokenInfo)) {
assert tokenInfosCopy.equals(tokenInfos);
return new Region(regionOffset, token.getStartIndex() - regionOffset);
}
@@ -271,6 +270,10 @@ public class FastDamagerRepairer extends AbstractDamagerRepairer {
return new Region(regionOffset, regionLength);
}
+ private boolean tokenCorrespondsToTokenInfo(CommonToken token, TokenInfo tokenInfo) {
+ return tokenInfo.type != token.getType() || getTokenLength(token) != tokenInfo.length;
+ }
+
private int getTokenLength(CommonToken token) {
return token.getStopIndex() - token.getStartIndex() + 1;
}