Skip to content

Commit db94d1e

Browse files
authored
fix(LibraryReader) classes should return all classes, including parts (#372)
Also prepare to release 0.9.0+1
1 parent 0532c41 commit db94d1e

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

source_gen/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.9.0+1
2+
3+
* Fix `LibraryReader.classElements` to return classes from parts, if they exist,
4+
as well as from the defining library file.
5+
16
## 0.9.0
27

38
* Introduce `SharedPartBuilder` for creating part files that can be merged

source_gen/lib/src/library.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class LibraryReader {
166166

167167
/// All of the `class` elements in this library.
168168
Iterable<ClassElement> get classElements =>
169-
element.definingCompilationUnit.types;
169+
element.units.expand((cu) => cu.types);
170170

171171
static Iterable<Element> _getElements(CompilationUnitMember member) {
172172
if (member is TopLevelVariableDeclaration) {

source_gen/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: source_gen
2-
version: 0.9.0
2+
version: 0.9.0+1
33
author: Dart Team <[email protected]>
44
description: Automated source code generation for Dart.
55
homepage: https://github.com/dart-lang/source_gen

source_gen/test/library/find_type_test.dart

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,39 @@ final _source = r'''
1414
export 'package:source_gen/source_gen.dart' show Generator;
1515
import 'dart:async' show Stream;
1616
17+
part 'part.dart';
18+
1719
class Example {}
1820
''';
1921

22+
final _partSource = r'''
23+
part of 'source.dart';
24+
25+
class PartClass {}
26+
''';
27+
2028
void main() {
2129
LibraryReader library;
2230

2331
setUpAll(() async {
24-
library = await resolveSource(
25-
_source,
32+
library = await resolveSources(
33+
{'a|source.dart': _source, 'a|part.dart': _partSource},
2634
(r) async => new LibraryReader(await r.findLibraryByName('test_lib')),
2735
);
2836
});
2937

38+
test('class count', () {
39+
expect(library.classElements, hasLength(2));
40+
});
41+
3042
test('should return a type not exported', () {
3143
expect(library.findType('Example'), _isClassElement);
3244
});
3345

46+
test('should return a type from a part', () {
47+
expect(library.findType('PartClass'), _isClassElement);
48+
});
49+
3450
test('should return a type exported from dart:', () {
3551
expect(library.findType('LinkedHashMap'), _isClassElement);
3652
});

0 commit comments

Comments
 (0)