Skip to content

Commit e04c53d

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
meta: add TargetKind to @factory
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try Change-Id: I5c0608637f2feb9986e890f3c83cf02884bef7f9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369789 Commit-Queue: Sam Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 3f47c93 commit e04c53d

File tree

12 files changed

+17
-102
lines changed

12 files changed

+17
-102
lines changed

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3534,8 +3534,6 @@ WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY:
35343534
35353535
The fix is to update the export directive so that the member using the name
35363536
is no longer exported.
3537-
WarningCode.INVALID_FACTORY_ANNOTATION:
3538-
status: hasFix
35393537
WarningCode.INVALID_FACTORY_METHOD_DECL:
35403538
status: noFix
35413539
WarningCode.INVALID_FACTORY_METHOD_IMPL:

pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,9 +1525,6 @@ final _builtInNonLintProducers = <ErrorCode, List<ProducerGenerator>>{
15251525
WarningCode.INVALID_ANNOTATION_TARGET: [
15261526
RemoveAnnotation.new,
15271527
],
1528-
WarningCode.INVALID_FACTORY_ANNOTATION: [
1529-
RemoveAnnotation.new,
1530-
],
15311528
WarningCode.INVALID_INTERNAL_ANNOTATION: [
15321529
RemoveAnnotation.new,
15331530
],

pkg/analyzer/lib/src/error/annotation_verifier.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ class AnnotationVerifier {
6969
void _checkFactory(Annotation node) {
7070
var parent = node.parent;
7171
if (parent is! MethodDeclaration) {
72-
_errorReporter.atNode(
73-
node.name,
74-
WarningCode.INVALID_FACTORY_ANNOTATION,
75-
);
72+
// Warning reported by `_checkKinds`.
7673
return;
7774
}
7875
var returnType = parent.returnType?.type;

pkg/analyzer/lib/src/error/codes.g.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6599,13 +6599,6 @@ class WarningCode extends AnalyzerErrorCode {
65996599
hasPublishedDocs: true,
66006600
);
66016601

6602-
/// This warning is generated anywhere a @factory annotation is associated
6603-
/// with anything other than a method.
6604-
static const WarningCode INVALID_FACTORY_ANNOTATION = WarningCode(
6605-
'INVALID_FACTORY_ANNOTATION',
6606-
"Only methods can be annotated as factories.",
6607-
);
6608-
66096602
/// Parameters:
66106603
/// 0: The name of the method
66116604
static const WarningCode INVALID_FACTORY_METHOD_DECL = WarningCode(

pkg/analyzer/lib/src/error/error_code_values.g.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,6 @@ const List<ErrorCode> errorCodeValues = [
10101010
WarningCode.INVALID_ANNOTATION_TARGET,
10111011
WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT,
10121012
WarningCode.INVALID_EXPORT_OF_INTERNAL_ELEMENT_INDIRECTLY,
1013-
WarningCode.INVALID_FACTORY_ANNOTATION,
10141013
WarningCode.INVALID_FACTORY_METHOD_DECL,
10151014
WarningCode.INVALID_FACTORY_METHOD_IMPL,
10161015
WarningCode.INVALID_INTERNAL_ANNOTATION,

pkg/analyzer/lib/src/test_utilities/mock_packages.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ class _Experimental {
227227
const _Experimental();
228228
}
229229
230+
@Target({
231+
TargetKind.method,
232+
})
230233
class _Factory {
231234
const _Factory();
232235
}

pkg/analyzer/messages.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24014,12 +24014,6 @@ WarningCode:
2401424014
If the function doesn't need to be exported, then stop exporting it,
2401524015
either by removing it from the `show` clause, adding it to the `hide`
2401624016
clause, or by removing the export.
24017-
INVALID_FACTORY_ANNOTATION:
24018-
problemMessage: Only methods can be annotated as factories.
24019-
hasPublishedDocs: false
24020-
comment: |-
24021-
This warning is generated anywhere a @factory annotation is associated
24022-
with anything other than a method.
2402324017
INVALID_FACTORY_METHOD_DECL:
2402424018
problemMessage: "Factory method '{0}' must have a return type."
2402524019
hasPublishedDocs: true

pkg/analyzer/test/src/diagnostics/invalid_factory_annotation_test.dart

Lines changed: 0 additions & 67 deletions
This file was deleted.

pkg/analyzer/test/src/diagnostics/test_all.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ import 'invalid_export_of_internal_element_test.dart'
428428
as invalid_export_of_internal_element;
429429
import 'invalid_extension_argument_count_test.dart'
430430
as invalid_extension_argument_count;
431-
import 'invalid_factory_annotation_test.dart' as invalid_factory_annotation;
432431
import 'invalid_factory_method_impl_test.dart' as invalid_factory_method_impl;
433432
import 'invalid_factory_name_not_a_class_test.dart'
434433
as invalid_factory_name_not_a_class;
@@ -1190,7 +1189,6 @@ main() {
11901189
invalid_exception_value.main();
11911190
invalid_export_of_internal_element.main();
11921191
invalid_extension_argument_count.main();
1193-
invalid_factory_annotation.main();
11941192
invalid_factory_method_impl.main();
11951193
invalid_factory_name_not_a_class.main();
11961194
invalid_field_type_in_struct.main();

pkg/analyzer_utilities/lib/test/mock_packages/package_content/meta/lib/meta.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,9 @@ class _Experimental {
642642
const _Experimental();
643643
}
644644

645-
// TODO(srawlins): Enforce with `TargetKind.method`.
645+
@Target({
646+
TargetKind.method,
647+
})
646648
class _Factory {
647649
const _Factory();
648650
}

pkg/meta/CHANGELOG.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
## 1.16.0-dev
22

3-
- Require that `@Immutable` is only used on classes, extensions, and mixins.
4-
Previously, this behavior was custom-wired into the Dart analyzer, but now it
5-
is specified with TargetKinds.
6-
- Require that `@mustBeOverridden` and `@mustCallSuper` are only used on
7-
overridable members. Previously, this behavior was custom-wired into the Dart
8-
analyzer, but now it is specified with TargetKinds.
9-
- Require that `@sealed` is only used on classes. Previously, this behavior was
10-
custom-wired into the Dart analyzer, but now it is specified with TargetKinds.
3+
- Add `TargetKind`s to a few annotations to match custom-wired behavior that the
4+
Dart analyzer has been providing:
5+
- Require that `@factory` is only used on methods.
6+
- Require that `@Immutable` is only used on classes, extensions, and mixins.
7+
- Require that `@mustBeOverridden` and `@mustCallSuper` are only used on
8+
overridable members.
9+
- Require that `@sealed` is only used on classes.
1110

1211
## 1.15.0
1312

pkg/meta/lib/meta.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,9 @@ class _Experimental {
673673
const _Experimental();
674674
}
675675

676-
// TODO(srawlins): Enforce with `TargetKind.method`.
676+
@Target({
677+
TargetKind.method,
678+
})
677679
class _Factory {
678680
const _Factory();
679681
}

0 commit comments

Comments
 (0)