Issue #2451: removed excess hierarchy from NoCloneCheck

This commit is contained in:
rnveach 2015-11-06 14:15:55 -05:00 committed by Roman Ivanov
parent 17eaaa5a0a
commit 03a24c2e44
1 changed files with 35 additions and 6 deletions

View File

@ -19,6 +19,10 @@
package com.puppycrawl.tools.checkstyle.checks.coding;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
/**
* <p>
* Checks that the clone method is not overridden from the
@ -112,7 +116,7 @@ package com.puppycrawl.tools.checkstyle.checks.coding;
* @author Travis Schneeberger
* @see Object#clone()
*/
public class NoCloneCheck extends AbstractIllegalMethodCheck {
public class NoCloneCheck extends Check {
/**
* A key is pointing to the warning message text in "messages.properties"
@ -120,10 +124,35 @@ public class NoCloneCheck extends AbstractIllegalMethodCheck {
*/
public static final String MSG_KEY = "avoid.clone.method";
/**
* Creates an instance.
*/
public NoCloneCheck() {
super("clone", MSG_KEY);
@Override
public int[] getDefaultTokens() {
return getAcceptableTokens();
}
@Override
public int[] getAcceptableTokens() {
return new int[] {TokenTypes.METHOD_DEF};
}
@Override
public int[] getRequiredTokens() {
return getAcceptableTokens();
}
@Override
public void visitToken(DetailAST aAST) {
final DetailAST mid = aAST.findFirstToken(TokenTypes.IDENT);
final String name = mid.getText();
if ("clone".equals(name)) {
final DetailAST params = aAST.findFirstToken(TokenTypes.PARAMETERS);
final boolean hasEmptyParamList =
!params.branchContains(TokenTypes.PARAMETER_DEF);
if (hasEmptyParamList) {
log(aAST.getLineNo(), MSG_KEY);
}
}
}
}