NNBD i13n: Add line numbers to a few messages

fixes #38920

Change-Id: I6656a2e47901cbe66ccbd040d3d2fe6913f7031a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121867
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
This commit is contained in:
Sam Rawlins
2019-10-16 22:52:01 +00:00
committed by commit-bot@chromium.org
parent 558875d480
commit 3e992eb8fe
2 changed files with 15 additions and 12 deletions
@@ -114,7 +114,7 @@ class InfoBuilder {
/// If the [node] is the return expression for a function body, return the
/// function body. Otherwise return `null`.
AstNode findFunctionBody() {
FunctionBody findFunctionBody() {
if (parent is ExpressionFunctionBody) {
return parent;
} else {
@@ -126,16 +126,18 @@ class InfoBuilder {
}
}
AstNode functionBody = findFunctionBody();
FunctionBody functionBody = findFunctionBody();
if (functionBody != null) {
CompilationUnit unit = node.thisOrAncestorOfType<CompilationUnit>();
int lineNumber = unit.lineInfo.getLocation(node.offset).lineNumber;
AstNode function = functionBody.parent;
if (function is MethodDeclaration) {
if (function.isGetter) {
return "This getter returns a nullable value";
return "This getter returns a nullable value on line $lineNumber";
}
return "This method returns a nullable value";
return "This method returns a nullable value on line $lineNumber";
}
return "This function returns a nullable value";
return "This function returns a nullable value on line $lineNumber";
} else if (parent is VariableDeclaration) {
AstNode grandparent = parent.parent?.parent;
if (grandparent is FieldDeclaration) {
@@ -198,7 +200,8 @@ class InfoBuilder {
CompilationUnit unit = type.thisOrAncestorOfType<CompilationUnit>();
target = _targetForNode(unit.declaredElement.source.fullName, type);
return RegionDetail(
"The corresponding parameter in the overridden method is nullable",
"The corresponding parameter in the overridden method is "
"nullable",
target);
// TODO(srawlins): Also, this could be where a return type in an
// overridden method is made nullable because an overriding method
@@ -137,7 +137,7 @@ String? g() => 1 == 2 ? "Hello" : null;
assertRegion(
region: regions[0],
offset: 6,
details: ["This function returns a nullable value"]);
details: ["This function returns a nullable value on line 1"]);
assertDetail(detail: regions[0].details[0], offset: 11, length: 2);
}
@@ -516,7 +516,7 @@ String? g() {
assertRegion(
region: regions[0],
offset: 6,
details: ["This function returns a nullable value"]);
details: ["This function returns a nullable value on line 3"]);
assertInTargets(targets: unit.targets, offset: 40, length: 6); // "return"
}
@@ -540,7 +540,7 @@ String? g() {
assertRegion(
region: regions[0],
offset: 6,
details: ["This function returns a nullable value"]);
details: ["This function returns a nullable value on line 2"]);
assertDetail(detail: regions[0].details[0], offset: 15, length: 6);
}
@@ -566,7 +566,7 @@ int? f() => _f;
assertRegion(
region: regions[1],
offset: 19,
details: ["This function returns a nullable value"]);
details: ["This function returns a nullable value on line 2"]);
}
test_returnType_getter_block() async {
@@ -599,7 +599,7 @@ class A {
assertRegion(
region: regions[1],
offset: 33,
details: ["This getter returns a nullable value"]);
details: ["This getter returns a nullable value on line 4"]);
}
test_returnType_getter_expression() async {
@@ -628,7 +628,7 @@ class A {
assertRegion(
region: regions[1],
offset: 33,
details: ["This getter returns a nullable value"]);
details: ["This getter returns a nullable value on line 3"]);
}
test_topLevelVariable() async {