1 19 20 package org.netbeans.lib.lexer.inc; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import org.netbeans.api.lexer.LanguagePath; 25 import org.netbeans.api.lexer.TokenId; 26 import org.netbeans.lib.lexer.LAState; 27 import org.netbeans.lib.lexer.TokenList; 28 import org.netbeans.lib.lexer.token.AbstractToken; 29 30 40 41 public final class TokenListChange<T extends TokenId> { 42 43 private final TokenChangeInfo<T> tokenChangeInfo; 44 45 private List <AbstractToken<T>> addedTokens; 46 47 private LAState laState; 48 49 private int offsetGapIndex; 50 51 private int removedEndOffset; 52 53 private int addedEndOffset; 54 55 public TokenListChange(TokenList<T> tokenList) { 56 tokenChangeInfo = new TokenChangeInfo<T>(tokenList); 57 } 58 59 public TokenChangeInfo<T> tokenChangeInfo() { 60 return tokenChangeInfo; 61 } 62 63 public LanguagePath languagePath() { 64 return tokenChangeInfo.currentTokenList().languagePath(); 65 } 66 67 public int index() { 68 return tokenChangeInfo.index(); 69 } 70 71 public void setIndex(int tokenIndex) { 72 tokenChangeInfo.setIndex(tokenIndex); 73 } 74 75 public int offset() { 76 return tokenChangeInfo.offset(); 77 } 78 79 public void setOffset(int offset) { 80 tokenChangeInfo.setOffset(offset); 81 } 82 83 public int offsetGapIndex() { 84 return offsetGapIndex; 85 } 86 87 public void setOffsetGapIndex(int offsetGapIndex) { 88 this.offsetGapIndex = offsetGapIndex; 89 } 90 91 public void addToken(AbstractToken<T> token, int lookahead, Object state) { 92 if (addedTokens == null) { 93 addedTokens = new ArrayList <AbstractToken<T>>(2); 94 laState = LAState.empty(); 95 } 96 addedTokens.add(token); 97 laState = laState.add(lookahead, state); 98 } 99 100 public List <AbstractToken<T>> addedTokens() { 101 return addedTokens; 102 } 103 104 public void syncAddedTokenCount() { 105 tokenChangeInfo.setAddedTokenCount(addedTokens.size()); 106 } 107 108 public void setRemovedTokens(Object [] removedTokensOrBranches) { 109 tokenChangeInfo.setRemovedTokenList(new RemovedTokenList<T>( 110 languagePath(), removedTokensOrBranches)); 111 } 112 113 public int removedEndOffset() { 114 return removedEndOffset; 115 } 116 117 public void setRemovedEndOffset(int removedEndOffset) { 118 this.removedEndOffset = removedEndOffset; 119 } 120 121 public int addedEndOffset() { 122 return addedEndOffset; 123 } 124 125 public void setAddedEndOffset(int addedEndOffset) { 126 this.addedEndOffset = addedEndOffset; 127 } 128 129 public LAState laState() { 130 return laState; 131 } 132 133 } | Popular Tags |