View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.cpd;
5   
6   import java.util.ArrayList;
7   import java.util.Iterator;
8   import java.util.List;
9   
10  public class Tokens {
11  
12      private List<TokenEntry> tokens = new ArrayList<>();
13  
14      public void add(TokenEntry tokenEntry) {
15          this.tokens.add(tokenEntry);
16      }
17  
18      public Iterator<TokenEntry> iterator() {
19          return tokens.iterator();
20      }
21  
22      private TokenEntry get(int index) {
23          return tokens.get(index);
24      }
25  
26      public int size() {
27          return tokens.size();
28      }
29  
30      public int getLineCount(TokenEntry mark, Match match) {
31          TokenEntry endTok = get(mark.getIndex() + match.getTokenCount() - 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  }