groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Trivial refactoring: simplify the logic of handling tokens to render
Date Tue, 16 Oct 2018 16:07:57 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 1191a5002 -> 1277ab967


Trivial refactoring: simplify the logic of handling tokens to render


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/1277ab96
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/1277ab96
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/1277ab96

Branch: refs/heads/master
Commit: 1277ab9679dfbc0c3bd08670b174226d7b021792
Parents: 1191a50
Author: Daniel Sun <sunlan@apache.org>
Authored: Wed Oct 17 00:07:51 2018 +0800
Committer: Daniel Sun <sunlan@apache.org>
Committed: Wed Oct 17 00:07:51 2018 +0800

----------------------------------------------------------------------
 .../main/groovy/groovy/ui/text/SmartDocumentFilter.java | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/1277ab96/subprojects/groovy-console/src/main/groovy/groovy/ui/text/SmartDocumentFilter.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/ui/text/SmartDocumentFilter.java
b/subprojects/groovy-console/src/main/groovy/groovy/ui/text/SmartDocumentFilter.java
index 1a5dd58..2425cb7 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/ui/text/SmartDocumentFilter.java
+++ b/subprojects/groovy-console/src/main/groovy/groovy/ui/text/SmartDocumentFilter.java
@@ -18,7 +18,6 @@
  */
 package groovy.ui.text;
 
-import groovy.lang.Tuple2;
 import org.antlr.v4.runtime.CharStream;
 import org.antlr.v4.runtime.CharStreams;
 import org.antlr.v4.runtime.CommonTokenStream;
@@ -190,10 +189,9 @@ public class SmartDocumentFilter extends DocumentFilter {
         }
 
         List<Token> tokenList = tokenStream.getTokens();
-        Tuple2<Integer, Integer> indexTuple = findTokensToRender(tokenList, latestTokenList);
+        List<Token> tokenListToRender = findTokensToRender(tokenList);
 
-        for (int i = indexTuple.getFirst(), n = indexTuple.getSecond(); i < n; i++) {
-            Token token = tokenList.get(i);
+        for (Token token : tokenListToRender) {
             int tokenType = token.getType();
 
 //                if (token instanceof CommonToken) {
@@ -225,12 +223,12 @@ public class SmartDocumentFilter extends DocumentFilter {
         this.latestTokenList = tokenList;
     }
 
-    private static Tuple2<Integer, Integer> findTokensToRender(List<Token> tokenList,
List<Token> latestTokenList) {
+    private List<Token> findTokensToRender(List<Token> tokenList) {
         int tokenListSize = tokenList.size();
         int latestTokenListSize = latestTokenList.size();
 
         if (0 == tokenListSize || 0 == latestTokenListSize) {
-            return new Tuple2<>(0, tokenListSize);
+            return tokenList;
         }
 
         int startTokenIndex = 0;
@@ -274,7 +272,7 @@ public class SmartDocumentFilter extends DocumentFilter {
             break;
         }
 
-        return new Tuple2<>(startTokenIndex, stopTokenIndex);
+        return tokenList.subList(startTokenIndex, stopTokenIndex);
     }
 
     private Style findStyleByTokenType(int tokenType) {


Mime
View raw message