Reporting unnecessary safe calls on Java's @NotNull values

This commit is contained in:
Andrey Breslav
2015-02-04 19:53:43 +03:00
parent 1d4109aec1
commit 30f5c1b953
4 changed files with 62 additions and 1 deletions
@@ -201,11 +201,12 @@ public class JavaNullabilityWarningsChecker : AdditionalTypeChecker {
safeAccess: Boolean,
c: CallResolutionContext<*>
) {
val dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiverArgument, c.trace.getBindingContext())
if (!safeAccess) {
doCheckType(
receiverArgument.getType(),
receiverParameter.getType(),
DataFlowValueFactory.createDataFlowValue(receiverArgument, c.trace.getBindingContext()),
dataFlowValue,
c.dataFlowInfo
) {
expectedMustNotBeNull,
@@ -222,5 +223,12 @@ public class JavaNullabilityWarningsChecker : AdditionalTypeChecker {
}
}
else {
if (c.dataFlowInfo.getNullability(dataFlowValue).canBeNull()
&& receiverArgument.getType().mustNotBeNull() == NullabilityInformationSource.JAVA) {
c.trace.report(Errors.UNNECESSARY_SAFE_CALL.on(c.call.getCallOperationNode().getPsi(), receiverArgument.getType()))
}
}
}
}