Enum BinaryOp
- java.lang.Object
-
- java.lang.Enum<BinaryOp>
-
- net.sourceforge.pmd.lang.java.ast.BinaryOp
-
- All Implemented Interfaces:
Serializable
,Comparable<BinaryOp>
public enum BinaryOp extends Enum<BinaryOp>
Represents the operator of an infix expression. Constants are roughly ordered by precedence, except some of them have the same precedence.All of those operators are left-associative.
- See Also:
UnaryOp
,AssignmentOp
-
-
Enum Constant Summary
Enum Constants Enum Constant Description ADD
Addition"+"
operator, or string concatenation.AND
AND"&"
operator.CONDITIONAL_AND
Conditional (shortcut) AND"&&"
operator.CONDITIONAL_OR
Conditional (shortcut) OR"||"
operator.DIV
Division"/"
operator.EQ
Equals"=="
operator.GE
Greater-or-equal">="
operator.GT
Greater-than">"
operator.INSTANCEOF
Type test"instanceof"
operator.LE
Lower-or-equal"<="
operator.LEFT_SHIFT
Left shift"<<"
operator.LT
Lower-than"<"
operator.MOD
Modulo"%"
operator.MUL
Multiplication"*"
operator.NE
Not-equals"!="
operator.OR
OR"|"
operator.RIGHT_SHIFT
Right shift">>"
operator.SUB
Subtraction"-"
operator.UNSIGNED_RIGHT_SHIFT
Unsigned right shift">>>"
operator.XOR
XOR"^"
operator.
-
Field Summary
Fields Modifier and Type Field Description static Set<BinaryOp>
COMPARISON_OPS
Set of<
,<=
,>=
and>
.static Set<BinaryOp>
CONDITIONAL_OPS
Set of&&
and||
.static Set<BinaryOp>
EQUALITY_OPS
Set of==
and!=
.static Set<BinaryOp>
SHIFT_OPS
Set of<<
,>>
and>>>
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
comparePrecedence(@NonNull BinaryOp other)
Compare the precedence of this operator with that of the other, as if with aComparator
.@Nullable BinaryOp
getComplement()
Complement, for boolean operators.String
getToken()
boolean
hasSamePrecedenceAs(@NonNull BinaryOp other)
Returns true if this operator has the same relative precedence as the argument.static Set<BinaryOp>
opsWithGreaterPrecedence(BinaryOp op)
Returns the ops with strictly greater precedence than the given op.String
toString()
static BinaryOp
valueOf(String name)
Returns the enum constant of this type with the specified name.static BinaryOp[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
CONDITIONAL_OR
public static final BinaryOp CONDITIONAL_OR
Conditional (shortcut) OR"||"
operator.
-
CONDITIONAL_AND
public static final BinaryOp CONDITIONAL_AND
Conditional (shortcut) AND"&&"
operator.
-
OR
public static final BinaryOp OR
OR"|"
operator. Either logical or bitwise depending on the type of the operands.
-
XOR
public static final BinaryOp XOR
XOR"^"
operator. Either logical or bitwise depending on the type of the operands.
-
AND
public static final BinaryOp AND
AND"&"
operator. Either logical or bitwise depending on the type of the operands.
-
EQ
public static final BinaryOp EQ
Equals"=="
operator.
-
NE
public static final BinaryOp NE
Not-equals"!="
operator.
-
LE
public static final BinaryOp LE
Lower-or-equal"<="
operator.
-
GE
public static final BinaryOp GE
Greater-or-equal">="
operator.
-
GT
public static final BinaryOp GT
Greater-than">"
operator.
-
LT
public static final BinaryOp LT
Lower-than"<"
operator.
-
INSTANCEOF
public static final BinaryOp INSTANCEOF
Type test"instanceof"
operator.
-
LEFT_SHIFT
public static final BinaryOp LEFT_SHIFT
Left shift"<<"
operator.
-
RIGHT_SHIFT
public static final BinaryOp RIGHT_SHIFT
Right shift">>"
operator.
-
UNSIGNED_RIGHT_SHIFT
public static final BinaryOp UNSIGNED_RIGHT_SHIFT
Unsigned right shift">>>"
operator.
-
ADD
public static final BinaryOp ADD
Addition"+"
operator, or string concatenation.
-
SUB
public static final BinaryOp SUB
Subtraction"-"
operator.
-
MUL
public static final BinaryOp MUL
Multiplication"*"
operator.
-
DIV
public static final BinaryOp DIV
Division"/"
operator.
-
MOD
public static final BinaryOp MOD
Modulo"%"
operator.
-
-
Field Detail
-
CONDITIONAL_OPS
public static final Set<BinaryOp> CONDITIONAL_OPS
Set of&&
and||
. Use withJavaAstUtils.isInfixExprWithOperator(JavaNode, Set)
.
-
COMPARISON_OPS
public static final Set<BinaryOp> COMPARISON_OPS
Set of<
,<=
,>=
and>
. Use withJavaAstUtils.isInfixExprWithOperator(JavaNode, Set)
.
-
EQUALITY_OPS
public static final Set<BinaryOp> EQUALITY_OPS
Set of==
and!=
. Use withJavaAstUtils.isInfixExprWithOperator(JavaNode, Set)
.
-
-
Method Detail
-
values
public static BinaryOp[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (BinaryOp c : BinaryOp.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static BinaryOp valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
getToken
public String getToken()
-
comparePrecedence
public int comparePrecedence(@NonNull BinaryOp other)
Compare the precedence of this operator with that of the other, as if with aComparator
. Returns a positive integer if this operator has a higher precedence as the argument, zero if they have the same precedence, etc.- Throws:
NullPointerException
- If the argument is null
-
hasSamePrecedenceAs
public boolean hasSamePrecedenceAs(@NonNull BinaryOp other)
Returns true if this operator has the same relative precedence as the argument. For example,ADD
andSUB
have the same precedence.- Throws:
NullPointerException
- If the argument is null
-
opsWithGreaterPrecedence
public static Set<BinaryOp> opsWithGreaterPrecedence(BinaryOp op)
Returns the ops with strictly greater precedence than the given op. This may return an empty set.
-
getComplement
public @Nullable BinaryOp getComplement()
Complement, for boolean operators. Eg for==
, return!=
, for<=
, returns>
. Returns null if this is another kind of operator.
-
-