private Nullness calcInherentNullability() { PsiModifierListOwner var = getPsiVariable(); Nullness nullability = DfaPsiUtil.getElementNullability(getVariableType(), var); if (nullability != Nullness.UNKNOWN) { return nullability; } Nullness defaultNullability = myFactory.isUnknownMembersAreNullable() && MEMBER_OR_METHOD_PARAMETER.accepts(var) ? Nullness.NULLABLE : Nullness.UNKNOWN; if (var instanceof PsiParameter && var.getParent() instanceof PsiForeachStatement) { PsiExpression iteratedValue = ((PsiForeachStatement) var.getParent()).getIteratedValue(); if (iteratedValue != null) { PsiType itemType = JavaGenericsUtil.getCollectionItemType(iteratedValue); if (itemType != null) { return DfaPsiUtil.getElementNullability(itemType, var); } } } if (var instanceof PsiField && DfaPsiUtil.isFinalField((PsiVariable) var) && myFactory.isHonorFieldInitializers()) { List<PsiExpression> initializers = DfaPsiUtil.findAllConstructorInitializers((PsiField) var); if (initializers.isEmpty()) { return defaultNullability; } boolean hasUnknowns = false; for (PsiExpression expression : initializers) { Nullness nullness = getFieldInitializerNullness(expression); if (nullness == Nullness.NULLABLE) { return Nullness.NULLABLE; } if (nullness == Nullness.UNKNOWN) { hasUnknowns = true; } } if (hasUnknowns) { if (DfaPsiUtil.isInitializedNotNull((PsiField) var)) { return Nullness.NOT_NULL; } return defaultNullability; } return Nullness.NOT_NULL; } return defaultNullability; }
public boolean isFlushableByCalls() { if (myVariable instanceof PsiLocalVariable || myVariable instanceof PsiParameter) return false; if (myVariable instanceof PsiVariable && myVariable.hasModifierProperty(PsiModifier.FINAL)) { return myQualifier != null && myQualifier.isFlushableByCalls(); } return true; }
private DfaVariableValue( @NotNull PsiModifierListOwner variable, @Nullable PsiType varType, boolean isNegated, DfaValueFactory factory, @Nullable DfaVariableValue qualifier) { super(factory); myVariable = variable; myIsNegated = isNegated; myQualifier = qualifier; myVarType = varType; DfaValue typeValue = myFactory.createTypeValue(varType, Nullness.UNKNOWN); myTypeValue = typeValue instanceof DfaTypeValue ? (DfaTypeValue) typeValue : null; if (varType != null && !varType.isValid()) { PsiUtil.ensureValidType( varType, "Variable: " + variable + " of class " + variable.getClass()); } }