forked from dart-lang/dartdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.dart
85 lines (65 loc) · 2.46 KB
/
class.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2019, 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:analyzer/dart/element/element.dart';
import 'package:dartdoc/src/model/model.dart';
/// A [Container] defined with a `class` declaration.
///
/// Members follow similar naming rules to [Container], with the following
/// additions:
///
/// **instance**: As with [Container], but also includes inherited children.
/// **inherited**: Filtered getters giving only inherited children.
class Class extends InheritingContainer with Constructable, MixedInTypes {
@override
final ClassElement element;
@override
late final List<ModelElement> allModelElements = [
...super.allModelElements,
...constructors,
];
@override
String get sidebarPath => '${library.dirName}/$name-class-sidebar.html';
@override
late final List<InheritingContainer> inheritanceChain = [
this,
// Caching should make this recursion a little less painful.
for (var container in mixedInElements.reversed)
...container.inheritanceChain,
for (var container in superChain.modelElements)
...container.inheritanceChain,
// Interfaces need to come last, because classes in the superChain might
// implement them even when they aren't mentioned.
...interfaceElements.expandInheritanceChain,
];
Class(this.element, Library library, PackageGraph packageGraph)
: super(library, packageGraph) {
packageGraph.specialClasses.addSpecial(this);
}
@override
String get fileName => '$name-class.html';
@override
bool get isAbstract => element.isAbstract;
@override
bool get isBase => element.isBase && !element.isSealed;
bool get isErrorOrException {
bool isError(InterfaceElement element) =>
element.library.isDartCore &&
(element.name == 'Exception' || element.name == 'Error');
final element = this.element;
if (isError(element)) return true;
return element.allSupertypes.map((t) => t.element).any(isError);
}
@override
bool get isFinal => element.isFinal && !element.isSealed;
@override
bool get isInterface => element.isInterface && !element.isSealed;
@override
bool get isMixinClass => element.isMixinClass;
@override
bool get isSealed => element.isSealed;
@override
Kind get kind => Kind.class_;
@override
String get relationshipsClass => 'clazz-relationships';
}