diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java b/src/main/java/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java index 809315bde..dc5ae7cc8 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java @@ -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 PropertyCacheFile instance. diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/XMLLogger.java b/src/main/java/com/puppycrawl/tools/checkstyle/XMLLogger.java index 5912be9c6..33d1c847e 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/XMLLogger.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/XMLLogger.java @@ -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; diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/SeverityLevelCounter.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/SeverityLevelCounter.java index 8c48cd4b7..92e06d4d5 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/SeverityLevelCounter.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/SeverityLevelCounter.java @@ -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; diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/AvoidEscapedUnicodeCharactersCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/AvoidEscapedUnicodeCharactersCheck.java index cb7927668..1379d3380 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/AvoidEscapedUnicodeCharactersCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/AvoidEscapedUnicodeCharactersCheck.java @@ -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(); } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/HideUtilityClassConstructorCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/HideUtilityClassConstructorCheck.java index 7199507db..de76b9d0e 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/HideUtilityClassConstructorCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/HideUtilityClassConstructorCheck.java @@ -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 */ diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/OneTopLevelClassCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/OneTopLevelClassCheck.java index bd6d85413..565504875 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/OneTopLevelClassCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/OneTopLevelClassCheck.java @@ -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 lineNumberTypeMap = new TreeMap<>(); + private final SortedMap lineNumberTypeMap = new TreeMap<>(); @Override public int[] getDefaultTokens() { diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/VisibilityModifierCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/VisibilityModifierCheck.java index eb38d0bd8..2fc52500e 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/VisibilityModifierCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/VisibilityModifierCheck.java @@ -292,7 +292,7 @@ public class VisibilityModifierCheck new ArrayList<>(DEFAULT_IGNORE_ANNOTATIONS); /** List of ignore annotations short names. */ - private List ignoreAnnotationShortNames = + private final List ignoreAnnotationShortNames = getClassShortNames(DEFAULT_IGNORE_ANNOTATIONS); /** Allows immutable fields to be declared as public. */ diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/CustomImportOrderCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/CustomImportOrderCheck.java index 312fb4598..35aaa1222 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/CustomImportOrderCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/CustomImportOrderCheck.java @@ -324,7 +324,7 @@ public class CustomImportOrderCheck extends Check { private int samePackageMatchingDepth = 2; /** Contains objects with import attributes */ - private List importToGroupList = new ArrayList<>(); + private final List importToGroupList = new ArrayList<>(); /** * Sets standardRegExp specified by user. diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/LineWrappingHandler.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/LineWrappingHandler.java index 9752ce57e..7417be81c 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/LineWrappingHandler.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/LineWrappingHandler.java @@ -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. diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/SynchronizedHandler.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/SynchronizedHandler.java index 0e76ee2bc..8895f86d3 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/SynchronizedHandler.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/SynchronizedHandler.java @@ -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, diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AbstractJavadocCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AbstractJavadocCheck.java index 67ee9d6b3..e667f9167 100755 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AbstractJavadocCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AbstractJavadocCheck.java @@ -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. diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTag.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTag.java index 46b8d0b1a..c9594d2c6 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTag.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocTag.java @@ -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 **/ diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/naming/LocalVariableNameCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/naming/LocalVariableNameCheck.java index cd2d38c2b..28ca49509 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/naming/LocalVariableNameCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/naming/LocalVariableNameCheck.java @@ -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); diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpMultilineCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpMultilineCheck.java index 1c174e027..b713f2e79 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpMultilineCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpMultilineCheck.java @@ -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; diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineCheck.java index 74caf003c..8669c44ee 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineCheck.java @@ -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; diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineJavaCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineJavaCheck.java index 93ff8bfa6..b1dc6c797 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineJavaCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpSinglelineJavaCheck.java @@ -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. */