mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-74934 "Constant conditions & exceptions": take type parameters into consideration, take 2 (fields)
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
package com.intellij.codeInspection.dataFlow;
|
||||
|
||||
import com.intellij.codeInsight.ExceptionUtil;
|
||||
import com.intellij.codeInsight.NullableNotNullManager;
|
||||
import com.intellij.codeInspection.dataFlow.instructions.*;
|
||||
import com.intellij.codeInspection.dataFlow.value.DfaUnknownValue;
|
||||
import com.intellij.codeInspection.dataFlow.value.DfaValue;
|
||||
@@ -1523,7 +1522,8 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
dfaValue = createChainedVariableValue(expression);
|
||||
}
|
||||
if (dfaValue == null) {
|
||||
return myFactory.getTypeFactory().create(field.getType(), NullableNotNullManager.isNullable(field));
|
||||
PsiType type = expression.getType();
|
||||
return myFactory.createTypeValueWithNullability(type, DfaUtil.getElementNullability(type, field));
|
||||
}
|
||||
return dfaValue;
|
||||
}
|
||||
|
||||
+4
-5
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.dataFlow;
|
||||
|
||||
import com.intellij.codeInsight.NullableNotNullManager;
|
||||
import com.intellij.codeInspection.dataFlow.instructions.*;
|
||||
import com.intellij.codeInspection.dataFlow.value.*;
|
||||
import com.intellij.psi.*;
|
||||
@@ -105,7 +104,6 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DfaInstructionState[] visitAssign(AssignInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
|
||||
DfaValue dfaSource = memState.pop();
|
||||
@@ -114,8 +112,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
if (dfaDest instanceof DfaVariableValue) {
|
||||
DfaVariableValue var = (DfaVariableValue) dfaDest;
|
||||
final PsiVariable psiVariable = var.getPsiVariable();
|
||||
final NullableNotNullManager nullableManager = NullableNotNullManager.getInstance(psiVariable.getProject());
|
||||
if (nullableManager.isNotNull(psiVariable, false)) {
|
||||
if (DfaUtil.getElementNullability(var.getVariableType(), psiVariable) == Boolean.FALSE) {
|
||||
if (!memState.applyNotNull(dfaSource)) {
|
||||
onAssigningToNotNullableVariable(instruction, runner);
|
||||
}
|
||||
@@ -123,6 +120,8 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
if (!(psiVariable instanceof PsiField) || !psiVariable.hasModifierProperty(PsiModifier.VOLATILE)) {
|
||||
memState.setVarValue(var, dfaSource);
|
||||
}
|
||||
} else if (dfaDest instanceof DfaNotNullValue && !memState.applyNotNull(dfaSource)) {
|
||||
onAssigningToNotNullableVariable(instruction, runner);
|
||||
}
|
||||
|
||||
memState.push(dfaDest);
|
||||
@@ -240,7 +239,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
final MethodCallInstruction.MethodType methodType = instruction.getMethodType();
|
||||
if (type != null && (type instanceof PsiClassType || type.getArrayDimensions() > 0)) {
|
||||
@Nullable final Boolean nullability = myReturnTypeNullability.get(instruction);
|
||||
return nullability == Boolean.FALSE ? factory.getNotNullFactory().create(type) : factory.getTypeFactory().create(type, nullability == Boolean.TRUE);
|
||||
return factory.createTypeValueWithNullability(type, nullability);
|
||||
}
|
||||
|
||||
if (methodType == MethodCallInstruction.MethodType.UNBOXING) {
|
||||
|
||||
@@ -27,6 +27,7 @@ package com.intellij.codeInspection.dataFlow.value;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -43,7 +44,7 @@ public class DfaNotNullValue extends DfaValue {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DfaValue create(PsiType type) {
|
||||
public DfaValue create(@Nullable PsiType type) {
|
||||
if (type == null) return DfaUnknownValue.getInstance();
|
||||
mySharedInstance.myType = type;
|
||||
|
||||
|
||||
@@ -49,7 +49,11 @@ public class DfaValueFactory {
|
||||
myRelationFactory = new DfaRelationValue.Factory(this);
|
||||
}
|
||||
|
||||
int createID() {
|
||||
public DfaValue createTypeValueWithNullability(@Nullable PsiType type, @Nullable Boolean nullability) {
|
||||
return nullability == Boolean.FALSE ? getNotNullFactory().create(type) : getTypeFactory().create(type, nullability == Boolean.TRUE);
|
||||
}
|
||||
|
||||
int createID() {
|
||||
myLastID++;
|
||||
LOG.assertTrue(myLastID >= 0, "Overflow");
|
||||
return myLastID;
|
||||
|
||||
@@ -18,10 +18,10 @@ class Test {
|
||||
}
|
||||
|
||||
private static void test3(Ref<@NotNull Object> ref) {
|
||||
if (ref.value == null) {
|
||||
if (<warning descr="Condition 'ref.value == null' is always 'false'">ref.value == null</warning>) {
|
||||
return;
|
||||
}
|
||||
ref.value = null;
|
||||
ref.value = <warning descr="'null' is assigned to a variable that is annotated with @NotNull">null</warning>;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user