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

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

Issue 1710223002: Resynthesize enum constant field evaluation results. (Closed) Base URL: git@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/summary/resynthesize.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 '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';
11 import 'package:analyzer/dart/element/type.dart'; 11 import 'package:analyzer/dart/element/type.dart';
12 import 'package:analyzer/src/dart/ast/ast.dart'; 12 import 'package:analyzer/src/dart/ast/ast.dart';
13 import 'package:analyzer/src/dart/element/element.dart'; 13 import 'package:analyzer/src/dart/element/element.dart';
14 import 'package:analyzer/src/dart/element/member.dart'; 14 import 'package:analyzer/src/dart/element/member.dart';
15 import 'package:analyzer/src/dart/element/type.dart'; 15 import 'package:analyzer/src/dart/element/type.dart';
16 import 'package:analyzer/src/generated/constant.dart' show DartObject;
16 import 'package:analyzer/src/generated/element_handle.dart'; 17 import 'package:analyzer/src/generated/element_handle.dart';
17 import 'package:analyzer/src/generated/engine.dart'; 18 import 'package:analyzer/src/generated/engine.dart';
18 import 'package:analyzer/src/generated/resolver.dart' 19 import 'package:analyzer/src/generated/resolver.dart'
19 show Namespace, TypeProvider; 20 show Namespace, TypeProvider;
20 import 'package:analyzer/src/generated/source.dart'; 21 import 'package:analyzer/src/generated/source.dart';
21 import 'package:analyzer/src/summary/idl.dart'; 22 import 'package:analyzer/src/summary/idl.dart';
22 import 'package:analyzer/src/summary/resynthesize.dart'; 23 import 'package:analyzer/src/summary/resynthesize.dart';
23 import 'package:analyzer/src/summary/summarize_elements.dart'; 24 import 'package:analyzer/src/summary/summarize_elements.dart';
24 import 'package:unittest/unittest.dart'; 25 import 'package:unittest/unittest.dart';
25 26
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 } 491 }
491 if (original.redirectedConstructor == null) { 492 if (original.redirectedConstructor == null) {
492 expect(resynthesized.redirectedConstructor, isNull, reason: desc); 493 expect(resynthesized.redirectedConstructor, isNull, reason: desc);
493 } else { 494 } else {
494 compareConstructorElements(resynthesized.redirectedConstructor, 495 compareConstructorElements(resynthesized.redirectedConstructor,
495 original.redirectedConstructor, '$desc redirectedConstructor'); 496 original.redirectedConstructor, '$desc redirectedConstructor');
496 } 497 }
497 checkPossibleMember(resynthesized, original, desc); 498 checkPossibleMember(resynthesized, original, desc);
498 } 499 }
499 500
501 void compareConstValues(
502 DartObject resynthesized, DartObject original, String desc) {
503 if (original == null) {
504 expect(resynthesized, isNull, reason: desc);
505 } else {
506 expect(resynthesized, isNotNull, reason: desc);
507 compareTypes(resynthesized.type, original.type, desc);
508 expect(resynthesized.hasKnownValue, original.hasKnownValue, reason: desc);
509 if (original.isNull) {
510 expect(resynthesized.isNull, isTrue, reason: desc);
511 } else if (original.toBoolValue() != null) {
512 expect(resynthesized.toBoolValue(), original.toBoolValue(),
513 reason: desc);
514 } else if (original.toIntValue() != null) {
515 expect(resynthesized.toIntValue(), original.toIntValue(), reason: desc);
516 } else if (original.toDoubleValue() != null) {
517 expect(resynthesized.toDoubleValue(), original.toDoubleValue(),
518 reason: desc);
519 } else if (original.toListValue() != null) {
520 List<DartObject> resynthesizedList = resynthesized.toListValue();
521 List<DartObject> originalList = original.toListValue();
522 expect(resynthesizedList, hasLength(originalList.length));
523 for (int i = 0; i < originalList.length; i++) {
524 compareConstValues(resynthesizedList[i], originalList[i], desc);
525 }
526 } else if (original.toMapValue() != null) {
527 Map<DartObject, DartObject> resynthesizedMap =
528 resynthesized.toMapValue();
529 Map<DartObject, DartObject> originalMap = original.toMapValue();
530 expect(resynthesizedMap, hasLength(originalMap.length));
531 List<DartObject> resynthesizedKeys = resynthesizedMap.keys.toList();
532 List<DartObject> originalKeys = originalMap.keys.toList();
533 for (int i = 0; i < originalKeys.length; i++) {
534 DartObject resynthesizedKey = resynthesizedKeys[i];
535 DartObject originalKey = originalKeys[i];
536 compareConstValues(resynthesizedKey, originalKey, desc);
537 DartObject resynthesizedValue = resynthesizedMap[resynthesizedKey];
538 DartObject originalValue = originalMap[originalKey];
539 compareConstValues(resynthesizedValue, originalValue, desc);
540 }
541 } else if (original.toStringValue() != null) {
542 expect(resynthesized.toStringValue(), original.toStringValue(),
543 reason: desc);
544 } else if (original.toSymbolValue() != null) {
545 expect(resynthesized.toSymbolValue(), original.toSymbolValue(),
546 reason: desc);
547 } else if (original.toTypeValue() != null) {
548 fail('Not implemented');
549 }
550 }
551 }
552
500 void compareElementAnnotations(ElementAnnotationImpl resynthesized, 553 void compareElementAnnotations(ElementAnnotationImpl resynthesized,
501 ElementAnnotationImpl original, String desc) { 554 ElementAnnotationImpl original, String desc) {
502 expect(resynthesized.element, isNotNull, reason: desc); 555 expect(resynthesized.element, isNotNull, reason: desc);
503 expect(resynthesized.element.kind, original.element.kind, reason: desc); 556 expect(resynthesized.element.kind, original.element.kind, reason: desc);
504 expect(resynthesized.element.location, original.element.location, 557 expect(resynthesized.element.location, original.element.location,
505 reason: desc); 558 reason: desc);
506 expect(resynthesized.compilationUnit, isNotNull, reason: desc); 559 expect(resynthesized.compilationUnit, isNotNull, reason: desc);
507 expect(resynthesized.compilationUnit.location, 560 expect(resynthesized.compilationUnit.location,
508 original.compilationUnit.location, 561 original.compilationUnit.location,
509 reason: desc); 562 reason: desc);
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 VariableElement resynthesized, VariableElement original, String desc) { 940 VariableElement resynthesized, VariableElement original, String desc) {
888 compareElements(resynthesized, original, desc); 941 compareElements(resynthesized, original, desc);
889 compareTypes(resynthesized.type, original.type, desc); 942 compareTypes(resynthesized.type, original.type, desc);
890 // TODO(scheglov) VariableMember.initializer is not implemented 943 // TODO(scheglov) VariableMember.initializer is not implemented
891 if (original is! VariableMember) { 944 if (original is! VariableMember) {
892 compareFunctionElements( 945 compareFunctionElements(
893 resynthesized.initializer, original.initializer, desc); 946 resynthesized.initializer, original.initializer, desc);
894 } 947 }
895 VariableElementImpl originalActual = getActualElement(original, desc); 948 VariableElementImpl originalActual = getActualElement(original, desc);
896 if (originalActual is ConstVariableElement) { 949 if (originalActual is ConstVariableElement) {
897 VariableElementImpl resynthesizedActual = 950 Element oEnclosing = original.enclosingElement;
898 getActualElement(resynthesized, desc); 951 if (oEnclosing is ClassElement && oEnclosing.isEnum) {
899 Expression initializer = resynthesizedActual.constantInitializer; 952 compareConstValues(
900 if (constantInitializersAreInvalid) { 953 resynthesized.constantValue, original.constantValue, desc);
901 _assertUnresolvedIdentifier(initializer, desc);
902 } else { 954 } else {
903 compareConstAsts(initializer, originalActual.constantInitializer, 955 VariableElementImpl resynthesizedActual =
904 '$desc initializer'); 956 getActualElement(resynthesized, desc);
957 Expression initializer = resynthesizedActual.constantInitializer;
958 if (constantInitializersAreInvalid) {
959 _assertUnresolvedIdentifier(initializer, desc);
960 } else {
961 compareConstAsts(initializer, originalActual.constantInitializer,
962 '$desc initializer');
963 }
905 } 964 }
906 } 965 }
907 checkPossibleMember(resynthesized, original, desc); 966 checkPossibleMember(resynthesized, original, desc);
908 checkPossibleLocalElements(resynthesized, original); 967 checkPossibleLocalElements(resynthesized, original);
909 } 968 }
910 969
911 /** 970 /**
912 * Serialize the given [library] into a summary. Then create a 971 * Serialize the given [library] into a summary. Then create a
913 * [_TestSummaryResynthesizer] which can deserialize it, along with any 972 * [_TestSummaryResynthesizer] which can deserialize it, along with any
914 * references it makes to `dart:core`. 973 * references it makes to `dart:core`.
(...skipping 2837 matching lines...) Expand 10 before | Expand all | Expand 10 after
3752 fail('Unexpectedly tried to get unlinked summary for $uri'); 3811 fail('Unexpectedly tried to get unlinked summary for $uri');
3753 } 3812 }
3754 return serializedUnit; 3813 return serializedUnit;
3755 } 3814 }
3756 3815
3757 @override 3816 @override
3758 bool hasLibrarySummary(String uri) { 3817 bool hasLibrarySummary(String uri) {
3759 return true; 3818 return true;
3760 } 3819 }
3761 } 3820 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698