From d99510292a0ead81c2820b25757fd4c4b30983eb Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Tue, 18 Nov 2008 21:34:32 +0300 Subject: [PATCH] IDEADEV-32886 (quickfix of "Unnecessary Parentheses" inspection removes too many parentheses) --- .../com/siyeh/ig/psiutils/ParenthesesUtils.java | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java index 1393511202..7ab4092f1a 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java @@ -252,12 +252,7 @@ public class ParenthesesUtils{ @NotNull PsiParenthesizedExpression parenthesizedExpression, boolean ignoreClarifyingParentheses) throws IncorrectOperationException { - PsiExpression body = parenthesizedExpression.getExpression(); - while(body instanceof PsiParenthesizedExpression){ - final PsiParenthesizedExpression innerParenthesizedExpression = - (PsiParenthesizedExpression)body; - body = innerParenthesizedExpression.getExpression(); - } + final PsiExpression body = parenthesizedExpression.getExpression(); if (body == null) { parenthesizedExpression.delete(); return; @@ -311,9 +306,10 @@ public class ParenthesesUtils{ return; } } - if (ignoreClarifyingParentheses && - !parentOperator.equals(bodyOperator)) { - removeParentheses(body, ignoreClarifyingParentheses); + if (ignoreClarifyingParentheses) { + if (parentOperator.equals(bodyOperator)) { + removeParentheses(body, ignoreClarifyingParentheses); + } } else { final PsiExpression newExpression = (PsiExpression) parenthesizedExpression.replace(body); @@ -325,10 +321,17 @@ public class ParenthesesUtils{ (PsiExpression) parenthesizedExpression.replace(body); removeParentheses(newExpression, ignoreClarifyingParentheses); } - } else{ - final PsiExpression newExpression = - (PsiExpression) parenthesizedExpression.replace(body); - removeParentheses(newExpression, ignoreClarifyingParentheses); + } else { + if (ignoreClarifyingParentheses && + parent instanceof PsiBinaryExpression && + (body instanceof PsiBinaryExpression || + body instanceof PsiInstanceOfExpression)) { + removeParentheses(body, ignoreClarifyingParentheses); + } else { + final PsiExpression newExpression = + (PsiExpression) parenthesizedExpression.replace(body); + removeParentheses(newExpression, ignoreClarifyingParentheses); + } } } -- 2.11.4.GIT