Skip to content

Migrate ModelElement and subclasses to NNBD #2843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a6ffd67
squash
jcollins-g Oct 12, 2021
e58770b
rebuild
jcollins-g Oct 12, 2021
42b4084
migrate more things
jcollins-g Oct 13, 2021
cd518ea
subprocess
jcollins-g Oct 13, 2021
574f9e0
type adjustment in grinder
jcollins-g Oct 13, 2021
a058b82
partial
jcollins-g Oct 14, 2021
922c7d8
partial 2
jcollins-g Oct 14, 2021
983e42c
no errors, ship it
jcollins-g Oct 14, 2021
5672bde
clean up a lot of warnings
jcollins-g Oct 14, 2021
3f064c3
All warnings done so really ship it
jcollins-g Oct 15, 2021
3e6812b
dartfmt
jcollins-g Oct 15, 2021
dbf8721
close
jcollins-g Oct 15, 2021
4f973d7
manual changes on renderers
jcollins-g Oct 20, 2021
32366cf
Merge branch 'nnbd' into nnbd-lib-miscellaneous
jcollins-g Oct 20, 2021
89641fb
Merge branch 'nnbd-lib-miscellaneous' into nnbd-lib-miscellaneous+tools
jcollins-g Oct 20, 2021
1abc062
Merge branch 'nnbd-lib-miscellaneous+tools' into nnbd-lib-miscellaneo…
jcollins-g Oct 20, 2021
5193190
comments
jcollins-g Oct 20, 2021
4dd55a3
Merge branch 'nnbd-lib-miscellaneous+tools' into nnbd-lib-miscellaneo…
jcollins-g Oct 20, 2021
1d0da25
partial
jcollins-g Oct 20, 2021
c66cc0b
fix some errors post-migration
jcollins-g Oct 21, 2021
a752169
holy cow it passes the tests now
jcollins-g Oct 21, 2021
b5a85e6
Merge branch 'nnbd' into nnbd-lib-miscellaneous+tools
jcollins-g Oct 21, 2021
4883978
Merge branch 'nnbd-lib-miscellaneous+tools' into nnbd-lib-miscellaneo…
jcollins-g Oct 21, 2021
735873a
Merge branch 'nnbd' into nnbd-lib-miscellaneous+tools
jcollins-g Oct 21, 2021
17f38f1
Merge branch 'nnbd-lib-miscellaneous+tools' into nnbd-lib-miscellaneo…
jcollins-g Oct 21, 2021
c53da36
make mustache happier and clean up an interface
jcollins-g Oct 21, 2021
00ff790
forgot to remove a fixme
jcollins-g Oct 21, 2021
420e1fd
Work around strange super-not-allowed error in stable
jcollins-g Oct 21, 2021
6e1360f
review comments
jcollins-g Oct 26, 2021
6bdeea8
Merge branch 'nnbd' into nnbd-modelelement
jcollins-g Oct 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.9
/// A documentation generator for Dart.
///
/// Library interface is still experimental.
Expand Down
8 changes: 4 additions & 4 deletions lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class DartdocFileMissing extends DartdocOptionError {
/// the 'categories' keyword in the options file, and populated by the
/// [CategoryConfiguration] class.
class CategoryDefinition {
/// Internal name of the category.
final String name;
/// Internal name of the category, or null for the default category.
final String? name;

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

/// Returns the [_displayName], if available, or else simply [name].
String get displayName => _displayName ?? name;
String get displayName => _displayName ?? name ?? '';
}

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

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

String get examplePathPrefix =>
String? get examplePathPrefix =>
optionSet['examplePathPrefix'].valueAt(context);

// TODO(srawlins): This memoization saved a lot of time in unit testing, but
Expand Down
76 changes: 38 additions & 38 deletions lib/src/element_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ abstract class ElementType extends Privacy
if (fElement == null ||
fElement.kind == ElementKind.DYNAMIC ||
fElement.kind == ElementKind.NEVER) {
// [UndefinedElementType]s.
if (f is FunctionType) {
if (f.alias?.element != null) {
return AliasedFunctionTypeElementType(
Expand All @@ -51,43 +52,42 @@ abstract class ElementType extends Privacy
return FunctionTypeElementType(f, library, packageGraph, returnedFrom);
}
return UndefinedElementType(f, library, packageGraph, returnedFrom);
} else {
var element = packageGraph.modelBuilder.fromElement(fElement);
// [TypeAliasElement.aliasElement] has different implications.
// In that case it is an actual type alias of some kind (generic
// or otherwise. Here however aliasElement signals that this is a
// type referring to an alias.
if (f is! TypeAliasElement && f.alias?.element != null) {
return AliasedElementType(f as ParameterizedType, library, packageGraph,
element, returnedFrom);
}
assert(f is ParameterizedType || f is TypeParameterType);
// TODO(jcollins-g): strip out all the cruft that's accumulated
// here for non-generic type aliases.
var isGenericTypeAlias = f.alias?.element != null && f is! InterfaceType;
if (f is FunctionType) {
assert(f is ParameterizedType);
// This is an indication we have an extremely out of date analyzer....
assert(
!isGenericTypeAlias, 'should never occur: out of date analyzer?');
// And finally, delete this case and its associated class
// after https://dart-review.googlesource.com/c/sdk/+/201520
// is in all published versions of analyzer this version of dartdoc
// is compatible with.
return CallableElementType(
f, library, packageGraph, element, returnedFrom);
} else if (isGenericTypeAlias) {
return GenericTypeAliasElementType(f as TypeParameterType, library,
packageGraph, element, returnedFrom);
}
if (f is TypeParameterType) {
return TypeParameterElementType(
f, library, packageGraph, element, returnedFrom);
}
assert(f is ParameterizedType);
return ParameterizedElementType(
}
// [DefinedElementType]s.
var element = packageGraph.modelBuilder.fromElement(fElement);
// [TypeAliasElement.aliasElement] has different implications.
// In that case it is an actual type alias of some kind (generic
// or otherwise. Here however aliasElement signals that this is a
// type referring to an alias.
if (f is! TypeAliasElement && f.alias?.element != null) {
return AliasedElementType(
f as ParameterizedType, library, packageGraph, element, returnedFrom);
}
assert(f is ParameterizedType || f is TypeParameterType);
// TODO(jcollins-g): strip out all the cruft that's accumulated
// here for non-generic type aliases.
var isGenericTypeAlias = f.alias?.element != null && f is! InterfaceType;
if (f is FunctionType) {
assert(f is ParameterizedType);
// This is an indication we have an extremely out of date analyzer....
assert(!isGenericTypeAlias, 'should never occur: out of date analyzer?');
// And finally, delete this case and its associated class
// after https://dart-review.googlesource.com/c/sdk/+/201520
// is in all published versions of analyzer this version of dartdoc
// is compatible with.
return CallableElementType(
f, library, packageGraph, element, returnedFrom);
} else if (isGenericTypeAlias) {
return GenericTypeAliasElementType(
f as TypeParameterType, library, packageGraph, element, returnedFrom);
}
if (f is TypeParameterType) {
return TypeParameterElementType(
f, library, packageGraph, element, returnedFrom);
}
assert(f is ParameterizedType);
return ParameterizedElementType(
f as ParameterizedType, library, packageGraph, element, returnedFrom);
}

bool get canHaveParameters => false;
Expand Down Expand Up @@ -260,7 +260,7 @@ class AliasedElementType extends ParameterizedElementType with Aliased {
ParameterizedType get type;

/// Parameters, if available, for the underlying typedef.
List<Parameter> get aliasedParameters =>
late final List<Parameter> aliasedParameters =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice optimization

modelElement.isCallable ? modelElement.parameters : [];

@override
Expand Down Expand Up @@ -298,7 +298,7 @@ abstract class DefinedElementType extends ElementType {
this.modelElement, ElementType? returnedFrom)
: super(type, library, packageGraph, returnedFrom);

Element get element => modelElement.element;
Element get element => modelElement.element!;

@override
String get name => type.element!.name!;
Expand Down Expand Up @@ -372,7 +372,7 @@ abstract class DefinedElementType extends ElementType {
modelElement.referenceParents;

@override
Iterable<CommentReferable> get referenceGrandparentOverrides =>
Iterable<CommentReferable>? get referenceGrandparentOverrides =>
modelElement.referenceGrandparentOverrides;

@internal
Expand Down
14 changes: 7 additions & 7 deletions lib/src/generator/generator_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import 'package:dartdoc/src/model/model_element.dart';
/// will likely want the same content for this.
String generateCategoryJson(Iterable<Categorization> categories, bool pretty) {
// ignore: omit_local_variable_types
final List<Map<String, Object>> indexItems =
final List<Map<String, Object?>> indexItems =
categories.map((Categorization categorization) {
final data = <String, Object>{
final data = <String, Object?>{
'name': categorization.name,
'qualifiedName': categorization.fullyQualifiedName,
'href': categorization.href,
Expand Down Expand Up @@ -49,21 +49,21 @@ String generateCategoryJson(Iterable<Categorization> categories, bool pretty) {
String generateSearchIndexJson(
Iterable<Indexable> indexedElements, bool pretty) {
final indexItems = indexedElements.map((Indexable indexable) {
final data = <String, Object>{
final data = <String, Object?>{
'name': indexable.name,
'qualifiedName': indexable.fullyQualifiedName,
'href': indexable.href,
'type': indexable.kind,
'overriddenDepth': indexable.overriddenDepth,
};
if (indexable is ModelElement) {
data['packageName'] = indexable.package.name;
data['packageName'] = indexable.package?.name;
}
if (indexable is EnclosedElement) {
final ee = indexable as EnclosedElement;
data['enclosedBy'] = {
'name': ee.enclosingElement.name,
'type': ee.enclosingElement.kind
data['enclosedBy'] = <String, Object?>{
'name': ee.enclosingElement!.name,
'type': ee.enclosingElement!.kind
};

data['qualifiedName'] = indexable.fullyQualifiedName;
Expand Down
3 changes: 2 additions & 1 deletion lib/src/generator/template_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ abstract class TemplateData<T extends Documentable> {

String get bareHref {
if (self is Indexable) {
return (self as Indexable).href.replaceAll(htmlBasePlaceholder, '');
var selfHref = (self as Indexable).href ?? '';
return selfHref.replaceAll(htmlBasePlaceholder, '');
}
return '';
}
Expand Down
82 changes: 40 additions & 42 deletions lib/src/generator/templates.aot_renderers_for_md.dart
Original file line number Diff line number Diff line change
Expand Up @@ -712,12 +712,10 @@ String renderClass(_i1.ClassTemplateData context0) {
''');
var context11 = context2.potentiallyApplicableExtensions;
if (context11 != null) {
for (var context12 in context11) {
buffer.writeln();
buffer.write('''
buffer.writeln();
buffer.write('''
- ''');
buffer.write(context12.linkedName.toString());
}
buffer.write(context2.linkedName.toString());
}
}
buffer.writeln();
Expand All @@ -726,13 +724,13 @@ String renderClass(_i1.ClassTemplateData context0) {
buffer.write('''
**Annotations**
''');
var context13 = context2.annotations;
if (context13 != null) {
for (var context14 in context13) {
var context12 = context2.annotations;
if (context12 != null) {
for (var context13 in context12) {
buffer.writeln();
buffer.write('''
- ''');
buffer.write(context14.linkedNameWithParameters.toString());
buffer.write(context13.linkedNameWithParameters.toString());
}
}
}
Expand All @@ -743,25 +741,25 @@ String renderClass(_i1.ClassTemplateData context0) {
buffer.write('''
## Constructors
''');
var context15 = context2.publicConstructorsSorted;
if (context15 != null) {
for (var context16 in context15) {
var context14 = context2.publicConstructorsSorted;
if (context14 != null) {
for (var context15 in context14) {
buffer.writeln();
buffer.write(context16.linkedName.toString());
buffer.write(context15.linkedName.toString());
buffer.write(''' (''');
buffer.write(context16.linkedParams.toString());
buffer.write(context15.linkedParams.toString());
buffer.write(''')

''');
buffer.write(context16.oneLineDoc.toString());
buffer.write(context15.oneLineDoc.toString());
buffer.write(' ');
buffer.write(context16.extendedDocLink.toString());
buffer.write(context15.extendedDocLink.toString());
buffer.write(' ');
if (context16.isConst == true) {
if (context15.isConst == true) {
buffer.write('''_const_''');
}
buffer.write(' ');
if (context16.isFactory == true) {
if (context15.isFactory == true) {
buffer.write('''_factory_''');
}
buffer.writeln();
Expand All @@ -774,12 +772,12 @@ String renderClass(_i1.ClassTemplateData context0) {
buffer.write('''
## Properties
''');
var context17 = context2.publicInstanceFieldsSorted;
if (context17 != null) {
for (var context18 in context17) {
var context16 = context2.publicInstanceFieldsSorted;
if (context16 != null) {
for (var context17 in context16) {
buffer.writeln();
buffer.write(
_renderClass_partial_property_5(context18, context2, context0));
_renderClass_partial_property_5(context17, context2, context0));
buffer.writeln();
}
}
Expand All @@ -790,12 +788,12 @@ String renderClass(_i1.ClassTemplateData context0) {
buffer.write('''
## Methods
''');
var context19 = context2.publicInstanceMethodsSorted;
if (context19 != null) {
for (var context20 in context19) {
var context18 = context2.publicInstanceMethodsSorted;
if (context18 != null) {
for (var context19 in context18) {
buffer.writeln();
buffer.write(
_renderClass_partial_callable_6(context20, context2, context0));
_renderClass_partial_callable_6(context19, context2, context0));
buffer.writeln();
}
}
Expand All @@ -806,12 +804,12 @@ String renderClass(_i1.ClassTemplateData context0) {
buffer.write('''
## Operators
''');
var context21 = context2.publicInstanceOperatorsSorted;
if (context21 != null) {
for (var context22 in context21) {
var context20 = context2.publicInstanceOperatorsSorted;
if (context20 != null) {
for (var context21 in context20) {
buffer.writeln();
buffer.write(
_renderClass_partial_callable_6(context22, context2, context0));
_renderClass_partial_callable_6(context21, context2, context0));
buffer.writeln();
}
}
Expand All @@ -822,12 +820,12 @@ String renderClass(_i1.ClassTemplateData context0) {
buffer.write('''
## Static Properties
''');
var context23 = context2.publicVariableStaticFieldsSorted;
if (context23 != null) {
for (var context24 in context23) {
var context22 = context2.publicVariableStaticFieldsSorted;
if (context22 != null) {
for (var context23 in context22) {
buffer.writeln();
buffer.write(
_renderClass_partial_property_5(context24, context2, context0));
_renderClass_partial_property_5(context23, context2, context0));
buffer.writeln();
}
}
Expand All @@ -838,12 +836,12 @@ String renderClass(_i1.ClassTemplateData context0) {
buffer.write('''
## Static Methods
''');
var context25 = context2.publicStaticMethodsSorted;
if (context25 != null) {
for (var context26 in context25) {
var context24 = context2.publicStaticMethodsSorted;
if (context24 != null) {
for (var context25 in context24) {
buffer.writeln();
buffer.write(
_renderClass_partial_callable_6(context26, context2, context0));
_renderClass_partial_callable_6(context25, context2, context0));
buffer.writeln();
}
}
Expand All @@ -854,12 +852,12 @@ String renderClass(_i1.ClassTemplateData context0) {
buffer.write('''
## Constants
''');
var context27 = context2.publicConstantFieldsSorted;
if (context27 != null) {
for (var context28 in context27) {
var context26 = context2.publicConstantFieldsSorted;
if (context26 != null) {
for (var context27 in context26) {
buffer.writeln();
buffer.write(
_renderClass_partial_constant_7(context28, context2, context0));
_renderClass_partial_constant_7(context27, context2, context0));
buffer.writeln();
}
}
Expand Down
Loading