Recording work before documentation - based on patch #2953941

This commit is contained in:
Oliver Burn 2010-02-22 10:57:20 +00:00
parent 139609ac5d
commit ca9c59e8dc
2 changed files with 103 additions and 5 deletions

View File

@ -86,6 +86,13 @@ public class DeclarationOrderCheck extends Check
private Scope mDeclarationAccess = Scope.PUBLIC;
}
/** If true, ignores the check to constructors. */
private boolean mIgnoreConstructors;
/** If true, ignore the check to methods. */
private boolean mIgnoreMethods;
/** If true, ignore the check to modifiers (fields, ...). */
private boolean mIgnoreModifiers;
@Override
public int[] getDefaultTokens()
{
@ -115,7 +122,9 @@ public class DeclarationOrderCheck extends Check
state = mScopeStates.peek();
if (state.mScopeState > STATE_CTOR_DEF) {
log(aAST, "declaration.order.constructor");
if (!mIgnoreConstructors) {
log(aAST, "declaration.order.constructor");
}
}
else {
state.mScopeState = STATE_CTOR_DEF;
@ -129,7 +138,9 @@ public class DeclarationOrderCheck extends Check
}
if (state.mScopeState > STATE_METHOD_DEF) {
log(aAST, "declaration.order.method");
if (!mIgnoreMethods) {
log(aAST, "declaration.order.method");
}
}
else {
state.mScopeState = STATE_METHOD_DEF;
@ -147,7 +158,9 @@ public class DeclarationOrderCheck extends Check
state = mScopeStates.peek();
if (aAST.findFirstToken(TokenTypes.LITERAL_STATIC) != null) {
if (state.mScopeState > STATE_STATIC_VARIABLE_DEF) {
log(aAST, "declaration.order.static");
if (!mIgnoreModifiers) {
log(aAST, "declaration.order.static");
}
}
else {
state.mScopeState = STATE_STATIC_VARIABLE_DEF;
@ -155,7 +168,9 @@ public class DeclarationOrderCheck extends Check
}
else {
if (state.mScopeState > STATE_INSTANCE_VARIABLE_DEF) {
log(aAST, "declaration.order.instance");
if (!mIgnoreModifiers) {
log(aAST, "declaration.order.instance");
}
}
else if (state.mScopeState == STATE_STATIC_VARIABLE_DEF) {
state.mDeclarationAccess = Scope.PUBLIC;
@ -165,7 +180,9 @@ public class DeclarationOrderCheck extends Check
final Scope access = ScopeUtils.getScopeFromMods(aAST);
if (state.mDeclarationAccess.compareTo(access) > 0) {
log(aAST, "declaration.order.access");
if (!mIgnoreModifiers) {
log(aAST, "declaration.order.access");
}
}
else {
state.mDeclarationAccess = access;
@ -187,4 +204,31 @@ public class DeclarationOrderCheck extends Check
default:
}
}
/**
* Sets whether to ignore constructors.
* @param aIgnoreConstructors whether to ignore constructors.
*/
public void setIgnoreConstructors(boolean aIgnoreConstructors)
{
mIgnoreConstructors = aIgnoreConstructors;
}
/**
* Sets whether to ignore methods.
* @param aIgnoreMethods whether to ignore methods.
*/
public void setIgnoreMethods(boolean aIgnoreMethods)
{
mIgnoreMethods = aIgnoreMethods;
}
/**
* Sets whether to ignore modifiers.
* @param aIgnoreModifiers whether to ignore modifiers.
*/
public void setIgnoreModifiers(boolean aIgnoreModifiers)
{
mIgnoreModifiers = aIgnoreModifiers;
}
}

View File

@ -43,4 +43,58 @@ public class DeclarationOrderCheckTest
};
verify(checkConfig, getPath("coding/InputDeclarationOrder.java"), expected);
}
@Test
public void testOnlyConstructors() throws Exception
{
final DefaultConfiguration checkConfig =
createCheckConfig(DeclarationOrderCheck.class);
checkConfig.addAttribute("ignoreConstructors", "false");
checkConfig.addAttribute("ignoreMethods", "true");
checkConfig.addAttribute("ignoreModifiers", "true");
final String[] expected = {
"54:5: Constructor definition in wrong order.",
"152:5: Constructor definition in wrong order.",
};
verify(checkConfig, getPath("coding/InputDeclarationOrder.java"), expected);
}
@Test
public void testOnlyModifiers() throws Exception
{
final DefaultConfiguration checkConfig =
createCheckConfig(DeclarationOrderCheck.class);
checkConfig.addAttribute("ignoreConstructors", "true");
checkConfig.addAttribute("ignoreMethods", "true");
checkConfig.addAttribute("ignoreModifiers", "false");
final String[] expected = {
"8:5: Variable access definition in wrong order.",
"13:5: Variable access definition in wrong order.",
"18:5: Variable access definition in wrong order.",
"21:5: Variable access definition in wrong order.",
"27:5: Static variable definition in wrong order.",
"27:5: Variable access definition in wrong order.",
"34:9: Variable access definition in wrong order.",
"45:9: Static variable definition in wrong order.",
"45:9: Variable access definition in wrong order.",
"80:5: Instance variable definition in wrong order.",
"92:9: Variable access definition in wrong order.",
"100:9: Static variable definition in wrong order.",
"100:9: Variable access definition in wrong order.",
"106:5: Variable access definition in wrong order.",
"111:5: Variable access definition in wrong order.",
"116:5: Variable access definition in wrong order.",
"119:5: Variable access definition in wrong order.",
"125:5: Static variable definition in wrong order.",
"125:5: Variable access definition in wrong order.",
"132:9: Variable access definition in wrong order.",
"143:9: Static variable definition in wrong order.",
"143:9: Variable access definition in wrong order.",
"178:5: Instance variable definition in wrong order.",
};
verify(checkConfig, getPath("coding/InputDeclarationOrder.java"), expected);
}
}