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

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

Issue 1762663002: Add support for ConstructorElementImpl.isCycleFree to summaries. (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) 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 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 21 matching lines...) Expand all
32 main() { 32 main() {
33 groupSep = ' | '; 33 groupSep = ' | ';
34 runReflectiveTests(ResynthTest); 34 runReflectiveTests(ResynthTest);
35 } 35 }
36 36
37 @reflectiveTest 37 @reflectiveTest
38 class ResynthTest extends ResolverTestCase { 38 class ResynthTest extends ResolverTestCase {
39 Set<Source> otherLibrarySources = new Set<Source>(); 39 Set<Source> otherLibrarySources = new Set<Source>();
40 bool constantInitializersAreInvalid = false; 40 bool constantInitializersAreInvalid = false;
41 41
42 /**
43 * Determine the analysis options that should be used for this test.
44 */
45 AnalysisOptionsImpl createOptions() =>
46 new AnalysisOptionsImpl()..enableGenericMethods = true;
47
48 void addLibrary(String uri) { 42 void addLibrary(String uri) {
49 otherLibrarySources.add(analysisContext2.sourceFactory.forUri(uri)); 43 otherLibrarySources.add(analysisContext2.sourceFactory.forUri(uri));
50 } 44 }
51 45
52 void addLibrarySource(String filePath, String contents) { 46 void addLibrarySource(String filePath, String contents) {
53 otherLibrarySources.add(addNamedSource(filePath, contents)); 47 otherLibrarySources.add(addNamedSource(filePath, contents));
54 } 48 }
55 49
56 /** 50 /**
57 * Verify that the given prefix is safe to elide from a resynthesized AST. 51 * Verify that the given prefix is safe to elide from a resynthesized AST.
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 compareConstAstLists( 445 compareConstAstLists(
452 r.typeArguments?.arguments, o.typeArguments?.arguments, desc); 446 r.typeArguments?.arguments, o.typeArguments?.arguments, desc);
453 compareConstAstLists(r.entries, o.entries, desc); 447 compareConstAstLists(r.entries, o.entries, desc);
454 } else if (o is InstanceCreationExpression && 448 } else if (o is InstanceCreationExpression &&
455 r is InstanceCreationExpression) { 449 r is InstanceCreationExpression) {
456 compareElements(r.staticElement, o.staticElement, desc); 450 compareElements(r.staticElement, o.staticElement, desc);
457 ConstructorName oConstructor = o.constructorName; 451 ConstructorName oConstructor = o.constructorName;
458 ConstructorName rConstructor = r.constructorName; 452 ConstructorName rConstructor = r.constructorName;
459 expect(oConstructor, isNotNull, reason: desc); 453 expect(oConstructor, isNotNull, reason: desc);
460 expect(rConstructor, isNotNull, reason: desc); 454 expect(rConstructor, isNotNull, reason: desc);
461 compareConstructorElements( 455 // Note: just compare rConstructor.staticElement and
456 // oConstructor.staticElement as elements, because we just want to
457 // check that they're pointing to the correct elements; we don't want
458 // to check that their constructor initializers match, because that
459 // could lead to infinite regress.
460 compareElements(
462 rConstructor.staticElement, oConstructor.staticElement, desc); 461 rConstructor.staticElement, oConstructor.staticElement, desc);
463 TypeName oType = oConstructor.type; 462 TypeName oType = oConstructor.type;
464 TypeName rType = rConstructor.type; 463 TypeName rType = rConstructor.type;
465 expect(oType, isNotNull, reason: desc); 464 expect(oType, isNotNull, reason: desc);
466 expect(rType, isNotNull, reason: desc); 465 expect(rType, isNotNull, reason: desc);
467 compareConstAsts(rType.name, oType.name, desc); 466 compareConstAsts(rType.name, oType.name, desc);
468 compareConstAsts(rConstructor.name, oConstructor.name, desc); 467 compareConstAsts(rConstructor.name, oConstructor.name, desc);
469 compareConstAstLists(rType.typeArguments?.arguments, 468 compareConstAstLists(rType.typeArguments?.arguments,
470 oType.typeArguments?.arguments, desc); 469 oType.typeArguments?.arguments, desc);
471 compareConstAstLists( 470 compareConstAstLists(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 } 509 }
511 } 510 }
512 } 511 }
513 512
514 void compareConstructorElements(ConstructorElement resynthesized, 513 void compareConstructorElements(ConstructorElement resynthesized,
515 ConstructorElement original, String desc) { 514 ConstructorElement original, String desc) {
516 if (original == null && resynthesized == null) { 515 if (original == null && resynthesized == null) {
517 return; 516 return;
518 } 517 }
519 compareExecutableElements(resynthesized, original, desc); 518 compareExecutableElements(resynthesized, original, desc);
519 ConstructorElementImpl resynthesizedImpl =
520 getActualElement(resynthesized, desc);
521 ConstructorElementImpl originalImpl = getActualElement(original, desc);
520 if (original.isConst) { 522 if (original.isConst) {
521 ConstructorElementImpl resynthesizedImpl =
522 getActualElement(resynthesized, desc);
523 ConstructorElementImpl originalImpl = getActualElement(original, desc);
524 compareConstAstLists(resynthesizedImpl.constantInitializers, 523 compareConstAstLists(resynthesizedImpl.constantInitializers,
525 originalImpl.constantInitializers, desc); 524 originalImpl.constantInitializers, desc);
526 } 525 }
527 if (original.redirectedConstructor == null) { 526 if (original.redirectedConstructor == null) {
528 expect(resynthesized.redirectedConstructor, isNull, reason: desc); 527 expect(resynthesized.redirectedConstructor, isNull, reason: desc);
529 } else { 528 } else {
530 compareConstructorElements(resynthesized.redirectedConstructor, 529 compareConstructorElements(resynthesized.redirectedConstructor,
531 original.redirectedConstructor, '$desc redirectedConstructor'); 530 original.redirectedConstructor, '$desc redirectedConstructor');
532 } 531 }
533 checkPossibleMember(resynthesized, original, desc); 532 checkPossibleMember(resynthesized, original, desc);
534 expect(resynthesized.nameEnd, original.nameEnd, reason: desc); 533 expect(resynthesized.nameEnd, original.nameEnd, reason: desc);
535 expect(resynthesized.periodOffset, original.periodOffset, reason: desc); 534 expect(resynthesized.periodOffset, original.periodOffset, reason: desc);
535 expect(resynthesizedImpl.isCycleFree, originalImpl.isCycleFree,
536 reason: desc);
536 } 537 }
537 538
538 void compareConstValues( 539 void compareConstValues(
539 DartObject resynthesized, DartObject original, String desc) { 540 DartObject resynthesized, DartObject original, String desc) {
540 if (original == null) { 541 if (original == null) {
541 expect(resynthesized, isNull, reason: desc); 542 expect(resynthesized, isNull, reason: desc);
542 } else { 543 } else {
543 expect(resynthesized, isNotNull, reason: desc); 544 expect(resynthesized, isNotNull, reason: desc);
544 compareTypes(resynthesized.type, original.type, desc); 545 compareTypes(resynthesized.type, original.type, desc);
545 expect(resynthesized.hasKnownValue, original.hasKnownValue, reason: desc); 546 expect(resynthesized.hasKnownValue, original.hasKnownValue, reason: desc);
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 compareConstAsts(initializer, originalActual.constantInitializer, 1025 compareConstAsts(initializer, originalActual.constantInitializer,
1025 '$desc initializer'); 1026 '$desc initializer');
1026 } 1027 }
1027 } 1028 }
1028 } 1029 }
1029 checkPossibleMember(resynthesized, original, desc); 1030 checkPossibleMember(resynthesized, original, desc);
1030 checkPossibleLocalElements(resynthesized, original); 1031 checkPossibleLocalElements(resynthesized, original);
1031 } 1032 }
1032 1033
1033 /** 1034 /**
1035 * Determine the analysis options that should be used for this test.
1036 */
1037 AnalysisOptionsImpl createOptions() =>
1038 new AnalysisOptionsImpl()..enableGenericMethods = true;
1039
1040 /**
1034 * Serialize the given [library] into a summary. Then create a 1041 * Serialize the given [library] into a summary. Then create a
1035 * [_TestSummaryResynthesizer] which can deserialize it, along with any 1042 * [_TestSummaryResynthesizer] which can deserialize it, along with any
1036 * references it makes to `dart:core`. 1043 * references it makes to `dart:core`.
1037 * 1044 *
1038 * Errors will lead to a test failure unless [allowErrors] is `true`. 1045 * Errors will lead to a test failure unless [allowErrors] is `true`.
1039 */ 1046 */
1040 _TestSummaryResynthesizer encodeLibrary(LibraryElementImpl library, 1047 _TestSummaryResynthesizer encodeLibrary(LibraryElementImpl library,
1041 {bool allowErrors: false, bool dumpSummaries: false}) { 1048 {bool allowErrors: false, bool dumpSummaries: false}) {
1042 if (!allowErrors) { 1049 if (!allowErrors) {
1043 assertNoErrors(library.source); 1050 assertNoErrors(library.source);
(...skipping 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after
2506 2513
2507 test_constructor_redirected_thisInvocation_unnamed_generic() { 2514 test_constructor_redirected_thisInvocation_unnamed_generic() {
2508 checkLibrary(''' 2515 checkLibrary('''
2509 class C<T> { 2516 class C<T> {
2510 C(); 2517 C();
2511 C.named() : this(); 2518 C.named() : this();
2512 } 2519 }
2513 '''); 2520 ''');
2514 } 2521 }
2515 2522
2523 test_constructor_withCycles_const() {
2524 checkLibrary('''
2525 class C {
2526 final x;
2527 const C() : x = const D();
2528 }
2529 class D {
2530 final x;
2531 const D() : x = const C();
2532 }
2533 ''');
2534 }
2535
2536 test_constructor_withCycles_nonConst() {
2537 checkLibrary('''
2538 class C {
2539 final x;
2540 C() : x = new D();
2541 }
2542 class D {
2543 final x;
2544 D() : x = new C();
2545 }
2546 ''');
2547 }
2548
2516 test_core() { 2549 test_core() {
2517 if (createOptions().strongMode) { 2550 if (createOptions().strongMode) {
2518 // The fake `dart:core` library is always in spec mode, so don't bother 2551 // The fake `dart:core` library is always in spec mode, so don't bother
2519 // trying to check that it resynthesizes properly; it won't. 2552 // trying to check that it resynthesizes properly; it won't.
2520 return; 2553 return;
2521 } 2554 }
2522 String uri = 'dart:core'; 2555 String uri = 'dart:core';
2523 LibraryElementImpl original = 2556 LibraryElementImpl original =
2524 resolve2(analysisContext2.sourceFactory.forUri(uri)); 2557 resolve2(analysisContext2.sourceFactory.forUri(uri));
2525 LibraryElementImpl resynthesized = resynthesizeLibraryElement( 2558 LibraryElementImpl resynthesized = resynthesizeLibraryElement(
(...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after
4076 fail('Unexpectedly tried to get unlinked summary for $uri'); 4109 fail('Unexpectedly tried to get unlinked summary for $uri');
4077 } 4110 }
4078 return serializedUnit; 4111 return serializedUnit;
4079 } 4112 }
4080 4113
4081 @override 4114 @override
4082 bool hasLibrarySummary(String uri) { 4115 bool hasLibrarySummary(String uri) {
4083 return true; 4116 return true;
4084 } 4117 }
4085 } 4118 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_elements.dart ('k') | pkg/analyzer/test/src/summary/summary_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698