Move things from BinaryOp
This commit is contained in:
8 files changed
+33
-32
No files matched your search
@@ -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<BinaryOp> 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<BinaryOp> 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<BinaryOp> 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<BinaryOp> 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<BinaryOp> 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;
|
||||
}
|
||||
}
|
||||
+23
-1
@@ -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<BinaryOp> 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;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user