| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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_OK() { |
| 1130 Source source = addSource(r''' |
| 1131 import 'package:meta/meta.dart'; |
| 1132 |
| 1133 class Stateful { |
| 1134 @factory |
| 1135 createState() { |
| 1136 return new Stateful(); |
| 1137 } |
| 1138 } |
| 1139 '''); |
| 1140 computeLibrarySourceErrors(source); |
| 1141 // Null return types will get flagged elsewhere, no need to pile-on here. |
| 1142 assertNoErrors(source); |
| 1143 verify([source]); |
| 1144 } |
| 1145 |
| 1146 void test_factory_subclass_OK() { |
| 1147 Source source = addSource(r''' |
| 1148 import 'package:meta/meta.dart'; |
| 1149 |
| 1150 abstract class Stateful { |
| 1151 @factory |
| 1152 State createState(); |
| 1153 } |
| 1154 |
| 1155 class MyThing extends Stateful { |
| 1156 @override |
| 1157 State createState() { |
| 1158 print('my state'); |
| 1159 return new MyState(); |
| 1160 } |
| 1161 } |
| 1162 |
| 1163 class State { } |
| 1164 class MyState extends State { } |
| 1165 '''); |
| 1166 computeLibrarySourceErrors(source); |
| 1167 assertNoErrors(source); |
| 1168 verify([source]); |
| 1169 } |
| 1170 |
| 1171 void test_factory_void_return() { |
| 1172 Source source = addSource(r''' |
| 1173 import 'package:meta/meta.dart'; |
| 1174 |
| 1175 class Stateful { |
| 1176 @factory |
| 1177 void createState() {} |
| 1178 } |
| 1179 '''); |
| 1180 computeLibrarySourceErrors(source); |
| 1181 assertErrors(source, [HintCode.INVALID_FACTORY_METHOD_DECL]); |
| 1182 verify([source]); |
| 1183 } |
| 1184 |
| 1005 void test_importDeferredLibraryWithLoadFunction() { | 1185 void test_importDeferredLibraryWithLoadFunction() { |
| 1006 resolveWithErrors(<String>[ | 1186 resolveWithErrors(<String>[ |
| 1007 r''' | 1187 r''' |
| 1008 library lib1; | 1188 library lib1; |
| 1009 loadLibrary() {} | 1189 loadLibrary() {} |
| 1010 f() {}''', | 1190 f() {}''', |
| 1011 r''' | 1191 r''' |
| 1012 library root; | 1192 library root; |
| 1013 import 'lib1.dart' deferred as lib1; | 1193 import 'lib1.dart' deferred as lib1; |
| 1014 main() { lib1.f(); }''' | 1194 main() { lib1.f(); }''' |
| (...skipping 2598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3613 n() { | 3793 n() { |
| 3614 var a = m(), b = m(); | 3794 var a = m(), b = m(); |
| 3615 } | 3795 } |
| 3616 }'''); | 3796 }'''); |
| 3617 computeLibrarySourceErrors(source); | 3797 computeLibrarySourceErrors(source); |
| 3618 assertErrors( | 3798 assertErrors( |
| 3619 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); | 3799 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); |
| 3620 verify([source]); | 3800 verify([source]); |
| 3621 } | 3801 } |
| 3622 } | 3802 } |
| OLD | NEW |