Fix DeclarationOrder check violations in Checkstyle code, issue #1049
This commit is contained in:
parent
1df2edb7d6
commit
0f543a21fe
|
|
@ -236,6 +236,7 @@
|
|||
<module name="AvoidStaticImport"/>
|
||||
<module name="ClassTypeParameterName"/>
|
||||
<module name="CovariantEquals"/>
|
||||
<module name="DeclarationOrder"/>
|
||||
<module name="DefaultComesLast"/>
|
||||
<module name="DescendantToken"/>
|
||||
<module name="EmptyCatchBlock"/>
|
||||
|
|
@ -252,7 +253,6 @@
|
|||
<module name="ClassDataAbstractionCoupling"/>
|
||||
<module name="ClassFanOutComplexity"/>
|
||||
<module name="CustomImportOrder"/>
|
||||
<module name="DeclarationOrder"/>
|
||||
<module name="DesignForExtension"/>
|
||||
<module name="EmptyForInitializerPad"/>
|
||||
<module name="EmptyStatement"/>
|
||||
|
|
|
|||
|
|
@ -229,20 +229,6 @@ public final class ConfigurationLoader
|
|||
/** flags if modules with the severity 'ignore' should be omitted. */
|
||||
private final boolean omitIgnoredModules;
|
||||
|
||||
/**
|
||||
* Creates mapping between local resources and dtd ids.
|
||||
* @return map between local resources and dtd ids.
|
||||
*/
|
||||
private static Map<String, String> createIdToResourceNameMap()
|
||||
{
|
||||
final Map<String, String> map = Maps.newHashMap();
|
||||
map.put(DTD_PUBLIC_ID_1_0, DTD_RESOURCE_NAME_1_0);
|
||||
map.put(DTD_PUBLIC_ID_1_1, DTD_RESOURCE_NAME_1_1);
|
||||
map.put(DTD_PUBLIC_ID_1_2, DTD_RESOURCE_NAME_1_2);
|
||||
map.put(DTD_PUBLIC_ID_1_3, DTD_RESOURCE_NAME_1_3);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>ConfigurationLoader</code> instance.
|
||||
* @param overrideProps resolver for overriding properties
|
||||
|
|
@ -260,6 +246,20 @@ public final class ConfigurationLoader
|
|||
this.omitIgnoredModules = omitIgnoredModules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates mapping between local resources and dtd ids.
|
||||
* @return map between local resources and dtd ids.
|
||||
*/
|
||||
private static Map<String, String> createIdToResourceNameMap()
|
||||
{
|
||||
final Map<String, String> map = Maps.newHashMap();
|
||||
map.put(DTD_PUBLIC_ID_1_0, DTD_RESOURCE_NAME_1_0);
|
||||
map.put(DTD_PUBLIC_ID_1_1, DTD_RESOURCE_NAME_1_1);
|
||||
map.put(DTD_PUBLIC_ID_1_2, DTD_RESOURCE_NAME_1_2);
|
||||
map.put(DTD_PUBLIC_ID_1_3, DTD_RESOURCE_NAME_1_3);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the specified input source loading the configuration information.
|
||||
* The stream wrapped inside the source, if any, is NOT
|
||||
|
|
|
|||
|
|
@ -25,14 +25,14 @@ package com.puppycrawl.tools.checkstyle;
|
|||
**/
|
||||
public final class Definitions
|
||||
{
|
||||
/** Name of resource bundle for Checkstyle. */
|
||||
public static final String CHECKSTYLE_BUNDLE =
|
||||
"com.puppycrawl.tools.checkstyle.messages";
|
||||
|
||||
/**
|
||||
* Do no allow <code>Definitions</code> instances to be created.
|
||||
**/
|
||||
private Definitions()
|
||||
{
|
||||
}
|
||||
|
||||
/** Name of resource bundle for Checkstyle. */
|
||||
public static final String CHECKSTYLE_BUNDLE =
|
||||
"com.puppycrawl.tools.checkstyle.messages";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,11 @@ import org.apache.commons.cli.PosixParser;
|
|||
**/
|
||||
public final class Main
|
||||
{
|
||||
/** Don't create instance of this class, use {@link #main(String[])} method instead. */
|
||||
private Main()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Loops over the files specified checking them for errors. The exit code
|
||||
* is the number of errors found in all the files.
|
||||
|
|
@ -163,11 +168,6 @@ public final class Main
|
|||
}
|
||||
}
|
||||
|
||||
/** Don't create instance of this class, use {@link #main(String[])} method instead. */
|
||||
private Main()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the Checker object.
|
||||
* @param config
|
||||
|
|
|
|||
|
|
@ -62,6 +62,18 @@ final class PropertyCacheFile
|
|||
*/
|
||||
private static final String CONFIG_HASH_KEY = "configuration*?";
|
||||
|
||||
/** hex digits */
|
||||
private static final char[] HEX_CHARS = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
|
||||
};
|
||||
|
||||
/** mask for last byte */
|
||||
private static final int MASK_0X0F = 0x0F;
|
||||
|
||||
/** bit shift */
|
||||
private static final int SHIFT_4 = 4;
|
||||
|
||||
/** name of file to store details **/
|
||||
private final String detailsFile;
|
||||
/** the details on files **/
|
||||
|
|
@ -204,18 +216,6 @@ final class PropertyCacheFile
|
|||
}
|
||||
}
|
||||
|
||||
/** hex digits */
|
||||
private static final char[] HEX_CHARS = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
|
||||
};
|
||||
|
||||
/** mask for last byte */
|
||||
private static final int MASK_0X0F = 0x0F;
|
||||
|
||||
/** bit shift */
|
||||
private static final int SHIFT_4 = 4;
|
||||
|
||||
/**
|
||||
* Hex-encodes a byte array.
|
||||
* @param byteArray the byte array
|
||||
|
|
|
|||
|
|
@ -83,6 +83,9 @@ public final class TreeWalker
|
|||
/** default distance between tab stops */
|
||||
private static final int DEFAULT_TAB_WIDTH = 8;
|
||||
|
||||
/** logger for debug purpose */
|
||||
private static final Log LOG = LogFactory.getLog(TreeWalker.class);
|
||||
|
||||
/** maps from token name to ordinary checks */
|
||||
private final Multimap<String, Check> tokenToOrdinaryChecks =
|
||||
HashMultimap.create();
|
||||
|
|
@ -112,9 +115,6 @@ public final class TreeWalker
|
|||
/** a factory for creating submodules (i.e. the Checks) */
|
||||
private ModuleFactory moduleFactory;
|
||||
|
||||
/** logger for debug purpose */
|
||||
private static final Log LOG = LogFactory.getLog(TreeWalker.class);
|
||||
|
||||
/**
|
||||
* Creates a new <code>TreeWalker</code> instance.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -49,16 +49,16 @@ public class XMLLogger
|
|||
/** hex radix */
|
||||
private static final int BASE_16 = 16;
|
||||
|
||||
/** some known entities to detect */
|
||||
private static final String[] ENTITIES = {"gt", "amp", "lt", "apos",
|
||||
"quot", };
|
||||
|
||||
/** close output stream in auditFinished */
|
||||
private boolean closeStream;
|
||||
|
||||
/** helper writer that allows easy encoding and printing */
|
||||
private PrintWriter writer;
|
||||
|
||||
/** some known entities to detect */
|
||||
private static final String[] ENTITIES = {"gt", "amp", "lt", "apos",
|
||||
"quot", };
|
||||
|
||||
/**
|
||||
* Creates a new <code>XMLLogger</code> instance.
|
||||
* Sets the output to a defined stream.
|
||||
|
|
|
|||
|
|
@ -65,6 +65,9 @@ public final class LocalizedMessage
|
|||
private static final Map<String, ResourceBundle> BUNDLE_CACHE =
|
||||
Collections.synchronizedMap(new HashMap<String, ResourceBundle>());
|
||||
|
||||
/** the default severity level if one is not specified */
|
||||
private static final SeverityLevel DEFAULT_SEVERITY = SeverityLevel.ERROR;
|
||||
|
||||
/** the line number **/
|
||||
private final int lineNo;
|
||||
/** the column number **/
|
||||
|
|
@ -76,9 +79,6 @@ public final class LocalizedMessage
|
|||
/** the id of the module generating the message. */
|
||||
private final String moduleId;
|
||||
|
||||
/** the default severity level if one is not specified */
|
||||
private static final SeverityLevel DEFAULT_SEVERITY = SeverityLevel.ERROR;
|
||||
|
||||
/** key for the message format **/
|
||||
private final String key;
|
||||
|
||||
|
|
@ -94,51 +94,6 @@ public final class LocalizedMessage
|
|||
/** a custom message overriding the default message from the bundle. */
|
||||
private final String customMessage;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object)
|
||||
{
|
||||
if (this == object) {
|
||||
return true;
|
||||
}
|
||||
if (!(object instanceof LocalizedMessage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final LocalizedMessage localizedMessage = (LocalizedMessage) object;
|
||||
|
||||
if (colNo != localizedMessage.colNo) {
|
||||
return false;
|
||||
}
|
||||
if (lineNo != localizedMessage.lineNo) {
|
||||
return false;
|
||||
}
|
||||
if (!key.equals(localizedMessage.key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Arrays.equals(args, localizedMessage.args)) {
|
||||
return false;
|
||||
}
|
||||
// ignoring bundle for perf reasons.
|
||||
|
||||
// we currently never load the same error from different bundles.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result;
|
||||
result = lineNo;
|
||||
result = HASH_MULT * result + colNo;
|
||||
result = HASH_MULT * result + key.hashCode();
|
||||
for (final Object element : args) {
|
||||
result = HASH_MULT * result + element.hashCode();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>LocalizedMessage</code> instance.
|
||||
*
|
||||
|
|
@ -255,6 +210,51 @@ public final class LocalizedMessage
|
|||
sourceClass, customMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object)
|
||||
{
|
||||
if (this == object) {
|
||||
return true;
|
||||
}
|
||||
if (!(object instanceof LocalizedMessage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final LocalizedMessage localizedMessage = (LocalizedMessage) object;
|
||||
|
||||
if (colNo != localizedMessage.colNo) {
|
||||
return false;
|
||||
}
|
||||
if (lineNo != localizedMessage.lineNo) {
|
||||
return false;
|
||||
}
|
||||
if (!key.equals(localizedMessage.key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Arrays.equals(args, localizedMessage.args)) {
|
||||
return false;
|
||||
}
|
||||
// ignoring bundle for perf reasons.
|
||||
|
||||
// we currently never load the same error from different bundles.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result;
|
||||
result = lineNo;
|
||||
result = HASH_MULT * result + colNo;
|
||||
result = HASH_MULT * result + key.hashCode();
|
||||
for (final Object element : args) {
|
||||
result = HASH_MULT * result + element.hashCode();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Clears the cache. */
|
||||
public static void clearCache()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -37,11 +37,6 @@ import com.puppycrawl.tools.checkstyle.grammars.GeneratedJavaTokenTypes;
|
|||
*/
|
||||
public final class TokenTypes
|
||||
{
|
||||
/** prevent instantiation */
|
||||
private TokenTypes()
|
||||
{
|
||||
}
|
||||
|
||||
// The following three types are never part of an AST,
|
||||
// left here as a reminder so nobody will read them accidentally
|
||||
|
||||
|
|
@ -3533,6 +3528,11 @@ public final class TokenTypes
|
|||
TOKEN_VALUE_TO_NAME = tempTokenValueToName;
|
||||
}
|
||||
|
||||
/** prevent instantiation */
|
||||
private TokenTypes()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of a token for a given ID.
|
||||
* @param iD the ID of the token name to get
|
||||
|
|
|
|||
|
|
@ -74,6 +74,12 @@ public abstract class AbstractTypeAwareCheck extends Check
|
|||
*/
|
||||
private boolean logLoadErrors = true;
|
||||
|
||||
/**
|
||||
* Whether to show class loading errors in the checkstyle report.
|
||||
* Request ID 1491630
|
||||
*/
|
||||
private boolean suppressLoadErrors;
|
||||
|
||||
/**
|
||||
* Controls whether to log class loading errors to the checkstyle report
|
||||
* instead of throwing a RTE.
|
||||
|
|
@ -85,12 +91,6 @@ public abstract class AbstractTypeAwareCheck extends Check
|
|||
this.logLoadErrors = logLoadErrors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to show class loading errors in the checkstyle report.
|
||||
* Request ID 1491630
|
||||
*/
|
||||
private boolean suppressLoadErrors;
|
||||
|
||||
/**
|
||||
* Controls whether to show class loading errors in the checkstyle report.
|
||||
*
|
||||
|
|
@ -428,15 +428,6 @@ public abstract class AbstractTypeAwareCheck extends Check
|
|||
/** <code>FullIdent</code> associated with this class. */
|
||||
private final Token name;
|
||||
|
||||
/** @return class name */
|
||||
public final Token getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/** @return <code>Class</code> associated with an object. */
|
||||
public abstract Class<?> getClazz();
|
||||
|
||||
/**
|
||||
* Creates new instance of class inforamtion object.
|
||||
* @param className token which represents class name.
|
||||
|
|
@ -449,6 +440,15 @@ public abstract class AbstractTypeAwareCheck extends Check
|
|||
}
|
||||
name = className;
|
||||
}
|
||||
|
||||
/** @return class name */
|
||||
public final Token getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/** @return <code>Class</code> associated with an object. */
|
||||
public abstract Class<?> getClazz();
|
||||
}
|
||||
|
||||
/** Represents regular classes/enumes. */
|
||||
|
|
|
|||
|
|
@ -34,6 +34,16 @@ import java.util.List;
|
|||
*/
|
||||
public final class CheckUtils
|
||||
{
|
||||
// constants for parseDouble()
|
||||
/** octal radix */
|
||||
private static final int BASE_8 = 8;
|
||||
|
||||
/** decimal radix */
|
||||
private static final int BASE_10 = 10;
|
||||
|
||||
/** hex radix */
|
||||
private static final int BASE_16 = 16;
|
||||
|
||||
/** prevent instances */
|
||||
private CheckUtils()
|
||||
{
|
||||
|
|
@ -132,16 +142,6 @@ public final class CheckUtils
|
|||
return FullIdent.createFullIdent(typeAST.getFirstChild());
|
||||
}
|
||||
|
||||
// constants for parseDouble()
|
||||
/** octal radix */
|
||||
private static final int BASE_8 = 8;
|
||||
|
||||
/** decimal radix */
|
||||
private static final int BASE_10 = 10;
|
||||
|
||||
/** hex radix */
|
||||
private static final int BASE_16 = 16;
|
||||
|
||||
/**
|
||||
* Returns the value represented by the specified string of the specified
|
||||
* type. Returns 0 for types other than float, double, int, and long.
|
||||
|
|
|
|||
|
|
@ -59,20 +59,6 @@ public class FinalParametersCheck extends Check
|
|||
*/
|
||||
public static final String MSG_KEY = "final.parameter";
|
||||
|
||||
/**
|
||||
* Option to ignore primitive types as params.
|
||||
*/
|
||||
private boolean ignorePrimitiveTypes;
|
||||
|
||||
/**
|
||||
* Sets ignoring primitive types as params.
|
||||
* @param ignorePrimitiveTypes true or false.
|
||||
*/
|
||||
public void setIgnorePrimitiveTypes(boolean ignorePrimitiveTypes)
|
||||
{
|
||||
this.ignorePrimitiveTypes = ignorePrimitiveTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains
|
||||
* <a href="http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html">
|
||||
|
|
@ -88,6 +74,20 @@ public class FinalParametersCheck extends Check
|
|||
TokenTypes.LITERAL_BOOLEAN,
|
||||
TokenTypes.LITERAL_CHAR);
|
||||
|
||||
/**
|
||||
* Option to ignore primitive types as params.
|
||||
*/
|
||||
private boolean ignorePrimitiveTypes;
|
||||
|
||||
/**
|
||||
* Sets ignoring primitive types as params.
|
||||
* @param ignorePrimitiveTypes true or false.
|
||||
*/
|
||||
public void setIgnorePrimitiveTypes(boolean ignorePrimitiveTypes)
|
||||
{
|
||||
this.ignorePrimitiveTypes = ignorePrimitiveTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getDefaultTokens()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -113,6 +113,15 @@ public class TrailingCommentCheck extends AbstractFormatCheck
|
|||
/** pattern for legal trailing comment. */
|
||||
private Pattern legalComment;
|
||||
|
||||
/**
|
||||
* Creates new instance of the check.
|
||||
* @throws ConversionException unable to parse DEFAULT_FORMAT.
|
||||
*/
|
||||
public TrailingCommentCheck() throws ConversionException
|
||||
{
|
||||
super(DEFAULT_FORMAT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets patter for legal trailing comments.
|
||||
* @param format format to set.
|
||||
|
|
@ -123,14 +132,6 @@ public class TrailingCommentCheck extends AbstractFormatCheck
|
|||
{
|
||||
legalComment = Utils.createPattern(format);
|
||||
}
|
||||
/**
|
||||
* Creates new instance of the check.
|
||||
* @throws ConversionException unable to parse DEFAULT_FORMAT.
|
||||
*/
|
||||
public TrailingCommentCheck() throws ConversionException
|
||||
{
|
||||
super(DEFAULT_FORMAT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getDefaultTokens()
|
||||
|
|
|
|||
|
|
@ -121,13 +121,6 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
*/
|
||||
public final class AnnotationUseStyleCheck extends Check
|
||||
{
|
||||
/**
|
||||
* the element name used to receive special linguistic support
|
||||
* for annotation use.
|
||||
*/
|
||||
private static final String ANNOTATION_ELEMENT_SINGLE_NAME =
|
||||
"value";
|
||||
|
||||
/**
|
||||
* A key is pointing to the warning message text in "messages.properties"
|
||||
* file.
|
||||
|
|
@ -163,6 +156,13 @@ public final class AnnotationUseStyleCheck extends Check
|
|||
public static final String MSG_KEY_ANNOTATION_TRAILING_COMMA_PRESENT =
|
||||
"annotation.trailing.comma.present";
|
||||
|
||||
/**
|
||||
* the element name used to receive special linguistic support
|
||||
* for annotation use.
|
||||
*/
|
||||
private static final String ANNOTATION_ELEMENT_SINGLE_NAME =
|
||||
"value";
|
||||
|
||||
//not extending AbstractOptionCheck because check
|
||||
//has more than one option type.
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,26 @@ import com.puppycrawl.tools.checkstyle.Utils;
|
|||
*/
|
||||
public final class MissingDeprecatedCheck extends Check
|
||||
{
|
||||
/**
|
||||
* A key is pointing to the warning message text in "messages.properties"
|
||||
* file.
|
||||
*/
|
||||
public static final String MSG_KEY_ANNOTATION_MISSING_DEPRECATED =
|
||||
"annotation.missing.deprecated";
|
||||
|
||||
/**
|
||||
* A key is pointing to the warning message text in "messages.properties"
|
||||
* file.
|
||||
*/
|
||||
public static final String MSG_KEY_JAVADOC_DUPLICATE_TAG =
|
||||
"javadoc.duplicateTag";
|
||||
|
||||
/**
|
||||
* A key is pointing to the warning message text in "messages.properties"
|
||||
* file.
|
||||
*/
|
||||
public static final String MSG_KEY_JAVADOC_MISSING = "javadoc.missing";
|
||||
|
||||
/** {@link Deprecated Deprecated} annotation name */
|
||||
private static final String DEPRECATED = "Deprecated";
|
||||
|
||||
|
|
@ -97,26 +117,6 @@ public final class MissingDeprecatedCheck extends Check
|
|||
/** Multiline finished at next Javadoc * */
|
||||
private static final String NEXT_TAG = "@";
|
||||
|
||||
/**
|
||||
* A key is pointing to the warning message text in "messages.properties"
|
||||
* file.
|
||||
*/
|
||||
public static final String MSG_KEY_ANNOTATION_MISSING_DEPRECATED =
|
||||
"annotation.missing.deprecated";
|
||||
|
||||
/**
|
||||
* A key is pointing to the warning message text in "messages.properties"
|
||||
* file.
|
||||
*/
|
||||
public static final String MSG_KEY_JAVADOC_DUPLICATE_TAG =
|
||||
"javadoc.duplicateTag";
|
||||
|
||||
/**
|
||||
* A key is pointing to the warning message text in "messages.properties"
|
||||
* file.
|
||||
*/
|
||||
public static final String MSG_KEY_JAVADOC_MISSING = "javadoc.missing";
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int[] getDefaultTokens()
|
||||
|
|
|
|||
|
|
@ -77,16 +77,6 @@ import com.puppycrawl.tools.checkstyle.Utils;
|
|||
*/
|
||||
public final class MissingOverrideCheck extends Check
|
||||
{
|
||||
/** {@link Override Override} annotation name */
|
||||
private static final String OVERRIDE = "Override";
|
||||
|
||||
/** fully-qualified {@link Override Override} annotation name */
|
||||
private static final String FQ_OVERRIDE = "java.lang." + OVERRIDE;
|
||||
|
||||
/** compiled regexp to match Javadoc tags with no argument and {} * */
|
||||
private static final Pattern MATCH_INHERITDOC =
|
||||
Utils.createPattern("\\{\\s*@(inheritDoc)\\s*\\}");
|
||||
|
||||
/**
|
||||
* A key is pointing to the warning message text in "messages.properties"
|
||||
* file.
|
||||
|
|
@ -100,6 +90,16 @@ public final class MissingOverrideCheck extends Check
|
|||
public static final String MSG_KEY_ANNOTATION_MISSING_OVERRIDE =
|
||||
"annotation.missing.override";
|
||||
|
||||
/** {@link Override Override} annotation name */
|
||||
private static final String OVERRIDE = "Override";
|
||||
|
||||
/** fully-qualified {@link Override Override} annotation name */
|
||||
private static final String FQ_OVERRIDE = "java.lang." + OVERRIDE;
|
||||
|
||||
/** compiled regexp to match Javadoc tags with no argument and {} * */
|
||||
private static final Pattern MATCH_INHERITDOC =
|
||||
Utils.createPattern("\\{\\s*@(inheritDoc)\\s*\\}");
|
||||
|
||||
/** @see #setJavaFiveCompatibility(boolean) */
|
||||
private boolean javaFiveCompatibility;
|
||||
|
||||
|
|
|
|||
|
|
@ -87,6 +87,13 @@ import com.puppycrawl.tools.checkstyle.checks.AbstractFormatCheck;
|
|||
*/
|
||||
public class SuppressWarningsCheck extends AbstractFormatCheck
|
||||
{
|
||||
/**
|
||||
* A key is pointing to the warning message text in "messages.properties"
|
||||
* file.
|
||||
*/
|
||||
public static final String MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED =
|
||||
"suppressed.warning.not.allowed";
|
||||
|
||||
/** {@link SuppressWarnings SuppressWarnings} annotation name */
|
||||
private static final String SUPPRESS_WARNINGS = "SuppressWarnings";
|
||||
|
||||
|
|
@ -97,13 +104,6 @@ public class SuppressWarningsCheck extends AbstractFormatCheck
|
|||
private static final String FQ_SUPPRESS_WARNINGS =
|
||||
"java.lang." + SUPPRESS_WARNINGS;
|
||||
|
||||
/**
|
||||
* A key is pointing to the warning message text in "messages.properties"
|
||||
* file.
|
||||
*/
|
||||
public static final String MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED =
|
||||
"suppressed.warning.not.allowed";
|
||||
|
||||
/**
|
||||
* Ctor that specifies the default for the format property
|
||||
* as specified in the class javadocs.
|
||||
|
|
|
|||
|
|
@ -87,18 +87,18 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
|||
*/
|
||||
public class AvoidNestedBlocksCheck extends Check
|
||||
{
|
||||
/**
|
||||
* Whether nested blocks are allowed if they are the
|
||||
* only child of a switch case.
|
||||
*/
|
||||
private boolean allowInSwitchCase;
|
||||
|
||||
/**
|
||||
* A key is pointing to the warning message text in "messages.properties"
|
||||
* file.
|
||||
*/
|
||||
public static final String MSG_KEY_BLOCK_NESTED = "block.nested";
|
||||
|
||||
/**
|
||||
* Whether nested blocks are allowed if they are the
|
||||
* only child of a switch case.
|
||||
*/
|
||||
private boolean allowInSwitchCase;
|
||||
|
||||
@Override
|
||||
public int[] getDefaultTokens()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -76,9 +76,6 @@ import com.puppycrawl.tools.checkstyle.checks.AbstractOptionCheck;
|
|||
public class LeftCurlyCheck
|
||||
extends AbstractOptionCheck<LeftCurlyOption>
|
||||
{
|
||||
/** default maximum line length */
|
||||
private static final int DEFAULT_MAX_LINE_LENGTH = 80;
|
||||
|
||||
/**
|
||||
* A key is pointing to the warning message text in "messages.properties"
|
||||
* file.
|
||||
|
|
@ -97,6 +94,9 @@ public class LeftCurlyCheck
|
|||
*/
|
||||
public static final String MSG_KEY_LINE_BREAK_AFTER = "line.break.after";
|
||||
|
||||
/** default maximum line length */
|
||||
private static final int DEFAULT_MAX_LINE_LENGTH = 80;
|
||||
|
||||
/** maxLineLength **/
|
||||
private int maxLineLength = DEFAULT_MAX_LINE_LENGTH;
|
||||
|
||||
|
|
|
|||
|
|
@ -103,17 +103,17 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
*/
|
||||
public class NeedBracesCheck extends Check
|
||||
{
|
||||
/**
|
||||
* Check's option for skipping single-line statements.
|
||||
*/
|
||||
private boolean allowSingleLineStatement;
|
||||
|
||||
/**
|
||||
* A key is pointing to the warning message text in "messages.properties"
|
||||
* file.
|
||||
*/
|
||||
public static final String MSG_KEY_NEED_BRACES = "needBraces";
|
||||
|
||||
/**
|
||||
* Check's option for skipping single-line statements.
|
||||
*/
|
||||
private boolean allowSingleLineStatement;
|
||||
|
||||
/**
|
||||
* Setter.
|
||||
* @param allowSingleLineStatement Check's option for skipping single-line statements
|
||||
|
|
|
|||
|
|
@ -72,9 +72,6 @@ import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
|
|||
*/
|
||||
public class RightCurlyCheck extends AbstractOptionCheck<RightCurlyOption>
|
||||
{
|
||||
/** Do we need to check if rculry starts line. */
|
||||
private boolean shouldStartLine = true;
|
||||
|
||||
/**
|
||||
* A key is pointing to the warning message text in "messages.properties"
|
||||
* file.
|
||||
|
|
@ -99,6 +96,9 @@ public class RightCurlyCheck extends AbstractOptionCheck<RightCurlyOption>
|
|||
*/
|
||||
public static final String MSG_KEY_LINE_NEW = "line.new";
|
||||
|
||||
/** Do we need to check if rculry starts line. */
|
||||
private boolean shouldStartLine = true;
|
||||
|
||||
/**
|
||||
* Sets the right curly option to same.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -64,15 +64,6 @@ public class MultipleStringLiteralsCheck extends Check
|
|||
*/
|
||||
private int allowedDuplicates = 1;
|
||||
|
||||
/**
|
||||
* Sets the maximum allowed duplicates of a string.
|
||||
* @param allowedDuplicates The maximum number of duplicates.
|
||||
*/
|
||||
public void setAllowedDuplicates(int allowedDuplicates)
|
||||
{
|
||||
this.allowedDuplicates = allowedDuplicates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pattern for matching ignored strings.
|
||||
*/
|
||||
|
|
@ -87,6 +78,15 @@ public class MultipleStringLiteralsCheck extends Check
|
|||
ignoreOccurrenceContext.set(TokenTypes.ANNOTATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum allowed duplicates of a string.
|
||||
* @param allowedDuplicates The maximum number of duplicates.
|
||||
*/
|
||||
public void setAllowedDuplicates(int allowedDuplicates)
|
||||
{
|
||||
this.allowedDuplicates = allowedDuplicates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets regular expression pattern for ignored strings.
|
||||
* @param ignoreStringsRegexp
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ public class InnerTypeLastCheck extends Check
|
|||
*/
|
||||
public static final String MSG_KEY = "arrangement.members.before.inner";
|
||||
|
||||
/** Meet a root class. */
|
||||
private boolean rootClass = true;
|
||||
|
||||
@Override
|
||||
public int[] getDefaultTokens()
|
||||
{
|
||||
|
|
@ -53,9 +56,6 @@ public class InnerTypeLastCheck extends Check
|
|||
return new int[] {TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF};
|
||||
}
|
||||
|
||||
/** Meet a root class. */
|
||||
private boolean rootClass = true;
|
||||
|
||||
@Override
|
||||
public void visitToken(DetailAST ast)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -238,6 +238,39 @@ public class VisibilityModifierCheck
|
|||
*/
|
||||
public static final String MSG_KEY = "variable.notPrivate";
|
||||
|
||||
/** Default immutable types canonical names. */
|
||||
private static final List<String> DEFAULT_IMMUTABLE_TYPES = ImmutableList.of(
|
||||
"java.lang.String",
|
||||
"java.lang.Integer",
|
||||
"java.lang.Byte",
|
||||
"java.lang.Character",
|
||||
"java.lang.Short",
|
||||
"java.lang.Boolean",
|
||||
"java.lang.Long",
|
||||
"java.lang.Double",
|
||||
"java.lang.Float",
|
||||
"java.lang.StackTraceElement",
|
||||
"java.math.BigInteger",
|
||||
"java.math.BigDecimal",
|
||||
"java.io.File",
|
||||
"java.util.Locale",
|
||||
"java.util.UUID",
|
||||
"java.net.URL",
|
||||
"java.net.URI",
|
||||
"java.net.Inet4Address",
|
||||
"java.net.Inet6Address",
|
||||
"java.net.InetSocketAddress"
|
||||
);
|
||||
|
||||
/** Default ignore annotations canonical names. */
|
||||
private static final List<String> DEFAULT_IGNORE_ANNOTATIONS = ImmutableList.of(
|
||||
"org.junit.Rule",
|
||||
"com.google.common.annotations.VisibleForTesting"
|
||||
);
|
||||
|
||||
/** contains explicit access modifiers. */
|
||||
private static final String[] EXPLICIT_MODS = {"public", "private", "protected"};
|
||||
|
||||
/** whether protected members are allowed */
|
||||
private boolean protectedAllowed;
|
||||
|
||||
|
|
@ -274,39 +307,6 @@ public class VisibilityModifierCheck
|
|||
private final List<String> immutableClassShortNames =
|
||||
getClassShortNames(DEFAULT_IMMUTABLE_TYPES);
|
||||
|
||||
/** Default immutable types canonical names. */
|
||||
private static final List<String> DEFAULT_IMMUTABLE_TYPES = ImmutableList.of(
|
||||
"java.lang.String",
|
||||
"java.lang.Integer",
|
||||
"java.lang.Byte",
|
||||
"java.lang.Character",
|
||||
"java.lang.Short",
|
||||
"java.lang.Boolean",
|
||||
"java.lang.Long",
|
||||
"java.lang.Double",
|
||||
"java.lang.Float",
|
||||
"java.lang.StackTraceElement",
|
||||
"java.math.BigInteger",
|
||||
"java.math.BigDecimal",
|
||||
"java.io.File",
|
||||
"java.util.Locale",
|
||||
"java.util.UUID",
|
||||
"java.net.URL",
|
||||
"java.net.URI",
|
||||
"java.net.Inet4Address",
|
||||
"java.net.Inet6Address",
|
||||
"java.net.InetSocketAddress"
|
||||
);
|
||||
|
||||
/** Default ignore annotations canonical names. */
|
||||
private static final List<String> DEFAULT_IGNORE_ANNOTATIONS = ImmutableList.of(
|
||||
"org.junit.Rule",
|
||||
"com.google.common.annotations.VisibleForTesting"
|
||||
);
|
||||
|
||||
/** contains explicit access modifiers. */
|
||||
private static final String[] EXPLICIT_MODS = {"public", "private", "protected"};
|
||||
|
||||
/** @return whether protected members are allowed */
|
||||
public boolean isProtectedAllowed()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -56,12 +56,12 @@ final class ImportControlLoader extends AbstractLoader
|
|||
private static final String DTD_RESOURCE_NAME_1_1 =
|
||||
"com/puppycrawl/tools/checkstyle/checks/imports/import_control_1_1.dtd";
|
||||
|
||||
/** Used to hold the {@link PkgControl} objects. */
|
||||
private final Deque<PkgControl> stack = new ArrayDeque<>();
|
||||
|
||||
/** the map to lookup the resource name by the id */
|
||||
private static final Map<String, String> DTD_RESOURCE_BY_ID = new HashMap<>();
|
||||
|
||||
/** Used to hold the {@link PkgControl} objects. */
|
||||
private final Deque<PkgControl> stack = new ArrayDeque<>();
|
||||
|
||||
/** Initialise the map */
|
||||
static {
|
||||
DTD_RESOURCE_BY_ID.put(DTD_PUBLIC_ID_1_0, DTD_RESOURCE_NAME_1_0);
|
||||
|
|
|
|||
|
|
@ -56,15 +56,6 @@ public class BlockParentHandler extends ExpressionHandler
|
|||
TokenTypes.LITERAL_CONTINUE,
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns array of token types which should be checked among childrens.
|
||||
* @return array of token types to check.
|
||||
*/
|
||||
protected int[] getCheckedChildren()
|
||||
{
|
||||
return CHECKED_CHILDREN.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance of this handler with the given indentation check,
|
||||
* name, abstract syntax tree, and parent handler.
|
||||
|
|
@ -80,6 +71,15 @@ public class BlockParentHandler extends ExpressionHandler
|
|||
super(indentCheck, name, ast, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array of token types which should be checked among childrens.
|
||||
* @return array of token types to check.
|
||||
*/
|
||||
protected int[] getCheckedChildren()
|
||||
{
|
||||
return CHECKED_CHILDREN.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the top level expression being managed by this handler.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -45,30 +45,9 @@ public class HandlerFactory
|
|||
private final Map<Integer, Constructor<?>> typeHandlers =
|
||||
Maps.newHashMap();
|
||||
|
||||
/**
|
||||
* registers a handler
|
||||
*
|
||||
* @param type
|
||||
* type from TokenTypes
|
||||
* @param handlerClass
|
||||
* the handler to register
|
||||
*/
|
||||
private void register(int type, Class<?> handlerClass)
|
||||
{
|
||||
try {
|
||||
final Constructor<?> ctor = handlerClass
|
||||
.getConstructor(new Class[] {IndentationCheck.class,
|
||||
DetailAST.class, // current AST
|
||||
ExpressionHandler.class, // parent
|
||||
});
|
||||
typeHandlers.put(type, ctor);
|
||||
}
|
||||
catch (final NoSuchMethodException | SecurityException e) {
|
||||
final String message = "couldn't find ctor for " + handlerClass;
|
||||
LOG.debug(message, e);
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
}
|
||||
/** cache for created method call handlers */
|
||||
private final Map<DetailAST, ExpressionHandler> createdHandlers =
|
||||
Maps.newHashMap();
|
||||
|
||||
/** Creates a HandlerFactory. */
|
||||
public HandlerFactory()
|
||||
|
|
@ -104,6 +83,31 @@ public class HandlerFactory
|
|||
register(TokenTypes.LITERAL_SYNCHRONIZED, SynchronizedHandler.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* registers a handler
|
||||
*
|
||||
* @param type
|
||||
* type from TokenTypes
|
||||
* @param handlerClass
|
||||
* the handler to register
|
||||
*/
|
||||
private void register(int type, Class<?> handlerClass)
|
||||
{
|
||||
try {
|
||||
final Constructor<?> ctor = handlerClass
|
||||
.getConstructor(new Class[] {IndentationCheck.class,
|
||||
DetailAST.class, // current AST
|
||||
ExpressionHandler.class, // parent
|
||||
});
|
||||
typeHandlers.put(type, ctor);
|
||||
}
|
||||
catch (final NoSuchMethodException | SecurityException e) {
|
||||
final String message = "couldn't find ctor for " + handlerClass;
|
||||
LOG.debug(message, e);
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this type (form TokenTypes) is handled.
|
||||
*
|
||||
|
|
@ -209,8 +213,4 @@ public class HandlerFactory
|
|||
{
|
||||
createdHandlers.clear();
|
||||
}
|
||||
|
||||
/** cache for created method call handlers */
|
||||
private final Map<DetailAST, ExpressionHandler> createdHandlers =
|
||||
Maps.newHashMap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,14 +74,14 @@ 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]$");
|
||||
|
||||
/**
|
||||
* Allow one character name for initialization expression in FOR loop.
|
||||
*/
|
||||
private boolean allowOneCharVarInForLoop;
|
||||
|
||||
/** Regexp for one-char loop variables. */
|
||||
private static Pattern sSingleChar = Pattern.compile("^[a-z]$");
|
||||
|
||||
/** Creates a new <code>LocalVariableNameCheck</code> instance. */
|
||||
public LocalVariableNameCheck()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -80,11 +80,6 @@ public class MethodNameCheck
|
|||
*/
|
||||
public static final String MSG_KEY = "method.name.equals.class.name";
|
||||
|
||||
/**
|
||||
* for allowing method name to be the same as the class name.
|
||||
*/
|
||||
private boolean allowClassName;
|
||||
|
||||
/**
|
||||
* {@link Override Override} annotation name.
|
||||
*/
|
||||
|
|
@ -95,6 +90,11 @@ public class MethodNameCheck
|
|||
*/
|
||||
private static final String CANONICAL_OVERRIDE = "java.lang." + OVERRIDE;
|
||||
|
||||
/**
|
||||
* for allowing method name to be the same as the class name.
|
||||
*/
|
||||
private boolean allowClassName;
|
||||
|
||||
/** Creates a new <code>MethodNameCheck</code> instance. */
|
||||
public MethodNameCheck()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -63,12 +63,12 @@ public class MethodLengthCheck extends Check
|
|||
*/
|
||||
public static final String MSG_KEY = "maxLen.method";
|
||||
|
||||
/** whether to ignore empty lines and single line comments */
|
||||
private boolean countEmpty = true;
|
||||
|
||||
/** default maximum number of lines */
|
||||
private static final int DEFAULT_MAX_LINES = 150;
|
||||
|
||||
/** whether to ignore empty lines and single line comments */
|
||||
private boolean countEmpty = true;
|
||||
|
||||
/** the maximum number of lines */
|
||||
private int max = DEFAULT_MAX_LINES;
|
||||
|
||||
|
|
|
|||
|
|
@ -84,6 +84,10 @@ public class MethodParamPadCheck
|
|||
*/
|
||||
public static final String WS_NOT_PRECEDED = "ws.notPreceded";
|
||||
|
||||
/** Whether whitespace is allowed if the method identifier is at a
|
||||
* linebreak */
|
||||
private boolean allowLineBreaks;
|
||||
|
||||
/**
|
||||
* Sets the pad option to nospace.
|
||||
*/
|
||||
|
|
@ -92,10 +96,6 @@ public class MethodParamPadCheck
|
|||
super(PadOption.NOSPACE, PadOption.class);
|
||||
}
|
||||
|
||||
/** Whether whitespace is allowed if the method identifier is at a
|
||||
* linebreak */
|
||||
private boolean allowLineBreaks;
|
||||
|
||||
@Override
|
||||
public int[] getDefaultTokens()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -36,24 +36,6 @@ class CSVFilter implements IntFilter
|
|||
/** filter set */
|
||||
private final Set<IntFilter> filters = Sets.newHashSet();
|
||||
|
||||
/**
|
||||
* Adds a IntFilter to the set.
|
||||
* @param filter the IntFilter to add.
|
||||
*/
|
||||
public void addFilter(IntFilter filter)
|
||||
{
|
||||
filters.add(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the IntFilters of the filter set.
|
||||
* @return the IntFilters of the filter set.
|
||||
*/
|
||||
protected Set<IntFilter> getFilters()
|
||||
{
|
||||
return filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>CSVFilter</code> from a CSV, Comma-Separated Values,
|
||||
* string. Each value is an integer, or a range of integers. A range of
|
||||
|
|
@ -84,6 +66,24 @@ class CSVFilter implements IntFilter
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a IntFilter to the set.
|
||||
* @param filter the IntFilter to add.
|
||||
*/
|
||||
public void addFilter(IntFilter filter)
|
||||
{
|
||||
filters.add(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the IntFilters of the filter set.
|
||||
* @return the IntFilters of the filter set.
|
||||
*/
|
||||
protected Set<IntFilter> getFilters()
|
||||
{
|
||||
return filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether an Integer matches a CSV integer value.
|
||||
* @param intValue the Integer to check.
|
||||
|
|
|
|||
|
|
@ -34,10 +34,10 @@ import static com.puppycrawl.tools.checkstyle.checks.regexp.MultilineDetector.RE
|
|||
|
||||
public class RegexpMultilineCheckTest extends BaseFileSetCheckTestSupport
|
||||
{
|
||||
private DefaultConfiguration checkConfig;
|
||||
|
||||
@Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
private DefaultConfiguration checkConfig;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue