respect precedence for div as production argument (IDEA-187205)

This commit is contained in:
Anna.Kozlova
2018-03-07 09:18:32 +01:00
parent 5be28ade9e
commit 9bdd5f11e3
4 changed files with 42 additions and 0 deletions
@@ -53,6 +53,11 @@ public class ReplaceExpressionUtil {
if (priority < parentPriority) return true;
PsiElement element = SourceTreeToPsiMap.treeElementToPsi(oldParent);
IElementType opType = ((PsiPolyadicExpression)element).getOperationTokenType();
IElementType newI = newExpr.getElementType();
if (newI == JavaElementType.BINARY_EXPRESSION || newI == JavaElementType.POLYADIC_EXPRESSION) {
IElementType newType = ((PsiPolyadicExpression)newExpr).getOperationTokenType();
if (newType == JavaTokenType.DIV) return true;
}
return ((CompositeElement)oldParent).getChildRole(oldExpr) != ChildRole.LOPERAND &&
opType != JavaTokenType.PLUS &&
opType != JavaTokenType.ASTERISK &&
@@ -0,0 +1,8 @@
// "Remove redundant cast(s)" "true"
class Test {
{
int i = 1;
int j = 2;
System.out.println(j * (i / j));
}
}
@@ -0,0 +1,8 @@
// "Remove redundant cast(s)" "true"
class Test {
{
int i = 1;
int j = 2;
System.out.println(j * (i<caret>nt)(i / j));
}
}
@@ -0,0 +1,21 @@
// 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.
package com.intellij.java.codeInsight.daemon.quickFix;
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
import com.intellij.codeInspection.redundantCast.RedundantCastInspection;
public class RemoveRedundantCastTest extends LightQuickFixParameterizedTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
enableInspectionTool(new RedundantCastInspection());
}
public void test() { doAllTests(); }
@Override
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/redundantCast";
}
}