From e6571e6f5703fdd89bc6cbeddcce767e58ddbf50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20K=C3=BChne?= Date: Thu, 7 Nov 2002 19:10:10 +0000 Subject: [PATCH] removed paranoia checks to increase code coverage --- .../checks/EqualsHashCodeCheck.java | 9 ------- .../checks/SimplifyBooleanReturnCheck.java | 26 +++++++++++-------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/EqualsHashCodeCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/EqualsHashCodeCheck.java index 9c40cdce8..904af5dc4 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/EqualsHashCodeCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/EqualsHashCodeCheck.java @@ -70,11 +70,6 @@ public class EqualsHashCodeCheck /** @see Check */ public void visitToken(DetailAST aAST) { - // paranoia - if (aAST.getType() != TokenTypes.METHOD_DEF) { - return; - } - DetailAST modifiers = (DetailAST) aAST.getFirstChild(); AST type = modifiers.getNextSibling(); @@ -106,10 +101,6 @@ public class EqualsHashCodeCheck */ private boolean isObjectParam(AST aFirstChild) { - if (aFirstChild.getType() != TokenTypes.PARAMETER_DEF) { - return false; - } - final AST modifiers = aFirstChild.getFirstChild(); AST type = modifiers.getNextSibling(); switch (type.getFirstChild().getType()) { diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/SimplifyBooleanReturnCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/SimplifyBooleanReturnCheck.java index a886b11db..78add91b7 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/SimplifyBooleanReturnCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/SimplifyBooleanReturnCheck.java @@ -30,7 +30,7 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST; * * Idea shamelessly stolen from the equivalent PMD rule (pmd.sourceforge.net). * - * @author Lars K?hne + * @author Lars Kühne */ public class SimplifyBooleanReturnCheck extends Check @@ -44,11 +44,6 @@ public class SimplifyBooleanReturnCheck /** @see com.puppycrawl.tools.checkstyle.api.Check */ public void visitToken(DetailAST aAST) { - // paranoia - what an untrusting sole :-) - if (aAST.getType() != TokenTypes.LITERAL_IF) { - throw new IllegalArgumentException("not an if"); - } - // LITERAL_IF has the following four or five children: // '(' // condition @@ -97,7 +92,7 @@ public class SimplifyBooleanReturnCheck * @param aAST the sytax tree to check * @return if aAST is a return statment with a boolean literal. */ - private boolean returnsOnlyBooleanLiteral(AST aAST) + private static boolean returnsOnlyBooleanLiteral(AST aAST) { if (isBooleanLiteralReturnStatement(aAST)) { return true; @@ -119,7 +114,7 @@ public class SimplifyBooleanReturnCheck * @param aAST the sytax tree to check * @return if aAST is a return statment with a boolean literal. */ - private boolean isBooleanLiteralReturnStatement(AST aAST) + private static boolean isBooleanLiteralReturnStatement(AST aAST) { if (aAST == null || aAST.getType() != TokenTypes.LITERAL_RETURN) { return false; @@ -132,9 +127,18 @@ public class SimplifyBooleanReturnCheck } final AST value = expr.getFirstChild(); + return isBooleanLiteralType(value.getType()); + } - final int valueType = value.getType(); - return ((valueType == TokenTypes.LITERAL_TRUE) - || (valueType == TokenTypes.LITERAL_FALSE)); + /** + * Checks if a token type is a literal true or false. + * @param aTokenType the TokenType + * @return true iff aTokenType is LITERAL_TRUE or LITERAL_FALSE + */ + private static boolean isBooleanLiteralType(final int aTokenType) + { + final boolean isTrue = (aTokenType == TokenTypes.LITERAL_TRUE); + final boolean isFalse = (aTokenType == TokenTypes.LITERAL_FALSE); + return isTrue || isFalse; } }