Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RegexpSinglelineJavaCheck |
|
| 1.1111111111111112;1.111 |
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 com.puppycrawl.tools.checkstyle.api.Check; | |
22 | import com.puppycrawl.tools.checkstyle.api.DetailAST; | |
23 | import java.util.Arrays; | |
24 | ||
25 | /** | |
26 | * Implementation of a check that looks for a single line in Java files. | |
27 | * Supports ignoring comments for matches. | |
28 | * @author Oliver Burn | |
29 | */ | |
30 | 18 | public class RegexpSinglelineJavaCheck extends Check |
31 | { | |
32 | /** The detection options to use. */ | |
33 | 18 | private DetectorOptions mOptions = new DetectorOptions(0, this); |
34 | /** The detector to use. */ | |
35 | private SinglelineDetector mDetector; | |
36 | /** The suppressor to use. */ | |
37 | 18 | private final CommentSuppressor mSuppressor = new CommentSuppressor(); |
38 | ||
39 | @Override | |
40 | public int[] getDefaultTokens() | |
41 | { | |
42 | 18 | return new int[0]; |
43 | } | |
44 | ||
45 | @Override | |
46 | public void init() | |
47 | { | |
48 | 18 | super.init(); |
49 | 18 | mDetector = new SinglelineDetector(mOptions); |
50 | 18 | } |
51 | ||
52 | @Override | |
53 | public void beginTree(DetailAST aRootAST) | |
54 | { | |
55 | 18 | mSuppressor.setCurrentContents(getFileContents()); |
56 | 18 | mDetector.processLines(Arrays.asList(getLines())); |
57 | 18 | } |
58 | ||
59 | /** | |
60 | * Set the format of the regular expression to match. | |
61 | * @param aFormat the format of the regular expression to match. | |
62 | */ | |
63 | public void setFormat(String aFormat) | |
64 | { | |
65 | 18 | mOptions.setFormat(aFormat); |
66 | 18 | } |
67 | ||
68 | /** | |
69 | * Set the message to report for a match. | |
70 | * @param aMessage the message to report for a match. | |
71 | */ | |
72 | public void setMessage(String aMessage) | |
73 | { | |
74 | 1 | mOptions.setMessage(aMessage); |
75 | 1 | } |
76 | ||
77 | /** | |
78 | * Set the minimum number of matches required per file. | |
79 | * @param aMinimum the minimum number of matches required per file. | |
80 | */ | |
81 | public void setMinimum(int aMinimum) | |
82 | { | |
83 | 3 | mOptions.setMinimum(aMinimum); |
84 | 3 | } |
85 | ||
86 | /** | |
87 | * Set the maximum number of matches required per file. | |
88 | * @param aMaximum the maximum number of matches required per file. | |
89 | */ | |
90 | public void setMaximum(int aMaximum) | |
91 | { | |
92 | 3 | mOptions.setMaximum(aMaximum); |
93 | 3 | } |
94 | ||
95 | /** | |
96 | * Set whether to ignore case when matching. | |
97 | * @param aIgnore whether to ignore case when matching. | |
98 | */ | |
99 | public void setIgnoreCase(boolean aIgnore) | |
100 | { | |
101 | 2 | mOptions.setIgnoreCase(aIgnore); |
102 | 2 | } |
103 | ||
104 | /** | |
105 | * Set whether to ignore comments when matching. | |
106 | * @param aIgnore whether to ignore comments when matching. | |
107 | */ | |
108 | public void setIgnoreComments(boolean aIgnore) | |
109 | { | |
110 | 11 | if (aIgnore) { |
111 | 9 | mOptions.setSuppressor(mSuppressor); |
112 | } | |
113 | else { | |
114 | 2 | mOptions.setSuppressor(NeverSuppress.INSTANCE); |
115 | } | |
116 | 11 | } |
117 | } |