|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RegexpHeaderChecker | Line # 33 | 97.9% |
0.9791667
|
14 | 28 | 14 | 14 | 0.5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ( 10 of 12) | |||
| Result | |||
|
0.7916667
|
com.puppycrawl.tools.checkstyle.checks.header.HeaderCheckTest.testRegexpHeaderMulti5
com.puppycrawl.tools.checkstyle.checks.header.HeaderCheckTest.testRegexpHeaderMulti5
|
1 PASS | |
|
0.7708333
|
com.puppycrawl.tools.checkstyle.checks.header.CrossLanguageRegexpHeaderCheckTest.testComplexHeaderConfigOnXml
com.puppycrawl.tools.checkstyle.checks.header.CrossLanguageRegexpHeaderCheckTest.testComplexHeaderConfigOnXml
|
1 PASS | |
|
0.7708333
|
com.puppycrawl.tools.checkstyle.checks.header.CrossLanguageRegexpHeaderCheckTest.testComplexHeaderConfigOnJava
com.puppycrawl.tools.checkstyle.checks.header.CrossLanguageRegexpHeaderCheckTest.testComplexHeaderConfigOnJava
|
1 PASS | |
|
0.75
|
com.puppycrawl.tools.checkstyle.checks.header.CrossLanguageRegexpHeaderCheckTest.testComplexHeaderConfigOnProperties
com.puppycrawl.tools.checkstyle.checks.header.CrossLanguageRegexpHeaderCheckTest.testComplexHeaderConfigOnProperties
|
1 PASS | |
|
0.7083333
|
com.puppycrawl.tools.checkstyle.checks.header.HeaderCheckTest.testRegexpHeaderMulti1
com.puppycrawl.tools.checkstyle.checks.header.HeaderCheckTest.testRegexpHeaderMulti1
|
1 PASS | |
|
0.7083333
|
com.puppycrawl.tools.checkstyle.checks.header.HeaderCheckTest.testRegexpHeaderMulti3
com.puppycrawl.tools.checkstyle.checks.header.HeaderCheckTest.testRegexpHeaderMulti3
|
1 PASS | |
|
0.7083333
|
com.puppycrawl.tools.checkstyle.checks.header.HeaderCheckTest.testRegexpHeaderMulti2
com.puppycrawl.tools.checkstyle.checks.header.HeaderCheckTest.testRegexpHeaderMulti2
|
1 PASS | |
|
0.7083333
|
com.puppycrawl.tools.checkstyle.checks.header.HeaderCheckTest.testRegexpHeaderMulti4
com.puppycrawl.tools.checkstyle.checks.header.HeaderCheckTest.testRegexpHeaderMulti4
|
1 PASS | |
|
0.6875
|
com.puppycrawl.tools.checkstyle.checks.header.HeaderCheckTest.testRegexpHeaderSmallHeader
com.puppycrawl.tools.checkstyle.checks.header.HeaderCheckTest.testRegexpHeaderSmallHeader
|
1 PASS | |
|
0.6666667
|
com.puppycrawl.tools.checkstyle.checks.header.HeaderCheckTest.testRegexpHeader
com.puppycrawl.tools.checkstyle.checks.header.HeaderCheckTest.testRegexpHeader
|
1 PASS | |
| 2 tests are not displayed. This report was configured to show the top 10 tests that covered this file. | |||
| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
| 3 | // Copyright (C) 2001-2005 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 | ||
| 20 | package com.puppycrawl.tools.checkstyle.checks.header; | |
| 21 | ||
| 22 | import java.util.Arrays; | |
| 23 | import java.util.regex.Pattern; | |
| 24 | ||
| 25 | /** | |
| 26 | * Isolates the check funtionality in RegexpHeaderCheck in an external class. | |
| 27 | * This makes it easier to use the funtionality both in a Java | |
| 28 | * {@link com.puppycrawl.tools.checkstyle.api.Check} and in | |
| 29 | * a {@link com.puppycrawl.tools.checkstyle.api.FileSetCheck}. | |
| 30 | * | |
| 31 | * @author lk | |
| 32 | */ | |
| 33 | class RegexpHeaderChecker | |
| 34 | { | |
| 35 | /** the lines of the header file. */ | |
| 36 | private final String[] mHeaderLines; | |
| 37 | ||
| 38 | /** the compiled regular expressions */ | |
| 39 | private Pattern[] mHeaderRegexps; | |
| 40 | ||
| 41 | /** the header lines to repeat (0 or more) in the check, sorted. */ | |
| 42 | private int[] mMultiLines; | |
| 43 | ||
| 44 | /** A monitor for the violations that are detected. */ | |
| 45 | private final HeaderViolationMonitor mViolationObserver; | |
| 46 | ||
| 47 | /** | |
| 48 | * Creates a new instance. | |
| 49 | * | |
| 50 | * @param aRegexpHeaderInfo check parameters | |
| 51 | * @param aViolationObserver error reporting strategy object | |
| 52 | */ | |
| 53 | 12 |
RegexpHeaderChecker( |
| 54 | RegexpHeaderInfo aRegexpHeaderInfo, | |
| 55 | HeaderViolationMonitor aViolationObserver) | |
| 56 | { | |
| 57 | 12 | mHeaderLines = aRegexpHeaderInfo.getHeaderLines(); |
| 58 | 12 | mHeaderRegexps = aRegexpHeaderInfo.geHeaderRegexps(); |
| 59 | 12 | mMultiLines = aRegexpHeaderInfo.getMultLines(); |
| 60 | 12 | mViolationObserver = aViolationObserver; |
| 61 | } | |
| 62 | ||
| 63 | /** | |
| 64 | * Checks the lines of an individual file against the | |
| 65 | * {@link #getHeaderLines() header lines}. | |
| 66 | * | |
| 67 | * @param aLines the lines of an individual file | |
| 68 | */ | |
| 69 | 21 |
void checkLines(final String[] aLines) |
| 70 | { | |
| 71 | 21 | final int headerSize = mHeaderLines.length; |
| 72 | 21 | final int fileSize = aLines.length; |
| 73 | ||
| 74 | 21 | if (headerSize - mMultiLines.length > fileSize) { |
| 75 | 1 | mViolationObserver.reportHeaderMissing(); |
| 76 | } | |
| 77 | else { | |
| 78 | 20 | int headerLineNo = 0; |
| 79 | 20 | int i; |
| 80 | 103 | for (i = 0; (headerLineNo < headerSize) && (i < fileSize); i++) { |
| 81 | 87 | final String line = aLines[i]; |
| 82 | 87 | boolean isMatch = isMatch(line, headerLineNo); |
| 83 | 110 | while (!isMatch && isMultiLine(headerLineNo)) { |
| 84 | 23 | headerLineNo++; |
| 85 | 23 | isMatch = (headerLineNo == headerSize) |
| 86 | || isMatch(line, headerLineNo); | |
| 87 | } | |
| 88 | 87 | if (!isMatch) { |
| 89 | 4 | mViolationObserver.reportHeaderMismatch( |
| 90 | i + 1, mHeaderLines[headerLineNo]); | |
| 91 | 4 | break; // stop checking |
| 92 | } | |
| 93 | 83 | if (!isMultiLine(headerLineNo)) { |
| 94 | 64 | headerLineNo++; |
| 95 | } | |
| 96 | } | |
| 97 | 20 | if (i == fileSize) { |
| 98 | // if file finished, but we have at least one non-multi-line | |
| 99 | // header isn't completed | |
| 100 | 2 | for (; headerLineNo < headerSize; headerLineNo++) { |
| 101 | 2 | if (!isMultiLine(headerLineNo)) { |
| 102 | 1 | mViolationObserver.reportHeaderMissing(); |
| 103 | 1 | break; |
| 104 | } | |
| 105 | } | |
| 106 | } | |
| 107 | } | |
| 108 | } | |
| 109 | ||
| 110 | /** | |
| 111 | * Checks if a code line matches the required header line. | |
| 112 | * @param aLine the code line | |
| 113 | * @param aHeaderLineNo the header line number. | |
| 114 | * @return true if and only if the line matches the required header line. | |
| 115 | */ | |
| 116 | 108 |
private boolean isMatch(String aLine, int aHeaderLineNo) |
| 117 | { | |
| 118 | 108 | return mHeaderRegexps[aHeaderLineNo].matcher(aLine).find(); |
| 119 | } | |
| 120 | ||
| 121 | /** | |
| 122 | * @param aLineNo a line number | |
| 123 | * @return if <code>aLineNo</code> is one of the repeat header lines. | |
| 124 | */ | |
| 125 | 112 |
private boolean isMultiLine(int aLineNo) |
| 126 | { | |
| 127 | 112 | return (Arrays.binarySearch(mMultiLines, aLineNo + 1) >= 0); |
| 128 | } | |
| 129 | ||
| 130 | ||
| 131 | } | |
|
|||||||||||||