Enum UnaryOp
- java.lang.Object
-
- java.lang.Enum<UnaryOp>
-
- net.sourceforge.pmd.lang.java.ast.UnaryOp
-
- All Implemented Interfaces:
Serializable
,Comparable<UnaryOp>
public enum UnaryOp extends Enum<UnaryOp>
A unary operator, either prefix or postfix. This is used byUnaryExpression
to abstract over the syntactic form of the operator.UnaryOp ::= PrefixOp | PostfixOp PrefixOp ::= "+" | "-" | "~" | "!" | "++" | "--" PostfixOp ::= "++" | "--"
- See Also:
BinaryOp
,AssignmentOp
-
-
Enum Constant Summary
Enum Constants Enum Constant Description COMPLEMENT
Bitwise complement operator"~"
.NEGATION
Logical complement operator"!"
.POST_DECREMENT
Postfix decrement operator"--"
.POST_INCREMENT
Postfix increment operator"++"
.PRE_DECREMENT
Prefix decrement operator"--"
.PRE_INCREMENT
Prefix increment operator"++"
.UNARY_MINUS
Arithmetic negation operation"-"
.UNARY_PLUS
Unary numeric promotion operator"+"
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getToken()
boolean
isDecrement()
Returns true if this is one ofPRE_DECREMENT
orPOST_DECREMENT
.boolean
isIncrement()
Returns true if this is one ofPRE_INCREMENT
orPOST_INCREMENT
.boolean
isPostfix()
Returns true if this is a postfix operator.boolean
isPrefix()
Returns true if this is a prefix operator.boolean
isPure()
Returns true if this operator is pure, ie the evaluation of the unary expression doesn't produce side-effects.static boolean
isUnaryExprWithOperator(@Nullable JavaNode e, Set<UnaryOp> operators)
Tests if the node is anASTUnaryExpression
with one of the given operators.static boolean
isUnaryExprWithOperator(@Nullable JavaNode e, UnaryOp operator)
Tests if the node is anASTUnaryExpression
with the given operator.String
toString()
static UnaryOp
valueOf(String name)
Returns the enum constant of this type with the specified name.static UnaryOp[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
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 nameNullPointerException
- 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())
-
isIncrement
public boolean isIncrement()
Returns true if this is one ofPRE_INCREMENT
orPOST_INCREMENT
.
-
isDecrement
public boolean isDecrement()
Returns true if this is one ofPRE_DECREMENT
orPOST_DECREMENT
.
-
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 anASTUnaryExpression
with one of the given operators.
-
isUnaryExprWithOperator
public static boolean isUnaryExprWithOperator(@Nullable JavaNode e, UnaryOp operator)
Tests if the node is anASTUnaryExpression
with the given operator.
-
-