Coverage Report - com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck
 
Classes in this File Line Coverage Branch Coverage Complexity
RegexpSinglelineCheck
100%
25/25
N/A
1
 
 1  
 ////////////////////////////////////////////////////////////////////////////////
 2  
 // checkstyle: Checks Java source code for adherence to a set of rules.
 3  
 // Copyright (C) 2001-2017 the original author or authors.
 4  
 //
 5  
 // This library is free software; you can redistribute it and/or
 6  
 // modify it under the terms of the GNU Lesser General Public
 7  
 // License as published by the Free Software Foundation; either
 8  
 // version 2.1 of the License, or (at your option) any later version.
 9  
 //
 10  
 // This library is distributed in the hope that it will be useful,
 11  
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 // Lesser General Public License for more details.
 14  
 //
 15  
 // You should have received a copy of the GNU Lesser General Public
 16  
 // License along with this library; if not, write to the Free Software
 17  
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  
 ////////////////////////////////////////////////////////////////////////////////
 19  
 
 20  
 package com.puppycrawl.tools.checkstyle.checks.regexp;
 21  
 
 22  
 import java.io.File;
 23  
 
 24  
 import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
 25  
 import com.puppycrawl.tools.checkstyle.api.FileText;
 26  
 
 27  
 /**
 28  
  * Implementation of a check that looks for a single line in any file type.
 29  
  * @author Oliver Burn
 30  
  */
 31  15
 public class RegexpSinglelineCheck extends AbstractFileSetCheck {
 32  
 
 33  
     /** The format of the regular expression to match. */
 34  15
     private String format = "$.";
 35  
     /** The message to report for a match. */
 36  
     private String message;
 37  
     /** The minimum number of matches required per file. */
 38  
     private int minimum;
 39  
     /** The maximum number of matches required per file. */
 40  
     private int maximum;
 41  
     /** Whether to ignore case when matching. */
 42  
     private boolean ignoreCase;
 43  
 
 44  
     /** The detector to use. */
 45  
     private SinglelineDetector detector;
 46  
 
 47  
     @Override
 48  
     public void beginProcessing(String charset) {
 49  13
         final DetectorOptions options = DetectorOptions.newBuilder()
 50  13
             .reporter(this)
 51  13
             .compileFlags(0)
 52  13
             .format(format)
 53  13
             .message(message)
 54  13
             .minimum(minimum)
 55  13
             .maximum(maximum)
 56  13
             .ignoreCase(ignoreCase)
 57  13
             .build();
 58  13
         detector = new SinglelineDetector(options);
 59  13
     }
 60  
 
 61  
     @Override
 62  
     protected void processFiltered(File file, FileText fileText) {
 63  13
         detector.processLines(fileText);
 64  13
     }
 65  
 
 66  
     /**
 67  
      * Set the format of the regular expression to match.
 68  
      * @param format the format of the regular expression to match.
 69  
      */
 70  
     public void setFormat(String format) {
 71  13
         this.format = format;
 72  13
     }
 73  
 
 74  
     /**
 75  
      * Set the message to report for a match.
 76  
      * @param message the message to report for a match.
 77  
      */
 78  
     public void setMessage(String message) {
 79  2
         this.message = message;
 80  2
     }
 81  
 
 82  
     /**
 83  
      * Set the minimum number of matches required per file.
 84  
      * @param minimum the minimum number of matches required per file.
 85  
      */
 86  
     public void setMinimum(int minimum) {
 87  3
         this.minimum = minimum;
 88  3
     }
 89  
 
 90  
     /**
 91  
      * Set the maximum number of matches required per file.
 92  
      * @param maximum the maximum number of matches required per file.
 93  
      */
 94  
     public void setMaximum(int maximum) {
 95  3
         this.maximum = maximum;
 96  3
     }
 97  
 
 98  
     /**
 99  
      * Set whether to ignore case when matching.
 100  
      * @param ignoreCase whether to ignore case when matching.
 101  
      */
 102  
     public void setIgnoreCase(boolean ignoreCase) {
 103  2
         this.ignoreCase = ignoreCase;
 104  2
     }
 105  
 }