Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RegexpMultilineCheck |
|
| 1.0;1 |
1 | //////////////////////////////////////////////////////////////////////////////// | |
2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
3 | // Copyright (C) 2001-2014 Oliver Burn | |
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 | package com.puppycrawl.tools.checkstyle.checks.regexp; | |
20 | ||
21 | import java.util.regex.Pattern; | |
22 | ||
23 | import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck; | |
24 | import com.puppycrawl.tools.checkstyle.api.FileText; | |
25 | import java.io.File; | |
26 | import java.util.List; | |
27 | ||
28 | /** | |
29 | * Implementation of a check that looks that matches across multiple lines in | |
30 | * any file type. | |
31 | * @author Oliver Burn | |
32 | */ | |
33 | 5 | public class RegexpMultilineCheck extends AbstractFileSetCheck |
34 | { | |
35 | /** The detection options to use. */ | |
36 | 5 | private DetectorOptions mOptions = new DetectorOptions(Pattern.MULTILINE, |
37 | this); | |
38 | /** The detector to use. */ | |
39 | private MultilineDetector mDetector; | |
40 | ||
41 | @Override | |
42 | public void beginProcessing(String aCharset) | |
43 | { | |
44 | 5 | super.beginProcessing(aCharset); |
45 | 5 | mDetector = new MultilineDetector(mOptions); |
46 | 5 | } |
47 | ||
48 | @Override | |
49 | protected void processFiltered(File aFile, List<String> aLines) | |
50 | { | |
51 | 5 | mDetector.processLines(FileText.fromLines(aFile, aLines)); |
52 | 5 | } |
53 | ||
54 | /** | |
55 | * Set the format of the regular expression to match. | |
56 | * @param aFormat the format of the regular expression to match. | |
57 | */ | |
58 | public void setFormat(String aFormat) | |
59 | { | |
60 | 5 | mOptions.setFormat(aFormat); |
61 | 5 | } |
62 | ||
63 | /** | |
64 | * Set the message to report for a match. | |
65 | * @param aMessage the message to report for a match. | |
66 | */ | |
67 | public void setMessage(String aMessage) | |
68 | { | |
69 | 1 | mOptions.setMessage(aMessage); |
70 | 1 | } |
71 | ||
72 | /** | |
73 | * Set the minimum number of matches required per file. | |
74 | * @param aMinimum the minimum number of matches required per file. | |
75 | */ | |
76 | public void setMinimum(int aMinimum) | |
77 | { | |
78 | 0 | mOptions.setMinimum(aMinimum); |
79 | 0 | } |
80 | ||
81 | /** | |
82 | * Set the maximum number of matches required per file. | |
83 | * @param aMaximum the maximum number of matches required per file. | |
84 | */ | |
85 | public void setMaximum(int aMaximum) | |
86 | { | |
87 | 0 | mOptions.setMaximum(aMaximum); |
88 | 0 | } |
89 | ||
90 | /** | |
91 | * Set whether to ignore case when matching. | |
92 | * @param aIgnore whether to ignore case when matching. | |
93 | */ | |
94 | public void setIgnoreCase(boolean aIgnore) | |
95 | { | |
96 | 2 | mOptions.setIgnoreCase(aIgnore); |
97 | 2 | } |
98 | } |