DFA: provide range info for variable even when qualifier is unknown

GitOrigin-RevId: 9cb8bce64df614e5c88572e739ee1ed49a92fd81
This commit is contained in:
Tagir Valeev
2019-09-19 05:10:13 +00:00
committed by intellij-monorepo-bot
parent 8262ac4c0b
commit b01db09ad7
3 changed files with 16 additions and 3 deletions
@@ -21,7 +21,8 @@ public class DfaFactMapValue extends DfaValue {
}
public <T> DfaValue withFact(@NotNull DfaFactType<T> factType, @Nullable T value) {
return getFactory().getFactFactory().createValue(myFacts.with(factType, value));
DfaFactMap newFacts = myFacts.with(factType, value);
return newFacts == myFacts ? this : getFactory().getFactFactory().createValue(newFacts);
}
public DfaFactMap getFacts() {
@@ -1,7 +1,9 @@
// 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.codeInspection.dataFlow.value;
import com.intellij.codeInspection.dataFlow.DfaFactType;
import com.intellij.codeInspection.dataFlow.DfaPsiUtil;
import com.intellij.codeInspection.dataFlow.rangeSet.LongRangeSet;
import com.intellij.psi.PsiModifierListOwner;
import com.intellij.psi.PsiType;
import org.jetbrains.annotations.NotNull;
@@ -59,7 +61,9 @@ public interface VariableDescriptor {
return factory.getVarFactory().createVariableValue(this, (DfaVariableValue)qualifier);
}
PsiType type = getType(null);
return factory.createTypeValue(type, DfaPsiUtil.getElementNullability(type, getPsiElement()));
LongRangeSet range = LongRangeSet.fromPsiElement(getPsiElement());
return factory.withFact(factory.createTypeValue(type, DfaPsiUtil.getElementNullability(type, getPsiElement())),
DfaFactType.RANGE, range);
}
/**
@@ -352,7 +352,15 @@ public class LongRangeKnownMethods {
if (<warning descr="Condition 's.length() > 7' is always 'false'">s.length() > 7</warning>) {}
}
}
void testChainCall() {
if (<warning descr="Condition 'getByte(0).intValue() == 256' is always 'false'">getByte(0).intValue() == 256</warning>) {
}
}
native Byte getByte(int x);
void testNumberToStringExact(boolean b) {
int i = b ? 123 : 456;
String s = Integer.toString(i);