-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathcontainer_member.dart
61 lines (53 loc) · 2.22 KB
/
container_member.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
// 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:dartdoc/src/model/model.dart';
/// A [ModelElement] that is a [Container] member.
mixin ContainerMember on ModelElement implements EnclosedElement {
/// True if this [ContainerMember] is from an applicable [Extension].
/// False otherwise, including if this [ContainerMember]'s [enclosingElement]
/// is the extension it was declared in.
// TODO(jcollins-g): This semantic is a little confusing, because a declared
// extension member element returns false. The rationale is an
// extension member is not extending itself.
// FIXME(jcollins-g): Remove concrete implementation after [Extendable] is
// implemented.
bool get isExtended => false;
Container _definingEnclosingContainer;
Container get definingEnclosingContainer {
if (_definingEnclosingContainer == null) {
_definingEnclosingContainer =
ModelElement.fromElement(element.enclosingElement, packageGraph);
}
return _definingEnclosingContainer;
}
@override
Set<String> get features {
Set<String> _features = super.features;
if (isExtended) _features.add('extended');
return _features;
}
bool _canonicalEnclosingContainerIsSet = false;
Container _canonicalEnclosingContainer;
Container get canonicalEnclosingContainer {
if (!_canonicalEnclosingContainerIsSet) {
_canonicalEnclosingContainer = computeCanonicalEnclosingContainer();
_canonicalEnclosingContainerIsSet = true;
assert(_canonicalEnclosingContainer == null ||
_canonicalEnclosingContainer.isDocumented);
}
return _canonicalEnclosingContainer;
}
Container computeCanonicalEnclosingContainer() {
// TODO(jcollins-g): move Extension specific code to [Extendable]
if (enclosingElement is Extension && enclosingElement.isDocumented) {
return packageGraph
.findCanonicalModelElementFor(enclosingElement.element);
}
if (enclosingElement is! Extension) {
return packageGraph
.findCanonicalModelElementFor(element.enclosingElement);
}
return null;
}
}