Skip to content

Commit dda699a

Browse files
authored
Prepare mixin-like classes for Dart 3.0.0 (#3385)
1 parent a0755f5 commit dda699a

19 files changed

+33
-74
lines changed

lib/src/dartdoc_options.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ class DartdocOptionSyntheticOnly<T> extends DartdocOption<T>
651651
: super(name, null, help, optionIs, mustExist, null, resourceProvider);
652652
}
653653

654-
abstract class DartdocSyntheticOption<T> implements DartdocOption<T> {
654+
mixin DartdocSyntheticOption<T> implements DartdocOption<T> {
655655
T Function(DartdocSyntheticOption<T>, Folder) get _compute;
656656

657657
@override
@@ -841,7 +841,7 @@ class DartdocOptionFileOnly<T> extends DartdocOption<T>
841841
}
842842

843843
/// Implements checking for options contained in dartdoc.yaml.
844-
abstract class _DartdocFileOption<T> implements DartdocOption<T> {
844+
mixin _DartdocFileOption<T> implements DartdocOption<T> {
845845
/// If true, the parent directory's value overrides the child's.
846846
///
847847
/// Otherwise, the child's value overrides values in parents.
@@ -1018,7 +1018,7 @@ abstract class _DartdocFileOption<T> implements DartdocOption<T> {
10181018
}
10191019

10201020
/// Mixin class implementing command-line arguments for [DartdocOption].
1021-
abstract class _DartdocArgOption<T> implements DartdocOption<T> {
1021+
mixin _DartdocArgOption<T> implements DartdocOption<T> {
10221022
/// For [ArgParser], set to true if the argument can be negated with `--no` on
10231023
/// the command line.
10241024
bool get negatable;

lib/src/element_type.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ mixin ElementTypeBuilderImpl implements ElementTypeBuilder {
2525

2626
/// Base class representing a type in Dartdoc. It wraps a [DartType], and
2727
/// may link to a [ModelElement].
28-
abstract class ElementType extends Privacy
29-
with CommentReferable, Nameable, ModelBuilder {
28+
abstract class ElementType
29+
with CommentReferable, Nameable, ModelBuilder
30+
implements Privacy {
3031
final DartType type;
3132
@override
3233
final PackageGraph packageGraph;

lib/src/experiment_options.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import 'package:analyzer/file_system/file_system.dart';
1313
import 'package:analyzer/src/dart/analysis/experiments.dart';
1414
import 'package:dartdoc/src/dartdoc_options.dart';
1515

16-
abstract class DartdocExperimentOptionContext
17-
implements DartdocOptionContextBase {
16+
mixin DartdocExperimentOptionContext implements DartdocOptionContextBase {
1817
List<String> get enableExperiment =>
1918
optionSet['enable-experiment'].valueAt(context);
2019
}

lib/src/generator/templates.runtime_renderers.dart

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,6 @@ class _Renderer_Categorization extends RendererBase<Categorization> {
757757
_propertyMapCache.putIfAbsent(
758758
CT_,
759759
() => {
760-
..._Renderer_Object.propertyMap<CT_>(),
761760
'categories': Property(
762761
getValue: (CT_ c) => c.categories,
763762
renderVariable: (CT_ c, Property<CT_> self,
@@ -4110,7 +4109,7 @@ class _Renderer_ElementType extends RendererBase<ElementType> {
41104109
_propertyMapCache.putIfAbsent(
41114110
CT_,
41124111
() => {
4113-
..._Renderer_Privacy.propertyMap<CT_>(),
4112+
..._Renderer_Object.propertyMap<CT_>(),
41144113
..._Renderer_CommentReferable.propertyMap<CT_>(),
41154114
..._Renderer_Nameable.propertyMap<CT_>(),
41164115
..._Renderer_ModelBuilder.propertyMap<CT_>(),
@@ -6535,7 +6534,6 @@ class _Renderer_Indexable extends RendererBase<Indexable> {
65356534
_propertyMapCache.putIfAbsent(
65366535
CT_,
65376536
() => {
6538-
..._Renderer_Object.propertyMap<CT_>(),
65396537
'href': Property(
65406538
getValue: (CT_ c) => c.href,
65416539
renderVariable:
@@ -8546,7 +8544,6 @@ class _Renderer_Locatable extends RendererBase<Locatable> {
85468544
_propertyMapCache.putIfAbsent(
85478545
CT_,
85488546
() => {
8549-
..._Renderer_Object.propertyMap<CT_>(),
85508547
'documentationFrom': Property(
85518548
getValue: (CT_ c) => c.documentationFrom,
85528549
renderVariable: (CT_ c, Property<CT_> self,
@@ -9754,11 +9751,10 @@ class _Renderer_ModelElement extends RendererBase<ModelElement> {
97549751
() => {
97559752
..._Renderer_Canonicalization.propertyMap<CT_>(),
97569753
..._Renderer_CommentReferable.propertyMap<CT_>(),
9757-
..._Renderer_Privacy.propertyMap<CT_>(),
97589754
..._Renderer_Warnable.propertyMap<CT_>(),
97599755
..._Renderer_Locatable.propertyMap<CT_>(),
97609756
..._Renderer_Nameable.propertyMap<CT_>(),
9761-
..._Renderer_SourceCodeMixin.propertyMap<CT_>(),
9757+
..._Renderer_SourceCode.propertyMap<CT_>(),
97629758
..._Renderer_Indexable.propertyMap<CT_>(),
97639759
..._Renderer_FeatureSet.propertyMap<CT_>(),
97649760
..._Renderer_DocumentationComment.propertyMap<CT_>(),
@@ -12657,36 +12653,6 @@ class _Renderer_ParameterizedElementType
1265712653
}
1265812654
}
1265912655

12660-
class _Renderer_Privacy extends RendererBase<Privacy> {
12661-
static final Map<Type, Object> _propertyMapCache = {};
12662-
static Map<String, Property<CT_>> propertyMap<CT_ extends Privacy>() =>
12663-
_propertyMapCache.putIfAbsent(
12664-
CT_,
12665-
() => {
12666-
..._Renderer_Object.propertyMap<CT_>(),
12667-
'isPublic': Property(
12668-
getValue: (CT_ c) => c.isPublic,
12669-
renderVariable: (CT_ c, Property<CT_> self,
12670-
List<String> remainingNames) =>
12671-
self.renderSimpleVariable(c, remainingNames, 'bool'),
12672-
getBool: (CT_ c) => c.isPublic == true,
12673-
),
12674-
}) as Map<String, Property<CT_>>;
12675-
12676-
_Renderer_Privacy(Privacy context, RendererBase<Object>? parent,
12677-
Template template, StringSink sink)
12678-
: super(context, parent, template, sink);
12679-
12680-
@override
12681-
Property<Privacy>? getProperty(String key) {
12682-
if (propertyMap<Privacy>().containsKey(key)) {
12683-
return propertyMap<Privacy>()[key];
12684-
} else {
12685-
return null;
12686-
}
12687-
}
12688-
}
12689-
1269012656
String renderProperty(PropertyTemplateData context, Template template) {
1269112657
var buffer = StringBuffer();
1269212658
_render_PropertyTemplateData(context, template.ast, template, buffer);
@@ -12991,14 +12957,12 @@ class _Renderer_Rendered extends RendererBase<Rendered> {
1299112957
}
1299212958
}
1299312959

12994-
class _Renderer_SourceCodeMixin extends RendererBase<SourceCodeMixin> {
12960+
class _Renderer_SourceCode extends RendererBase<SourceCode> {
1299512961
static final Map<Type, Object> _propertyMapCache = {};
12996-
static Map<String, Property<CT_>> propertyMap<
12997-
CT_ extends SourceCodeMixin>() =>
12962+
static Map<String, Property<CT_>> propertyMap<CT_ extends SourceCode>() =>
1299812963
_propertyMapCache.putIfAbsent(
1299912964
CT_,
1300012965
() => {
13001-
..._Renderer_Object.propertyMap<CT_>(),
1300212966
'characterLocation': Property(
1300312967
getValue: (CT_ c) => c.characterLocation,
1300412968
renderVariable: (CT_ c, Property<CT_> self,
@@ -13090,14 +13054,14 @@ class _Renderer_SourceCodeMixin extends RendererBase<SourceCodeMixin> {
1309013054
),
1309113055
}) as Map<String, Property<CT_>>;
1309213056

13093-
_Renderer_SourceCodeMixin(SourceCodeMixin context,
13094-
RendererBase<Object>? parent, Template template, StringSink sink)
13057+
_Renderer_SourceCode(SourceCode context, RendererBase<Object>? parent,
13058+
Template template, StringSink sink)
1309513059
: super(context, parent, template, sink);
1309613060

1309713061
@override
13098-
Property<SourceCodeMixin>? getProperty(String key) {
13099-
if (propertyMap<SourceCodeMixin>().containsKey(key)) {
13100-
return propertyMap<SourceCodeMixin>()[key];
13062+
Property<SourceCode>? getProperty(String key) {
13063+
if (propertyMap<SourceCode>().containsKey(key)) {
13064+
return propertyMap<SourceCode>()[key];
1310113065
} else {
1310213066
return null;
1310313067
}
@@ -13789,7 +13753,6 @@ class _Renderer_TopLevelContainer extends RendererBase<TopLevelContainer> {
1378913753
_propertyMapCache.putIfAbsent(
1379013754
CT_,
1379113755
() => {
13792-
..._Renderer_Object.propertyMap<CT_>(),
1379313756
'classes': Property(
1379413757
getValue: (CT_ c) => c.classes,
1379513758
renderVariable: (CT_ c, Property<CT_> self,
@@ -16255,10 +16218,8 @@ const _invisibleGetters = {
1625516218
'documentationFrom',
1625616219
'documentationIsLocal',
1625716220
'fullyQualifiedName',
16258-
'hashCode',
1625916221
'href',
16260-
'location',
16261-
'runtimeType'
16222+
'location'
1626216223
},
1626316224
'Map': {
1626416225
'entries',

lib/src/logging.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void startLogging(LoggingContext config) {
125125
}
126126
}
127127

128-
abstract class LoggingContext implements DartdocOptionContextBase {
128+
mixin LoggingContext on DartdocOptionContextBase {
129129
bool get json => optionSet['json'].valueAt(context);
130130

131131
bool get showProgress => optionSet['showProgress'].valueAt(context);

lib/src/model/canonicalization.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'package:dartdoc/src/model/model.dart';
66

77
/// Classes extending this class have canonicalization support in Dartdoc.
8-
abstract class Canonicalization implements Locatable, Documentable {
8+
abstract /*mixin*/ class Canonicalization implements Locatable, Documentable {
99
bool get isCanonical;
1010

1111
Library? get canonicalLibrary;

lib/src/model/categorization.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ final RegExp _categoryRegExp = RegExp(
1010
multiLine: true);
1111

1212
/// Mixin implementing dartdoc categorization for ModelElements.
13-
abstract class Categorization implements ModelElement {
13+
mixin Categorization implements ModelElement {
1414
@override
1515
String buildDocumentationAddition(String rawDocs) =>
1616
_stripAndSetDartdocCategories(rawDocs);

lib/src/model/documentation_comment.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ final _htmlInjectRegExp = RegExp(r'<dartdoc-html>([a-f0-9]+)</dartdoc-html>');
3636
///
3737
/// [_processCommentWithoutTools] and [processComment] are the primary
3838
/// entrypoints.
39-
mixin DocumentationComment
40-
on Documentable, Warnable, Locatable, SourceCodeMixin {
39+
mixin DocumentationComment on Documentable, Warnable, Locatable, SourceCode {
4140
@override
4241
Element get element;
4342

lib/src/model/indexable.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'package:dartdoc/src/model/model.dart';
66

77
/// Something able to be indexed.
8-
abstract class Indexable implements Nameable {
8+
mixin Indexable implements Nameable {
99
String? get href;
1010

1111
String get kind;

lib/src/model/library_container.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:dartdoc/src/model_utils.dart' as model_utils;
1010
///
1111
/// Do not cache return values of any methods or members excepting [libraries]
1212
/// and [name] before finishing initialization of a [LibraryContainer].
13-
abstract class LibraryContainer
13+
abstract /*mixin*/ class LibraryContainer
1414
implements Nameable, Comparable<LibraryContainer> {
1515
final List<Library> libraries = [];
1616

lib/src/model/locatable.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'package:analyzer/dart/element/element.dart' show Element;
66

77
/// Something that can be located for warning purposes.
8-
abstract class Locatable {
8+
mixin Locatable {
99
List<Locatable> get documentationFrom;
1010

1111
/// True if documentationFrom contains only one item, [this].

lib/src/model/model_element.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,15 @@ mixin ModelElementBuilderImpl implements ModelElementBuilder {
114114
abstract class ModelElement extends Canonicalization
115115
with
116116
CommentReferable,
117-
Privacy,
118117
Warnable,
119118
Locatable,
120119
Nameable,
121-
SourceCodeMixin,
120+
SourceCode,
122121
Indexable,
123122
FeatureSet,
124123
DocumentationComment,
125124
ModelBuilder
126-
implements Comparable<ModelElement>, Documentable {
125+
implements Comparable<ModelElement>, Documentable, Privacy {
127126
// TODO(jcollins-g): This really wants a "member that has a type" class.
128127
final Member? _originalMember;
129128
final Library _library;

lib/src/model/nameable.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:collection/collection.dart';
77
import 'locatable.dart';
88

99
/// Something that has a name.
10-
abstract class Nameable {
10+
abstract /*mixin*/ class Nameable {
1111
String get name;
1212

1313
String get fullyQualifiedName => name;

lib/src/model/privacy.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
/// Classes implementing this have a public/private distinction.
6-
abstract class Privacy {
6+
abstract /*interface*/ class Privacy {
77
bool get isPublic;
88
}

lib/src/model/source_code_mixin.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:analyzer/dart/element/element.dart';
66
import 'package:analyzer/source/line_info.dart';
77
import 'package:dartdoc/src/model/model.dart';
88

9-
abstract class SourceCodeMixin implements Documentable {
9+
mixin SourceCode implements Documentable {
1010
ModelNode? get modelNode;
1111

1212
CharacterLocation? get characterLocation;

lib/src/model/top_level_container.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package:dartdoc/src/model_utils.dart' as model_utils;
1111
///
1212
/// Do not call any methods or members excepting [name] and the private Lists
1313
/// below before finishing initialization of a [TopLevelContainer].
14-
abstract class TopLevelContainer implements Nameable {
14+
mixin TopLevelContainer implements Nameable {
1515
Iterable<Class> get classes;
1616

1717
Iterable<Extension> get extensions;

lib/src/source_linker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'package:path/path.dart' as p;
1212

1313
final _uriTemplateRegExp = RegExp(r'(%[frl]%)');
1414

15-
abstract class SourceLinkerOptionContext implements DartdocOptionContextBase {
15+
mixin SourceLinkerOptionContext implements DartdocOptionContextBase {
1616
List<String> get linkToSourceExcludes =>
1717
optionSet['linkToSource']['excludes'].valueAt(context);
1818

lib/src/warnings.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'package:dartdoc/src/package_meta.dart';
1414

1515
const _namePlaceholder = '@@name@@';
1616

17-
abstract class PackageWarningOptionContext implements DartdocOptionContextBase {
17+
mixin PackageWarningOptionContext implements DartdocOptionContextBase {
1818
bool get allowNonLocalWarnings =>
1919
optionSet['allowNonLocalWarnings'].valueAt(context);
2020

test/package_meta_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void main() {
131131
expect(
132132
resourceProvider
133133
.readAsMalformedAllowedStringSync(p.getReadmeContents()!),
134-
startsWith('Welcome'));
134+
contains('Welcome to the'));
135135
});
136136

137137
test('does not have a license', () {

0 commit comments

Comments
 (0)