| 1 | /* |
|---|
| 2 | * $Id$ |
|---|
| 3 | * |
|---|
| 4 | * Copyright 2006, The jCoderZ.org Project. All rights reserved. |
|---|
| 5 | * |
|---|
| 6 | * Redistribution and use in source and binary forms, with or without |
|---|
| 7 | * modification, are permitted provided that the following conditions are |
|---|
| 8 | * met: |
|---|
| 9 | * |
|---|
| 10 | * * Redistributions of source code must retain the above copyright |
|---|
| 11 | * notice, this list of conditions and the following disclaimer. |
|---|
| 12 | * * Redistributions in binary form must reproduce the above |
|---|
| 13 | * copyright notice, this list of conditions and the following |
|---|
| 14 | * disclaimer in the documentation and/or other materials |
|---|
| 15 | * provided with the distribution. |
|---|
| 16 | * * Neither the name of the jCoderZ.org Project nor the names of |
|---|
| 17 | * its contributors may be used to endorse or promote products |
|---|
| 18 | * derived from this software without specific prior written |
|---|
| 19 | * permission. |
|---|
| 20 | * |
|---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND |
|---|
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|---|
| 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS |
|---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|---|
| 28 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|---|
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|---|
| 30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|---|
| 31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 32 | */ |
|---|
| 33 | package org.jcoderz.phoenix.report; |
|---|
| 34 | |
|---|
| 35 | import java.util.ArrayList; |
|---|
| 36 | import java.util.List; |
|---|
| 37 | |
|---|
| 38 | import javax.xml.bind.JAXBContext; |
|---|
| 39 | import javax.xml.bind.Unmarshaller; |
|---|
| 40 | |
|---|
| 41 | import org.jcoderz.phoenix.checkstyle.message.jaxb.CheckstyleMessages; |
|---|
| 42 | import org.jcoderz.phoenix.checkstyle.message.jaxb.FindingData; |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * Enumeration type for checkstyle findings. |
|---|
| 46 | * It also holds a method to get the finding type from the message |
|---|
| 47 | * received. This is needed due to the fact that there is no reliable |
|---|
| 48 | * enumeration of checkstyle findings delivered with checkstyle. |
|---|
| 49 | * <p>New patterns might be needed with each checkstyle update.</p> |
|---|
| 50 | * <p>Once assigned the symbols should not be changed without a urgent |
|---|
| 51 | * need. The symbols are used to generate wiki page link.</p> |
|---|
| 52 | * |
|---|
| 53 | * @author Andreas Mandel |
|---|
| 54 | */ |
|---|
| 55 | public final class CheckstyleFindingType |
|---|
| 56 | extends FindingType |
|---|
| 57 | { |
|---|
| 58 | private static final List<CheckstyleFindingType> CHECKSTYLE_FINDING_TYPES; |
|---|
| 59 | |
|---|
| 60 | private static final String CHECKSTYLE_MESSAGE_JAXB_CONTEXT |
|---|
| 61 | = "org.jcoderz.phoenix.checkstyle.message.jaxb"; |
|---|
| 62 | |
|---|
| 63 | private static final String CHECKSTYLE_MESSAGE_FILE |
|---|
| 64 | = "org/jcoderz/phoenix/checkstyle/checkstyle-messages.xml"; |
|---|
| 65 | |
|---|
| 66 | private final String mMessagePattern; |
|---|
| 67 | private final Severity mSeverity; |
|---|
| 68 | |
|---|
| 69 | static |
|---|
| 70 | { |
|---|
| 71 | CHECKSTYLE_FINDING_TYPES = new ArrayList<CheckstyleFindingType>(); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | /** |
|---|
| 75 | * Checkstyle finding type that relates to: |
|---|
| 76 | * <i>Interfaces should describe a type and hence have methods</i>. |
|---|
| 77 | */ |
|---|
| 78 | public static final CheckstyleFindingType CS_INTERFACE_TYPE = |
|---|
| 79 | new CheckstyleFindingType("CS_INTERFACE_TYPE", "Interface type.", |
|---|
| 80 | "Interfaces should describe a type and hence have methods.", |
|---|
| 81 | "interfaces should describe a type and hence have methods.", |
|---|
| 82 | Severity.DESIGN); |
|---|
| 83 | |
|---|
| 84 | /** |
|---|
| 85 | * Checkstyle finding type that relates to: |
|---|
| 86 | * <i>Line is longer than the allowed number of characters</i>. |
|---|
| 87 | */ |
|---|
| 88 | public static final CheckstyleFindingType CS_LINE_TO_LONG = |
|---|
| 89 | new CheckstyleFindingType("CS_LINE_TO_LONG", "Line too long.", |
|---|
| 90 | "Line is longer than the allowed number of characters.", |
|---|
| 91 | "Line is longer than [0-9]+ characters."); |
|---|
| 92 | |
|---|
| 93 | /** |
|---|
| 94 | * Checkstyle finding type that relates to: |
|---|
| 95 | * <i>Line does not match expected header line</i>. |
|---|
| 96 | */ |
|---|
| 97 | public static final CheckstyleFindingType CS_HEADER_MISMATCH = |
|---|
| 98 | new CheckstyleFindingType("CS_HEADER_MISMATCH", "Header does not match.", |
|---|
| 99 | "Line does not match expected header line. " |
|---|
| 100 | + "Please use the global header.", |
|---|
| 101 | "Line does not match expected header line of .*\\."); |
|---|
| 102 | |
|---|
| 103 | /** |
|---|
| 104 | * Checkstyle finding type that relates to: |
|---|
| 105 | * <i>Missing a Javadoc comment</i>. |
|---|
| 106 | */ |
|---|
| 107 | public static final CheckstyleFindingType CS_JAVADOC_MISSING = |
|---|
| 108 | new CheckstyleFindingType("CS_JAVADOC_MISSING", |
|---|
| 109 | "Missing a Javadoc comment.", |
|---|
| 110 | "Missing a Javadoc comment.", |
|---|
| 111 | "Missing a Javadoc comment\\."); |
|---|
| 112 | |
|---|
| 113 | /** |
|---|
| 114 | * Checkstyle finding type that relates to: |
|---|
| 115 | * <i>Missing a Javadoc comment</i>. |
|---|
| 116 | */ |
|---|
| 117 | public static final CheckstyleFindingType CS_JAVADOC_EMPTY_DESC = |
|---|
| 118 | new CheckstyleFindingType("CS_JAVADOC_EMPTY_DESC", |
|---|
| 119 | "Javadoc has empty description section.", |
|---|
| 120 | "Javadoc has empty description section.", |
|---|
| 121 | "Javadoc has empty description section\\."); |
|---|
| 122 | |
|---|
| 123 | /** |
|---|
| 124 | * Checkstyle finding type that relates to: |
|---|
| 125 | * <i>Unused Javadoc tag</i>. |
|---|
| 126 | */ |
|---|
| 127 | public static final CheckstyleFindingType CS_JAVADOC_UNUSED_TAG = |
|---|
| 128 | new CheckstyleFindingType("CS_JAVADOC_UNUSED_TAG", |
|---|
| 129 | "Unused Javadoc tag.", |
|---|
| 130 | "Unused Javadoc tag.", |
|---|
| 131 | "Unused .* tag for '.*'\\."); |
|---|
| 132 | |
|---|
| 133 | /** |
|---|
| 134 | * Checkstyle finding type that relates to: |
|---|
| 135 | * <i>Expected an @return tag</i>. |
|---|
| 136 | */ |
|---|
| 137 | public static final CheckstyleFindingType CS_JAVADOC_RETURN_EXPECTED = |
|---|
| 138 | new CheckstyleFindingType("CS_JAVADOC_RETURN_EXPECTED", |
|---|
| 139 | "Expected an @return tag.", |
|---|
| 140 | "Expected an @return tag.", |
|---|
| 141 | "Expected an @return tag."); |
|---|
| 142 | |
|---|
| 143 | /** |
|---|
| 144 | * Checkstyle finding type that relates to: |
|---|
| 145 | * <i>Missing Javadoc tag</i>. |
|---|
| 146 | */ |
|---|
| 147 | public static final CheckstyleFindingType CS_JAVADOC_EXPECTED_TAG = |
|---|
| 148 | new CheckstyleFindingType("CS_JAVADOC_EXPECTED_TAG", |
|---|
| 149 | "Missing Javadoc tag.", |
|---|
| 150 | "Missing Javadoc tag.", |
|---|
| 151 | "Expected .* tag for '.*'\\."); |
|---|
| 152 | |
|---|
| 153 | /** |
|---|
| 154 | * Checkstyle finding type that relates to: |
|---|
| 155 | * <i>Unable to get class information for something</i>. |
|---|
| 156 | */ |
|---|
| 157 | public static final CheckstyleFindingType CS_JAVADOC_CLASS_INFO = |
|---|
| 158 | new CheckstyleFindingType("CS_JAVADOC_CLASS_INFO", |
|---|
| 159 | "Unable to get class information for something.", |
|---|
| 160 | "Unable to get class information for something.", |
|---|
| 161 | "Unable to get class information for .* tag '.*'\\."); |
|---|
| 162 | |
|---|
| 163 | /** |
|---|
| 164 | * Checkstyle finding type that relates to: |
|---|
| 165 | * <i>Incomplete/Unclosed HTML tag</i>. |
|---|
| 166 | */ |
|---|
| 167 | public static final CheckstyleFindingType CS_JAVADOC_HTML_UNCLOSED = |
|---|
| 168 | new CheckstyleFindingType("CS_JAVADOC_HTML_UNCLOSED", |
|---|
| 169 | "Incomplete HTML tag.", |
|---|
| 170 | "Incomplete/Unclosed HTML tag.", |
|---|
| 171 | "Incomplete HTML tag found: .*"); |
|---|
| 172 | |
|---|
| 173 | /** |
|---|
| 174 | * Checkstyle finding type that relates to: |
|---|
| 175 | * <i>Name does not match given pattern</i>. |
|---|
| 176 | */ |
|---|
| 177 | public static final CheckstyleFindingType CS_INVALID_PATTERN = |
|---|
| 178 | new CheckstyleFindingType("CS_INVALID_PATTERN", |
|---|
| 179 | "Name does not match given pattern.", |
|---|
| 180 | "Name does not match given pattern.", |
|---|
| 181 | "Name '.*' must match pattern '.*'\\."); |
|---|
| 182 | |
|---|
| 183 | /** |
|---|
| 184 | * Checkstyle finding type that relates to: |
|---|
| 185 | * <i>After the method declaration there should be a ' '</i>. |
|---|
| 186 | */ |
|---|
| 187 | public static final CheckstyleFindingType CS_NO_WHITESPACE_AFTER_MSG_DECL = |
|---|
| 188 | new CheckstyleFindingType("CS_NO_WHITESPACE_AFTER_MSG_DECL", |
|---|
| 189 | "Missing whitespace.", |
|---|
| 190 | "After the method declaration there should be a ' '.", |
|---|
| 191 | "No whitespace \\( \\(\\) after method declaration\\."); |
|---|
| 192 | |
|---|
| 193 | /** |
|---|
| 194 | * Checkstyle finding type that relates to: |
|---|
| 195 | * <i>Comment matches to-do format</i>. |
|---|
| 196 | */ |
|---|
| 197 | public static final CheckstyleFindingType CS_TODO = |
|---|
| 198 | new CheckstyleFindingType("CS_TODO", |
|---|
| 199 | "Comment matches to-do format.", |
|---|
| 200 | "Comment matches to-do format.", |
|---|
| 201 | "Comment matches to-do format '.*'\\.", |
|---|
| 202 | Severity.INFO); |
|---|
| 203 | |
|---|
| 204 | /** |
|---|
| 205 | * Checkstyle finding type that relates to: |
|---|
| 206 | * <i>Dont use magics in the code</i>. |
|---|
| 207 | */ |
|---|
| 208 | public static final CheckstyleFindingType CS_MAGIC = |
|---|
| 209 | new CheckstyleFindingType("CS_MAGIC", |
|---|
| 210 | "Dont use magics in the code.", |
|---|
| 211 | "Magics make the code hard to maintain and understand. " |
|---|
| 212 | + " Define appropriate constant instead.", |
|---|
| 213 | "Dont use magic .* in the code\\."); |
|---|
| 214 | |
|---|
| 215 | /** |
|---|
| 216 | * Checkstyle finding type that relates to: |
|---|
| 217 | * <i>Whitespace not allowed</i>. |
|---|
| 218 | */ |
|---|
| 219 | public static final CheckstyleFindingType CS_WHITESPACE_AFTER = |
|---|
| 220 | new CheckstyleFindingType("CS_WHITESPACE_AFTER", |
|---|
| 221 | "Whitespace not allowed.", |
|---|
| 222 | "Whitespace not allowed.", |
|---|
| 223 | "'.*' is followed by whitespace\\."); |
|---|
| 224 | |
|---|
| 225 | /** |
|---|
| 226 | * Checkstyle finding type that relates to: |
|---|
| 227 | * <i>Whitespace expected</i>. |
|---|
| 228 | */ |
|---|
| 229 | public static final CheckstyleFindingType CS_NO_WHITESPACE_AFTER = |
|---|
| 230 | new CheckstyleFindingType("CS_NO_WHITESPACE_AFTER", |
|---|
| 231 | "Whitespace expected.", |
|---|
| 232 | "Whitespace expected.", |
|---|
| 233 | "'.*' is not followed by whitespace\\."); |
|---|
| 234 | |
|---|
| 235 | /** |
|---|
| 236 | * Checkstyle finding type that relates to: |
|---|
| 237 | * <i>Whitespace not allowed</i>. |
|---|
| 238 | */ |
|---|
| 239 | public static final CheckstyleFindingType CS_WHITESPACE_BEFORE = |
|---|
| 240 | new CheckstyleFindingType("CS_WHITESPACE_BEFORE", |
|---|
| 241 | "Whitespace not allowed.", |
|---|
| 242 | "Whitespace not allowed.", |
|---|
| 243 | "'.*' is preceeded with whitespace\\."); |
|---|
| 244 | |
|---|
| 245 | /** |
|---|
| 246 | * Checkstyle finding type that relates to: |
|---|
| 247 | * <i>Whitespace expected</i>. |
|---|
| 248 | */ |
|---|
| 249 | public static final CheckstyleFindingType CS_NO_WHITESPACE_BEFORE = |
|---|
| 250 | new CheckstyleFindingType("CS_NO_WHITESPACE_AFTER", |
|---|
| 251 | "Whitespace expected.", |
|---|
| 252 | "Whitespace expected.", |
|---|
| 253 | "'.*' is not preceeded with whitespace\\."); |
|---|
| 254 | |
|---|
| 255 | /** |
|---|
| 256 | * Checkstyle finding type that relates to: |
|---|
| 257 | * <i>A required javadoc tag is missing</i>. |
|---|
| 258 | */ |
|---|
| 259 | public static final CheckstyleFindingType CS_MISSING_TAG = |
|---|
| 260 | new CheckstyleFindingType("CS_MISSING_TAG", |
|---|
| 261 | "A required javadoc tag is missing.", |
|---|
| 262 | "A required javadoc tag is missing.", |
|---|
| 263 | "Type Javadoc comment is missing an .* tag\\."); |
|---|
| 264 | |
|---|
| 265 | /** |
|---|
| 266 | * Checkstyle finding type that relates to: |
|---|
| 267 | * <i>A field is hidden</i>. |
|---|
| 268 | */ |
|---|
| 269 | public static final CheckstyleFindingType CS_HIDDEN_FIELD = |
|---|
| 270 | new CheckstyleFindingType("CS_HIDDEN_FIELD", |
|---|
| 271 | "A field is hidden.", |
|---|
| 272 | "A field is hidden.", |
|---|
| 273 | "'.*' hides a field\\.", Severity.DESIGN); |
|---|
| 274 | |
|---|
| 275 | /** |
|---|
| 276 | * Checkstyle finding type that relates to: |
|---|
| 277 | * <i>Line contains a tab character</i>. |
|---|
| 278 | */ |
|---|
| 279 | public static final CheckstyleFindingType CS_CONTAINS_TAB = |
|---|
| 280 | new CheckstyleFindingType("CS_CONTAINS_TAB", |
|---|
| 281 | "Line contains a tab character.", |
|---|
| 282 | "Line contains a tab character. You should use spaces for " |
|---|
| 283 | + "indentation.", |
|---|
| 284 | "Line contains a tab character\\."); |
|---|
| 285 | |
|---|
| 286 | /** |
|---|
| 287 | * Checkstyle finding type that relates to: |
|---|
| 288 | * <i>File does not end with a newline</i>. |
|---|
| 289 | */ |
|---|
| 290 | public static final CheckstyleFindingType CS_NO_NEWLINE = |
|---|
| 291 | new CheckstyleFindingType("CS_NO_NEWLINE", |
|---|
| 292 | "File does not end with a newline.", |
|---|
| 293 | "File does not end with a newline.", |
|---|
| 294 | "File does not end with a newline\\."); |
|---|
| 295 | |
|---|
| 296 | /** |
|---|
| 297 | * Checkstyle finding type that relates to: |
|---|
| 298 | * <i>Method length exceeds the maximum allowed length</i>. |
|---|
| 299 | */ |
|---|
| 300 | public static final CheckstyleFindingType CS_MAX_LEN_METHOD = |
|---|
| 301 | new CheckstyleFindingType("CS_MAX_LEN_METHOD", |
|---|
| 302 | "Method length exceeds the maximum allowed length.", |
|---|
| 303 | "A Method should have a moderate length...", |
|---|
| 304 | "Method length is [\\.,0-9]+ lines \\(max allowed is [\\.,0-9]+\\)\\.", |
|---|
| 305 | Severity.DESIGN); |
|---|
| 306 | |
|---|
| 307 | /** |
|---|
| 308 | * Checkstyle finding type that relates to: |
|---|
| 309 | * <i>Length of anonymous inner class exceeds the maximum allowed length</i>. |
|---|
| 310 | */ |
|---|
| 311 | public static final CheckstyleFindingType CS_MAX_LEN_ANON_CLASS = |
|---|
| 312 | new CheckstyleFindingType("CS_MAX_LEN_ANON_CLASS", |
|---|
| 313 | "Length of anonymous inner class exceeds the maximum allowed length.", |
|---|
| 314 | "A anonymous inner class should have a moderate length...", |
|---|
| 315 | "Anonymous inner class length is [0-9]+ lines " |
|---|
| 316 | + "\\(max allowed is [0-9]+\\)\\.", |
|---|
| 317 | Severity.DESIGN); |
|---|
| 318 | |
|---|
| 319 | /** |
|---|
| 320 | * Checkstyle finding type that relates to: |
|---|
| 321 | * <i>Empty block detected</i>. |
|---|
| 322 | */ |
|---|
| 323 | public static final CheckstyleFindingType CS_EMPTY_BLOCK = |
|---|
| 324 | new CheckstyleFindingType("CS_EMPTY_BLOCK", |
|---|
| 325 | "Empty block detected.", |
|---|
| 326 | "If you think this is ok you must at least put a comment inside " |
|---|
| 327 | + "this block, describing why it is ok.", |
|---|
| 328 | "Empty .* block\\."); |
|---|
| 329 | |
|---|
| 330 | /** |
|---|
| 331 | * Checkstyle finding type that relates to: |
|---|
| 332 | * <i>Unused import</i>. |
|---|
| 333 | */ |
|---|
| 334 | public static final CheckstyleFindingType CS_IMPORT_UNUSED = |
|---|
| 335 | new CheckstyleFindingType("CS_IMPORT_UNUSED", |
|---|
| 336 | "Unused import.", |
|---|
| 337 | "Unused import.", |
|---|
| 338 | "Unused import - .*\\."); |
|---|
| 339 | |
|---|
| 340 | /** |
|---|
| 341 | * Checkstyle finding type that relates to: |
|---|
| 342 | * <i>Indentation violation</i>. |
|---|
| 343 | */ |
|---|
| 344 | public static final CheckstyleFindingType CS_SPECIAL_INDENT = |
|---|
| 345 | new CheckstyleFindingType("CS_SPECIAL_INDENT", |
|---|
| 346 | "Indentation violation.", |
|---|
| 347 | "Several keywords require a special indentation.", |
|---|
| 348 | "Expected indentation for '.*' is '.*' but was at '.*'\\."); |
|---|
| 349 | |
|---|
| 350 | /** |
|---|
| 351 | * Checkstyle finding type that relates to: |
|---|
| 352 | * <i>Deeply nested tries</i>. |
|---|
| 353 | */ |
|---|
| 354 | public static final CheckstyleFindingType CS_NESTED_TRY_DEPTH = |
|---|
| 355 | new CheckstyleFindingType("CS_NESTED_TRY_DEPTH", |
|---|
| 356 | "Deeply nested tries.", |
|---|
| 357 | "The nesting level for the try/catches is to deep.", |
|---|
| 358 | "Nested try depth is [0-9]+ \\(max allowed is [0-9]+\\)\\.", |
|---|
| 359 | Severity.DESIGN); |
|---|
| 360 | |
|---|
| 361 | /** |
|---|
| 362 | * Checkstyle finding type that relates to: |
|---|
| 363 | * <i>Too many parameters</i>. |
|---|
| 364 | */ |
|---|
| 365 | public static final CheckstyleFindingType CS_NUMBER_OF_PARAMETERS = |
|---|
| 366 | new CheckstyleFindingType("CS_NUMBER_OF_PARAMETERS", |
|---|
| 367 | "Too many parameters.", |
|---|
| 368 | "Too many parameters.", |
|---|
| 369 | "More than [0-9]+ parameters\\.", |
|---|
| 370 | Severity.DESIGN); |
|---|
| 371 | |
|---|
| 372 | /** |
|---|
| 373 | * Checkstyle finding type that relates to: |
|---|
| 374 | * <i>Method unused</i>. |
|---|
| 375 | */ |
|---|
| 376 | public static final CheckstyleFindingType CS_METHOD_UNUSED = |
|---|
| 377 | new CheckstyleFindingType("CS_METHOD_UNUSED", |
|---|
| 378 | "Method unused.", |
|---|
| 379 | "Method is never used.", |
|---|
| 380 | "Unused private method '.*'\\."); |
|---|
| 381 | |
|---|
| 382 | /** |
|---|
| 383 | * Checkstyle finding type that relates to: |
|---|
| 384 | * <i>Local variable unused</i>. |
|---|
| 385 | */ |
|---|
| 386 | public static final CheckstyleFindingType CS_LOCAL_VARIABLE_UNUSED = |
|---|
| 387 | new CheckstyleFindingType("CS_LOCAL_VARIABLE_UNUSED", |
|---|
| 388 | "Local variable unused.", |
|---|
| 389 | "Local variable is never used.", |
|---|
| 390 | "Unused local variable '.*'\\."); |
|---|
| 391 | |
|---|
| 392 | /** |
|---|
| 393 | * Checkstyle finding type that relates to: |
|---|
| 394 | * <i>Indentation must be a multiple of 4</i>. |
|---|
| 395 | */ |
|---|
| 396 | public static final CheckstyleFindingType CS_ILLEGAL_INDENTATION = |
|---|
| 397 | new CheckstyleFindingType("CS_ILLEGAL_INDENTATION", |
|---|
| 398 | "Indentation must be a multiple of 4.", |
|---|
| 399 | "Indentation must be a multiple of 4.", |
|---|
| 400 | "Indentation must be a multiple of 4\\."); |
|---|
| 401 | |
|---|
| 402 | /** |
|---|
| 403 | * Checkstyle finding type that relates to: |
|---|
| 404 | * <i>Field is never used</i>. |
|---|
| 405 | */ |
|---|
| 406 | public static final CheckstyleFindingType CS_FIELD_UNUSED = |
|---|
| 407 | new CheckstyleFindingType("CS_FIELD_UNUSED", |
|---|
| 408 | "Field unused.", |
|---|
| 409 | "Field is never used.", |
|---|
| 410 | "Unused private field '.*'\\."); |
|---|
| 411 | |
|---|
| 412 | /** |
|---|
| 413 | * Checkstyle finding type that relates to: |
|---|
| 414 | * <i>The equals operator should be on a new line</i>. |
|---|
| 415 | */ |
|---|
| 416 | public static final CheckstyleFindingType CS_EQUALS_NEWLINE = |
|---|
| 417 | new CheckstyleFindingType("CS_EQUALS_NEWLINE", |
|---|
| 418 | "The equals operator should be on a new line.", |
|---|
| 419 | "The equals operator should be on a new line.", |
|---|
| 420 | "The equals operator should be on a new line\\."); |
|---|
| 421 | |
|---|
| 422 | /** |
|---|
| 423 | * Checkstyle finding type that relates to: |
|---|
| 424 | * <i>Line matches a illegal pattern</i>. |
|---|
| 425 | */ |
|---|
| 426 | public static final CheckstyleFindingType CS_ILLEGAL_LINE = |
|---|
| 427 | new CheckstyleFindingType("CS_ILLEGAL_PATTERN", |
|---|
| 428 | "Line matches a illegal pattern.", |
|---|
| 429 | "Line matches a illegal pattern.", |
|---|
| 430 | "Line matches the illegal pattern '.*'\\."); |
|---|
| 431 | |
|---|
| 432 | /** |
|---|
| 433 | * Checkstyle finding type that relates to: |
|---|
| 434 | * <i>Long constants should use a uppercase L</i>. |
|---|
| 435 | */ |
|---|
| 436 | public static final CheckstyleFindingType CS_UPPER_CASE_L = |
|---|
| 437 | new CheckstyleFindingType("CS_UPPER_CASE_L", "Use uppercase L.", |
|---|
| 438 | "Long constants should use a uppercase L the lower case L looks " |
|---|
| 439 | + "a lot like 1. 123L vs. 123l.", |
|---|
| 440 | "Should use uppercase 'L'\\."); |
|---|
| 441 | |
|---|
| 442 | /** |
|---|
| 443 | * Checkstyle finding type that relates to: |
|---|
| 444 | * <i>Invalid log level for trace log</i>. |
|---|
| 445 | */ |
|---|
| 446 | public static final CheckstyleFindingType CS_NO_LOG_LEVEL_INFO = |
|---|
| 447 | new CheckstyleFindingType("CS_NO_LOG_LEVEL_INFO", |
|---|
| 448 | "Invalid log level for trace log.", |
|---|
| 449 | "Trace log messages should have log level smaller than info, for " |
|---|
| 450 | + "higher severity use predefined log messages.", |
|---|
| 451 | "Maximum allowed log level for trace log is '.*' but was '.*'\\.", |
|---|
| 452 | Severity.DESIGN); |
|---|
| 453 | |
|---|
| 454 | /** |
|---|
| 455 | * Checkstyle finding type that relates to: |
|---|
| 456 | * <i>The brace should not be on a new line</i>. |
|---|
| 457 | */ |
|---|
| 458 | public static final CheckstyleFindingType CS_BRACE_ON_NEW_LINE = |
|---|
| 459 | new CheckstyleFindingType("CS_BRACE_ON_NEW_LINE", |
|---|
| 460 | "The brace should not be on a new line.", |
|---|
| 461 | "The brace should not be on a new line.", |
|---|
| 462 | "'[\\{\\}\\(\\)]' should be on the (previous|same) line\\."); |
|---|
| 463 | |
|---|
| 464 | /** |
|---|
| 465 | * Checkstyle finding type that relates to: |
|---|
| 466 | * <i>Avoid inline conditionals</i>. |
|---|
| 467 | */ |
|---|
| 468 | public static final CheckstyleFindingType CS_INLINE_CONDITIONAL = |
|---|
| 469 | new CheckstyleFindingType("CS_INLINE_CONDITIONAL", |
|---|
| 470 | "Avoid inline conditionals.", |
|---|
| 471 | "Avoid inline conditionals.", |
|---|
| 472 | "Avoid inline conditionals\\."); |
|---|
| 473 | |
|---|
| 474 | /** |
|---|
| 475 | * Checkstyle finding type that relates to: |
|---|
| 476 | * <i>Avoid redundant code</i>. |
|---|
| 477 | */ |
|---|
| 478 | public static final CheckstyleFindingType CS_REDUNDANT_MODIFIER = |
|---|
| 479 | new CheckstyleFindingType("CS_REDUNDANT_MODIFIER", |
|---|
| 480 | "Avoid redundant code.", |
|---|
| 481 | "Avoid redundant code.", |
|---|
| 482 | "Redundant '.*' modifier\\."); |
|---|
| 483 | |
|---|
| 484 | /** |
|---|
| 485 | * Checkstyle finding type that relates to: |
|---|
| 486 | * <i>Javadoc Pattern</i>. |
|---|
| 487 | */ |
|---|
| 488 | public static final CheckstyleFindingType CS_JAVADOC_PATTERN = |
|---|
| 489 | new CheckstyleFindingType("CS_JAVADOC_PATTERN", |
|---|
| 490 | "Javadoc pattern violation.", |
|---|
| 491 | "The javadoc tag does not comply to the required pattern.", |
|---|
| 492 | "Type Javadoc tag .* must match pattern '.*'\\."); |
|---|
| 493 | |
|---|
| 494 | /** |
|---|
| 495 | * Checkstyle finding type that relates to: |
|---|
| 496 | * <i>Redundant throws with subclass.</i>. |
|---|
| 497 | */ |
|---|
| 498 | public static final CheckstyleFindingType CS_REDUNDANT_THROWS_SUBCLASS = |
|---|
| 499 | new CheckstyleFindingType("CS_REDUNDANT_THROWS_SUBCLASS", |
|---|
| 500 | "Redundant throws declaration of a subclass.", |
|---|
| 501 | "The throws statement already contains the superclass and so" |
|---|
| 502 | + "declaring a subclass is redundant.", |
|---|
| 503 | "Redundant throws: '.*' is subclass of '.*'\\."); |
|---|
| 504 | |
|---|
| 505 | /** |
|---|
| 506 | * Checkstyle finding type that relates to: |
|---|
| 507 | * <i>Redundant throws with unchecked exception.</i>. |
|---|
| 508 | */ |
|---|
| 509 | public static final CheckstyleFindingType CS_REDUNDANT_THROWS_UNCHECKED = |
|---|
| 510 | new CheckstyleFindingType("CS_REDUNDANT_THROWS_UNCHECKED", |
|---|
| 511 | "Throws declaration of a unchecked exception is not needed.", |
|---|
| 512 | "Throws declaration of a unchecked exception is not needed.", |
|---|
| 513 | "Redundant throws: '.*' is unchecked exception\\."); |
|---|
| 514 | |
|---|
| 515 | /** |
|---|
| 516 | * Checkstyle finding type that relates to: |
|---|
| 517 | * <i>Boolean expression complexity is ... (max allowed is ...).</i>. |
|---|
| 518 | */ |
|---|
| 519 | public static final CheckstyleFindingType CS_BOOLEAN_EXPRESSION_COMPLEXITY = |
|---|
| 520 | new CheckstyleFindingType("CS_BOOLEAN_EXPRESSION_COMPLEXITY", |
|---|
| 521 | "Boolean expression is too complex.", |
|---|
| 522 | "Boolean expression is too complex. " |
|---|
| 523 | + "Too many conditions leads to code that is difficult to " |
|---|
| 524 | + "read and hence debug and maintain.", |
|---|
| 525 | "Boolean expression complexity is .* \\(max allowed is .*\\)\\."); |
|---|
| 526 | |
|---|
| 527 | /** |
|---|
| 528 | * Checkstyle finding type that relates to: |
|---|
| 529 | * <i>String comparison with ==.</i>. |
|---|
| 530 | */ |
|---|
| 531 | public static final CheckstyleFindingType CS_STRING_EQUALS_COMPARISON = |
|---|
| 532 | new CheckstyleFindingType("CS_STRING_EQUALS_COMPARISON", |
|---|
| 533 | "String comparison with ==.", |
|---|
| 534 | "String comparison with ==.", |
|---|
| 535 | "Literal Strings should be compared using equals\\(\\), not '=='\\."); |
|---|
| 536 | |
|---|
| 537 | /** |
|---|
| 538 | * Checkstyle finding type that relates to: |
|---|
| 539 | * <i>Missing package documentation file.</i>. |
|---|
| 540 | */ |
|---|
| 541 | public static final CheckstyleFindingType CS_MISSING_PACKAGE_DOCUMENTATION = |
|---|
| 542 | new CheckstyleFindingType("CS_MISSING_PACKAGE_DOCUMENTATION", |
|---|
| 543 | "Missing package documentation file.", |
|---|
| 544 | "Package content should be documentet using a package.html or" |
|---|
| 545 | + " package.xml file.", |
|---|
| 546 | "Missing package documentation file\\."); |
|---|
| 547 | |
|---|
| 548 | /** |
|---|
| 549 | * Checkstyle finding type that relates to: |
|---|
| 550 | * <i>Unable to get class information for .....</i>. |
|---|
| 551 | */ |
|---|
| 552 | public static final CheckstyleFindingType CS_EXCEPTION_CLASS_NOT_FOUND = |
|---|
| 553 | new CheckstyleFindingType("CS_EXCEPTION_CLASS_NOT_FOUND", |
|---|
| 554 | "Unable to get class information for certain class.", |
|---|
| 555 | "Mostly this is caused by a checkstyle internal issue or a finder" |
|---|
| 556 | + "class path setting.", |
|---|
| 557 | "Unable to get class information for .*\\."); |
|---|
| 558 | |
|---|
| 559 | /** |
|---|
| 560 | * Checkstyle finding type that relates to: |
|---|
| 561 | * <i>Using '.*' is not allowed.</i>. |
|---|
| 562 | */ |
|---|
| 563 | public static final CheckstyleFindingType CS_TYPE_NOT_ALLOWED = |
|---|
| 564 | new CheckstyleFindingType("CS_TYPE_NOT_ALLOWED", |
|---|
| 565 | "Use of a type that is not permited.", |
|---|
| 566 | "The type noted in the message should not be used.", |
|---|
| 567 | "Using '.*' is not allowed\\."); |
|---|
| 568 | |
|---|
| 569 | /** |
|---|
| 570 | * A internal checkstyle exception was triggered we shoulds also |
|---|
| 571 | * report this! |
|---|
| 572 | */ |
|---|
| 573 | public static final CheckstyleFindingType CS_EXCEPTION = |
|---|
| 574 | new CheckstyleFindingType("CS_EXCEPTION", |
|---|
| 575 | "Checkstyle analysis exception.", |
|---|
| 576 | "Exception during checkstyle analysis. There seems to be " |
|---|
| 577 | + "something strange here. One often problem is a reference to a " |
|---|
| 578 | + "Unknown or not visible class in Javadoc.", |
|---|
| 579 | "Got an exception - .*\\."); |
|---|
| 580 | |
|---|
| 581 | private CheckstyleFindingType (String symbol, String shortText, |
|---|
| 582 | String description, String messagePattern, Severity severity) |
|---|
| 583 | { |
|---|
| 584 | super(symbol, shortText, description); |
|---|
| 585 | mMessagePattern = messagePattern; |
|---|
| 586 | mSeverity = severity; |
|---|
| 587 | CHECKSTYLE_FINDING_TYPES.add(this); |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | |
|---|
| 591 | |
|---|
| 592 | private CheckstyleFindingType (String symbol, String shortText, |
|---|
| 593 | String description, String messagePattern) |
|---|
| 594 | { |
|---|
| 595 | this(symbol, shortText, description, messagePattern, |
|---|
| 596 | Severity.CODE_STYLE); |
|---|
| 597 | } |
|---|
| 598 | |
|---|
| 599 | /** |
|---|
| 600 | * Reads the given message and tries to find a matching finding type. |
|---|
| 601 | * @param message the message to read. |
|---|
| 602 | * @return the finding type matching to the message, or null if no such |
|---|
| 603 | * type was found. |
|---|
| 604 | */ |
|---|
| 605 | public static FindingType detectFindingTypeForMessage (String message) |
|---|
| 606 | { |
|---|
| 607 | new FindingType.LazyInit(); |
|---|
| 608 | FindingType result = null; |
|---|
| 609 | |
|---|
| 610 | for (final CheckstyleFindingType type : CHECKSTYLE_FINDING_TYPES) |
|---|
| 611 | { |
|---|
| 612 | if (message.matches(type.getMessagePattern())) |
|---|
| 613 | { |
|---|
| 614 | result = type; |
|---|
| 615 | break; |
|---|
| 616 | } |
|---|
| 617 | } |
|---|
| 618 | return result; |
|---|
| 619 | } |
|---|
| 620 | |
|---|
| 621 | /** @return the severity assigned to findings of this type by default. */ |
|---|
| 622 | public Severity getSeverity () |
|---|
| 623 | { |
|---|
| 624 | return mSeverity; |
|---|
| 625 | } |
|---|
| 626 | |
|---|
| 627 | /** |
|---|
| 628 | * @return Returns the messagePattern. |
|---|
| 629 | */ |
|---|
| 630 | private String getMessagePattern () |
|---|
| 631 | { |
|---|
| 632 | return mMessagePattern; |
|---|
| 633 | } |
|---|
| 634 | |
|---|
| 635 | /** |
|---|
| 636 | * Init of the enum. |
|---|
| 637 | */ |
|---|
| 638 | public static void initialize () |
|---|
| 639 | { |
|---|
| 640 | try |
|---|
| 641 | { |
|---|
| 642 | final JAXBContext jaxbContext |
|---|
| 643 | = JAXBContext.newInstance(CHECKSTYLE_MESSAGE_JAXB_CONTEXT, |
|---|
| 644 | CheckstyleFindingType.class.getClassLoader()); |
|---|
| 645 | final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); |
|---|
| 646 | final CheckstyleMessages messageCollection |
|---|
| 647 | = (CheckstyleMessages) unmarshaller.unmarshal( |
|---|
| 648 | CheckstyleFindingType.class.getClassLoader(). |
|---|
| 649 | getResourceAsStream(CHECKSTYLE_MESSAGE_FILE)); |
|---|
| 650 | for (final FindingData e |
|---|
| 651 | : (List<FindingData>) messageCollection.getFindingType()) |
|---|
| 652 | { |
|---|
| 653 | new CheckstyleFindingType(e.getSymbol(), e.getShortDescription(), |
|---|
| 654 | e.getDetailedDescription(), e.getMessagePattern()); |
|---|
| 655 | |
|---|
| 656 | } |
|---|
| 657 | } |
|---|
| 658 | catch (Exception e) |
|---|
| 659 | { |
|---|
| 660 | throw new RuntimeException( |
|---|
| 661 | "Cannot initialize CheckstyleFindingTypes", e); |
|---|
| 662 | } |
|---|
| 663 | } |
|---|
| 664 | } |
|---|