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

Side by Side Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 1773803002: Validation of `@mustCallSuper` overrides. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.resolver_test; 5 library analyzer.test.generated.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 2469 matching lines...) Expand 10 before | Expand all | Expand 10 after
2480 assertNoErrors(source3); 2480 assertNoErrors(source3);
2481 verify([source, source2, source3]); 2481 verify([source, source2, source3]);
2482 } 2482 }
2483 2483
2484 @override 2484 @override
2485 void reset() { 2485 void reset() {
2486 analysisContext2 = AnalysisContextFactory.contextWithCoreAndPackages({ 2486 analysisContext2 = AnalysisContextFactory.contextWithCoreAndPackages({
2487 'package:meta/meta.dart': r''' 2487 'package:meta/meta.dart': r'''
2488 library meta; 2488 library meta;
2489 2489
2490 const _Factory factory = const _Factory();
2491 const _Literal literal = const _Literal();
2492 const _MustCallSuper mustCallSuper = const _MustCallSuper();
2493 const _Override override = const _Override();
2490 const _Protected protected = const _Protected(); 2494 const _Protected protected = const _Protected();
2495 const _Required required = const _Required();
2491 2496
2497 class _Factory {
2498 const _Factory();
2499 }
2500 class _Literal {
2501 const _Literal();
2502 }
2503 class _MustCallSuper {
2504 const _MustCallSuper();
2505 }
2506 class _Override {
2507 const _Override();
2508 }
2492 class _Protected { 2509 class _Protected {
2493 const _Protected(); 2510 const _Protected();
2494 } 2511 }
2512 class _Required {
2513 final String reason;
2514 const _Required([this.reason]));
2515 }
2495 ''' 2516 '''
2496 }); 2517 });
2497 } 2518 }
2498 2519
2499 void test_argumentTypeNotAssignable_functionType() { 2520 void test_argumentTypeNotAssignable_functionType() {
2500 Source source = addSource(r''' 2521 Source source = addSource(r'''
2501 m() { 2522 m() {
2502 var a = new A(); 2523 var a = new A();
2503 a.n(() => 0); 2524 a.n(() => 0);
2504 } 2525 }
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
2981 } 3002 }
2982 f(A a) { 3003 f(A a) {
2983 A b; 3004 A b;
2984 a += b; 3005 a += b;
2985 }'''); 3006 }''');
2986 computeLibrarySourceErrors(source); 3007 computeLibrarySourceErrors(source);
2987 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 3008 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
2988 verify([source]); 3009 verify([source]);
2989 } 3010 }
2990 3011
2991 void test_deprecatedAnnotationUse_deprecated() { 3012 void test_deprecatedAnnotationUse_Deprecated() {
2992 Source source = addSource(r''' 3013 Source source = addSource(r'''
2993 class A { 3014 class A {
2994 @deprecated 3015 @Deprecated('0.9')
2995 m() {} 3016 m() {}
2996 n() {m();} 3017 n() {m();}
2997 }'''); 3018 }''');
2998 computeLibrarySourceErrors(source); 3019 computeLibrarySourceErrors(source);
2999 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 3020 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
3000 verify([source]); 3021 verify([source]);
3001 } 3022 }
3002 3023
3003 void test_deprecatedAnnotationUse_Deprecated() { 3024 void test_deprecatedAnnotationUse_deprecated() {
3004 Source source = addSource(r''' 3025 Source source = addSource(r'''
3005 class A { 3026 class A {
3006 @Deprecated('0.9') 3027 @deprecated
3007 m() {} 3028 m() {}
3008 n() {m();} 3029 n() {m();}
3009 }'''); 3030 }''');
3010 computeLibrarySourceErrors(source); 3031 computeLibrarySourceErrors(source);
3011 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); 3032 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
3012 verify([source]); 3033 verify([source]);
3013 } 3034 }
3014 3035
3015 void test_deprecatedAnnotationUse_export() { 3036 void test_deprecatedAnnotationUse_export() {
3016 Source source = addSource("export 'deprecated_library.dart';"); 3037 Source source = addSource("export 'deprecated_library.dart';");
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
3607 void test_missingReturn_method() { 3628 void test_missingReturn_method() {
3608 Source source = addSource(r''' 3629 Source source = addSource(r'''
3609 class A { 3630 class A {
3610 int m() {} 3631 int m() {}
3611 }'''); 3632 }''');
3612 computeLibrarySourceErrors(source); 3633 computeLibrarySourceErrors(source);
3613 assertErrors(source, [HintCode.MISSING_RETURN]); 3634 assertErrors(source, [HintCode.MISSING_RETURN]);
3614 verify([source]); 3635 verify([source]);
3615 } 3636 }
3616 3637
3638 void test_mustCallSuper() {
3639 Source source = addSource(r'''
3640 import 'package:meta/meta.dart';
3641 class A {
3642 @mustCallSuper
3643 void a() {}
3644 }
3645 class B extends A {
3646 @override
3647 void a()
3648 {}
3649 }
3650 ''');
3651 computeLibrarySourceErrors(source);
3652 assertErrors(source, [HintCode.MUST_CALL_SUPER]);
3653 verify([source]);
3654 }
3655
3656 void test_mustCallSuper_indirect() {
3657 Source source = addSource(r'''
3658 import 'package:meta/meta.dart';
3659 class A {
3660 @mustCallSuper
3661 void a() {}
3662 }
3663 class C extends A {
3664 @override
3665 void a() {
3666 super.a();
3667 }
3668 }
3669 class D extends C {
3670 @override
3671 void a() {}
3672 }
3673 ''');
3674 computeLibrarySourceErrors(source);
3675 assertErrors(source, [HintCode.MUST_CALL_SUPER]);
3676 verify([source]);
3677 }
3678
3679 void test_mustCallSuper_OK() {
3680 Source source = addSource(r'''
3681 import 'package:meta/meta.dart';
3682 class A {
3683 @mustCallSuper
3684 void a() {}
3685 }
3686 class C extends A {
3687 @override
3688 void a() {
3689 super.a(); //OK
3690 }
3691 }
3692 ''');
3693 computeLibrarySourceErrors(source);
3694 assertErrors(source, []);
3695 verify([source]);
3696 }
3697
3698 @override
3617 void test_nullAwareInCondition_assert() { 3699 void test_nullAwareInCondition_assert() {
3618 Source source = addSource(r''' 3700 Source source = addSource(r'''
3619 m(x) { 3701 m(x) {
3620 assert (x?.a); 3702 assert (x?.a);
3621 } 3703 }
3622 '''); 3704 ''');
3623 computeLibrarySourceErrors(source); 3705 computeLibrarySourceErrors(source);
3624 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]); 3706 assertErrors(source, [HintCode.NULL_AWARE_IN_CONDITION]);
3625 verify([source]); 3707 verify([source]);
3626 } 3708 }
(...skipping 13765 matching lines...) Expand 10 before | Expand all | Expand 10 after
17392 17474
17393 void _resolveTestUnit(String code) { 17475 void _resolveTestUnit(String code) {
17394 testCode = code; 17476 testCode = code;
17395 testSource = addSource(testCode); 17477 testSource = addSource(testCode);
17396 LibraryElement library = resolve2(testSource); 17478 LibraryElement library = resolve2(testSource);
17397 assertNoErrors(testSource); 17479 assertNoErrors(testSource);
17398 verify([testSource]); 17480 verify([testSource]);
17399 testUnit = resolveCompilationUnit(testSource, library); 17481 testUnit = resolveCompilationUnit(testSource, library);
17400 } 17482 }
17401 } 17483 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698