Skip to content

Commit b81bcce

Browse files
authored
Migrate ModelElement and subclasses to NNBD (#2843)
* squash * rebuild * migrate more things * subprocess * type adjustment in grinder * partial * partial 2 * no errors, ship it * clean up a lot of warnings * All warnings done so really ship it * dartfmt * close * manual changes on renderers * comments * partial * fix some errors post-migration * holy cow it passes the tests now * make mustache happier and clean up an interface * forgot to remove a fixme * Work around strange super-not-allowed error in stable * review comments
1 parent 5486049 commit b81bcce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1932
-2047
lines changed

lib/dartdoc.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart=2.9
65
/// A documentation generator for Dart.
76
///
87
/// Library interface is still experimental.

lib/src/dartdoc_options.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class DartdocFileMissing extends DartdocOptionError {
5858
/// the 'categories' keyword in the options file, and populated by the
5959
/// [CategoryConfiguration] class.
6060
class CategoryDefinition {
61-
/// Internal name of the category.
62-
final String name;
61+
/// Internal name of the category, or null for the default category.
62+
final String? name;
6363

6464
/// Displayed name of the category in docs, or null if there is none.
6565
final String? _displayName;
@@ -71,7 +71,7 @@ class CategoryDefinition {
7171
CategoryDefinition(this.name, this._displayName, this.documentationMarkdown);
7272

7373
/// Returns the [_displayName], if available, or else simply [name].
74-
String get displayName => _displayName ?? name;
74+
String get displayName => _displayName ?? name ?? '';
7575
}
7676

7777
/// A configuration class that can interpret category definitions from a YAML
@@ -1246,7 +1246,7 @@ class DartdocOptionContext extends DartdocOptionContextBase
12461246

12471247
List<String> get dropTextFrom => optionSet['dropTextFrom'].valueAt(context);
12481248

1249-
String get examplePathPrefix =>
1249+
String? get examplePathPrefix =>
12501250
optionSet['examplePathPrefix'].valueAt(context);
12511251

12521252
// TODO(srawlins): This memoization saved a lot of time in unit testing, but

lib/src/element_type.dart

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ abstract class ElementType extends Privacy
4343
if (fElement == null ||
4444
fElement.kind == ElementKind.DYNAMIC ||
4545
fElement.kind == ElementKind.NEVER) {
46+
// [UndefinedElementType]s.
4647
if (f is FunctionType) {
4748
if (f.alias?.element != null) {
4849
return AliasedFunctionTypeElementType(
@@ -51,43 +52,42 @@ abstract class ElementType extends Privacy
5152
return FunctionTypeElementType(f, library, packageGraph, returnedFrom);
5253
}
5354
return UndefinedElementType(f, library, packageGraph, returnedFrom);
54-
} else {
55-
var element = packageGraph.modelBuilder.fromElement(fElement);
56-
// [TypeAliasElement.aliasElement] has different implications.
57-
// In that case it is an actual type alias of some kind (generic
58-
// or otherwise. Here however aliasElement signals that this is a
59-
// type referring to an alias.
60-
if (f is! TypeAliasElement && f.alias?.element != null) {
61-
return AliasedElementType(f as ParameterizedType, library, packageGraph,
62-
element, returnedFrom);
63-
}
64-
assert(f is ParameterizedType || f is TypeParameterType);
65-
// TODO(jcollins-g): strip out all the cruft that's accumulated
66-
// here for non-generic type aliases.
67-
var isGenericTypeAlias = f.alias?.element != null && f is! InterfaceType;
68-
if (f is FunctionType) {
69-
assert(f is ParameterizedType);
70-
// This is an indication we have an extremely out of date analyzer....
71-
assert(
72-
!isGenericTypeAlias, 'should never occur: out of date analyzer?');
73-
// And finally, delete this case and its associated class
74-
// after https://dart-review.googlesource.com/c/sdk/+/201520
75-
// is in all published versions of analyzer this version of dartdoc
76-
// is compatible with.
77-
return CallableElementType(
78-
f, library, packageGraph, element, returnedFrom);
79-
} else if (isGenericTypeAlias) {
80-
return GenericTypeAliasElementType(f as TypeParameterType, library,
81-
packageGraph, element, returnedFrom);
82-
}
83-
if (f is TypeParameterType) {
84-
return TypeParameterElementType(
85-
f, library, packageGraph, element, returnedFrom);
86-
}
87-
assert(f is ParameterizedType);
88-
return ParameterizedElementType(
55+
}
56+
// [DefinedElementType]s.
57+
var element = packageGraph.modelBuilder.fromElement(fElement);
58+
// [TypeAliasElement.aliasElement] has different implications.
59+
// In that case it is an actual type alias of some kind (generic
60+
// or otherwise. Here however aliasElement signals that this is a
61+
// type referring to an alias.
62+
if (f is! TypeAliasElement && f.alias?.element != null) {
63+
return AliasedElementType(
8964
f as ParameterizedType, library, packageGraph, element, returnedFrom);
9065
}
66+
assert(f is ParameterizedType || f is TypeParameterType);
67+
// TODO(jcollins-g): strip out all the cruft that's accumulated
68+
// here for non-generic type aliases.
69+
var isGenericTypeAlias = f.alias?.element != null && f is! InterfaceType;
70+
if (f is FunctionType) {
71+
assert(f is ParameterizedType);
72+
// This is an indication we have an extremely out of date analyzer....
73+
assert(!isGenericTypeAlias, 'should never occur: out of date analyzer?');
74+
// And finally, delete this case and its associated class
75+
// after https://dart-review.googlesource.com/c/sdk/+/201520
76+
// is in all published versions of analyzer this version of dartdoc
77+
// is compatible with.
78+
return CallableElementType(
79+
f, library, packageGraph, element, returnedFrom);
80+
} else if (isGenericTypeAlias) {
81+
return GenericTypeAliasElementType(
82+
f as TypeParameterType, library, packageGraph, element, returnedFrom);
83+
}
84+
if (f is TypeParameterType) {
85+
return TypeParameterElementType(
86+
f, library, packageGraph, element, returnedFrom);
87+
}
88+
assert(f is ParameterizedType);
89+
return ParameterizedElementType(
90+
f as ParameterizedType, library, packageGraph, element, returnedFrom);
9191
}
9292

9393
bool get canHaveParameters => false;
@@ -260,7 +260,7 @@ class AliasedElementType extends ParameterizedElementType with Aliased {
260260
ParameterizedType get type;
261261

262262
/// Parameters, if available, for the underlying typedef.
263-
List<Parameter> get aliasedParameters =>
263+
late final List<Parameter> aliasedParameters =
264264
modelElement.isCallable ? modelElement.parameters : [];
265265

266266
@override
@@ -298,7 +298,7 @@ abstract class DefinedElementType extends ElementType {
298298
this.modelElement, ElementType? returnedFrom)
299299
: super(type, library, packageGraph, returnedFrom);
300300

301-
Element get element => modelElement.element;
301+
Element get element => modelElement.element!;
302302

303303
@override
304304
String get name => type.element!.name!;
@@ -372,7 +372,7 @@ abstract class DefinedElementType extends ElementType {
372372
modelElement.referenceParents;
373373

374374
@override
375-
Iterable<CommentReferable> get referenceGrandparentOverrides =>
375+
Iterable<CommentReferable>? get referenceGrandparentOverrides =>
376376
modelElement.referenceGrandparentOverrides;
377377

378378
@internal

lib/src/generator/generator_utils.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import 'package:dartdoc/src/model/model_element.dart';
1414
/// will likely want the same content for this.
1515
String generateCategoryJson(Iterable<Categorization> categories, bool pretty) {
1616
// ignore: omit_local_variable_types
17-
final List<Map<String, Object>> indexItems =
17+
final List<Map<String, Object?>> indexItems =
1818
categories.map((Categorization categorization) {
19-
final data = <String, Object>{
19+
final data = <String, Object?>{
2020
'name': categorization.name,
2121
'qualifiedName': categorization.fullyQualifiedName,
2222
'href': categorization.href,
@@ -49,21 +49,21 @@ String generateCategoryJson(Iterable<Categorization> categories, bool pretty) {
4949
String generateSearchIndexJson(
5050
Iterable<Indexable> indexedElements, bool pretty) {
5151
final indexItems = indexedElements.map((Indexable indexable) {
52-
final data = <String, Object>{
52+
final data = <String, Object?>{
5353
'name': indexable.name,
5454
'qualifiedName': indexable.fullyQualifiedName,
5555
'href': indexable.href,
5656
'type': indexable.kind,
5757
'overriddenDepth': indexable.overriddenDepth,
5858
};
5959
if (indexable is ModelElement) {
60-
data['packageName'] = indexable.package.name;
60+
data['packageName'] = indexable.package?.name;
6161
}
6262
if (indexable is EnclosedElement) {
6363
final ee = indexable as EnclosedElement;
64-
data['enclosedBy'] = {
65-
'name': ee.enclosingElement.name,
66-
'type': ee.enclosingElement.kind
64+
data['enclosedBy'] = <String, Object?>{
65+
'name': ee.enclosingElement!.name,
66+
'type': ee.enclosingElement!.kind
6767
};
6868

6969
data['qualifiedName'] = indexable.fullyQualifiedName;

lib/src/generator/template_data.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ abstract class TemplateData<T extends Documentable> {
5151

5252
String get bareHref {
5353
if (self is Indexable) {
54-
return (self as Indexable).href.replaceAll(htmlBasePlaceholder, '');
54+
var selfHref = (self as Indexable).href ?? '';
55+
return selfHref.replaceAll(htmlBasePlaceholder, '');
5556
}
5657
return '';
5758
}

lib/src/generator/templates.aot_renderers_for_md.dart

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -712,12 +712,10 @@ String renderClass(_i1.ClassTemplateData context0) {
712712
''');
713713
var context11 = context2.potentiallyApplicableExtensions;
714714
if (context11 != null) {
715-
for (var context12 in context11) {
716-
buffer.writeln();
717-
buffer.write('''
715+
buffer.writeln();
716+
buffer.write('''
718717
- ''');
719-
buffer.write(context12.linkedName.toString());
720-
}
718+
buffer.write(context2.linkedName.toString());
721719
}
722720
}
723721
buffer.writeln();
@@ -726,13 +724,13 @@ String renderClass(_i1.ClassTemplateData context0) {
726724
buffer.write('''
727725
**Annotations**
728726
''');
729-
var context13 = context2.annotations;
730-
if (context13 != null) {
731-
for (var context14 in context13) {
727+
var context12 = context2.annotations;
728+
if (context12 != null) {
729+
for (var context13 in context12) {
732730
buffer.writeln();
733731
buffer.write('''
734732
- ''');
735-
buffer.write(context14.linkedNameWithParameters.toString());
733+
buffer.write(context13.linkedNameWithParameters.toString());
736734
}
737735
}
738736
}
@@ -743,25 +741,25 @@ String renderClass(_i1.ClassTemplateData context0) {
743741
buffer.write('''
744742
## Constructors
745743
''');
746-
var context15 = context2.publicConstructorsSorted;
747-
if (context15 != null) {
748-
for (var context16 in context15) {
744+
var context14 = context2.publicConstructorsSorted;
745+
if (context14 != null) {
746+
for (var context15 in context14) {
749747
buffer.writeln();
750-
buffer.write(context16.linkedName.toString());
748+
buffer.write(context15.linkedName.toString());
751749
buffer.write(''' (''');
752-
buffer.write(context16.linkedParams.toString());
750+
buffer.write(context15.linkedParams.toString());
753751
buffer.write(''')
754752
755753
''');
756-
buffer.write(context16.oneLineDoc.toString());
754+
buffer.write(context15.oneLineDoc.toString());
757755
buffer.write(' ');
758-
buffer.write(context16.extendedDocLink.toString());
756+
buffer.write(context15.extendedDocLink.toString());
759757
buffer.write(' ');
760-
if (context16.isConst == true) {
758+
if (context15.isConst == true) {
761759
buffer.write('''_const_''');
762760
}
763761
buffer.write(' ');
764-
if (context16.isFactory == true) {
762+
if (context15.isFactory == true) {
765763
buffer.write('''_factory_''');
766764
}
767765
buffer.writeln();
@@ -774,12 +772,12 @@ String renderClass(_i1.ClassTemplateData context0) {
774772
buffer.write('''
775773
## Properties
776774
''');
777-
var context17 = context2.publicInstanceFieldsSorted;
778-
if (context17 != null) {
779-
for (var context18 in context17) {
775+
var context16 = context2.publicInstanceFieldsSorted;
776+
if (context16 != null) {
777+
for (var context17 in context16) {
780778
buffer.writeln();
781779
buffer.write(
782-
_renderClass_partial_property_5(context18, context2, context0));
780+
_renderClass_partial_property_5(context17, context2, context0));
783781
buffer.writeln();
784782
}
785783
}
@@ -790,12 +788,12 @@ String renderClass(_i1.ClassTemplateData context0) {
790788
buffer.write('''
791789
## Methods
792790
''');
793-
var context19 = context2.publicInstanceMethodsSorted;
794-
if (context19 != null) {
795-
for (var context20 in context19) {
791+
var context18 = context2.publicInstanceMethodsSorted;
792+
if (context18 != null) {
793+
for (var context19 in context18) {
796794
buffer.writeln();
797795
buffer.write(
798-
_renderClass_partial_callable_6(context20, context2, context0));
796+
_renderClass_partial_callable_6(context19, context2, context0));
799797
buffer.writeln();
800798
}
801799
}
@@ -806,12 +804,12 @@ String renderClass(_i1.ClassTemplateData context0) {
806804
buffer.write('''
807805
## Operators
808806
''');
809-
var context21 = context2.publicInstanceOperatorsSorted;
810-
if (context21 != null) {
811-
for (var context22 in context21) {
807+
var context20 = context2.publicInstanceOperatorsSorted;
808+
if (context20 != null) {
809+
for (var context21 in context20) {
812810
buffer.writeln();
813811
buffer.write(
814-
_renderClass_partial_callable_6(context22, context2, context0));
812+
_renderClass_partial_callable_6(context21, context2, context0));
815813
buffer.writeln();
816814
}
817815
}
@@ -822,12 +820,12 @@ String renderClass(_i1.ClassTemplateData context0) {
822820
buffer.write('''
823821
## Static Properties
824822
''');
825-
var context23 = context2.publicVariableStaticFieldsSorted;
826-
if (context23 != null) {
827-
for (var context24 in context23) {
823+
var context22 = context2.publicVariableStaticFieldsSorted;
824+
if (context22 != null) {
825+
for (var context23 in context22) {
828826
buffer.writeln();
829827
buffer.write(
830-
_renderClass_partial_property_5(context24, context2, context0));
828+
_renderClass_partial_property_5(context23, context2, context0));
831829
buffer.writeln();
832830
}
833831
}
@@ -838,12 +836,12 @@ String renderClass(_i1.ClassTemplateData context0) {
838836
buffer.write('''
839837
## Static Methods
840838
''');
841-
var context25 = context2.publicStaticMethodsSorted;
842-
if (context25 != null) {
843-
for (var context26 in context25) {
839+
var context24 = context2.publicStaticMethodsSorted;
840+
if (context24 != null) {
841+
for (var context25 in context24) {
844842
buffer.writeln();
845843
buffer.write(
846-
_renderClass_partial_callable_6(context26, context2, context0));
844+
_renderClass_partial_callable_6(context25, context2, context0));
847845
buffer.writeln();
848846
}
849847
}
@@ -854,12 +852,12 @@ String renderClass(_i1.ClassTemplateData context0) {
854852
buffer.write('''
855853
## Constants
856854
''');
857-
var context27 = context2.publicConstantFieldsSorted;
858-
if (context27 != null) {
859-
for (var context28 in context27) {
855+
var context26 = context2.publicConstantFieldsSorted;
856+
if (context26 != null) {
857+
for (var context27 in context26) {
860858
buffer.writeln();
861859
buffer.write(
862-
_renderClass_partial_constant_7(context28, context2, context0));
860+
_renderClass_partial_constant_7(context27, context2, context0));
863861
buffer.writeln();
864862
}
865863
}

0 commit comments

Comments
 (0)