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

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

Issue 1705773002: Discard function elements created while building elements in annotations (issue 25696) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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/lib/src/dart/element/builder.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) 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.all_the_rest_test; 5 library analyzer.test.generated.all_the_rest_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/token.dart'; 8 import 'package:analyzer/dart/ast/token.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 @reflectiveTest 268 @reflectiveTest
269 class ElementBuilderTest extends ParserTestCase { 269 class ElementBuilderTest extends ParserTestCase {
270 CompilationUnitElement compilationUnitElement; 270 CompilationUnitElement compilationUnitElement;
271 CompilationUnit compilationUnit; 271 CompilationUnit compilationUnit;
272 272
273 /** 273 /**
274 * Parse the given [code], pass it through [ElementBuilder], and return the 274 * Parse the given [code], pass it through [ElementBuilder], and return the
275 * resulting [ElementHolder]. 275 * resulting [ElementHolder].
276 */ 276 */
277 ElementHolder buildElementsForText(String code) { 277 ElementHolder buildElementsForText(String code) {
278 compilationUnit = ParserTestCase.parseCompilationUnit(code); 278 TestLogger logger = new TestLogger();
279 ElementHolder holder = new ElementHolder(); 279 AnalysisEngine.instance.logger = logger;
280 ElementBuilder builder = new ElementBuilder(holder, compilationUnitElement); 280 try {
281 compilationUnit.accept(builder); 281 compilationUnit = ParserTestCase.parseCompilationUnit(code);
282 return holder; 282 ElementHolder holder = new ElementHolder();
283 ElementBuilder builder =
284 new ElementBuilder(holder, compilationUnitElement);
285 compilationUnit.accept(builder);
286 return holder;
287 } finally {
288 expect(logger.log, hasLength(0));
289 AnalysisEngine.instance.logger = Logger.NULL;
290 }
283 } 291 }
284 292
285 /** 293 /**
286 * Verify that the given [metadata] has exactly one annotation, and that its 294 * Verify that the given [metadata] has exactly one annotation, and that its
287 * [ElementAnnotationImpl] is unresolved. 295 * [ElementAnnotationImpl] is unresolved.
288 */ 296 */
289 void checkAnnotation(NodeList<Annotation> metadata) { 297 void checkAnnotation(NodeList<Annotation> metadata) {
290 expect(metadata, hasLength(1)); 298 expect(metadata, hasLength(1));
291 expect(metadata[0], new isInstanceOf<AnnotationImpl>()); 299 expect(metadata[0], new isInstanceOf<AnnotationImpl>());
292 AnnotationImpl annotation = metadata[0]; 300 AnnotationImpl annotation = metadata[0];
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 ClassElement type = types[0]; 588 ClassElement type = types[0];
581 expect(type, isNotNull); 589 expect(type, isNotNull);
582 expect(type.name, className); 590 expect(type.name, className);
583 List<TypeParameterElement> typeParameters = type.typeParameters; 591 List<TypeParameterElement> typeParameters = type.typeParameters;
584 expect(typeParameters, hasLength(0)); 592 expect(typeParameters, hasLength(0));
585 expect(type.isAbstract, isTrue); 593 expect(type.isAbstract, isTrue);
586 expect(type.isMixinApplication, isFalse); 594 expect(type.isMixinApplication, isFalse);
587 expect(type.isSynthetic, isFalse); 595 expect(type.isSynthetic, isFalse);
588 } 596 }
589 597
598 void test_visitClassDeclaration_invalidFunctionInAnnotation_class() {
599 // https://github.com/dart-lang/sdk/issues/25696
600 String code = r'''
601 class A {
602 const A({f});
603 }
604
605 @A(f: () {})
606 class C {}
607 ''';
608 buildElementsForText(code);
609 }
610
611 void test_visitClassDeclaration_invalidFunctionInAnnotation_method() {
612 String code = r'''
613 class A {
614 const A({f});
615 }
616
617 class C {
618 @A(f: () {})
619 void m() {}
620 }
621 ''';
622 ElementHolder holder = buildElementsForText(code);
623 ClassElement elementC = holder.types[1];
624 expect(elementC, isNotNull);
625 MethodElement methodM = elementC.methods[0];
626 expect(methodM, isNotNull);
627 expect(methodM.functions, isEmpty);
628 }
629
590 void test_visitClassDeclaration_minimal() { 630 void test_visitClassDeclaration_minimal() {
591 ElementHolder holder = new ElementHolder(); 631 ElementHolder holder = new ElementHolder();
592 ElementBuilder builder = _makeBuilder(holder); 632 ElementBuilder builder = _makeBuilder(holder);
593 String className = "C"; 633 String className = "C";
594 ClassDeclaration classDeclaration = 634 ClassDeclaration classDeclaration =
595 AstFactory.classDeclaration(null, className, null, null, null, null); 635 AstFactory.classDeclaration(null, className, null, null, null, null);
596 classDeclaration.documentationComment = AstFactory.documentationComment( 636 classDeclaration.documentationComment = AstFactory.documentationComment(
597 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); 637 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []);
598 classDeclaration.accept(builder); 638 classDeclaration.accept(builder);
599 List<ClassElement> types = holder.types; 639 List<ClassElement> types = holder.types;
(...skipping 3454 matching lines...) Expand 10 before | Expand all | Expand 10 after
4054 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); 4094 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI));
4055 expect(UriKind.fromEncoding(0x58), same(null)); 4095 expect(UriKind.fromEncoding(0x58), same(null));
4056 } 4096 }
4057 4097
4058 void test_getEncoding() { 4098 void test_getEncoding() {
4059 expect(UriKind.DART_URI.encoding, 0x64); 4099 expect(UriKind.DART_URI.encoding, 0x64);
4060 expect(UriKind.FILE_URI.encoding, 0x66); 4100 expect(UriKind.FILE_URI.encoding, 0x66);
4061 expect(UriKind.PACKAGE_URI.encoding, 0x70); 4101 expect(UriKind.PACKAGE_URI.encoding, 0x70);
4062 } 4102 }
4063 } 4103 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/builder.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698