mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
[java-inspections] IDEA-351562 False negative for integer division in floating point context when using var
GitOrigin-RevId: 064ddb6d50110ba83060fe8785935ca2b4107234
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f0add46c89
commit
c41f8b8269
@@ -30,7 +30,6 @@ import com.siyeh.ig.psiutils.ExpectedTypeUtils;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -58,7 +57,7 @@ public final class IntegerDivisionInFloatingPointContextInspection extends BaseI
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable LocalQuickFix buildFix(Object... infos) {
|
||||
protected @NotNull LocalQuickFix buildFix(Object... infos) {
|
||||
String castTo = (String)infos[0];
|
||||
return new IntegerDivisionInFloatingPointContextFix(castTo);
|
||||
}
|
||||
@@ -83,7 +82,10 @@ public final class IntegerDivisionInFloatingPointContextInspection extends BaseI
|
||||
return;
|
||||
}
|
||||
final PsiExpression context = getContainingExpression(expression);
|
||||
final PsiType contextType = ExpectedTypeUtils.findExpectedType(context, true);
|
||||
PsiType contextType = ExpectedTypeUtils.findExpectedType(context, true);
|
||||
if (contextType == null) {
|
||||
contextType = context.getType();
|
||||
}
|
||||
String castTo;
|
||||
if (PsiTypes.floatType().equals(contextType) || PsiTypes.doubleType().equals(contextType)) {
|
||||
castTo = contextType.getCanonicalText();
|
||||
|
||||
@@ -14,4 +14,9 @@ public class IntegerDivisionInFloatingPointContext {
|
||||
if(<warning descr="'intValue/anotherIntValue': integer division in floating-point context">intValue/anotherIntValue</warning> > 0.1);
|
||||
float f = <warning descr="'intValue / anotherIntValue': integer division in floating-point context">intValue / anotherIntValue</warning>;
|
||||
}
|
||||
|
||||
void varUse() {
|
||||
double a = 1.0 + <warning descr="'5 / 2': integer division in floating-point context">5 / 2</warning>;
|
||||
var b = 1.0 + <warning descr="'5 / 2': integer division in floating-point context">5 / 2</warning>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user