-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support changes for induced modifiers in analyzer (#3371)
* Initial implementation * induced modifiers support * Fix up tests and clean up unused bits we might do later
- Loading branch information
1 parent
203a5e6
commit a094d22
Showing
8 changed files
with
502 additions
and
376 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// 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' show IterableExtension; | ||
|
||
/// Represents a single modifier applicable to containers. | ||
class ContainerModifier implements Comparable<ContainerModifier> { | ||
final String name; | ||
final String displayName; | ||
|
||
/// If this modifier is present with any of these modifiers, it should | ||
/// not be displayed as part of a fullKind prefix. | ||
final Set<ContainerModifier> hideIfPresent; | ||
|
||
/// The display order of this modifier. | ||
final int order; | ||
const ContainerModifier._( | ||
this.name, { | ||
required this.order, | ||
String? displayName, | ||
Set<ContainerModifier>? hideIfPresent, | ||
}) : displayName = displayName ?? name, | ||
hideIfPresent = hideIfPresent ?? const <ContainerModifier>{}; | ||
|
||
@override | ||
String toString() => displayName; | ||
|
||
@override | ||
int compareTo(ContainerModifier a) => order.compareTo(a.order); | ||
|
||
static const ContainerModifier sealed = | ||
ContainerModifier._('sealed', order: 0); | ||
static const ContainerModifier abstract = | ||
ContainerModifier._('abstract', order: 0, hideIfPresent: {sealed}); | ||
static const ContainerModifier base = ContainerModifier._('base', order: 1); | ||
static const ContainerModifier interface = | ||
ContainerModifier._('interface', order: 2); | ||
static const ContainerModifier finalModifier = | ||
ContainerModifier._('final', order: 3); | ||
static const ContainerModifier mixin = ContainerModifier._('mixin', order: 4); | ||
} | ||
|
||
extension ContainerModifiers on Iterable<ContainerModifier> { | ||
/// Returns a string suitable for prefixing the class name in Dartdoc | ||
/// title bars based on given modifiers. | ||
String modifiersAsFullKindPrefix() => sorted((a, b) => a.compareTo(b)) | ||
.where((m) => !m.hideIfPresent.any(contains)) | ||
.join(' '); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// 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:dartdoc/src/model/container_modifiers.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('fullKind string tests', () { | ||
test('basic', () { | ||
var l = { | ||
ContainerModifier.base, | ||
ContainerModifier.interface, | ||
ContainerModifier.abstract | ||
}; | ||
expect(l.modifiersAsFullKindPrefix(), equals('abstract base interface')); | ||
}); | ||
|
||
test('hide abstract on sealed', () { | ||
var l = {ContainerModifier.abstract, ContainerModifier.sealed}; | ||
expect(l.modifiersAsFullKindPrefix(), equals('sealed')); | ||
}); | ||
|
||
test('empty', () { | ||
var l = <ContainerModifier>{}; | ||
expect(l.modifiersAsFullKindPrefix(), equals('')); | ||
}); | ||
}); | ||
} |