diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/ReplaceExpressionUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/ReplaceExpressionUtil.java index afc1240ba47f..c390122014bd 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/ReplaceExpressionUtil.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/ReplaceExpressionUtil.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl.source.tree.java; import com.intellij.lang.ASTNode; @@ -38,14 +38,15 @@ public class ReplaceExpressionUtil { else if (i == JavaElementType.BINARY_EXPRESSION || i == JavaElementType.POLYADIC_EXPRESSION) { if (priority < parentPriority) return true; PsiElement element = SourceTreeToPsiMap.treeElementToPsi(oldParent); + assert element != null; IElementType opType = ((PsiPolyadicExpression)element).getOperationTokenType(); IElementType newI = newExpr.getElementType(); + if (((CompositeElement)oldParent).getChildRole(oldExpr) == ChildRole.LOPERAND) return false; if (newI == JavaElementType.BINARY_EXPRESSION || newI == JavaElementType.POLYADIC_EXPRESSION) { IElementType newType = ((PsiPolyadicExpression)newExpr).getOperationTokenType(); - if (newType == JavaTokenType.DIV || newExpr == JavaTokenType.PERC) return true; + if (newType == JavaTokenType.DIV || newType == JavaTokenType.PERC) return true; } - return ((CompositeElement)oldParent).getChildRole(oldExpr) != ChildRole.LOPERAND && - opType != JavaTokenType.PLUS && + return opType != JavaTokenType.PLUS && opType != JavaTokenType.ASTERISK && opType != JavaTokenType.ANDAND && opType != JavaTokenType.OROR; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantCast/afterPrecedencePerc2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantCast/afterPrecedencePerc2.java new file mode 100644 index 000000000000..6907bf41f803 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantCast/afterPrecedencePerc2.java @@ -0,0 +1,8 @@ +// "Remove redundant cast(s)" "true" +class Test { + { + int i = 1; + int j = 2; + System.out.println(j * (i % j)); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantCast/beforePrecedencePerc2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantCast/beforePrecedencePerc2.java new file mode 100644 index 000000000000..4e576aaaa796 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantCast/beforePrecedencePerc2.java @@ -0,0 +1,8 @@ +// "Remove redundant cast(s)" "true" +class Test { + { + int i = 1; + int j = 2; + System.out.println(j * ((int)(i % j))); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/parentheses/Division2.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/parentheses/Division2.after.java new file mode 100644 index 000000000000..b0bfcf6361ab --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/parentheses/Division2.after.java @@ -0,0 +1,6 @@ +class Divistion { + void zz() { + long actual = 987987; + long roundedActual = actual / 1000 * 1000; + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/parentheses/Division2.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/parentheses/Division2.java new file mode 100644 index 000000000000..45fe422b1acb --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/parentheses/Division2.java @@ -0,0 +1,6 @@ +class Divistion { + void zz() { + long actual = 987987; + long roundedActual = (actual / 1000) * 1000; + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/parenthesis/UnnecessaryParenthesesQuickFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/parenthesis/UnnecessaryParenthesesQuickFixTest.java index fb114fc8ce45..9de6e74ba293 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/parenthesis/UnnecessaryParenthesesQuickFixTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/parenthesis/UnnecessaryParenthesesQuickFixTest.java @@ -34,6 +34,7 @@ public class UnnecessaryParenthesesQuickFixTest extends IGQuickFixesTestCase { public void testLambdaCast() { doTest(); } public void testLambdaBody() { doTest(); } public void testDivision() { doTest(); } + public void testDivision2() { doTest(); } public void testSwitchExpression() { doTest(); } @Override