-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathcontainer_modifiers.dart
51 lines (42 loc) · 1.95 KB
/
container_modifiers.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// 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/language_feature.dart';
/// 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 BuildLanguageFeatureSet on Iterable<ContainerModifier> {
/// Transforms [ContainerModifiers] into a series of [LanguageFeature] objects
/// suitable for rendering as chips. Assumes iterable is sorted.
Iterable<LanguageFeature> get asLanguageFeatureSet =>
where((m) => !m.hideIfPresent.any(contains))
.map((m) => LanguageFeature(m.name));
}