diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnaryPlusInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnaryPlusInspection.java index eeae65da6c94..3847d0e0866f 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnaryPlusInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnaryPlusInspection.java @@ -123,12 +123,17 @@ public class UnaryPlusInspection extends BaseInspection { } if (onlyReportInsideBinaryExpression) { final PsiElement parent = ParenthesesUtils.getParentSkipParentheses(prefixExpression); - if (!(operand instanceof PsiParenthesizedExpression) && !(operand instanceof PsiPrefixExpression) && - !(parent instanceof PsiPolyadicExpression) && !(parent instanceof PsiPrefixExpression)) { + if (!(operand instanceof PsiParenthesizedExpression || + operand instanceof PsiPrefixExpression || + parent instanceof PsiPolyadicExpression || + parent instanceof PsiPrefixExpression || + parent instanceof PsiAssignmentExpression || + parent instanceof PsiVariable)) { return; } } - else if (TypeUtils.unaryNumericPromotion(type) != type && MethodCallUtils.isNecessaryForSurroundingMethodCall(prefixExpression, operand)) { + else if (TypeUtils.unaryNumericPromotion(type) != type && + MethodCallUtils.isNecessaryForSurroundingMethodCall(prefixExpression, operand)) { // unary plus might have been used as cast to int return; } diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/UnaryPlus.html b/plugins/InspectionGadgets/src/inspectionDescriptions/UnaryPlus.html index 45b136aefda1..d305e2e7bd11 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/UnaryPlus.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/UnaryPlus.html @@ -1,12 +1,13 @@
Reports any uses of the unary + operator. Unary plus is usually a null operation, and -its presence may represent a coding error, particularly in combination with the increment operator, ++. +its presence may represent a coding error. +Particularly in combination with the increment operator, +++, or the equals operator, =+Use the checkbox below to only report when an unary plus is used together with a binary or another unary expression. -This means the inspection won't warn when an unary plus expression is for example used as a variable initializer, as an argument to a method -or as the right-hand side of an assignment. In such cases it is much less confusing. +This means the inspection won't warn when an unary plus expression is used for example as a method argument, or in an array +initializer expression. In such cases it is much less confusing.
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unary_plus/UnaryPlusConfusing.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unary_plus/UnaryPlusConfusing.java
new file mode 100644
index 000000000000..41166a3a7508
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unary_plus/UnaryPlusConfusing.java
@@ -0,0 +1,15 @@
+class UnaryPlusConfusing {
+
+ void confusing(int x) {
+ x =