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

Side by Side Diff: pkg/analyzer/test/src/summary/resynthesize_common.dart

Issue 2658483002: Fix summary handling of invalid annotations of the form `@a.b.c`. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « pkg/analyzer/test/generated/non_error_resolver_driver_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 test.src.serialization.elements_test; 5 library test.src.serialization.elements_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
9 import 'package:analyzer/dart/constant/value.dart'; 9 import 'package:analyzer/dart/constant/value.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 compareConstAstLists(rType.typeArguments?.arguments, 525 compareConstAstLists(rType.typeArguments?.arguments,
526 oType.typeArguments?.arguments, desc); 526 oType.typeArguments?.arguments, desc);
527 } 527 }
528 compareConstAstLists( 528 compareConstAstLists(
529 r.argumentList.arguments, o.argumentList.arguments, desc); 529 r.argumentList.arguments, o.argumentList.arguments, desc);
530 } else if (o is AnnotationImpl && r is AnnotationImpl) { 530 } else if (o is AnnotationImpl && r is AnnotationImpl) {
531 expect(o.atSign.lexeme, r.atSign.lexeme, reason: desc); 531 expect(o.atSign.lexeme, r.atSign.lexeme, reason: desc);
532 Identifier rName = r.name; 532 Identifier rName = r.name;
533 Identifier oName = o.name; 533 Identifier oName = o.name;
534 if (oName is PrefixedIdentifier && 534 if (oName is PrefixedIdentifier &&
535 rName is PrefixedIdentifier &&
535 o.constructorName != null && 536 o.constructorName != null &&
536 o.element != null) { 537 o.element != null &&
537 // E.g. `@prefix.cls.ctor`. This gets resynthesized as `@cls.ctor`, 538 r.constructorName == null) {
538 // with `cls.ctor` represented as a PrefixedIdentifier. 539 // E.g. `@prefix.cls.ctor`. This sometimes gets resynthesized as
539 expect(rName, new isInstanceOf<PrefixedIdentifier>(), reason: desc); 540 // `@cls.ctor`, with `cls.ctor` represented as a PrefixedIdentifier.
540 if (rName is PrefixedIdentifier) { 541 compareConstAsts(rName.prefix, oName.identifier, desc);
541 compareConstAsts(rName.prefix, oName.identifier, desc); 542 expect(rName.period.lexeme, '.', reason: desc);
542 expect(rName.period.lexeme, '.', reason: desc); 543 compareConstAsts(rName.identifier, o.constructorName, desc);
543 compareConstAsts(rName.identifier, o.constructorName, desc); 544 expect(r.period, isNull, reason: desc);
544 expect(r.period, isNull, reason: desc); 545 expect(r.constructorName, isNull, reason: desc);
545 expect(r.constructorName, isNull, reason: desc);
546 }
547 } else { 546 } else {
548 compareConstAsts(r.name, o.name, desc); 547 compareConstAsts(r.name, o.name, desc);
549 expect(r.period?.lexeme, o.period?.lexeme, reason: desc); 548 expect(r.period?.lexeme, o.period?.lexeme, reason: desc);
550 compareConstAsts(r.constructorName, o.constructorName, desc); 549 compareConstAsts(r.constructorName, o.constructorName, desc);
551 } 550 }
552 compareConstAstLists( 551 compareConstAstLists(
553 r.arguments?.arguments, o.arguments?.arguments, desc); 552 r.arguments?.arguments, o.arguments?.arguments, desc);
554 compareElements(r.element, o.element, desc); 553 compareElements(r.element, o.element, desc);
555 // elementAnnotation should be null; it is only used in the full AST. 554 // elementAnnotation should be null; it is only used in the full AST.
556 expect(o.elementAnnotation, isNull); 555 expect(o.elementAnnotation, isNull);
(...skipping 3203 matching lines...) Expand 10 before | Expand all | Expand 10 after
3760 '''); 3759 ''');
3761 } 3760 }
3762 3761
3763 test_instantiateToBounds_simple() { 3762 test_instantiateToBounds_simple() {
3764 checkLibrary(''' 3763 checkLibrary('''
3765 class C<T extends num> {} 3764 class C<T extends num> {}
3766 C c; 3765 C c;
3767 '''); 3766 ''');
3768 } 3767 }
3769 3768
3769 test_invalid_annotation_prefixed_constructor() {
scheglov 2017/01/24 20:10:18 Can we also add tests for using static const field
3770 addLibrarySource(
3771 '/a.dart',
3772 r'''
3773 class C {
3774 const C.named();
3775 }
3776 ''');
3777 checkLibrary('''
3778 import "a.dart" as a;
3779 @a.C.named
3780 class D {}
3781 ''');
3782 }
3783
3784 test_invalid_annotation_unprefixed_constructor() {
3785 addLibrarySource(
3786 '/a.dart',
3787 r'''
3788 class C {
3789 const C.named();
3790 }
3791 ''');
3792 checkLibrary('''
3793 import "a.dart";
3794 @C.named
3795 class D {}
3796 ''');
3797 }
3798
3770 test_library() { 3799 test_library() {
3771 checkLibrary(''); 3800 checkLibrary('');
3772 } 3801 }
3773 3802
3774 test_library_documented() { 3803 test_library_documented() {
3775 checkLibrary(''' 3804 checkLibrary('''
3776 // Extra comment so doc comment offset != 0 3805 // Extra comment so doc comment offset != 0
3777 /** 3806 /**
3778 * Docs 3807 * Docs
3779 */ 3808 */
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after
4938 fail('Unexpectedly tried to get unlinked summary for $uri'); 4967 fail('Unexpectedly tried to get unlinked summary for $uri');
4939 } 4968 }
4940 return serializedUnit; 4969 return serializedUnit;
4941 } 4970 }
4942 4971
4943 @override 4972 @override
4944 bool hasLibrarySummary(String uri) { 4973 bool hasLibrarySummary(String uri) {
4945 return true; 4974 return true;
4946 } 4975 }
4947 } 4976 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/non_error_resolver_driver_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698