IDEA-203016 support branch-specific reporting in returns (IDEA-CR-40527)

This commit is contained in:
Tagir Valeev
2018-11-30 16:48:48 +07:00
parent 0c5e8ec0d6
commit 55d9ea807a
3 changed files with 8 additions and 4 deletions
@@ -863,14 +863,14 @@ public class DataFlowInspectionBase extends AbstractBaseJavaLocalInspectionTool
for (NullabilityProblem<PsiExpression> problem : visitor.problems().map(NullabilityProblemKind.nullableReturn::asMyProblem).nonNull()) {
final PsiExpression anchor = problem.getAnchor();
PsiExpression expr = PsiUtil.skipParenthesizedExprDown(anchor);
PsiExpression expr = problem.getDereferencedExpression();
if (nullability == Nullability.NOT_NULL) {
String presentable = NullableStuffInspectionBase.getPresentableAnnoName(anno);
final String text = isNullLiteralExpression(expr) || visitor.getConstantExpressions().get(expr) == ConstantResult.NULL
? InspectionsBundle.message("dataflow.message.return.null.from.notnull", presentable)
: InspectionsBundle.message("dataflow.message.return.nullable.from.notnull", presentable);
reporter.registerProblem(anchor, text);
reporter.registerProblem(expr, text);
}
else if (AnnotationUtil.isAnnotatingApplicable(anchor)) {
final String defaultNullable = manager.getDefaultNullable();
@@ -882,7 +882,7 @@ public class DataFlowInspectionBase extends AbstractBaseJavaLocalInspectionTool
PsiTreeUtil.getParentOfType(anchor, PsiMethod.class, PsiLambdaExpression.class) instanceof PsiLambdaExpression
? LocalQuickFix.EMPTY_ARRAY
: new LocalQuickFix[]{ new AnnotateMethodFix(defaultNullable, ArrayUtil.toStringArray(manager.getNotNulls()))};
reporter.registerProblem(anchor, text, fixes);
reporter.registerProblem(expr, text, fixes);
}
}
}
@@ -31,7 +31,7 @@ class Test {
@NotNull Object testReturn(Object x1, Object x2) {
if(x1 == null) return <warning descr="'null' is returned by the method declared as @NotNull">x1</warning>;
if(x2 == null) return <warning descr="'null' is returned by the method declared as @NotNull">(x2)</warning>;
if(x2 == null) return (<warning descr="'null' is returned by the method declared as @NotNull">x2</warning>);
return new Object();
}
@@ -13,4 +13,8 @@ final class MyClass {
cons(<warning descr="Argument 'f1 ? f2 ? a : b : ((Object)c)' might be null but passed to non-annotated parameter">f1 ? f2 ? a : b : ((Object)c)</warning>);
cons(f1 ? <warning descr="Argument 'f2 ? a : b' might be null but passed to non-annotated parameter">f2 ? a : b</warning> : f2 ? <warning descr="Argument 'c' might be null but passed to non-annotated parameter">c</warning> : new Object());
}
@NotNull String testReturn(boolean b) {
return b ? "hello" : <warning descr="'null' is returned by the method declared as @NotNull">null</warning>;
}
}