Enum UnaryOp

  • All Implemented Interfaces:
    Serializable, Comparable<UnaryOp>

    public enum UnaryOp
    extends Enum<UnaryOp>
    A unary operator, either prefix or postfix. This is used by UnaryExpression to abstract over the syntactic form of the operator.
    
     UnaryOp ::= PrefixOp | PostfixOp
    
     PrefixOp ::= "+" | "-" | "~" | "!" | "++" | "--"
    
     PostfixOp ::= "++" | "--"
    
      
    See Also:
    BinaryOp, AssignmentOp
    • Enum Constant Detail

      • UNARY_PLUS

        public static final UnaryOp UNARY_PLUS
        Unary numeric promotion operator "+".
      • UNARY_MINUS

        public static final UnaryOp UNARY_MINUS
        Arithmetic negation operation "-".
      • COMPLEMENT

        public static final UnaryOp COMPLEMENT
        Bitwise complement operator "~".
      • NEGATION

        public static final UnaryOp NEGATION
        Logical complement operator "!".
      • PRE_INCREMENT

        public static final UnaryOp PRE_INCREMENT
        Prefix increment operator "++".
      • PRE_DECREMENT

        public static final UnaryOp PRE_DECREMENT
        Prefix decrement operator "--".
      • POST_INCREMENT

        public static final UnaryOp POST_INCREMENT
        Postfix increment operator "++".
      • POST_DECREMENT

        public static final UnaryOp POST_DECREMENT
        Postfix decrement operator "--".
    • Method Detail

      • values

        public static UnaryOp[] 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 (UnaryOp c : UnaryOp.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static UnaryOp 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 name
        NullPointerException - if the argument is null
      • isPure

        public boolean isPure()
        Returns true if this operator is pure, ie the evaluation of the unary expression doesn't produce side-effects. Only increment and decrement operators are impure.

        This can be used to fetch all increment or decrement operations, regardless of whether they're postfix or prefix. E.g.

        
          node.descendants(ASTUnaryExpression.class)
              .filterNot(it -> it.getOperator().isPure())
         
      • isPrefix

        public boolean isPrefix()
        Returns true if this is a prefix operator.
      • isPostfix

        public boolean isPostfix()
        Returns true if this is a postfix operator.
      • getToken

        public String getToken()
      • isUnaryExprWithOperator

        public static boolean isUnaryExprWithOperator​(@Nullable JavaNode e,
                                                      Set<UnaryOp> operators)
        Tests if the node is an ASTUnaryExpression with one of the given operators.
      • isUnaryExprWithOperator

        public static boolean isUnaryExprWithOperator​(@Nullable JavaNode e,
                                                      UnaryOp operator)
        Tests if the node is an ASTUnaryExpression with the given operator.