diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/BinaryOp.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/BinaryOp.java index 0e53569546..a740fa67da 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/BinaryOp.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/BinaryOp.java @@ -86,14 +86,14 @@ public enum BinaryOp implements InternalInterfaces.OperatorLike { /** Modulo {@code "%"} operator. */ MOD("%"); - /** Set of {@code &&} and {@code ||}. Use with {@link #isInfixExprWithOperator(JavaNode, Set)}. */ + /** Set of {@code &&} and {@code ||}. Use with {@link net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils#isInfixExprWithOperator(JavaNode, Set)}. */ public static final Set CONDITIONAL_OPS = CollectionUtil.immutableEnumSet(CONDITIONAL_AND, CONDITIONAL_OR); - /** Set of {@code <}, {@code <=}, {@code >=} and {@code >}. Use with {@link #isInfixExprWithOperator(JavaNode, Set)}. */ + /** Set of {@code <}, {@code <=}, {@code >=} and {@code >}. Use with {@link net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils#isInfixExprWithOperator(JavaNode, Set)}. */ public static final Set COMPARISON_OPS = CollectionUtil.immutableEnumSet(LE, GE, GT, LT); - /** Set of {@code ==} and {@code !=}. Use with {@link #isInfixExprWithOperator(JavaNode, Set)}. */ + /** Set of {@code ==} and {@code !=}. Use with {@link net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils#isInfixExprWithOperator(JavaNode, Set)}. */ public static final Set EQUALITY_OPS = CollectionUtil.immutableEnumSet(EQ, NE); - /** Set of {@code <<}, {@code >>} and {@code >>>}. Use with {@link #isInfixExprWithOperator(JavaNode, Set)}. */ + /** Set of {@code <<}, {@code >>} and {@code >>>}. Use with {@link net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils#isInfixExprWithOperator(JavaNode, Set)}. */ public static final Set SHIFT_OPS = CollectionUtil.immutableEnumSet(LEFT_SHIFT, RIGHT_SHIFT, UNSIGNED_RIGHT_SHIFT); private final String code; @@ -212,25 +212,4 @@ public enum BinaryOp implements InternalInterfaces.OperatorLike { } - /** - * Tests if the node is an {@link ASTInfixExpression} with one of the given operators. - */ - public static boolean isInfixExprWithOperator(@Nullable JavaNode e, Set operators) { - if (e instanceof ASTInfixExpression) { - ASTInfixExpression infix = (ASTInfixExpression) e; - return operators.contains(infix.getOperator()); - } - return false; - } - - /** - * Tests if the node is an {@link ASTInfixExpression} with the given operator. - */ - public static boolean isInfixExprWithOperator(@Nullable JavaNode e, BinaryOp operator) { - if (e instanceof ASTInfixExpression) { - ASTInfixExpression infix = (ASTInfixExpression) e; - return operator == infix.getOperator(); - } - return false; - } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/internal/JavaAstUtils.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/internal/JavaAstUtils.java index ac4d64a5e3..7214dbeb30 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/internal/JavaAstUtils.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/internal/JavaAstUtils.java @@ -86,7 +86,7 @@ public final class JavaAstUtils { public static boolean isConditional(JavaNode ifx) { - return BinaryOp.isInfixExprWithOperator(ifx, BinaryOp.CONDITIONAL_OPS); + return isInfixExprWithOperator(ifx, BinaryOp.CONDITIONAL_OPS); } public static int numAlternatives(ASTSwitchBranch n) { @@ -693,4 +693,26 @@ public final class JavaAstUtils { || it instanceof ASTSwitchStatement || it instanceof ASTLabeledStatement; } + + /** + * Tests if the node is an {@link ASTInfixExpression} with one of the given operators. + */ + public static boolean isInfixExprWithOperator(@Nullable JavaNode e, Set operators) { + if (e instanceof ASTInfixExpression) { + ASTInfixExpression infix = (ASTInfixExpression) e; + return operators.contains(infix.getOperator()); + } + return false; + } + + /** + * Tests if the node is an {@link ASTInfixExpression} with the given operator. + */ + public static boolean isInfixExprWithOperator(@Nullable JavaNode e, BinaryOp operator) { + if (e instanceof ASTInfixExpression) { + ASTInfixExpression infix = (ASTInfixExpression) e; + return operator == infix.getOperator(); + } + return false; + } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/ForLoopCanBeForeachRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/ForLoopCanBeForeachRule.java index 59eb021efd..542ebadedb 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/ForLoopCanBeForeachRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/ForLoopCanBeForeachRule.java @@ -139,7 +139,7 @@ public class ForLoopCanBeForeachRule extends AbstractJavaRulechainRule { * @return The name, or null if it couldn't be found or the guard condition is not safe to refactor (then abort) */ private @Nullable ASTNamedReferenceExpr findIterableFromCondition(ASTExpression guardCondition, ASTVariableDeclaratorId indexVar) { - if (!BinaryOp.isInfixExprWithOperator(guardCondition, BinaryOp.COMPARISON_OPS)) { + if (!JavaAstUtils.isInfixExprWithOperator(guardCondition, BinaryOp.COMPARISON_OPS)) { return null; } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/SimplifiableTestAssertionRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/SimplifiableTestAssertionRule.java index 64c6c60af9..cf477cbc77 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/SimplifiableTestAssertionRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/SimplifiableTestAssertionRule.java @@ -129,7 +129,7 @@ public class SimplifiableTestAssertionRule extends AbstractJavaRulechainRule { private ASTInfixExpression asEqualityExpr(ASTExpression node) { - if (BinaryOp.isInfixExprWithOperator(node, BinaryOp.EQUALITY_OPS)) { + if (JavaAstUtils.isInfixExprWithOperator(node, BinaryOp.EQUALITY_OPS)) { return (ASTInfixExpression) node; } return null; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryCastRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryCastRule.java index 6cad24aebc..5d422e65fd 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryCastRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryCastRule.java @@ -14,7 +14,7 @@ import static net.sourceforge.pmd.lang.java.ast.BinaryOp.MOD; import static net.sourceforge.pmd.lang.java.ast.BinaryOp.MUL; import static net.sourceforge.pmd.lang.java.ast.BinaryOp.SHIFT_OPS; import static net.sourceforge.pmd.lang.java.ast.BinaryOp.SUB; -import static net.sourceforge.pmd.lang.java.ast.BinaryOp.isInfixExprWithOperator; +import static net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils.isInfixExprWithOperator; import java.util.EnumSet; import java.util.Set; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/LawOfDemeterRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/LawOfDemeterRule.java index fa100cfbc0..d6aa57e247 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/LawOfDemeterRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/LawOfDemeterRule.java @@ -5,9 +5,9 @@ package net.sourceforge.pmd.lang.java.rule.design; import static net.sourceforge.pmd.lang.java.ast.BinaryOp.INSTANCEOF; -import static net.sourceforge.pmd.lang.java.ast.BinaryOp.isInfixExprWithOperator; import static net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils.isArrayLengthFieldAccess; import static net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils.isCallOnThisInstance; +import static net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils.isInfixExprWithOperator; import static net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils.isRefToFieldOfThisClass; import static net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils.isThisOrSuper; import static net.sourceforge.pmd.lang.java.rule.internal.JavaRuleUtil.isGetterCall; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SimplifyBooleanReturnsRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SimplifyBooleanReturnsRule.java index 24f4bb9f11..ae0a84cd17 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SimplifyBooleanReturnsRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SimplifyBooleanReturnsRule.java @@ -12,10 +12,10 @@ import static net.sourceforge.pmd.lang.java.ast.BinaryOp.GT; import static net.sourceforge.pmd.lang.java.ast.BinaryOp.LE; import static net.sourceforge.pmd.lang.java.ast.BinaryOp.LT; import static net.sourceforge.pmd.lang.java.ast.BinaryOp.NE; -import static net.sourceforge.pmd.lang.java.ast.BinaryOp.isInfixExprWithOperator; import static net.sourceforge.pmd.lang.java.ast.BinaryOp.opsWithGreaterPrecedence; import static net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils.areComplements; import static net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils.isBooleanLiteral; +import static net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils.isInfixExprWithOperator; import java.util.EnumSet; import java.util.Set; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SimplifyConditionalRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SimplifyConditionalRule.java index e465af2da8..fb44ca8fca 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SimplifyConditionalRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SimplifyConditionalRule.java @@ -8,9 +8,9 @@ import static net.sourceforge.pmd.lang.java.ast.BinaryOp.CONDITIONAL_AND; import static net.sourceforge.pmd.lang.java.ast.BinaryOp.CONDITIONAL_OR; import static net.sourceforge.pmd.lang.java.ast.BinaryOp.INSTANCEOF; import static net.sourceforge.pmd.lang.java.ast.BinaryOp.NE; -import static net.sourceforge.pmd.lang.java.ast.BinaryOp.isInfixExprWithOperator; import static net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils.getOtherOperandIfInInfixExpr; import static net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils.isBooleanNegation; +import static net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils.isInfixExprWithOperator; import static net.sourceforge.pmd.lang.java.rule.internal.JavaRuleUtil.isNullCheck; import net.sourceforge.pmd.lang.java.ast.ASTExpression;