Skip to content

Commit e06cdb8

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Make SourceFactory.resolveUri take non-nullable parameters
The function mostly returned null/nonsense if given a null argument, and the few call sites with nullable arguments (in tests and tools) are easily tweaked. Change-Id: I7f9993696c4bd822b648a5a89114e6af25eac552 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/490020 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Samuel Rawlins <srawlins@google.com>
1 parent 5874342 commit e06cdb8

5 files changed

Lines changed: 8 additions & 11 deletions

File tree

pkg/analyzer/lib/src/context/source.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,7 @@ class SourceFactoryImpl implements SourceFactory {
122122
}
123123

124124
@override
125-
Source? resolveUri(Source? containingSource, String? containedUri) {
126-
if (containedUri == null) {
127-
return null;
128-
}
125+
Source? resolveUri(Source containingSource, String containedUri) {
129126
if (containedUri.isEmpty) {
130127
return containingSource;
131128
}
@@ -138,9 +135,7 @@ class SourceFactoryImpl implements SourceFactory {
138135
} on FormatException {
139136
return null;
140137
} catch (exception, stackTrace) {
141-
String containingFullName = containingSource != null
142-
? containingSource.fullName
143-
: '<null>';
138+
String containingFullName = containingSource.fullName;
144139
// TODO(39284): should this exception be silent?
145140
AnalysisEngine.instance.instrumentationService.logException(
146141
SilentException(

pkg/analyzer/lib/src/generated/source.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ abstract class SourceFactory {
152152
/// [containingSource], whether or not the resulting source exists, or `null`
153153
/// if either the [containedUri] is invalid or if it cannot be resolved
154154
/// against the [containingSource]'s URI.
155-
Source? resolveUri(Source? containingSource, String? containedUri);
155+
Source? resolveUri(Source containingSource, String containedUri);
156156
}
157157

158158
/// The abstract class `UriResolver` defines the behavior of objects that are

pkg/analyzer/test/generated/source_factory_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class SourceFactoryTest with ResourceProviderMixin {
5959
void test_resolveUri_absolute() {
6060
UriResolver_absolute resolver = UriResolver_absolute();
6161
SourceFactory factory = SourceFactory([resolver]);
62-
factory.resolveUri(null, "dart:core");
62+
String sourcePath = convertPath('/does/not/exist.dart');
63+
Source sourceSource = FileSource(getFile(sourcePath));
64+
factory.resolveUri(sourceSource, "dart:core");
6365
expect(resolver.invoked, isTrue);
6466
}
6567

pkg/analyzer_cli/tool/perf.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void collectSources(Source? start, Set<Source?> files) {
7878
var unit = parseDirectives(start!);
7979
for (var directive in unit.directives) {
8080
if (directive is UriBasedDirective) {
81-
var next = sources.resolveUri(start, directive.uri.stringValue);
81+
var next = sources.resolveUri(start, directive.uri.stringValue!);
8282
collectSources(next, files);
8383
}
8484
}

pkg/front_end/tool/perf.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void collectSources(Source start, Set<Source> files) {
103103
var unit = parseDirectives(start);
104104
for (var directive in unit.directives) {
105105
if (directive is UriBasedDirective) {
106-
var next = sources.resolveUri(start, directive.uri.stringValue)!;
106+
var next = sources.resolveUri(start, directive.uri.stringValue!)!;
107107
collectSources(next, files);
108108
}
109109
}

0 commit comments

Comments
 (0)