From d9aed80e28235b057505e84fdf3a801227470e97 Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Thu, 30 Dec 2021 22:47:24 -0600 Subject: [PATCH 1/2] Clean up model/categorization migration to simply template generation migration --- lib/src/model/categorization.dart | 55 ++++++++++++++++--------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/lib/src/model/categorization.dart b/lib/src/model/categorization.dart index 2ecea4edf7..dc60683c9f 100644 --- a/lib/src/model/categorization.dart +++ b/lib/src/model/categorization.dart @@ -2,6 +2,7 @@ // 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. +import 'package:collection/collection.dart'; import 'package:dartdoc/src/model/model.dart'; final RegExp _categoryRegExp = RegExp( @@ -49,66 +50,68 @@ abstract class Categorization implements ModelElement { return rawDocs; } - bool get hasSubCategoryNames => subCategoryNames!.isNotEmpty; + bool get hasSubCategoryNames => subCategoryNames?.isNotEmpty ?? false; List? _subCategoryNames; /// Either a set of strings containing all declared subcategories for this symbol, - /// or a set containing Null if none were declared. - List? get subCategoryNames { + /// or 'null' if none were declared. + late final List? subCategoryNames = () { // TODO(jcollins-g): avoid side-effect dependency if (_subCategoryNames == null) documentationLocal; return _subCategoryNames; - } + }(); @override - bool get hasCategoryNames => categoryNames!.isNotEmpty; + bool get hasCategoryNames => categoryNames?.isNotEmpty ?? false; List? _categoryNames; /// Either a set of strings containing all declared categories for this symbol, - /// or a set containing Null if none were declared. - List? get categoryNames { + /// or 'null' if none were declared. + late final List? categoryNames = () { // TODO(jcollins-g): avoid side-effect dependency if (_categoryNames == null) documentationLocal; return _categoryNames; - } + }(); bool get hasImage => image!.isNotEmpty; String? _image; - /// Either a URI to a defined image, or the empty string if none - /// was declared. - String? get image { + /// Either a URI to a defined image, + /// or 'null' if one was not declared. + late final String? image = () { // TODO(jcollins-g): avoid side-effect dependency if (_image == null) documentationLocal; return _image; - } + }(); - bool get hasSamples => samples!.isNotEmpty; + bool get hasSamples => samples?.isNotEmpty ?? false; String? _samples; - /// Either a URI to documentation with samples, or the empty string if none - /// was declared. - String? get samples { + /// Either a URI to documentation with samples, + /// or 'null' if one was not declared. + late final String? samples = () { // TODO(jcollins-g): avoid side-effect dependency if (_samples == null) documentationLocal; return _samples; - } + }(); - Iterable? _categories; + late final Iterable categories = () { + var categoryNames = this.categoryNames; + if (categoryNames == null) { + return []; + } - Iterable get categories { - _categories ??= categoryNames! + return categoryNames .map((n) => package?.nameToCategory[n]) - .where((c) => c != null) + .whereNotNull() .toList() ..sort(); - return _categories!; - } + }(); @override - Iterable get displayedCategories { + Iterable get displayedCategories { if (config.showUndocumentedCategories) return categories; - return categories.where((c) => c!.isDocumented); + return categories.where((c) => c.isDocumented); } bool? _hasCategorization; @@ -117,6 +120,6 @@ abstract class Categorization implements ModelElement { /// declared. late final bool hasCategorization = () { if (_hasCategorization == null) documentationLocal; - return _hasCategorization!; + return _hasCategorization ?? false; }(); } From baceacb08175b54cdd43c87a92e28fd9cae32d15 Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Thu, 30 Dec 2021 22:50:47 -0600 Subject: [PATCH 2/2] Revert some changes to late final --- lib/src/model/categorization.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/src/model/categorization.dart b/lib/src/model/categorization.dart index dc60683c9f..fea885221b 100644 --- a/lib/src/model/categorization.dart +++ b/lib/src/model/categorization.dart @@ -55,11 +55,11 @@ abstract class Categorization implements ModelElement { /// Either a set of strings containing all declared subcategories for this symbol, /// or 'null' if none were declared. - late final List? subCategoryNames = () { + List? get subCategoryNames { // TODO(jcollins-g): avoid side-effect dependency if (_subCategoryNames == null) documentationLocal; return _subCategoryNames; - }(); + } @override bool get hasCategoryNames => categoryNames?.isNotEmpty ?? false; @@ -67,33 +67,33 @@ abstract class Categorization implements ModelElement { /// Either a set of strings containing all declared categories for this symbol, /// or 'null' if none were declared. - late final List? categoryNames = () { + List? get categoryNames { // TODO(jcollins-g): avoid side-effect dependency if (_categoryNames == null) documentationLocal; return _categoryNames; - }(); + } bool get hasImage => image!.isNotEmpty; String? _image; /// Either a URI to a defined image, /// or 'null' if one was not declared. - late final String? image = () { + String? get image { // TODO(jcollins-g): avoid side-effect dependency if (_image == null) documentationLocal; return _image; - }(); + } bool get hasSamples => samples?.isNotEmpty ?? false; String? _samples; /// Either a URI to documentation with samples, /// or 'null' if one was not declared. - late final String? samples = () { + String? get samples { // TODO(jcollins-g): avoid side-effect dependency if (_samples == null) documentationLocal; return _samples; - }(); + } late final Iterable categories = () { var categoryNames = this.categoryNames;