01: /**
02: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03: */package net.sourceforge.pmd.cpd;
04:
05: import java.util.ArrayList;
06: import java.util.Iterator;
07: import java.util.List;
08:
09: public class Tokens {
10:
11: private List<TokenEntry> tokens = new ArrayList<TokenEntry>();
12:
13: public void add(TokenEntry tokenEntry) {
14: this .tokens.add(tokenEntry);
15: }
16:
17: public Iterator<TokenEntry> iterator() {
18: return tokens.iterator();
19: }
20:
21: private TokenEntry get(int index) {
22: return tokens.get(index);
23: }
24:
25: public int size() {
26: return tokens.size();
27: }
28:
29: public int getLineCount(TokenEntry mark, Match match) {
30: TokenEntry endTok = get(mark.getIndex() + match.getTokenCount()
31: - 1);
32: if (endTok == TokenEntry.EOF) {
33: endTok = get(mark.getIndex() + match.getTokenCount() - 2);
34: }
35: return endTok.getBeginLine() - mark.getBeginLine() + 1;
36: }
37:
38: public List<TokenEntry> getTokens() {
39: return tokens;
40: }
41:
42: }
|