Skip to content

Commit afc4082

Browse files
authored
Make mixins appear with reexports (#1786)
* Make mixins appear with reexports * Rebuild test package docs
1 parent f5a64a8 commit afc4082

35 files changed

+2713
-8
lines changed

lib/src/model.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,11 @@ class Mixin extends Class {
440440
_inheritanceChain.add(this);
441441

442442
// Mix-in interfaces come before other interfaces.
443-
_inheritanceChain.addAll(superclassConstraints.expand(
444-
(ParameterizedElementType i) =>
445-
(i.element as Class).inheritanceChain));
443+
_inheritanceChain.addAll(superclassConstraints
444+
.expand((ParameterizedElementType i) =>
445+
(i.element as Class).inheritanceChain)
446+
.where((Class c) =>
447+
c != packageGraph.specialClasses[SpecialClass.object]));
446448

447449
// Interfaces need to come last, because classes in the superChain might
448450
// implement them even when they aren't mentioned.
@@ -2151,9 +2153,13 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
21512153
@override
21522154
List<Mixin> get mixins {
21532155
if (_mixins != null) return _mixins;
2154-
List<MixinElementImpl> mixinClasses = [];
2155-
mixinClasses.addAll(
2156-
_exportedNamespace.definedNames.values.whereType<MixinElementImpl>());
2156+
2157+
/// Can not be [MixinElementImpl] because [ClassHandle]s are sometimes
2158+
/// returned from _exportedNamespace.
2159+
List<ClassElement> mixinClasses = [];
2160+
mixinClasses.addAll(_exportedNamespace.definedNames.values
2161+
.whereType<ClassElement>()
2162+
.where((ClassElement c) => c.isMixin));
21572163
_mixins = mixinClasses
21582164
.map((e) => new ModelElement.from(e, this, packageGraph) as Mixin)
21592165
.toList(growable: false)
@@ -2302,7 +2308,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
23022308
}
23032309

23042310
types.addAll(_exportedNamespace.definedNames.values
2305-
.where((e) => e is ClassElement && e is! MixinElementImpl)
2311+
.where((e) => e is ClassElement && !e.isMixin)
23062312
.cast<ClassElement>()
23072313
.where((element) => !element.isEnum));
23082314

@@ -2311,6 +2317,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
23112317
.toList(growable: false)
23122318
..sort(byName);
23132319

2320+
assert(!_classes.any((Class c) => c is Mixin));
23142321
return _classes;
23152322
}
23162323

test/model_test.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,11 @@ void main() {
543543
expect(exLibrary.hasPublicExceptions, isTrue);
544544
});
545545

546+
test('has mixins', () {
547+
expect(fakeLibrary.hasPublicMixins, isTrue);
548+
expect(reexportTwoLib.hasPublicMixins, isTrue);
549+
});
550+
546551
test('has enums', () {
547552
expect(exLibrary.hasPublicEnums, isTrue);
548553
});
@@ -1204,7 +1209,8 @@ void main() {
12041209
test('doc comment inherited from getter', () {
12051210
Field getterWithDocs = subForDocComments.instanceProperties
12061211
.firstWhere((m) => m.name == 'getterWithDocs');
1207-
expect(getterWithDocs.documentationAsHtml, contains('Some really great topics.'));
1212+
expect(getterWithDocs.documentationAsHtml,
1213+
contains('Some really great topics.'));
12081214
});
12091215

12101216
test(

testing/test_package/lib/reexport_two.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
library reexport_two;
66

77
export 'src/somelib.dart';
8+
9+
export 'src/mixins.dart' show MixedIn, AMixin;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
library mixins;
2+
3+
export 'mixins_base.dart';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
library mixins_base;
2+
3+
mixin AMixin {}
4+
5+
class ThisClass {
6+
String property;
7+
}
8+
9+
/// A class that extends another class with a new-style mixin, then is
10+
/// reexported a couple of times similar to how Flutter does things.
11+
class MixedIn extends ThisClass with AMixin {}

testing/test_package_docs/index.json

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9620,6 +9620,83 @@
96209620
"type": "library",
96219621
"overriddenDepth": 0
96229622
},
9623+
{
9624+
"name": "AMixin",
9625+
"qualifiedName": "reexport_two.AMixin",
9626+
"href": "reexport_two/AMixin/AMixin.html",
9627+
"type": "constructor",
9628+
"overriddenDepth": 0,
9629+
"enclosedBy": {
9630+
"name": "AMixin",
9631+
"type": "mixin"
9632+
}
9633+
},
9634+
{
9635+
"name": "AMixin",
9636+
"qualifiedName": "reexport_two.AMixin",
9637+
"href": "reexport_two/AMixin-mixin.html",
9638+
"type": "mixin",
9639+
"overriddenDepth": 0,
9640+
"enclosedBy": {
9641+
"name": "reexport_two",
9642+
"type": "library"
9643+
}
9644+
},
9645+
{
9646+
"name": "operator ==",
9647+
"qualifiedName": "reexport_two.AMixin.==",
9648+
"href": "reexport_two/AMixin/operator_equals.html",
9649+
"type": "method",
9650+
"overriddenDepth": 0,
9651+
"enclosedBy": {
9652+
"name": "AMixin",
9653+
"type": "mixin"
9654+
}
9655+
},
9656+
{
9657+
"name": "hashCode",
9658+
"qualifiedName": "reexport_two.AMixin.hashCode",
9659+
"href": "reexport_two/AMixin/hashCode.html",
9660+
"type": "property",
9661+
"overriddenDepth": 0,
9662+
"enclosedBy": {
9663+
"name": "AMixin",
9664+
"type": "mixin"
9665+
}
9666+
},
9667+
{
9668+
"name": "noSuchMethod",
9669+
"qualifiedName": "reexport_two.AMixin.noSuchMethod",
9670+
"href": "reexport_two/AMixin/noSuchMethod.html",
9671+
"type": "method",
9672+
"overriddenDepth": 0,
9673+
"enclosedBy": {
9674+
"name": "AMixin",
9675+
"type": "mixin"
9676+
}
9677+
},
9678+
{
9679+
"name": "runtimeType",
9680+
"qualifiedName": "reexport_two.AMixin.runtimeType",
9681+
"href": "reexport_two/AMixin/runtimeType.html",
9682+
"type": "property",
9683+
"overriddenDepth": 0,
9684+
"enclosedBy": {
9685+
"name": "AMixin",
9686+
"type": "mixin"
9687+
}
9688+
},
9689+
{
9690+
"name": "toString",
9691+
"qualifiedName": "reexport_two.AMixin.toString",
9692+
"href": "reexport_two/AMixin/toString.html",
9693+
"type": "method",
9694+
"overriddenDepth": 0,
9695+
"enclosedBy": {
9696+
"name": "AMixin",
9697+
"type": "mixin"
9698+
}
9699+
},
96239700
{
96249701
"name": "AUnicornClass",
96259702
"qualifiedName": "reexport_two.AUnicornClass",
@@ -9697,6 +9774,39 @@
96979774
"type": "class"
96989775
}
96999776
},
9777+
{
9778+
"name": "MixedIn",
9779+
"qualifiedName": "reexport_two.MixedIn",
9780+
"href": "reexport_two/MixedIn-class.html",
9781+
"type": "class",
9782+
"overriddenDepth": 0,
9783+
"enclosedBy": {
9784+
"name": "reexport_two",
9785+
"type": "library"
9786+
}
9787+
},
9788+
{
9789+
"name": "MixedIn",
9790+
"qualifiedName": "reexport_two.MixedIn",
9791+
"href": "reexport_two/MixedIn/MixedIn.html",
9792+
"type": "constructor",
9793+
"overriddenDepth": 0,
9794+
"enclosedBy": {
9795+
"name": "MixedIn",
9796+
"type": "class"
9797+
}
9798+
},
9799+
{
9800+
"name": "property",
9801+
"qualifiedName": "reexport_two.MixedIn.property",
9802+
"href": "reexport_two/MixedIn/property.html",
9803+
"type": "property",
9804+
"overriddenDepth": 0,
9805+
"enclosedBy": {
9806+
"name": "MixedIn",
9807+
"type": "class"
9808+
}
9809+
},
97009810
{
97019811
"name": "SomeClass",
97029812
"qualifiedName": "reexport_two.SomeClass",

0 commit comments

Comments
 (0)