Skip to content

Commit 5134899

Browse files
committed
lints
1 parent 39075e9 commit 5134899

File tree

7 files changed

+31
-19
lines changed

7 files changed

+31
-19
lines changed

example_usage/test/ensure_build_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ import 'package:test/test.dart';
1313
void main() {
1414
test(
1515
'ensure_build',
16-
() => expectBuildClean(packageRelativeDirectory: 'example_usage'),
16+
() async => expectBuildClean(packageRelativeDirectory: 'example_usage'),
1717
);
1818
}

source_gen/lib/src/library.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,21 @@ class LibraryReader {
141141
///
142142
/// Unlike [LibraryElement.getClass], this also correctly traverses
143143
/// identifiers that are accessible via one or more `export` directives.
144+
@Deprecated('Use findType2() instead')
144145
ClassElement? findType(String name) {
145146
final type = element.exportNamespace.get(name);
146147
return type is ClassElement ? type : null;
147148
}
148149

150+
/// Returns a top-level [ClassElement] publicly visible in by [name].
151+
///
152+
/// Unlike [LibraryElement.getClass], this also correctly traverses
153+
/// identifiers that are accessible via one or more `export` directives.
154+
ClassElement2? findType2(String name) {
155+
final type = element.exportNamespace.get2(name);
156+
return type is ClassElement2 ? type : null;
157+
}
158+
149159
/// Returns a [Uri] from the current library to the target [asset].
150160
///
151161
/// This is a typed convenience function for using [pathToUrl], and the same

source_gen/lib/src/output_helpers.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Stream<String> normalizeGeneratorOutput(Object? value) {
1111
if (value == null) {
1212
return const Stream.empty();
1313
} else if (value is Future) {
14+
// ignore:discarded_futures
1415
return StreamCompleter.fromFuture(value.then(normalizeGeneratorOutput));
1516
} else if (value is String) {
1617
value = [value];

source_gen/test/builder_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ $dartFormatWidth
174174

175175
test(
176176
'Simple Generator test for library',
177-
() => _generateTest(
177+
() async => _generateTest(
178178
const CommentGenerator(forClasses: false, forLibrary: true),
179179
_testGenPartContentForLibrary,
180180
),
181181
);
182182

183183
test(
184184
'Simple Generator test for classes and library',
185-
() => _generateTest(
185+
() async => _generateTest(
186186
const CommentGenerator(forLibrary: true),
187187
_testGenPartContentForClassesAndLibrary,
188188
),

source_gen/test/external_only_type_checker_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void main() {
3737
inputId: AssetId('source_gen', 'test/example.dart'),
3838
);
3939

40-
staticNonPublic = thisTest.findType('NonPublic')!.instantiate(
40+
staticNonPublic = thisTest.findType2('NonPublic')!.instantiate(
4141
typeArguments: const [],
4242
nullabilitySuffix: NullabilitySuffix.none,
4343
);

source_gen/test/library/find_type_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/dart/element/element.dart';
5+
import 'package:analyzer/dart/element/element2.dart';
66
import 'package:build_test/build_test.dart';
77
import 'package:source_gen/source_gen.dart';
88
import 'package:test/test.dart';
@@ -47,24 +47,24 @@ void main() {
4747
});
4848

4949
test('should return a type not exported', () {
50-
expect(library.findType('Example'), _isClassElement);
50+
expect(library.findType2('Example'), _isClassElement);
5151
});
5252

5353
test('should return a type from a part', () {
54-
expect(library.findType('PartClass'), _isClassElement);
54+
expect(library.findType2('PartClass'), _isClassElement);
5555
});
5656

5757
test('should return a type exported from dart:', () {
58-
expect(library.findType('LinkedHashMap'), _isClassElement);
58+
expect(library.findType2('LinkedHashMap'), _isClassElement);
5959
});
6060

6161
test('should return a type exported from package:', () {
62-
expect(library.findType('Generator'), _isClassElement);
62+
expect(library.findType2('Generator'), _isClassElement);
6363
});
6464

6565
test('should not return a type imported', () {
66-
expect(library.findType('Stream'), isNull);
66+
expect(library.findType2('Stream'), isNull);
6767
});
6868
}
6969

70-
const _isClassElement = TypeMatcher<ClassElement>();
70+
const _isClassElement = TypeMatcher<ClassElement2>();

source_gen/test/type_checker_test.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ library;
1111
import 'dart:collection';
1212

1313
import 'package:analyzer/dart/element/element.dart';
14+
import 'package:analyzer/dart/element/element2.dart';
1415
import 'package:analyzer/dart/element/nullability_suffix.dart';
1516
import 'package:analyzer/dart/element/type.dart';
1617
import 'package:build/build.dart';
@@ -91,28 +92,28 @@ void main() {
9192
);
9293
staticEnumChecker = TypeChecker.fromStatic(staticEnum);
9394
staticEnumMixin =
94-
(testSource.exportNamespace.get('MyEnumMixin')! as InterfaceElement)
95+
(testSource.exportNamespace.get2('MyEnumMixin')! as InterfaceElement2)
9596
.instantiate(
9697
typeArguments: [],
9798
nullabilitySuffix: NullabilitySuffix.none,
9899
);
99100
staticEnumMixinChecker = TypeChecker.fromStatic(staticEnumMixin);
100101
staticMapMixin =
101-
(testSource.exportNamespace.get('MyMapMixin')! as InterfaceElement)
102+
(testSource.exportNamespace.get2('MyMapMixin')! as InterfaceElement2)
102103
.instantiate(
103104
typeArguments: [],
104105
nullabilitySuffix: NullabilitySuffix.none,
105106
);
106107
staticMapMixinChecker = TypeChecker.fromStatic(staticMapMixin);
107108
staticMyEnum =
108-
(testSource.exportNamespace.get('MyEnum')! as InterfaceElement)
109+
(testSource.exportNamespace.get2('MyEnum')! as InterfaceElement2)
109110
.instantiate(
110111
typeArguments: [],
111112
nullabilitySuffix: NullabilitySuffix.none,
112113
);
113-
staticMyEnumWithMixin =
114-
(testSource.exportNamespace.get('MyEnumWithMixin')! as InterfaceElement)
115-
.instantiate(
114+
staticMyEnumWithMixin = (testSource.exportNamespace.get2('MyEnumWithMixin')!
115+
as InterfaceElement2)
116+
.instantiate(
116117
typeArguments: [],
117118
nullabilitySuffix: NullabilitySuffix.none,
118119
);
@@ -131,13 +132,13 @@ void main() {
131132
nullabilitySuffix: NullabilitySuffix.none,
132133
);
133134

134-
staticGenerator = sourceGen.findType('Generator')!.instantiate(
135+
staticGenerator = sourceGen.findType2('Generator')!.instantiate(
135136
typeArguments: [],
136137
nullabilitySuffix: NullabilitySuffix.none,
137138
);
138139
staticGeneratorChecker = TypeChecker.fromStatic(staticGenerator);
139140
staticGeneratorForAnnotation =
140-
sourceGen.findType('GeneratorForAnnotation')!.instantiate(
141+
sourceGen.findType2('GeneratorForAnnotation')!.instantiate(
141142
typeArguments: [core.typeProvider.dynamicType],
142143
nullabilitySuffix: NullabilitySuffix.none,
143144
);

0 commit comments

Comments
 (0)