Mark fields final where possible. #1538
This commit is contained in:
parent
1ce6badd8f
commit
30438ebdf9
|
|
@ -73,10 +73,10 @@ final class PropertyCacheFile {
|
|||
private final Properties details = new Properties();
|
||||
|
||||
/** configuration object **/
|
||||
private Configuration config;
|
||||
private final Configuration config;
|
||||
|
||||
/** file name of cache **/
|
||||
private String fileName;
|
||||
private final String fileName;
|
||||
|
||||
/**
|
||||
* Creates a new <code>PropertyCacheFile</code> instance.
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class XMLLogger
|
|||
"quot", };
|
||||
|
||||
/** close output stream in auditFinished */
|
||||
private boolean closeStream;
|
||||
private final boolean closeStream;
|
||||
|
||||
/** helper writer that allows easy encoding and printing */
|
||||
private PrintWriter writer;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ package com.puppycrawl.tools.checkstyle.api;
|
|||
*/
|
||||
public final class SeverityLevelCounter implements AuditListener {
|
||||
/** The severity level to watch out for. */
|
||||
private SeverityLevel level;
|
||||
private final SeverityLevel level;
|
||||
|
||||
/** Keeps track of the number of counted events. */
|
||||
private int count;
|
||||
|
|
|
|||
|
|
@ -107,25 +107,25 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
public class AvoidEscapedUnicodeCharactersCheck
|
||||
extends Check {
|
||||
/** Regular expression for Unicode chars */
|
||||
private static Pattern sUnicodeRegexp = Pattern.compile("\\\\u[a-fA-F0-9]{4}");
|
||||
private static final Pattern UNICODE_REGEXP = Pattern.compile("\\\\u[a-fA-F0-9]{4}");
|
||||
|
||||
/** Regular expression Unicode control characters */
|
||||
private static Pattern sUnicodeControl = Pattern.compile("\\\\(u|U)"
|
||||
private static final Pattern UNICODE_CONTROL = Pattern.compile("\\\\(u|U)"
|
||||
+ "(00[0-1][0-1A-Fa-f]|00[8-9][0-9A-Fa-f]|034(f|F)|070(f|F)"
|
||||
+ "|180(e|E)|200[b-fB-F]|202[b-eB-E]|206[0-4a-fA-F]"
|
||||
+ "|[fF]{3}[9a-bA-B]|[fF][eE][fF]{2})");
|
||||
|
||||
/** Regular expression for trail comment */
|
||||
private static Pattern sCommentRegexp = Pattern.compile(";[ ]*//+"
|
||||
private static final Pattern COMMENT_REGEXP = Pattern.compile(";[ ]*//+"
|
||||
+ "[a-zA-Z0-9 ]*|;[ ]*/[*]{1}+[a-zA-Z0-9 ]*");
|
||||
|
||||
/** Regular expression for all escaped chars */
|
||||
private static Pattern sAllEscapedChars =
|
||||
private static final Pattern ALL_ESCAPED_CHARS =
|
||||
Pattern.compile("^((\\\\u)[a-fA-F0-9]{4}"
|
||||
+ "||\\\\b|\\\\t|\\\\n|\\\\f|\\\\r|\\\\|\\\"|\\\')+$");
|
||||
|
||||
/** Regular expression for non-printable unicode chars */
|
||||
private static Pattern sNonPrintableChars = Pattern.compile("\\\\u1680|\\\\u2028"
|
||||
private static final Pattern NON_PRINTABLE_CHARS = Pattern.compile("\\\\u1680|\\\\u2028"
|
||||
+ "|\\\\u2029|\\\\u205(f|F)|\\\\u3000|\\\\u2007|\\\\u2000|\\\\u200(a|A)"
|
||||
+ "|\\\\u007(F|f)|\\\\u009(f|F)|\\\\u(f|F){4}|\\\\u007(F|f)|\\\\u00(a|A)(d|D)"
|
||||
+ "|\\\\u0600|\\\\u061(c|C)|\\\\u06(d|D){2}|\\\\u070(f|F)|\\\\u1680|\\\\u180(e|E)"
|
||||
|
|
@ -208,9 +208,9 @@ public class AvoidEscapedUnicodeCharactersCheck
|
|||
if (hasUnicodeChar(literal) && !(allowByTailComment && hasTrailComment(ast)
|
||||
|| isAllCharactersEscaped(literal)
|
||||
|| allowEscapesForControlCharacters
|
||||
&& isOnlyUnicodeValidChars(literal, sUnicodeControl)
|
||||
&& isOnlyUnicodeValidChars(literal, UNICODE_CONTROL)
|
||||
|| allowNonPrintableEscapes
|
||||
&& isOnlyUnicodeValidChars(literal, sNonPrintableChars))) {
|
||||
&& isOnlyUnicodeValidChars(literal, NON_PRINTABLE_CHARS))) {
|
||||
log(ast.getLineNo(), "forbid.escaped.unicode.char");
|
||||
}
|
||||
}
|
||||
|
|
@ -221,7 +221,7 @@ public class AvoidEscapedUnicodeCharactersCheck
|
|||
* @return true if literal has Unicode chars.
|
||||
*/
|
||||
private static boolean hasUnicodeChar(String literal) {
|
||||
return sUnicodeRegexp.matcher(literal).find();
|
||||
return UNICODE_REGEXP.matcher(literal).find();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -232,7 +232,7 @@ public class AvoidEscapedUnicodeCharactersCheck
|
|||
*/
|
||||
private static boolean isOnlyUnicodeValidChars(String literal, Pattern pattern) {
|
||||
final int unicodeMatchesCounter =
|
||||
countMatches(sUnicodeRegexp, literal);
|
||||
countMatches(UNICODE_REGEXP, literal);
|
||||
final int unicodeValidMatchesCouter =
|
||||
countMatches(pattern, literal);
|
||||
return unicodeMatchesCounter - unicodeValidMatchesCouter == 0;
|
||||
|
|
@ -264,7 +264,7 @@ public class AvoidEscapedUnicodeCharactersCheck
|
|||
final int lineNo = semi.getLineNo();
|
||||
final String currentLine = getLine(lineNo - 1);
|
||||
|
||||
if (sCommentRegexp.matcher(currentLine).find()) {
|
||||
if (COMMENT_REGEXP.matcher(currentLine).find()) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -325,7 +325,7 @@ public class AvoidEscapedUnicodeCharactersCheck
|
|||
*/
|
||||
private boolean isAllCharactersEscaped(String literal) {
|
||||
return allowIfAllCharactersEscaped
|
||||
&& sAllEscapedChars.matcher(literal.substring(1,
|
||||
&& ALL_ESCAPED_CHARS.matcher(literal.substring(1,
|
||||
literal.length() - 1)).find();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ public class HideUtilityClassConstructorCheck extends Check {
|
|||
*/
|
||||
private static class Details {
|
||||
/** class ast */
|
||||
private DetailAST ast;
|
||||
private final DetailAST ast;
|
||||
/** result of details gathering */
|
||||
private boolean hasMethodOrField;
|
||||
/** result of details gathering */
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ public class OneTopLevelClassCheck extends Check {
|
|||
private boolean publicTypeFound;
|
||||
|
||||
/** Mapping between type names and line numbers of the type declarations.*/
|
||||
private SortedMap<Integer, String> lineNumberTypeMap = new TreeMap<>();
|
||||
private final SortedMap<Integer, String> lineNumberTypeMap = new TreeMap<>();
|
||||
|
||||
@Override
|
||||
public int[] getDefaultTokens() {
|
||||
|
|
|
|||
|
|
@ -292,7 +292,7 @@ public class VisibilityModifierCheck
|
|||
new ArrayList<>(DEFAULT_IGNORE_ANNOTATIONS);
|
||||
|
||||
/** List of ignore annotations short names. */
|
||||
private List<String> ignoreAnnotationShortNames =
|
||||
private final List<String> ignoreAnnotationShortNames =
|
||||
getClassShortNames(DEFAULT_IGNORE_ANNOTATIONS);
|
||||
|
||||
/** Allows immutable fields to be declared as public. */
|
||||
|
|
|
|||
|
|
@ -324,7 +324,7 @@ public class CustomImportOrderCheck extends Check {
|
|||
private int samePackageMatchingDepth = 2;
|
||||
|
||||
/** Contains objects with import attributes */
|
||||
private List<ImportDetails> importToGroupList = new ArrayList<>();
|
||||
private final List<ImportDetails> importToGroupList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Sets standardRegExp specified by user.
|
||||
|
|
|
|||
|
|
@ -47,22 +47,22 @@ public class LineWrappingHandler {
|
|||
/**
|
||||
* Root node for current expression.
|
||||
*/
|
||||
private DetailAST firstNode;
|
||||
private final DetailAST firstNode;
|
||||
|
||||
/**
|
||||
* Last node for current expression.
|
||||
*/
|
||||
private DetailAST lastNode;
|
||||
private final DetailAST lastNode;
|
||||
|
||||
/**
|
||||
* User's value of line wrapping indentation.
|
||||
*/
|
||||
private int indentLevel;
|
||||
private final int indentLevel;
|
||||
|
||||
/**
|
||||
* Force strict condition in line wrapping case.
|
||||
*/
|
||||
private boolean forceStrictCondition;
|
||||
private final boolean forceStrictCondition;
|
||||
|
||||
/**
|
||||
* Sets values of class field, finds last node and calculates indentation level.
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public class SynchronizedHandler extends BlockParentHandler {
|
|||
/**
|
||||
* Determine that "synchronized" token used as modifier of method
|
||||
*/
|
||||
private boolean methodModifier;
|
||||
private final boolean methodModifier;
|
||||
|
||||
/**
|
||||
* Construct an instance of this handler with the given indentation check,
|
||||
|
|
|
|||
|
|
@ -636,17 +636,17 @@ public abstract class AbstractJavadocCheck extends Check {
|
|||
/**
|
||||
* Line number where parse error occurred.
|
||||
*/
|
||||
private int lineNumber;
|
||||
private final int lineNumber;
|
||||
|
||||
/**
|
||||
* Key for error message.
|
||||
*/
|
||||
private String messageKey;
|
||||
private final String messageKey;
|
||||
|
||||
/**
|
||||
* Error message arguments.
|
||||
*/
|
||||
private Object[] messageArguments;
|
||||
private final Object[] messageArguments;
|
||||
|
||||
/**
|
||||
* Initializes parse error message.
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class JavadocTag {
|
|||
/** the line number of the tag **/
|
||||
private final int lineNo;
|
||||
/** the column number of the tag **/
|
||||
private int columnNo;
|
||||
private final int columnNo;
|
||||
/** an optional first argument. For example the parameter name. **/
|
||||
private final String arg1;
|
||||
/** the JavadocTagInfo representing this tag **/
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
public class LocalVariableNameCheck
|
||||
extends AbstractNameCheck {
|
||||
/** Regexp for one-char loop variables. */
|
||||
private static Pattern sSingleChar = Pattern.compile("^[a-z]$");
|
||||
private static final Pattern SINGLE_CHAR = Pattern.compile("^[a-z]$");
|
||||
|
||||
/**
|
||||
* Allow one character name for initialization expression in FOR loop.
|
||||
|
|
@ -111,7 +111,7 @@ public class LocalVariableNameCheck
|
|||
if (allowOneCharVarInForLoop && isForLoopVariable(ast)) {
|
||||
final String variableName =
|
||||
ast.findFirstToken(TokenTypes.IDENT).getText();
|
||||
return !sSingleChar.matcher(variableName).find();
|
||||
return !SINGLE_CHAR.matcher(variableName).find();
|
||||
}
|
||||
final DetailAST modifiersAST =
|
||||
ast.findFirstToken(TokenTypes.MODIFIERS);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import com.puppycrawl.tools.checkstyle.api.FileText;
|
|||
*/
|
||||
public class RegexpMultilineCheck extends AbstractFileSetCheck {
|
||||
/** The detection options to use. */
|
||||
private DetectorOptions options = new DetectorOptions(Pattern.MULTILINE,
|
||||
private final DetectorOptions options = new DetectorOptions(Pattern.MULTILINE,
|
||||
this);
|
||||
/** The detector to use. */
|
||||
private MultilineDetector detector;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
|
|||
*/
|
||||
public class RegexpSinglelineCheck extends AbstractFileSetCheck {
|
||||
/** The detection options to use. */
|
||||
private DetectorOptions options = new DetectorOptions(0, this);
|
||||
private final DetectorOptions options = new DetectorOptions(0, this);
|
||||
/** The detector to use. */
|
||||
private SinglelineDetector detector;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
|||
*/
|
||||
public class RegexpSinglelineJavaCheck extends Check {
|
||||
/** The detection options to use. */
|
||||
private DetectorOptions options = new DetectorOptions(0, this);
|
||||
private final DetectorOptions options = new DetectorOptions(0, this);
|
||||
/** The detector to use. */
|
||||
private SinglelineDetector detector;
|
||||
/** The suppressor to use. */
|
||||
|
|
|
|||
Loading…
Reference in New Issue