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/error/error.dart'; | 7 import 'package:analyzer/error/error.dart'; |
8 import 'package:analyzer/src/error/codes.dart'; | 8 import 'package:analyzer/src/error/codes.dart'; |
9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
10 import 'package:analyzer/src/generated/parser.dart'; | 10 import 'package:analyzer/src/generated/parser.dart'; |
(...skipping 13 matching lines...) Expand all Loading... |
24 class HintCodeTest extends ResolverTestCase { | 24 class HintCodeTest extends ResolverTestCase { |
25 @override | 25 @override |
26 void reset() { | 26 void reset() { |
27 super.resetWith(packages: [ | 27 super.resetWith(packages: [ |
28 [ | 28 [ |
29 'meta', | 29 'meta', |
30 r''' | 30 r''' |
31 library meta; | 31 library meta; |
32 | 32 |
33 const _Factory factory = const _Factory(); | 33 const _Factory factory = const _Factory(); |
| 34 const Immutable immutable = const Immutable(); |
34 const _Literal literal = const _Literal(); | 35 const _Literal literal = const _Literal(); |
35 const _MustCallSuper mustCallSuper = const _MustCallSuper(); | 36 const _MustCallSuper mustCallSuper = const _MustCallSuper(); |
36 const _Protected protected = const _Protected(); | 37 const _Protected protected = const _Protected(); |
37 const Required required = const Required(); | 38 const Required required = const Required(); |
38 class Required { | 39 class Required { |
39 final String reason; | 40 final String reason; |
40 const Required([this.reason]); | 41 const Required([this.reason]); |
41 } | 42 } |
42 | 43 |
| 44 class Immutable { |
| 45 final String reason; |
| 46 const Immutable([this.reason]); |
| 47 } |
43 class _Factory { | 48 class _Factory { |
44 const _Factory(); | 49 const _Factory(); |
45 } | 50 } |
46 class _Literal { | 51 class _Literal { |
47 const _Literal(); | 52 const _Literal(); |
48 } | 53 } |
49 class _MustCallSuper { | 54 class _MustCallSuper { |
50 const _MustCallSuper(); | 55 const _MustCallSuper(); |
51 } | 56 } |
52 class _Protected { | 57 class _Protected { |
(...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1355 main() { | 1360 main() { |
1356 var p1 = new Point(0, 0); | 1361 var p1 = new Point(0, 0); |
1357 var p2 = new Point(10, 10); | 1362 var p2 = new Point(10, 10); |
1358 int n = p1 + p2; | 1363 int n = p1 + p2; |
1359 }'''); | 1364 }'''); |
1360 await computeAnalysisResult(source); | 1365 await computeAnalysisResult(source); |
1361 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); | 1366 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); |
1362 verify([source]); | 1367 verify([source]); |
1363 } | 1368 } |
1364 | 1369 |
| 1370 test_invalidImmutableAnnotation_method() async { |
| 1371 Source source = addSource(r''' |
| 1372 import 'package:meta/meta.dart'; |
| 1373 class A { |
| 1374 @immutable |
| 1375 void m() {} |
| 1376 } |
| 1377 '''); |
| 1378 await computeAnalysisResult(source); |
| 1379 assertErrors(source, [HintCode.INVALID_IMMUTABLE_ANNOTATION]); |
| 1380 verify([source]); |
| 1381 } |
| 1382 |
1365 test_invalidUseOfProtectedMember_closure() async { | 1383 test_invalidUseOfProtectedMember_closure() async { |
1366 Source source = addNamedSource( | 1384 Source source = addNamedSource( |
1367 '/lib1.dart', | 1385 '/lib1.dart', |
1368 r''' | 1386 r''' |
1369 import 'package:meta/meta.dart'; | 1387 import 'package:meta/meta.dart'; |
1370 | 1388 |
1371 class A { | 1389 class A { |
1372 @protected | 1390 @protected |
1373 int a() => 42; | 1391 int a() => 42; |
1374 } | 1392 } |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1968 test_missingReturn_method() async { | 1986 test_missingReturn_method() async { |
1969 Source source = addSource(r''' | 1987 Source source = addSource(r''' |
1970 class A { | 1988 class A { |
1971 int m() {} | 1989 int m() {} |
1972 }'''); | 1990 }'''); |
1973 await computeAnalysisResult(source); | 1991 await computeAnalysisResult(source); |
1974 assertErrors(source, [HintCode.MISSING_RETURN]); | 1992 assertErrors(source, [HintCode.MISSING_RETURN]); |
1975 verify([source]); | 1993 verify([source]); |
1976 } | 1994 } |
1977 | 1995 |
| 1996 test_mustBeImmutable_direct() async { |
| 1997 Source source = addSource(r''' |
| 1998 import 'package:meta/meta.dart'; |
| 1999 @immutable |
| 2000 class A { |
| 2001 int x; |
| 2002 } |
| 2003 '''); |
| 2004 await computeAnalysisResult(source); |
| 2005 assertErrors(source, [HintCode.MUST_BE_IMMUTABLE]); |
| 2006 verify([source]); |
| 2007 } |
| 2008 |
| 2009 test_mustBeImmutable_extends() async { |
| 2010 Source source = addSource(r''' |
| 2011 import 'package:meta/meta.dart'; |
| 2012 @immutable |
| 2013 class A {} |
| 2014 class B extends A { |
| 2015 int x; |
| 2016 } |
| 2017 '''); |
| 2018 await computeAnalysisResult(source); |
| 2019 assertErrors(source, [HintCode.MUST_BE_IMMUTABLE]); |
| 2020 verify([source]); |
| 2021 } |
| 2022 |
| 2023 test_mustBeImmutable_fromMixin() async { |
| 2024 Source source = addSource(r''' |
| 2025 import 'package:meta/meta.dart'; |
| 2026 @immutable |
| 2027 class A {} |
| 2028 class B { |
| 2029 int x; |
| 2030 } |
| 2031 class C extends A with B {} |
| 2032 '''); |
| 2033 await computeAnalysisResult(source); |
| 2034 assertErrors(source, [HintCode.MUST_BE_IMMUTABLE]); |
| 2035 verify([source]); |
| 2036 } |
| 2037 |
1978 test_mustCallSuper() async { | 2038 test_mustCallSuper() async { |
1979 Source source = addSource(r''' | 2039 Source source = addSource(r''' |
1980 import 'package:meta/meta.dart'; | 2040 import 'package:meta/meta.dart'; |
1981 class A { | 2041 class A { |
1982 @mustCallSuper | 2042 @mustCallSuper |
1983 void a() {} | 2043 void a() {} |
1984 } | 2044 } |
1985 class B extends A { | 2045 class B extends A { |
1986 @override | 2046 @override |
1987 void a() | 2047 void a() |
(...skipping 2104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4092 n() { | 4152 n() { |
4093 var a = m(), b = m(); | 4153 var a = m(), b = m(); |
4094 } | 4154 } |
4095 }'''); | 4155 }'''); |
4096 await computeAnalysisResult(source); | 4156 await computeAnalysisResult(source); |
4097 assertErrors( | 4157 assertErrors( |
4098 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); | 4158 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); |
4099 verify([source]); | 4159 verify([source]); |
4100 } | 4160 } |
4101 } | 4161 } |
OLD | NEW |