Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1176)

Unified Diff: pkg/analyzer/test/generated/hint_code_test.dart

Issue 2096103002: Analyzer support for `@factory` methods (linter#253). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/generated/hint_code_test.dart
diff --git a/pkg/analyzer/test/generated/hint_code_test.dart b/pkg/analyzer/test/generated/hint_code_test.dart
index 645ebeb93bf43ba20ae00bdfe9f7202451cfdc13..0f3ecbe7f06f1e90f30f597079bc40fed0a46b4b 100644
--- a/pkg/analyzer/test/generated/hint_code_test.dart
+++ b/pkg/analyzer/test/generated/hint_code_test.dart
@@ -707,10 +707,10 @@ class A {
verify([source]);
}
- void test_deprecatedAnnotationUse_Deprecated() {
+ void test_deprecatedAnnotationUse_deprecated() {
Source source = addSource(r'''
class A {
- @Deprecated('0.9')
+ @deprecated
m() {}
n() {m();}
}''');
@@ -719,10 +719,10 @@ class A {
verify([source]);
}
- void test_deprecatedAnnotationUse_deprecated() {
+ void test_deprecatedAnnotationUse_Deprecated() {
Source source = addSource(r'''
class A {
- @deprecated
+ @Deprecated('0.9')
m() {}
n() {m();}
}''');
@@ -1002,6 +1002,183 @@ class B {}''');
verify([source]);
}
+ void test_factory__expr_return_null_OK() {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+
+class Stateful {
+ @factory
+ State createState() => null;
+}
+
+class State { }
+''');
+ computeLibrarySourceErrors(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_factory_abstract_OK() {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+
+abstract class Stateful {
+ @factory
+ State createState();
+}
+
+class State { }
+''');
+ computeLibrarySourceErrors(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_factory_bad_return() {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+
+class Stateful {
+ State _s = new State();
+
+ @factory
+ State createState() => _s;
+}
+
+class State { }
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.INVALID_FACTORY_METHOD_IMPL]);
+ verify([source]);
+ }
+
+ void test_factory_block_OK() {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+
+class Stateful {
+ @factory
+ State createState() {
+ return new State();
+ }
+}
+
+class State { }
+''');
+ computeLibrarySourceErrors(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_factory_block_return_null_OK() {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+
+class Stateful {
+ @factory
+ State createState() {
+ return null;
+ }
+}
+
+class State { }
+''');
+ computeLibrarySourceErrors(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_factory_expr_OK() {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+
+class Stateful {
+ @factory
+ State createState() => new State();
+}
+
+class State { }
+''');
+ computeLibrarySourceErrors(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_factory_misplaced_annotation() {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+
+@factory
+class X {
+ @factory
+ int x;
+}
+
+@factory
+main() { }
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [
+ HintCode.INVALID_FACTORY_ANNOTATION,
+ HintCode.INVALID_FACTORY_ANNOTATION,
+ HintCode.INVALID_FACTORY_ANNOTATION
+ ]);
+ verify([source]);
+ }
+
+ void test_factory_no_return_type() {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+
+class Stateful {
+ @factory
+ createState() {}
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.INVALID_FACTORY_METHOD_DECL]);
+ verify([source]);
+ }
+
+ void test_factory_subclass_OK() {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+
+abstract class Stateful {
+ @factory
+ State createState();
+}
+
+class MyThing extends Stateful {
+ @override
+ State createState() {
+ print('my state');
+ return new MyState();
+ }
+}
+
+class State { }
+class MyState extends State { }
+''');
+ computeLibrarySourceErrors(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_factory_void_return() {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+
+class Stateful {
+ @factory
+ void createState() {}
+}
+''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.INVALID_FACTORY_METHOD_DECL]);
+ verify([source]);
+ }
+
void test_importDeferredLibraryWithLoadFunction() {
resolveWithErrors(<String>[
r'''
« pkg/analyzer/lib/src/generated/resolver.dart ('K') | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698