Skip to content

Commit 3e07e32

Browse files
authored
Convert some late final fields to getters; more fixes (#3549)
1 parent 117a53c commit 3e07e32

File tree

7 files changed

+29
-63
lines changed

7 files changed

+29
-63
lines changed

lib/src/element_type.dart

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class ParameterizedElementType extends DefinedElementType with Rendered {
212212

213213
/// A [ElementType] whose underlying type was referred to by a type alias.
214214
mixin Aliased implements ElementType, ModelBuilderInterface {
215-
late final Element typeAliasElement = type.alias!.element;
215+
Element get typeAliasElement => type.alias!.element;
216216

217217
@override
218218
String get name => typeAliasElement.name!;
@@ -236,10 +236,6 @@ class AliasedElementType extends ParameterizedElementType with Aliased {
236236
@override
237237
ParameterizedType get type;
238238

239-
/// Parameters, if available, for the underlying typedef.
240-
late final List<Parameter> aliasedParameters =
241-
modelElement.isCallable ? modelElement.parameters : [];
242-
243239
@override
244240
ElementTypeRenderer<AliasedElementType> get _renderer =>
245241
packageGraph.rendererFactory.aliasedElementTypeRenderer;
@@ -282,14 +278,6 @@ abstract class DefinedElementType extends ElementType {
282278
assert(f is ParameterizedType || f is TypeParameterType);
283279
assert(f is! FunctionType,
284280
'detected DefinedElementType for FunctionType: analyzer version too old?');
285-
// TODO(jcollins-g): strip out all the cruft that's accumulated
286-
// here for non-generic type aliases.
287-
var isGenericTypeAlias = f.alias?.element != null && f is! InterfaceType;
288-
if (isGenericTypeAlias) {
289-
assert(false);
290-
return GenericTypeAliasElementType(
291-
f as TypeParameterType, library, packageGraph, modelElement);
292-
}
293281
if (f is TypeParameterType) {
294282
return TypeParameterElementType(f, library, packageGraph, modelElement);
295283
}
@@ -428,12 +416,6 @@ class CallableElementType extends DefinedElementType with Rendered, Callable {
428416
const [];
429417
}
430418

431-
/// A non-callable type backed by a [GenericTypeAliasElement].
432-
class GenericTypeAliasElementType extends TypeParameterElementType {
433-
GenericTypeAliasElementType(
434-
super.t, super.library, super.packageGraph, super.element);
435-
}
436-
437419
extension on DartType {
438420
/// The dartdoc nullability suffix for this type in [library].
439421
String nullabilitySuffixWithin(Library library) {

lib/src/generator/templates.runtime_renderers.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -927,18 +927,6 @@ class _Renderer_Categorization extends RendererBase<Categorization> {
927927
_propertyMapCache.putIfAbsent(
928928
CT_,
929929
() => {
930-
'categories': Property(
931-
getValue: (CT_ c) => c.categories,
932-
renderVariable: (CT_ c, Property<CT_> self,
933-
List<String> remainingNames) =>
934-
self.renderSimpleVariable(
935-
c, remainingNames, 'Iterable<Category>'),
936-
renderIterable: (CT_ c, RendererBase<CT_> r,
937-
List<MustachioNode> ast, StringSink sink) {
938-
return c.categories.map((e) =>
939-
_render_Category(e, ast, r.template, sink, parent: r));
940-
},
941-
),
942930
'categoryNames': Property(
943931
getValue: (CT_ c) => c.categoryNames,
944932
renderVariable: (CT_ c, Property<CT_> self,

lib/src/model/directives/categorization.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:collection/collection.dart';
66
import 'package:dartdoc/src/model/model.dart';
7+
import 'package:meta/meta.dart';
78

89
final RegExp _categoryRegExp = RegExp(
910
r'[ ]*{@(api|category|subCategory|image|samples) (.+?)}[ ]*\n?',
@@ -90,9 +91,10 @@ mixin Categorization on DocumentationComment implements Indexable {
9091
return _samples;
9192
}
9293

93-
late final Iterable<Category> categories = [
94-
...?categoryNames?.map((n) => package.nameToCategory[n]).whereNotNull()
95-
]..sort();
94+
@visibleForTesting
95+
List<Category> get categories => [
96+
...?categoryNames?.map((n) => package.nameToCategory[n]).whereNotNull()
97+
]..sort();
9698

9799
Iterable<Category> get displayedCategories {
98100
if (config.showUndocumentedCategories) return categories;

lib/src/model/inheritable.dart

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,11 @@ mixin Inheritable on ContainerMember {
4343
canonicalEnclosingContainer?.canonicalLibrary;
4444

4545
@override
46-
late final ModelElement? canonicalModelElement = () {
47-
final canonicalEnclosingContainer = this.canonicalEnclosingContainer;
48-
if (canonicalEnclosingContainer == null) {
49-
return null;
50-
}
51-
return canonicalEnclosingContainer.allCanonicalModelElements
52-
.firstWhereOrNull((m) =>
53-
m.name == name &&
54-
m is PropertyAccessorElement == this is PropertyAccessorElement);
55-
}();
46+
late final ModelElement? canonicalModelElement = canonicalEnclosingContainer
47+
?.allCanonicalModelElements
48+
.firstWhereOrNull((m) =>
49+
m.name == name &&
50+
m is PropertyAccessorElement == this is PropertyAccessorElement);
5651

5752
@override
5853
Container? computeCanonicalEnclosingContainer() {
@@ -171,13 +166,13 @@ mixin Inheritable on ContainerMember {
171166
}();
172167

173168
@override
174-
late final int overriddenDepth = () {
169+
int get overriddenDepth {
175170
var depth = 0;
176171
var e = this;
177172
while (e.overriddenElement != null) {
178173
depth += 1;
179174
e = e.overriddenElement!;
180175
}
181176
return depth;
182-
}();
177+
}
183178
}

lib/src/model/package_graph.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
257257
return _implementors;
258258
}
259259

260-
late final Iterable<Extension> documentedExtensions =
260+
Iterable<Extension> get documentedExtensions =>
261261
utils.filterNonDocumented(extensions).toList(growable: false);
262262

263263
Iterable<Extension> get extensions {
@@ -603,8 +603,7 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
603603
late final Iterable<Library> libraries =
604604
packages.expand((p) => p.libraries).toList(growable: false)..sort();
605605

606-
/// The number of libraries.
607-
late final int libraryCount = libraries.length;
606+
int get libraryCount => libraries.length;
608607

609608
late final Set<Library> publicLibraries = () {
610609
assert(allLibrariesAdded);
@@ -630,11 +629,12 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
630629
?.linkedName ??
631630
'Object';
632631

633-
/// Return the set of [Class]es objects should inherit through if they
634-
/// show up in the inheritance chain. Do not call before interceptorElement is
635-
/// found. Add classes here if they are similar to Interceptor in that they
636-
/// are to be ignored even when they are the implementors of [Inheritable]s,
637-
/// and the class these inherit from should instead claim implementation.
632+
/// Return the set of [Class]es which objects should inherit through if they
633+
/// show up in the inheritance chain.
634+
///
635+
/// Add classes here if they are similar to Interceptor in that they are to be
636+
/// ignored even when they are the implementors of [Inheritable]s, and the
637+
/// class these inherit from should instead claim implementation.
638638
late final Set<Class> inheritThrough = () {
639639
var interceptorSpecialClass = specialClasses[SpecialClass.interceptor];
640640
if (interceptorSpecialClass == null) {
@@ -644,8 +644,8 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
644644
return {interceptorSpecialClass};
645645
}();
646646

647-
/// The set of [Class] objects that are similar to pragma
648-
/// in that we should never count them as documentable annotations.
647+
/// The set of [Class] objects that are similar to 'pragma' in that we should
648+
/// never count them as documentable annotations.
649649
late final Set<Class> invisibleAnnotations = () {
650650
var pragmaSpecialClass = specialClasses[SpecialClass.pragma];
651651
if (pragmaSpecialClass == null) {

lib/src/model/type_parameter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class TypeParameter extends ModelElement with HasNoPage {
3737
bool get hasParameters => false;
3838

3939
@override
40-
late final String name = element.bound != null
40+
String get name => element.bound != null
4141
? '${element.name} extends ${boundType!.nameWithGenerics}'
4242
: element.name;
4343

lib/src/package_meta.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,12 @@ abstract class PubPackageMeta extends PackageMeta {
294294
class _FilePackageMeta extends PubPackageMeta {
295295
File? _readme;
296296

297-
late final Map<dynamic, dynamic> _pubspec = () {
298-
var pubspec = dir.getChildAssumingFile('pubspec.yaml');
299-
assert(pubspec.exists);
300-
return loadYaml(pubspec.readAsStringSync()) as YamlMap;
301-
}();
297+
final Map<dynamic, dynamic> _pubspec;
302298

303-
_FilePackageMeta(super.dir, super.resourceProvider);
299+
_FilePackageMeta(super.dir, super.resourceProvider)
300+
: _pubspec = loadYaml(
301+
dir.getChildAssumingFile('pubspec.yaml').readAsStringSync())
302+
as YamlMap;
304303

305304
@override
306305
late final String? hostedAt = () {

0 commit comments

Comments
 (0)