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

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

Issue 1700203002: Serialize and resynthesize unresolved identifiers. (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
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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 expect(resynthesized.compilationUnit.location, 504 expect(resynthesized.compilationUnit.location,
505 original.compilationUnit.location, 505 original.compilationUnit.location,
506 reason: desc); 506 reason: desc);
507 expect(resynthesized.annotationAst, isNotNull, reason: desc); 507 expect(resynthesized.annotationAst, isNotNull, reason: desc);
508 compareConstAsts(resynthesized.annotationAst, original.annotationAst, desc); 508 compareConstAsts(resynthesized.annotationAst, original.annotationAst, desc);
509 } 509 }
510 510
511 void compareElements(Element resynthesized, Element original, String desc) { 511 void compareElements(Element resynthesized, Element original, String desc) {
512 ElementImpl rImpl = getActualElement(resynthesized, desc); 512 ElementImpl rImpl = getActualElement(resynthesized, desc);
513 ElementImpl oImpl = getActualElement(original, desc); 513 ElementImpl oImpl = getActualElement(original, desc);
514 if (oImpl == null && rImpl == null) {
515 return;
516 }
517 expect(original, isNotNull);
518 expect(resynthesized, isNotNull);
514 expect(rImpl.runtimeType, oImpl.runtimeType); 519 expect(rImpl.runtimeType, oImpl.runtimeType);
515 expect(resynthesized, isNotNull);
516 expect(resynthesized.kind, original.kind); 520 expect(resynthesized.kind, original.kind);
517 expect(resynthesized.location, original.location, reason: desc); 521 expect(resynthesized.location, original.location, reason: desc);
518 expect(resynthesized.name, original.name); 522 expect(resynthesized.name, original.name);
519 expect(resynthesized.nameOffset, original.nameOffset, reason: desc); 523 expect(resynthesized.nameOffset, original.nameOffset, reason: desc);
520 expect(resynthesized.documentationComment, original.documentationComment, 524 expect(resynthesized.documentationComment, original.documentationComment,
521 reason: desc); 525 reason: desc);
522 expect(resynthesized.docRange, original.docRange, reason: desc); 526 expect(resynthesized.docRange, original.docRange, reason: desc);
523 compareMetadata(resynthesized.metadata, original.metadata, desc); 527 compareMetadata(resynthesized.metadata, original.metadata, desc);
524 // Modifiers are a pain to test via handles. So just test them via the 528 // Modifiers are a pain to test via handles. So just test them via the
525 // actual element. 529 // actual element.
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 unlinkedSummaries, 928 unlinkedSummaries,
925 linkedSummaries, 929 linkedSummaries,
926 options.strongMode); 930 options.strongMode);
927 } 931 }
928 932
929 fail_library_hasExtUri() { 933 fail_library_hasExtUri() {
930 checkLibrary('import "dart-ext:doesNotExist.dart";'); 934 checkLibrary('import "dart-ext:doesNotExist.dart";');
931 } 935 }
932 936
933 ElementImpl getActualElement(Element element, String desc) { 937 ElementImpl getActualElement(Element element, String desc) {
934 if (element is ElementImpl) { 938 if (element == null) {
939 return null;
940 } else if (element is ElementImpl) {
935 return element; 941 return element;
936 } else if (element is ElementHandle) { 942 } else if (element is ElementHandle) {
937 Element actualElement = element.actualElement; 943 Element actualElement = element.actualElement;
938 // A handle should never point to a member, because if it did, then 944 // A handle should never point to a member, because if it did, then
939 // "is Member" checks on the handle would produce the wrong result. 945 // "is Member" checks on the handle would produce the wrong result.
940 expect(actualElement, isNot(new isInstanceOf<Member>()), reason: desc); 946 expect(actualElement, isNot(new isInstanceOf<Member>()), reason: desc);
941 return getActualElement(actualElement, desc); 947 return getActualElement(actualElement, desc);
942 } else if (element is Member) { 948 } else if (element is Member) {
943 return getActualElement(element.baseElement, desc); 949 return getActualElement(element.baseElement, desc);
944 } else { 950 } else {
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
1789 typedef F(int a, String b); 1795 typedef F(int a, String b);
1790 '''); 1796 ''');
1791 checkLibrary(r''' 1797 checkLibrary(r'''
1792 import 'a.dart' as p; 1798 import 'a.dart' as p;
1793 const vClass = p.C; 1799 const vClass = p.C;
1794 const vEnum = p.E; 1800 const vEnum = p.E;
1795 const vFunctionTypeAlias = p.F; 1801 const vFunctionTypeAlias = p.F;
1796 '''); 1802 ''');
1797 } 1803 }
1798 1804
1805 test_const_reference_unresolved_prefix0() {
1806 checkLibrary(
1807 r'''
1808 const V = foo;
1809 ''',
1810 allowErrors: true);
1811 }
1812
1813 test_const_reference_unresolved_prefix1() {
1814 checkLibrary(
1815 r'''
1816 class C {}
1817 const v = C.foo;
1818 ''',
1819 allowErrors: true);
1820 }
1821
1822 test_const_reference_unresolved_prefix2() {
1823 addLibrarySource(
1824 '/foo.dart',
1825 '''
1826 class C {}
1827 ''');
1828 checkLibrary(
1829 r'''
1830 import 'foo.dart' as p;
1831 const v = p.C.foo;
1832 ''',
1833 allowErrors: true);
1834 }
1835
1799 test_const_topLevel_binary() { 1836 test_const_topLevel_binary() {
1800 checkLibrary(r''' 1837 checkLibrary(r'''
1801 const vEqual = 1 == 2; 1838 const vEqual = 1 == 2;
1802 const vAnd = true && false; 1839 const vAnd = true && false;
1803 const vOr = false || true; 1840 const vOr = false || true;
1804 const vBitXor = 1 ^ 2; 1841 const vBitXor = 1 ^ 2;
1805 const vBitAnd = 1 & 2; 1842 const vBitAnd = 1 & 2;
1806 const vBitOr = 1 | 2; 1843 const vBitOr = 1 | 2;
1807 const vBitShiftLeft = 1 << 2; 1844 const vBitShiftLeft = 1 << 2;
1808 const vBitShiftRight = 1 >> 2; 1845 const vBitShiftRight = 1 >> 2;
(...skipping 1698 matching lines...) Expand 10 before | Expand all | Expand 10 after
3507 fail('Unexpectedly tried to get unlinked summary for $uri'); 3544 fail('Unexpectedly tried to get unlinked summary for $uri');
3508 } 3545 }
3509 return serializedUnit; 3546 return serializedUnit;
3510 } 3547 }
3511 3548
3512 @override 3549 @override
3513 bool hasLibrarySummary(String uri) { 3550 bool hasLibrarySummary(String uri) {
3514 return true; 3551 return true;
3515 } 3552 }
3516 } 3553 }
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