mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
dfa: variables shouldn't be marked unknown if they don't have known constant values
This commit is contained in:
+21
-7
@@ -815,22 +815,36 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
|
||||
@Override
|
||||
public void flushFields() {
|
||||
Set<DfaVariableValue> vars = ContainerUtil.newLinkedHashSet(getChangedVariables());
|
||||
for (EqClass aClass : myEqClasses) {
|
||||
if (aClass != null) {
|
||||
for (DfaVariableValue value : aClass.getVariables()) {
|
||||
if (value.isFlushableByCalls()) {
|
||||
doFlush(value, true);
|
||||
}
|
||||
}
|
||||
vars.addAll(aClass.getVariables());
|
||||
}
|
||||
}
|
||||
for (DfaVariableValue value : new ArrayList<DfaVariableValue>(getChangedVariables())) {
|
||||
for (DfaVariableValue value : vars) {
|
||||
if (value.isFlushableByCalls()) {
|
||||
doFlush(value, true);
|
||||
doFlush(value, shouldMarkUnknown(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldMarkUnknown(DfaVariableValue value) {
|
||||
int eqClassIndex = getEqClassIndex(value);
|
||||
if (eqClassIndex < 0) return false;
|
||||
|
||||
EqClass eqClass = myEqClasses.get(eqClassIndex);
|
||||
if (eqClass == null) return false;
|
||||
if (eqClass.findConstant(true) != null) return true;
|
||||
|
||||
for (UnorderedPair<EqClass> pair : getDistinctClassPairs()) {
|
||||
if (pair.first == eqClass && pair.second.findConstant(true) != null ||
|
||||
pair.second == eqClass && pair.first.findConstant(true) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Set<DfaVariableValue> getChangedVariables() {
|
||||
return myVariableStates.keySet();
|
||||
}
|
||||
|
||||
@@ -305,6 +305,8 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testNotEqualsTypo() { doTest(); }
|
||||
public void testAndEquals() { doTest(); }
|
||||
|
||||
public void testUnusedCallDoesNotMakeUnknown() { doTest(); }
|
||||
|
||||
public void testParametersAreNonnullByDefault() {
|
||||
myFixture.addClass("package javax.annotation; public @interface ParametersAreNonnullByDefault {}");
|
||||
myFixture.addClass("package javax.annotation; public @interface ParametersAreNullableByDefault {}");
|
||||
|
||||
Reference in New Issue
Block a user