summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Christiaens2010-09-28 07:13:08 (EDT)
committer Knut Wannheden2011-04-28 05:18:04 (EDT)
commit654a171df2cfef18e6042f7d37158970f811d304 (patch)
treed6156f5294d0113717f946e6f82e6b2c66a40cf8
parentbf26dfb6085475f62b9eed5912fa128335c0d744 (diff)
downloadorg.eclipse.xtext-654a171df2cfef18e6042f7d37158970f811d304.zip
org.eclipse.xtext-654a171df2cfef18e6042f7d37158970f811d304.tar.gz
org.eclipse.xtext-654a171df2cfef18e6042f7d37158970f811d304.tar.bz2
Started moving the first loop to iterators.
-rw-r--r--plugins/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/FastDamagerRepairer.java28
1 files changed, 20 insertions, 8 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 18917b3..8d20108 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
@@ -161,24 +161,32 @@ public class FastDamagerRepairer extends AbstractDamagerRepairer {
TokenSource source = createLexer(e.fDocument.get());
CommonToken token = (CommonToken) source.nextToken();
+ ListIterator<TokenInfo> tokenInfosIt = tokenInfos.listIterator();
+ TokenInfo tokenInfo = tokenInfosIt.next();
+
// find start idx
while (true) {
if (token == Token.EOF_TOKEN) {
tokenInfos.subList(tokenInfoIdx, tokenInfos.size()).clear();
break;
}
- if (tokenInfoIdx >= tokenInfos.size())
+
+ if (!tokenInfosIt.hasNext())
break;
- TokenInfo tokenInfo = tokenInfos.get(tokenInfoIdx);
- if (tokenInfo.type != token.getType()
- || token.getStopIndex() - token.getStartIndex() + 1 != tokenInfo.length)
+
+ tokenInfo = tokenInfosIt.next();
+
+ if (tokenInfo.type != token.getType() || getTokenLength(token) != tokenInfo.length)
break;
+
if (tokenStartsAt + tokenInfo.length > e.fOffset)
break;
- tokenStartsAt += tokenInfo.length;
+
tokenInfoIdx++;
+ tokenStartsAt += tokenInfo.length;
token = (CommonToken) source.nextToken();
}
+
regionLength -= tokenStartsAt;
regionOffset = tokenStartsAt;
@@ -201,14 +209,14 @@ public class FastDamagerRepairer extends AbstractDamagerRepairer {
if (tokenInfoIdx >= tokenInfos.size())
break;
- TokenInfo tokenInfo = tokenInfos.get(tokenInfoIdx);
+ tokenInfo = tokenInfos.get(tokenInfoIdx);
TokenInfo tokenInfoCopy = tokenInfosCopyIt.next();
assert tokenInfo == tokenInfoCopy;
if (token.getStartIndex() >= e.fOffset + e.fText.length()) {
if (tokenStartsAt + lengthDiff == token.getStartIndex() && tokenInfo.type == token.getType()
- && token.getStopIndex() - token.getStartIndex() + 1 == tokenInfo.length) {
+ && getTokenLength(token) == tokenInfo.length) {
assert tokenInfosCopy.equals(tokenInfos);
return new Region(regionOffset, token.getStartIndex() - regionOffset);
}
@@ -258,11 +266,15 @@ public class FastDamagerRepairer extends AbstractDamagerRepairer {
token = (CommonToken) source.nextToken();
}
}
-
+
assert tokenInfosCopy.equals(tokenInfos);
return new Region(regionOffset, regionLength);
}
+ private int getTokenLength(CommonToken token) {
+ return token.getStopIndex() - token.getStartIndex() + 1;
+ }
+
protected Lexer createLexer(String string) {
Lexer l = lexer.get();
l.setCharStream(new ANTLRStringStream(string));