resources.report.rules.pmd.AvoidMultipleUnaryOperators.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sanity4j Show documentation
Show all versions of sanity4j Show documentation
Sanity4J was created to simplify running multiple static code
analysis tools on the Java projects. It provides a single entry
point to run all the selected tools and produce a consolidated
report, which presents all findings in an easily accessible
manner.
The newest version!
AvoidMultipleUnaryOperators
AvoidMultipleUnaryOperators
Using multiple unary operators may be a bug, and/or is confusing.
Check the usage is not a bug, or consider simplifying the expression.
This rule is defined by the following XPath expression:
//UnaryExpression[
./UnaryExpression
or ./UnaryExpressionNotPlusMinus
or ./PrimaryExpression/PrimaryPrefix/Expression/UnaryExpression
or ./PrimaryExpression/PrimaryPrefix/Expression/UnaryExpressionNotPlusMinus
]
|
//UnaryExpressionNotPlusMinus[
./UnaryExpression
or ./UnaryExpressionNotPlusMinus
or ./PrimaryExpression/PrimaryPrefix/Expression/UnaryExpression
or ./PrimaryExpression/PrimaryPrefix/Expression/UnaryExpressionNotPlusMinus
]
Example:
[
// These are typo bugs, or at best needlessly complex and confusing:
int i = - -1;
int j = + - +1;
int z = ~~2;
boolean b = !!true;
boolean c = !!!true;
// These are better:
int i = 1;
int j = -1;
int z = 2;
boolean b = true;
boolean c = false;
// And these just make your brain hurt:
int i = ~-2;
int j = -~7;