Skip to content

Commit 291c829

Browse files
authored
Remove Library.sentinel. (#4155)
Use `null` instead of a sentinel value that throws on all member accessses. That lets the type system help with avoiding spurious runtime errors if forgetting to check for a sentinel. It makes it explicit, as a `.library!`, where code assumes that there is a valid library. (Some small drive-by tweaks.)
1 parent a9b71cb commit 291c829

23 files changed

Lines changed: 2322 additions & 2118 deletions

lib/resources/docs.dart.js

Lines changed: 1788 additions & 1754 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/resources/docs.dart.js.map

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/element_type.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ abstract class ElementType with CommentReferable, Nameable {
2424
@override
2525
final PackageGraph packageGraph;
2626
@override
27-
final Library library;
27+
final Library? library;
2828

2929
final String nullabilitySuffix;
3030

3131
ElementType._(this.type, this.library, this.packageGraph)
32-
: nullabilitySuffix = type.nullabilitySuffixWithin(library);
32+
: nullabilitySuffix = type.nullabilitySuffixWithin;
3333

3434
factory ElementType.for_(
35-
DartType type, Library library, PackageGraph packageGraph) {
35+
DartType type, Library? library, PackageGraph packageGraph) {
3636
runtimeStats.incrementAccumulator('elementTypeInstantiation');
3737
var fElement = type.documentableElement;
3838
if (fElement == null ||
@@ -74,7 +74,7 @@ class UndefinedElementType extends ElementType {
7474
: super._();
7575

7676
factory UndefinedElementType._from(
77-
DartType type, Library library, PackageGraph packageGraph) {
77+
DartType type, Library? library, PackageGraph packageGraph) {
7878
// [UndefinedElementType]s.
7979
if (type.alias != null) {
8080
if (type is FunctionType) {
@@ -262,7 +262,7 @@ abstract class DefinedElementType extends ElementType {
262262
: super._();
263263

264264
factory DefinedElementType._from(DartType type, ModelElement modelElement,
265-
Library library, PackageGraph packageGraph) {
265+
Library? library, PackageGraph packageGraph) {
266266
if (type is! TypeAliasElement && type.alias != null) {
267267
// Here, `alias.element` signals that this is a type referring to an
268268
// alias. (`TypeAliasElement.alias.element` has different implications.
@@ -360,7 +360,7 @@ mixin Rendered implements ElementType {
360360

361361
extension on DartType {
362362
/// The dartdoc nullability suffix for this type in [library].
363-
String nullabilitySuffixWithin(Library library) {
363+
String get nullabilitySuffixWithin {
364364
if (this is! VoidType && !isBottom) {
365365
/// If a legacy type appears inside the public interface of a Null
366366
/// safety library, we pretend it is nullable for the purpose of

lib/src/generator/generator_utils.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ int _packageRank(List<String> packageOrder, ModelElement element) {
9797
var index = packageOrder.indexOf(packageName);
9898
if (index == -1) return packageOrder.length * 10;
9999
if (packageName == 'Dart' &&
100-
!_dartCoreLibraries.contains(element.library.name)) {
100+
!_dartCoreLibraries.contains(element.library!.name)) {
101101
// Non-"core" Dart SDK libraries should be ranked slightly lower than "core"
102102
// Dart SDK libraries. The "core" Dart SDK libraries are the ones labeled as
103103
// such at <https://api.dart.dev>, which can be used in both VM and Web
@@ -149,7 +149,9 @@ extension on Nameable {
149149
if (self is Library) return name;
150150
if (self is ModelElement) {
151151
var library = self.canonicalLibrary ?? self.library;
152-
return '${library.name}.${self.qualifiedName}';
152+
if (library != null) {
153+
return '${library.name}.${self.qualifiedName}';
154+
}
153155
}
154156
return name;
155157
}

0 commit comments

Comments
 (0)