-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathlanguage_feature.dart
68 lines (57 loc) · 2.34 KB
/
language_feature.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2020, 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.
const Map<String, String> _featureDescriptions = {
'sealed':
'The direct subtypes of this class will be checked for exhaustiveness in switches.',
'abstract': 'This type can not be directly constructed.',
'base':
'This class or mixin can only be extended (not implemented or mixed in).',
'interface': 'This class can only be implemented (not extended or mixed in).',
'final': 'This class can neither be extended, implemented, nor mixed in.',
'mixin': 'This class can be used as a class and a mixin.',
};
const Map<String, String> _featureUrls = {
'sealed': 'https://dart.dev/language/class-modifiers#sealed',
'abstract': 'https://dart.dev/language/class-modifiers#abstract',
'base': 'https://dart.dev/language/class-modifiers#base',
'interface': 'https://dart.dev/language/class-modifiers#interface',
'final': 'https://dart.dev/language/class-modifiers#final',
'mixin': 'https://dart.dev/language/mixins',
};
/// An abstraction for a language feature; used to render tags ('chips') to
/// notify the user that the documentation should be specially interpreted.
class LanguageFeature {
/// The description of this language feature.
String? get featureDescription => _featureDescriptions[name];
/// A URL containing more information about this feature or `null` if there
/// is none.
String? get featureUrl => _featureUrls[name];
/// The rendered label for this language feature.
String get featureLabel {
final buffer = StringBuffer();
final url = featureUrl;
if (url != null) {
buffer.write('<a href="');
buffer.write(url);
buffer.write('"');
} else {
buffer.write('<span');
}
buffer.write(' class="feature feature-');
buffer.writeAll(name.toLowerCase().split(' '), '-');
buffer.write('" title="');
buffer.write(featureDescription);
buffer.write('">');
buffer.write(name);
if (url != null) {
buffer.write('</a>');
} else {
buffer.write('</span>');
}
return buffer.toString();
}
/// The name of this language feature.
final String name;
LanguageFeature(this.name) : assert(_featureDescriptions.containsKey(name));
}