View Javadoc

    1   package net.sourceforge.pmd;
    2
    3   import java.io.BufferedReader;
    4   import java.io.IOException;
    5   import java.io.Reader;
    6   import java.io.StringReader;
    7   import java.util.HashSet;
    8   import java.util.Set;
    9
    10  public class ExcludeLines {
    11
    12      public static final String EXCLUDE_MARKER = "NOPMD";
    13
    14      private Set lines = new HashSet();
    15      private String copy;
    16
    17      public ExcludeLines(Reader r, String marker) throws IOException {
    18          BufferedReader br = new BufferedReader(r);
    19          StringBuffer copyBuffer = new StringBuffer();
    20          String tmp;
    21          int counter = 1;
    22          while ((tmp = br.readLine()) != null) {
    23              copyBuffer.append(tmp + PMD.EOL);
    24              if (tmp.indexOf(marker) != -1) {
    25                  lines.add(new Integer(counter));
    26              }
    27              counter++;
    28          }
    29          copy = copyBuffer.toString();
    30      }
    31
    32      public ExcludeLines(Reader r) throws IOException {
    33          this(r, EXCLUDE_MARKER);
    34      }
    35
    36      public Reader getCopyReader() {
    37          return new StringReader(copy);
    38      }
    39
    40      public Set getLinesToExclude() {
    41          return lines;
    42      }
    43  }