Skip to content

Prepare mixin-like classes for Dart 3.0.0 #3385

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 3 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ class DartdocOptionSyntheticOnly<T> extends DartdocOption<T>
: super(name, null, help, optionIs, mustExist, null, resourceProvider);
}

abstract class DartdocSyntheticOption<T> implements DartdocOption<T> {
mixin DartdocSyntheticOption<T> implements DartdocOption<T> {
T Function(DartdocSyntheticOption<T>, Folder) get _compute;

@override
Expand Down Expand Up @@ -841,7 +841,7 @@ class DartdocOptionFileOnly<T> extends DartdocOption<T>
}

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

/// Mixin class implementing command-line arguments for [DartdocOption].
abstract class _DartdocArgOption<T> implements DartdocOption<T> {
mixin _DartdocArgOption<T> implements DartdocOption<T> {
/// For [ArgParser], set to true if the argument can be negated with `--no` on
/// the command line.
bool get negatable;
Expand Down
5 changes: 3 additions & 2 deletions lib/src/element_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ mixin ElementTypeBuilderImpl implements ElementTypeBuilder {

/// Base class representing a type in Dartdoc. It wraps a [DartType], and
/// may link to a [ModelElement].
abstract class ElementType extends Privacy
with CommentReferable, Nameable, ModelBuilder {
abstract class ElementType
with CommentReferable, Nameable, ModelBuilder
implements Privacy {
final DartType type;
@override
final PackageGraph packageGraph;
Expand Down
3 changes: 1 addition & 2 deletions lib/src/experiment_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/analysis/experiments.dart';
import 'package:dartdoc/src/dartdoc_options.dart';

abstract class DartdocExperimentOptionContext
implements DartdocOptionContextBase {
mixin DartdocExperimentOptionContext implements DartdocOptionContextBase {
List<String> get enableExperiment =>
optionSet['enable-experiment'].valueAt(context);
}
Expand Down
59 changes: 10 additions & 49 deletions lib/src/generator/templates.runtime_renderers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,6 @@ class _Renderer_Categorization extends RendererBase<Categorization> {
_propertyMapCache.putIfAbsent(
CT_,
() => {
..._Renderer_Object.propertyMap<CT_>(),
'categories': Property(
getValue: (CT_ c) => c.categories,
renderVariable: (CT_ c, Property<CT_> self,
Expand Down Expand Up @@ -4110,7 +4109,7 @@ class _Renderer_ElementType extends RendererBase<ElementType> {
_propertyMapCache.putIfAbsent(
CT_,
() => {
..._Renderer_Privacy.propertyMap<CT_>(),
..._Renderer_Object.propertyMap<CT_>(),
..._Renderer_CommentReferable.propertyMap<CT_>(),
..._Renderer_Nameable.propertyMap<CT_>(),
..._Renderer_ModelBuilder.propertyMap<CT_>(),
Expand Down Expand Up @@ -6535,7 +6534,6 @@ class _Renderer_Indexable extends RendererBase<Indexable> {
_propertyMapCache.putIfAbsent(
CT_,
() => {
..._Renderer_Object.propertyMap<CT_>(),
'href': Property(
getValue: (CT_ c) => c.href,
renderVariable:
Expand Down Expand Up @@ -8546,7 +8544,6 @@ class _Renderer_Locatable extends RendererBase<Locatable> {
_propertyMapCache.putIfAbsent(
CT_,
() => {
..._Renderer_Object.propertyMap<CT_>(),
'documentationFrom': Property(
getValue: (CT_ c) => c.documentationFrom,
renderVariable: (CT_ c, Property<CT_> self,
Expand Down Expand Up @@ -9754,11 +9751,10 @@ class _Renderer_ModelElement extends RendererBase<ModelElement> {
() => {
..._Renderer_Canonicalization.propertyMap<CT_>(),
..._Renderer_CommentReferable.propertyMap<CT_>(),
..._Renderer_Privacy.propertyMap<CT_>(),
..._Renderer_Warnable.propertyMap<CT_>(),
..._Renderer_Locatable.propertyMap<CT_>(),
..._Renderer_Nameable.propertyMap<CT_>(),
..._Renderer_SourceCodeMixin.propertyMap<CT_>(),
..._Renderer_SourceCode.propertyMap<CT_>(),
..._Renderer_Indexable.propertyMap<CT_>(),
..._Renderer_FeatureSet.propertyMap<CT_>(),
..._Renderer_DocumentationComment.propertyMap<CT_>(),
Expand Down Expand Up @@ -12657,36 +12653,6 @@ class _Renderer_ParameterizedElementType
}
}

class _Renderer_Privacy extends RendererBase<Privacy> {
static final Map<Type, Object> _propertyMapCache = {};
static Map<String, Property<CT_>> propertyMap<CT_ extends Privacy>() =>
_propertyMapCache.putIfAbsent(
CT_,
() => {
..._Renderer_Object.propertyMap<CT_>(),
'isPublic': Property(
getValue: (CT_ c) => c.isPublic,
renderVariable: (CT_ c, Property<CT_> self,
List<String> remainingNames) =>
self.renderSimpleVariable(c, remainingNames, 'bool'),
getBool: (CT_ c) => c.isPublic == true,
),
}) as Map<String, Property<CT_>>;

_Renderer_Privacy(Privacy context, RendererBase<Object>? parent,
Template template, StringSink sink)
: super(context, parent, template, sink);

@override
Property<Privacy>? getProperty(String key) {
if (propertyMap<Privacy>().containsKey(key)) {
return propertyMap<Privacy>()[key];
} else {
return null;
}
}
}

String renderProperty(PropertyTemplateData context, Template template) {
var buffer = StringBuffer();
_render_PropertyTemplateData(context, template.ast, template, buffer);
Expand Down Expand Up @@ -12991,14 +12957,12 @@ class _Renderer_Rendered extends RendererBase<Rendered> {
}
}

class _Renderer_SourceCodeMixin extends RendererBase<SourceCodeMixin> {
class _Renderer_SourceCode extends RendererBase<SourceCode> {
static final Map<Type, Object> _propertyMapCache = {};
static Map<String, Property<CT_>> propertyMap<
CT_ extends SourceCodeMixin>() =>
static Map<String, Property<CT_>> propertyMap<CT_ extends SourceCode>() =>
_propertyMapCache.putIfAbsent(
CT_,
() => {
..._Renderer_Object.propertyMap<CT_>(),
'characterLocation': Property(
getValue: (CT_ c) => c.characterLocation,
renderVariable: (CT_ c, Property<CT_> self,
Expand Down Expand Up @@ -13090,14 +13054,14 @@ class _Renderer_SourceCodeMixin extends RendererBase<SourceCodeMixin> {
),
}) as Map<String, Property<CT_>>;

_Renderer_SourceCodeMixin(SourceCodeMixin context,
RendererBase<Object>? parent, Template template, StringSink sink)
_Renderer_SourceCode(SourceCode context, RendererBase<Object>? parent,
Template template, StringSink sink)
: super(context, parent, template, sink);

@override
Property<SourceCodeMixin>? getProperty(String key) {
if (propertyMap<SourceCodeMixin>().containsKey(key)) {
return propertyMap<SourceCodeMixin>()[key];
Property<SourceCode>? getProperty(String key) {
if (propertyMap<SourceCode>().containsKey(key)) {
return propertyMap<SourceCode>()[key];
} else {
return null;
}
Expand Down Expand Up @@ -13789,7 +13753,6 @@ class _Renderer_TopLevelContainer extends RendererBase<TopLevelContainer> {
_propertyMapCache.putIfAbsent(
CT_,
() => {
..._Renderer_Object.propertyMap<CT_>(),
'classes': Property(
getValue: (CT_ c) => c.classes,
renderVariable: (CT_ c, Property<CT_> self,
Expand Down Expand Up @@ -16255,10 +16218,8 @@ const _invisibleGetters = {
'documentationFrom',
'documentationIsLocal',
'fullyQualifiedName',
'hashCode',
'href',
'location',
'runtimeType'
'location'
},
'Map': {
'entries',
Expand Down
2 changes: 1 addition & 1 deletion lib/src/logging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void startLogging(LoggingContext config) {
}
}

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

bool get showProgress => optionSet['showProgress'].valueAt(context);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/canonicalization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'package:dartdoc/src/model/model.dart';

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

Library? get canonicalLibrary;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/categorization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final RegExp _categoryRegExp = RegExp(
multiLine: true);

/// Mixin implementing dartdoc categorization for ModelElements.
abstract class Categorization implements ModelElement {
mixin Categorization implements ModelElement {
@override
String buildDocumentationAddition(String rawDocs) =>
_stripAndSetDartdocCategories(rawDocs);
Expand Down
3 changes: 1 addition & 2 deletions lib/src/model/documentation_comment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ final _htmlInjectRegExp = RegExp(r'<dartdoc-html>([a-f0-9]+)</dartdoc-html>');
///
/// [_processCommentWithoutTools] and [processComment] are the primary
/// entrypoints.
mixin DocumentationComment
on Documentable, Warnable, Locatable, SourceCodeMixin {
mixin DocumentationComment on Documentable, Warnable, Locatable, SourceCode {
@override
Element get element;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/indexable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'package:dartdoc/src/model/model.dart';

/// Something able to be indexed.
abstract class Indexable implements Nameable {
mixin Indexable implements Nameable {
String? get href;

String get kind;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/library_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:dartdoc/src/model_utils.dart' as model_utils;
///
/// Do not cache return values of any methods or members excepting [libraries]
/// and [name] before finishing initialization of a [LibraryContainer].
abstract class LibraryContainer
abstract /*mixin*/ class LibraryContainer
implements Nameable, Comparable<LibraryContainer> {
final List<Library> libraries = [];

Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/locatable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'package:analyzer/dart/element/element.dart' show Element;

/// Something that can be located for warning purposes.
abstract class Locatable {
mixin Locatable {
List<Locatable> get documentationFrom;

/// True if documentationFrom contains only one item, [this].
Expand Down
5 changes: 2 additions & 3 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,15 @@ mixin ModelElementBuilderImpl implements ModelElementBuilder {
abstract class ModelElement extends Canonicalization
with
CommentReferable,
Privacy,
Warnable,
Locatable,
Nameable,
SourceCodeMixin,
SourceCode,
Indexable,
FeatureSet,
DocumentationComment,
ModelBuilder
implements Comparable<ModelElement>, Documentable {
implements Comparable<ModelElement>, Documentable, Privacy {
// TODO(jcollins-g): This really wants a "member that has a type" class.
final Member? _originalMember;
final Library _library;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/nameable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:collection/collection.dart';
import 'locatable.dart';

/// Something that has a name.
abstract class Nameable {
abstract /*mixin*/ class Nameable {
String get name;

String get fullyQualifiedName => name;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/privacy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

/// Classes implementing this have a public/private distinction.
abstract class Privacy {
abstract /*interface*/ class Privacy {
bool get isPublic;
}
2 changes: 1 addition & 1 deletion lib/src/model/source_code_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/source/line_info.dart';
import 'package:dartdoc/src/model/model.dart';

abstract class SourceCodeMixin implements Documentable {
mixin SourceCode implements Documentable {
ModelNode? get modelNode;

CharacterLocation? get characterLocation;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/top_level_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:dartdoc/src/model_utils.dart' as model_utils;
///
/// Do not call any methods or members excepting [name] and the private Lists
/// below before finishing initialization of a [TopLevelContainer].
abstract class TopLevelContainer implements Nameable {
mixin TopLevelContainer implements Nameable {
Iterable<Class> get classes;

Iterable<Extension> get extensions;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/source_linker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:path/path.dart' as p;

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

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

Expand Down
2 changes: 1 addition & 1 deletion lib/src/warnings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'package:dartdoc/src/package_meta.dart';

const _namePlaceholder = '@@name@@';

abstract class PackageWarningOptionContext implements DartdocOptionContextBase {
mixin PackageWarningOptionContext implements DartdocOptionContextBase {
bool get allowNonLocalWarnings =>
optionSet['allowNonLocalWarnings'].valueAt(context);

Expand Down
2 changes: 1 addition & 1 deletion test/package_meta_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void main() {
expect(
resourceProvider
.readAsMalformedAllowedStringSync(p.getReadmeContents()!),
startsWith('Welcome'));
contains('Welcome to the'));
});

test('does not have a license', () {
Expand Down