Now ConstantName check will skip serialPersistentFields (bugid 1097285)
This commit is contained in:
parent
fe3a1a7100
commit
166157213b
|
|
@ -29,7 +29,8 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
* by the format property.
|
||||
* A <em>constant</em> is a <strong>static</strong> and <strong>final</strong>
|
||||
* field or an interface/annotation field, except
|
||||
* <strong>serialVersionUID</strong>. The format is a regular expression
|
||||
* <strong>serialVersionUID</strong> and <strong>serialPersistentFields
|
||||
* </strong>. The format is a regular expression
|
||||
* and defaults to <strong>^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$</strong>.
|
||||
* </p>
|
||||
* <p>
|
||||
|
|
@ -82,11 +83,12 @@ public class ConstantNameCheck
|
|||
if ((isStatic && isFinal)
|
||||
|| ScopeUtils.inInterfaceOrAnnotationBlock(aAST))
|
||||
{
|
||||
// Handle the serialVersionUID constant which is used for
|
||||
// Serialization. Cannot enforce rules on it. :-)
|
||||
// Handle the serialVersionUID and serialPersistentFields constants
|
||||
// which are used for Serialization. Cannot enforce rules on it. :-)
|
||||
final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT);
|
||||
if ((nameAST != null)
|
||||
&& !("serialVersionUID".equals(nameAST.getText())))
|
||||
&& !("serialVersionUID".equals(nameAST.getText()))
|
||||
&& !("serialPersistentFields".equals(nameAST.getText())))
|
||||
{
|
||||
retVal = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
public class InputConstantNames
|
||||
{
|
||||
private static final long serialVersionUID = 1L; //should be ignored
|
||||
private static final ObjectStreamField[] serialPersistentFields = {}; // should be ignored too
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package com.puppycrawl.tools.checkstyle.checks.naming;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
|
||||
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
|
||||
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
|
||||
|
|
@ -45,4 +47,14 @@ public class ConstantNameCheckTest
|
|||
};
|
||||
verify(checkConfig, getPath("InputInner.java"), expected);
|
||||
}
|
||||
|
||||
public void testDefault1()
|
||||
throws Exception
|
||||
{
|
||||
final DefaultConfiguration checkConfig =
|
||||
createCheckConfig(ConstantNameCheck.class);
|
||||
final String[] expected = {
|
||||
};
|
||||
verify(checkConfig, getPath("naming" + File.separator + "InputConstantNames.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue