Enum Class BinaryOp

java.lang.Object
java.lang.Enum<BinaryOp>
net.sourceforge.pmd.lang.java.ast.BinaryOp
All Implemented Interfaces:
Serializable, Comparable<BinaryOp>, Constable

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:
  • Enum Constant Details

    • 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 Details

    • CONDITIONAL_OPS

      public static final Set<BinaryOp> CONDITIONAL_OPS
      Set of && and ||. Use with JavaAstUtils.isInfixExprWithOperator(JavaNode, Set).
    • COMPARISON_OPS

      public static final Set<BinaryOp> COMPARISON_OPS
      Set of <, <=, >= and >. Use with JavaAstUtils.isInfixExprWithOperator(JavaNode, Set).
    • EQUALITY_OPS

      public static final Set<BinaryOp> EQUALITY_OPS
      Set of == and !=. Use with JavaAstUtils.isInfixExprWithOperator(JavaNode, Set).
    • SHIFT_OPS

      public static final Set<BinaryOp> SHIFT_OPS
      Set of <<, >> and >>>. Use with JavaAstUtils.isInfixExprWithOperator(JavaNode, Set).
  • Method Details

    • values

      public static BinaryOp[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static BinaryOp valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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 class has no constant with the specified name
      NullPointerException - if the argument is null
    • getToken

      public String getToken()
    • toString

      public String toString()
      Overrides:
      toString in class Enum<BinaryOp>
    • comparePrecedence

      public int comparePrecedence(@NonNull BinaryOp other)
      Compare the precedence of this operator with that of the other, as if with a Comparator. 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 and SUB 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.