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

Side by Side 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, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.generated.hint_code_test; 5 library analyzer.test.generated.hint_code_test;
6 6
7 import 'package:analyzer/src/generated/engine.dart'; 7 import 'package:analyzer/src/generated/engine.dart';
8 import 'package:analyzer/src/generated/error.dart'; 8 import 'package:analyzer/src/generated/error.dart';
9 import 'package:analyzer/src/generated/source_io.dart'; 9 import 'package:analyzer/src/generated/source_io.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 m() { 700 m() {
701 A a = new A(); 701 A a = new A();
702 a(); 702 a();
703 } 703 }
704 }'''); 704 }''');
705 computeLibrarySourceErrors(source); 705 computeLibrarySourceErrors(source);
706 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 706 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
707 verify([source]); 707 verify([source]);
708 } 708 }
709 709
710 void test_deprecatedAnnotationUse_Deprecated() { 710 void test_deprecatedAnnotationUse_deprecated() {
711 Source source = addSource(r''' 711 Source source = addSource(r'''
712 class A { 712 class A {
713 @Deprecated('0.9') 713 @deprecated
714 m() {} 714 m() {}
715 n() {m();} 715 n() {m();}
716 }'''); 716 }''');
717 computeLibrarySourceErrors(source); 717 computeLibrarySourceErrors(source);
718 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 718 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
719 verify([source]); 719 verify([source]);
720 } 720 }
721 721
722 void test_deprecatedAnnotationUse_deprecated() { 722 void test_deprecatedAnnotationUse_Deprecated() {
723 Source source = addSource(r''' 723 Source source = addSource(r'''
724 class A { 724 class A {
725 @deprecated 725 @Deprecated('0.9')
726 m() {} 726 m() {}
727 n() {m();} 727 n() {m();}
728 }'''); 728 }''');
729 computeLibrarySourceErrors(source); 729 computeLibrarySourceErrors(source);
730 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 730 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
731 verify([source]); 731 verify([source]);
732 } 732 }
733 733
734 void test_deprecatedAnnotationUse_export() { 734 void test_deprecatedAnnotationUse_export() {
735 Source source = addSource("export 'deprecated_library.dart';"); 735 Source source = addSource("export 'deprecated_library.dart';");
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 "/lib1.dart", 995 "/lib1.dart",
996 r''' 996 r'''
997 library lib1; 997 library lib1;
998 class A {} 998 class A {}
999 class B {}'''); 999 class B {}''');
1000 computeLibrarySourceErrors(source); 1000 computeLibrarySourceErrors(source);
1001 assertErrors(source, [HintCode.DUPLICATE_IMPORT]); 1001 assertErrors(source, [HintCode.DUPLICATE_IMPORT]);
1002 verify([source]); 1002 verify([source]);
1003 } 1003 }
1004 1004
1005 void test_factory__expr_return_null_OK() {
1006 Source source = addSource(r'''
1007 import 'package:meta/meta.dart';
1008
1009 class Stateful {
1010 @factory
1011 State createState() => null;
1012 }
1013
1014 class State { }
1015 ''');
1016 computeLibrarySourceErrors(source);
1017 assertNoErrors(source);
1018 verify([source]);
1019 }
1020
1021 void test_factory_abstract_OK() {
1022 Source source = addSource(r'''
1023 import 'package:meta/meta.dart';
1024
1025 abstract class Stateful {
1026 @factory
1027 State createState();
1028 }
1029
1030 class State { }
1031 ''');
1032 computeLibrarySourceErrors(source);
1033 assertNoErrors(source);
1034 verify([source]);
1035 }
1036
1037 void test_factory_bad_return() {
1038 Source source = addSource(r'''
1039 import 'package:meta/meta.dart';
1040
1041 class Stateful {
1042 State _s = new State();
1043
1044 @factory
1045 State createState() => _s;
1046 }
1047
1048 class State { }
1049 ''');
1050 computeLibrarySourceErrors(source);
1051 assertErrors(source, [HintCode.INVALID_FACTORY_METHOD_IMPL]);
1052 verify([source]);
1053 }
1054
1055 void test_factory_block_OK() {
1056 Source source = addSource(r'''
1057 import 'package:meta/meta.dart';
1058
1059 class Stateful {
1060 @factory
1061 State createState() {
1062 return new State();
1063 }
1064 }
1065
1066 class State { }
1067 ''');
1068 computeLibrarySourceErrors(source);
1069 assertNoErrors(source);
1070 verify([source]);
1071 }
1072
1073 void test_factory_block_return_null_OK() {
1074 Source source = addSource(r'''
1075 import 'package:meta/meta.dart';
1076
1077 class Stateful {
1078 @factory
1079 State createState() {
1080 return null;
1081 }
1082 }
1083
1084 class State { }
1085 ''');
1086 computeLibrarySourceErrors(source);
1087 assertNoErrors(source);
1088 verify([source]);
1089 }
1090
1091 void test_factory_expr_OK() {
1092 Source source = addSource(r'''
1093 import 'package:meta/meta.dart';
1094
1095 class Stateful {
1096 @factory
1097 State createState() => new State();
1098 }
1099
1100 class State { }
1101 ''');
1102 computeLibrarySourceErrors(source);
1103 assertNoErrors(source);
1104 verify([source]);
1105 }
1106
1107 void test_factory_misplaced_annotation() {
1108 Source source = addSource(r'''
1109 import 'package:meta/meta.dart';
1110
1111 @factory
1112 class X {
1113 @factory
1114 int x;
1115 }
1116
1117 @factory
1118 main() { }
1119 ''');
1120 computeLibrarySourceErrors(source);
1121 assertErrors(source, [
1122 HintCode.INVALID_FACTORY_ANNOTATION,
1123 HintCode.INVALID_FACTORY_ANNOTATION,
1124 HintCode.INVALID_FACTORY_ANNOTATION
1125 ]);
1126 verify([source]);
1127 }
1128
1129 void test_factory_no_return_type() {
1130 Source source = addSource(r'''
1131 import 'package:meta/meta.dart';
1132
1133 class Stateful {
1134 @factory
1135 createState() {}
1136 }
1137 ''');
1138 computeLibrarySourceErrors(source);
1139 assertErrors(source, [HintCode.INVALID_FACTORY_METHOD_DECL]);
1140 verify([source]);
1141 }
1142
1143 void test_factory_subclass_OK() {
1144 Source source = addSource(r'''
1145 import 'package:meta/meta.dart';
1146
1147 abstract class Stateful {
1148 @factory
1149 State createState();
1150 }
1151
1152 class MyThing extends Stateful {
1153 @override
1154 State createState() {
1155 print('my state');
1156 return new MyState();
1157 }
1158 }
1159
1160 class State { }
1161 class MyState extends State { }
1162 ''');
1163 computeLibrarySourceErrors(source);
1164 assertNoErrors(source);
1165 verify([source]);
1166 }
1167
1168 void test_factory_void_return() {
1169 Source source = addSource(r'''
1170 import 'package:meta/meta.dart';
1171
1172 class Stateful {
1173 @factory
1174 void createState() {}
1175 }
1176 ''');
1177 computeLibrarySourceErrors(source);
1178 assertErrors(source, [HintCode.INVALID_FACTORY_METHOD_DECL]);
1179 verify([source]);
1180 }
1181
1005 void test_importDeferredLibraryWithLoadFunction() { 1182 void test_importDeferredLibraryWithLoadFunction() {
1006 resolveWithErrors(<String>[ 1183 resolveWithErrors(<String>[
1007 r''' 1184 r'''
1008 library lib1; 1185 library lib1;
1009 loadLibrary() {} 1186 loadLibrary() {}
1010 f() {}''', 1187 f() {}''',
1011 r''' 1188 r'''
1012 library root; 1189 library root;
1013 import 'lib1.dart' deferred as lib1; 1190 import 'lib1.dart' deferred as lib1;
1014 main() { lib1.f(); }''' 1191 main() { lib1.f(); }'''
(...skipping 2598 matching lines...) Expand 10 before | Expand all | Expand 10 after
3613 n() { 3790 n() {
3614 var a = m(), b = m(); 3791 var a = m(), b = m();
3615 } 3792 }
3616 }'''); 3793 }''');
3617 computeLibrarySourceErrors(source); 3794 computeLibrarySourceErrors(source);
3618 assertErrors( 3795 assertErrors(
3619 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); 3796 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]);
3620 verify([source]); 3797 verify([source]);
3621 } 3798 }
3622 } 3799 }
OLDNEW
« 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