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

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

Issue 1610003002: Rename UnlinkedTypeRef to TypeRef. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
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 analyzer.test.src.summary.summary_test; 5 library analyzer.test.src.summary.summary_test;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 analysisContext.typeProvider.objectType.element.library, 51 analysisContext.typeProvider.objectType.element.library,
52 analysisContext.typeProvider.futureType.element.library 52 analysisContext.typeProvider.futureType.element.library
53 ]; 53 ];
54 for (LibraryElement library in libraries) { 54 for (LibraryElement library in libraries) {
55 summarize_elements.LibrarySerializationResult serializedLibrary = 55 summarize_elements.LibrarySerializationResult serializedLibrary =
56 summarize_elements.serializeLibrary( 56 summarize_elements.serializeLibrary(
57 library, analysisContext.typeProvider); 57 library, analysisContext.typeProvider);
58 for (int i = 0; i < serializedLibrary.unlinkedUnits.length; i++) { 58 for (int i = 0; i < serializedLibrary.unlinkedUnits.length; i++) {
59 uriToNamespace[serializedLibrary.unitUris[i]] = 59 uriToNamespace[serializedLibrary.unitUris[i]] =
60 new UnlinkedUnit.fromBuffer( 60 new UnlinkedUnit.fromBuffer(
61 serializedLibrary.unlinkedUnits[i].toBuffer()) 61 serializedLibrary.unlinkedUnits[i].toBuffer()).publicNamespace;
62 .publicNamespace;
63 } 62 }
64 } 63 }
65 return uriToNamespace; 64 return uriToNamespace;
66 } catch (_) { 65 } catch (_) {
67 return null; 66 return null;
68 } 67 }
69 }(); 68 }();
70 69
71 /** 70 /**
72 * Convert a summary object (or a portion of one) into a canonical form that 71 * Convert a summary object (or a portion of one) into a canonical form that
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 new Scanner(source, reader, AnalysisErrorListener.NULL_LISTENER); 112 new Scanner(source, reader, AnalysisErrorListener.NULL_LISTENER);
114 Parser parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER); 113 Parser parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER);
115 parser.parseGenericMethods = true; 114 parser.parseGenericMethods = true;
116 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize()); 115 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize());
117 UnlinkedPublicNamespace namespace = new UnlinkedPublicNamespace.fromBuffer( 116 UnlinkedPublicNamespace namespace = new UnlinkedPublicNamespace.fromBuffer(
118 public_namespace.computePublicNamespace(unit).toBuffer()); 117 public_namespace.computePublicNamespace(unit).toBuffer());
119 return namespace; 118 return namespace;
120 } 119 }
121 120
122 /** 121 /**
123 * Type of a function that validates an [UnlinkedTypeRef]. 122 * Type of a function that validates an [TypeRef].
124 */ 123 */
125 typedef bool _UnlinkedTypeRefValidator(UnlinkedTypeRef unlinkedTypeRef); 124 typedef bool _TypeRefValidator(TypeRef unlinkedTypeRef);
126 125
127 /** 126 /**
128 * Override of [SummaryTest] which verifies the correctness of the prelinker by 127 * Override of [SummaryTest] which verifies the correctness of the prelinker by
129 * creating summaries from the element model, discarding their prelinked 128 * creating summaries from the element model, discarding their prelinked
130 * information, and then recreating it using the prelinker. 129 * information, and then recreating it using the prelinker.
131 */ 130 */
132 @reflectiveTest 131 @reflectiveTest
133 class PrelinkerTest extends SummarizeElementsTest { 132 class PrelinkerTest extends SummarizeElementsTest {
134 final Map<String, UnlinkedPublicNamespace> uriToPublicNamespace = 133 final Map<String, UnlinkedPublicNamespace> uriToPublicNamespace =
135 <String, UnlinkedPublicNamespace>{}; 134 <String, UnlinkedPublicNamespace>{};
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 String expectedCommentText = 415 String expectedCommentText =
417 text.substring(commentStart, commentEnd).replaceAll('\r\n', '\n'); 416 text.substring(commentStart, commentEnd).replaceAll('\r\n', '\n');
418 expect(documentationComment.text, expectedCommentText); 417 expect(documentationComment.text, expectedCommentText);
419 expect(documentationComment.offset, commentStart); 418 expect(documentationComment.offset, commentStart);
420 expect(documentationComment.length, commentEnd - commentStart); 419 expect(documentationComment.length, commentEnd - commentStart);
421 } 420 }
422 421
423 /** 422 /**
424 * Verify that the given [typeRef] represents the type `dynamic`. 423 * Verify that the given [typeRef] represents the type `dynamic`.
425 */ 424 */
426 void checkDynamicTypeRef(UnlinkedTypeRef typeRef) { 425 void checkDynamicTypeRef(TypeRef typeRef) {
427 checkTypeRef(typeRef, null, null, null); 426 checkTypeRef(typeRef, null, null, null);
428 } 427 }
429 428
430 /** 429 /**
431 * Verify that the given [exportName] represents a reference to an entity 430 * Verify that the given [exportName] represents a reference to an entity
432 * declared in a file reachable via [absoluteUri] and [relativeUri], having 431 * declared in a file reachable via [absoluteUri] and [relativeUri], having
433 * name [expectedName]. [expectedKind] is the kind of object referenced. 432 * name [expectedName]. [expectedKind] is the kind of object referenced.
434 * [expectedTargetUnit] is the index of the compilation unit in which the 433 * [expectedTargetUnit] is the index of the compilation unit in which the
435 * target of the [exportName] is expected to appear; if not specified it is 434 * target of the [exportName] is expected to appear; if not specified it is
436 * assumed to be the defining compilation unit. 435 * assumed to be the defining compilation unit.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 if (dep.uri == relativeUri) { 485 if (dep.uri == relativeUri) {
487 fail('Unexpected dependency found: $relativeUri'); 486 fail('Unexpected dependency found: $relativeUri');
488 } 487 }
489 } 488 }
490 } 489 }
491 490
492 /** 491 /**
493 * Verify that the given [typeRef] represents a reference to a type parameter 492 * Verify that the given [typeRef] represents a reference to a type parameter
494 * having the given [deBruijnIndex]. 493 * having the given [deBruijnIndex].
495 */ 494 */
496 void checkParamTypeRef(UnlinkedTypeRef typeRef, int deBruijnIndex) { 495 void checkParamTypeRef(TypeRef typeRef, int deBruijnIndex) {
497 expect(typeRef, new isInstanceOf<UnlinkedTypeRef>()); 496 expect(typeRef, new isInstanceOf<TypeRef>());
498 expect(typeRef.reference, 0); 497 expect(typeRef.reference, 0);
499 expect(typeRef.typeArguments, isEmpty); 498 expect(typeRef.typeArguments, isEmpty);
500 expect(typeRef.paramReference, deBruijnIndex); 499 expect(typeRef.paramReference, deBruijnIndex);
501 } 500 }
502 501
503 /** 502 /**
504 * Verify that [prefixReference] is a valid reference to a prefix having the 503 * Verify that [prefixReference] is a valid reference to a prefix having the
505 * given [name]. 504 * given [name].
506 */ 505 */
507 void checkPrefix(int prefixReference, String name) { 506 void checkPrefix(int prefixReference, String name) {
(...skipping 12 matching lines...) Expand all
520 * reached via the given prefix. If [allowTypeParameters] is true, allow the 519 * reached via the given prefix. If [allowTypeParameters] is true, allow the
521 * type reference to supply type parameters. [expectedKind] is the kind of 520 * type reference to supply type parameters. [expectedKind] is the kind of
522 * object referenced. [linkedSourceUnit] and [unlinkedSourceUnit] refer 521 * object referenced. [linkedSourceUnit] and [unlinkedSourceUnit] refer
523 * to the compilation unit within which the [typeRef] appears; if not 522 * to the compilation unit within which the [typeRef] appears; if not
524 * specified they are assumed to refer to the defining compilation unit. 523 * specified they are assumed to refer to the defining compilation unit.
525 * [expectedTargetUnit] is the index of the compilation unit in which the 524 * [expectedTargetUnit] is the index of the compilation unit in which the
526 * target of the [typeRef] is expected to appear; if not specified it is 525 * target of the [typeRef] is expected to appear; if not specified it is
527 * assumed to be the defining compilation unit. [numTypeParameters] is the 526 * assumed to be the defining compilation unit. [numTypeParameters] is the
528 * number of type parameters of the thing being referred to. 527 * number of type parameters of the thing being referred to.
529 */ 528 */
530 void checkTypeRef(UnlinkedTypeRef typeRef, String absoluteUri, 529 void checkTypeRef(TypeRef typeRef, String absoluteUri, String relativeUri,
531 String relativeUri, String expectedName, 530 String expectedName,
532 {String expectedPrefix, 531 {String expectedPrefix,
533 bool allowTypeParameters: false, 532 bool allowTypeParameters: false,
534 ReferenceKind expectedKind: ReferenceKind.classOrEnum, 533 ReferenceKind expectedKind: ReferenceKind.classOrEnum,
535 int expectedTargetUnit: 0, 534 int expectedTargetUnit: 0,
536 LinkedUnit linkedSourceUnit, 535 LinkedUnit linkedSourceUnit,
537 UnlinkedUnit unlinkedSourceUnit, 536 UnlinkedUnit unlinkedSourceUnit,
538 int numTypeParameters: 0}) { 537 int numTypeParameters: 0}) {
539 linkedSourceUnit ??= definingUnit; 538 linkedSourceUnit ??= definingUnit;
540 unlinkedSourceUnit ??= unlinkedUnits[0]; 539 unlinkedSourceUnit ??= unlinkedUnits[0];
541 expect(typeRef, new isInstanceOf<UnlinkedTypeRef>()); 540 expect(typeRef, new isInstanceOf<TypeRef>());
542 expect(typeRef.paramReference, 0); 541 expect(typeRef.paramReference, 0);
543 int index = typeRef.reference; 542 int index = typeRef.reference;
544 UnlinkedReference reference = unlinkedSourceUnit.references[index]; 543 UnlinkedReference reference = unlinkedSourceUnit.references[index];
545 LinkedReference referenceResolution = linkedSourceUnit.references[index]; 544 LinkedReference referenceResolution = linkedSourceUnit.references[index];
546 if (index == 0) { 545 if (index == 0) {
547 // Index 0 is reserved for "dynamic". 546 // Index 0 is reserved for "dynamic".
548 expect(reference.name, isEmpty); 547 expect(reference.name, isEmpty);
549 expect(reference.prefixReference, 0); 548 expect(reference.prefixReference, 0);
550 } 549 }
551 if (absoluteUri == null) { 550 if (absoluteUri == null) {
(...skipping 24 matching lines...) Expand all
576 expect(referenceResolution.kind, expectedKind); 575 expect(referenceResolution.kind, expectedKind);
577 expect(referenceResolution.unit, expectedTargetUnit); 576 expect(referenceResolution.unit, expectedTargetUnit);
578 expect(referenceResolution.numTypeParameters, numTypeParameters); 577 expect(referenceResolution.numTypeParameters, numTypeParameters);
579 } 578 }
580 579
581 /** 580 /**
582 * Verify that the given [typeRef] represents a reference to an unresolved 581 * Verify that the given [typeRef] represents a reference to an unresolved
583 * type. 582 * type.
584 */ 583 */
585 void checkUnresolvedTypeRef( 584 void checkUnresolvedTypeRef(
586 UnlinkedTypeRef typeRef, String expectedPrefix, String expectedName) { 585 TypeRef typeRef, String expectedPrefix, String expectedName) {
587 // When serializing from the element model, unresolved type refs lose their 586 // When serializing from the element model, unresolved type refs lose their
588 // name. 587 // name.
589 checkTypeRef(typeRef, null, null, checkAstDerivedData ? expectedName : null, 588 checkTypeRef(typeRef, null, null, checkAstDerivedData ? expectedName : null,
590 expectedPrefix: expectedPrefix, expectedKind: ReferenceKind.unresolved); 589 expectedPrefix: expectedPrefix, expectedKind: ReferenceKind.unresolved);
591 } 590 }
592 591
593 fail_constExpr_pushInt_shiftOr() { 592 fail_constExpr_pushInt_shiftOr() {
594 UnlinkedVariable variable = 593 UnlinkedVariable variable =
595 serializeVariableText('const v = 0x111222333444555666;'); 594 serializeVariableText('const v = 0x111222333444555666;');
596 // ^^!!!!^^^^!!!!^^^^ 595 // ^^!!!!^^^^!!!!^^^^
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 * with the given [typedefName]. 786 * with the given [typedefName].
788 */ 787 */
789 UnlinkedTypedef serializeTypedefText(String text, 788 UnlinkedTypedef serializeTypedefText(String text,
790 [String typedefName = 'F']) { 789 [String typedefName = 'F']) {
791 serializeLibraryText(text); 790 serializeLibraryText(text);
792 return findTypedef(typedefName, failIfAbsent: true); 791 return findTypedef(typedefName, failIfAbsent: true);
793 } 792 }
794 793
795 /** 794 /**
796 * Serialize a type declaration using the given [text] as a type name, and 795 * Serialize a type declaration using the given [text] as a type name, and
797 * return a summary of the corresponding [UnlinkedTypeRef]. If the type 796 * return a summary of the corresponding [TypeRef]. If the type
798 * declaration needs to refer to types that are not available in core, those 797 * declaration needs to refer to types that are not available in core, those
799 * types may be declared in [otherDeclarations]. 798 * types may be declared in [otherDeclarations].
800 */ 799 */
801 UnlinkedTypeRef serializeTypeText(String text, 800 TypeRef serializeTypeText(String text,
802 {String otherDeclarations: '', bool allowErrors: false}) { 801 {String otherDeclarations: '', bool allowErrors: false}) {
803 return serializeVariableText('$otherDeclarations\n$text v;', 802 return serializeVariableText('$otherDeclarations\n$text v;',
804 allowErrors: allowErrors) 803 allowErrors: allowErrors).type;
805 .type;
806 } 804 }
807 805
808 /** 806 /**
809 * Serialize the given library [text] and return the summary of the variable 807 * Serialize the given library [text] and return the summary of the variable
810 * with the given [variableName]. 808 * with the given [variableName].
811 */ 809 */
812 UnlinkedVariable serializeVariableText(String text, 810 UnlinkedVariable serializeVariableText(String text,
813 {String variableName: 'v', bool allowErrors: false}) { 811 {String variableName: 'v', bool allowErrors: false}) {
814 serializeLibraryText(text, allowErrors: allowErrors); 812 serializeLibraryText(text, allowErrors: allowErrors);
815 return findVariable(variableName, failIfAbsent: true); 813 return findVariable(variableName, failIfAbsent: true);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 expect(cls.executables, isEmpty); 1013 expect(cls.executables, isEmpty);
1016 } 1014 }
1017 1015
1018 test_class_alias_private() { 1016 test_class_alias_private() {
1019 serializeClassText('class _C = _D with _E; class _D {} class _E {}', 1017 serializeClassText('class _C = _D with _E; class _D {} class _E {}',
1020 className: '_C'); 1018 className: '_C');
1021 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); 1019 expect(unlinkedUnits[0].publicNamespace.names, isEmpty);
1022 } 1020 }
1023 1021
1024 test_class_alias_reference_generic() { 1022 test_class_alias_reference_generic() {
1025 UnlinkedTypeRef typeRef = serializeTypeText('C', 1023 TypeRef typeRef = serializeTypeText('C',
1026 otherDeclarations: 'class C<D, E> = F with G; class F {} class G {}'); 1024 otherDeclarations: 'class C<D, E> = F with G; class F {} class G {}');
1027 checkTypeRef(typeRef, null, null, 'C', numTypeParameters: 2); 1025 checkTypeRef(typeRef, null, null, 'C', numTypeParameters: 2);
1028 } 1026 }
1029 1027
1030 test_class_alias_reference_generic_imported() { 1028 test_class_alias_reference_generic_imported() {
1031 addNamedSource( 1029 addNamedSource(
1032 '/lib.dart', 'class C<D, E> = F with G; class F {} class G {}'); 1030 '/lib.dart', 'class C<D, E> = F with G; class F {} class G {}');
1033 UnlinkedTypeRef typeRef = 1031 TypeRef typeRef =
1034 serializeTypeText('C', otherDeclarations: 'import "lib.dart";'); 1032 serializeTypeText('C', otherDeclarations: 'import "lib.dart";');
1035 checkTypeRef(typeRef, absUri('/lib.dart'), 'lib.dart', 'C', 1033 checkTypeRef(typeRef, absUri('/lib.dart'), 'lib.dart', 'C',
1036 numTypeParameters: 2); 1034 numTypeParameters: 2);
1037 } 1035 }
1038 1036
1039 test_class_alias_supertype() { 1037 test_class_alias_supertype() {
1040 UnlinkedClass cls = 1038 UnlinkedClass cls =
1041 serializeClassText('class C = D with E; class D {} class E {}'); 1039 serializeClassText('class C = D with E; class D {} class E {}');
1042 checkTypeRef(cls.supertype, null, null, 'D'); 1040 checkTypeRef(cls.supertype, null, null, 'D');
1043 expect(cls.hasNoSupertype, isFalse); 1041 expect(cls.hasNoSupertype, isFalse);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 UnlinkedClass cls = serializeClassText('class C {}'); 1157 UnlinkedClass cls = serializeClassText('class C {}');
1160 expect(cls.isMixinApplication, false); 1158 expect(cls.isMixinApplication, false);
1161 } 1159 }
1162 1160
1163 test_class_private() { 1161 test_class_private() {
1164 serializeClassText('class _C {}', className: '_C'); 1162 serializeClassText('class _C {}', className: '_C');
1165 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); 1163 expect(unlinkedUnits[0].publicNamespace.names, isEmpty);
1166 } 1164 }
1167 1165
1168 test_class_reference_generic() { 1166 test_class_reference_generic() {
1169 UnlinkedTypeRef typeRef = 1167 TypeRef typeRef =
1170 serializeTypeText('C', otherDeclarations: 'class C<D, E> {}'); 1168 serializeTypeText('C', otherDeclarations: 'class C<D, E> {}');
1171 checkTypeRef(typeRef, null, null, 'C', numTypeParameters: 2); 1169 checkTypeRef(typeRef, null, null, 'C', numTypeParameters: 2);
1172 } 1170 }
1173 1171
1174 test_class_reference_generic_imported() { 1172 test_class_reference_generic_imported() {
1175 addNamedSource('/lib.dart', 'class C<D, E> {}'); 1173 addNamedSource('/lib.dart', 'class C<D, E> {}');
1176 UnlinkedTypeRef typeRef = 1174 TypeRef typeRef =
1177 serializeTypeText('C', otherDeclarations: 'import "lib.dart";'); 1175 serializeTypeText('C', otherDeclarations: 'import "lib.dart";');
1178 checkTypeRef(typeRef, absUri('/lib.dart'), 'lib.dart', 'C', 1176 checkTypeRef(typeRef, absUri('/lib.dart'), 'lib.dart', 'C',
1179 numTypeParameters: 2); 1177 numTypeParameters: 2);
1180 } 1178 }
1181 1179
1182 test_class_superclass() { 1180 test_class_superclass() {
1183 UnlinkedClass cls = serializeClassText('class C {}'); 1181 UnlinkedClass cls = serializeClassText('class C {}');
1184 expect(cls.supertype, isNull); 1182 expect(cls.supertype, isNull);
1185 expect(cls.hasNoSupertype, isFalse); 1183 expect(cls.hasNoSupertype, isFalse);
1186 } 1184 }
1187 1185
1188 test_class_superclass_explicit() { 1186 test_class_superclass_explicit() {
1189 UnlinkedClass cls = serializeClassText('class C extends D {} class D {}'); 1187 UnlinkedClass cls = serializeClassText('class C extends D {} class D {}');
1190 expect(cls.supertype, isNotNull); 1188 expect(cls.supertype, isNotNull);
1191 checkTypeRef(cls.supertype, null, null, 'D'); 1189 checkTypeRef(cls.supertype, null, null, 'D');
1192 expect(cls.hasNoSupertype, isFalse); 1190 expect(cls.hasNoSupertype, isFalse);
1193 } 1191 }
1194 1192
1195 test_class_type_param_bound() { 1193 test_class_type_param_bound() {
1196 UnlinkedClass cls = serializeClassText('class C<T extends List> {}'); 1194 UnlinkedClass cls = serializeClassText('class C<T extends List> {}');
1197 expect(cls.typeParameters, hasLength(1)); 1195 expect(cls.typeParameters, hasLength(1));
1198 expect(cls.typeParameters[0].name, 'T'); 1196 expect(cls.typeParameters[0].name, 'T');
1199 expect(cls.typeParameters[0].bound, isNotNull); 1197 expect(cls.typeParameters[0].bound, isNotNull);
1200 checkTypeRef(cls.typeParameters[0].bound, 'dart:core', 'dart:core', 'List', 1198 checkTypeRef(cls.typeParameters[0].bound, 'dart:core', 'dart:core', 'List',
1201 allowTypeParameters: true, numTypeParameters: 1); 1199 allowTypeParameters: true, numTypeParameters: 1);
1202 } 1200 }
1203 1201
1204 test_class_type_param_f_bound() { 1202 test_class_type_param_f_bound() {
1205 UnlinkedClass cls = serializeClassText('class C<T, U extends List<T>> {}'); 1203 UnlinkedClass cls = serializeClassText('class C<T, U extends List<T>> {}');
1206 UnlinkedTypeRef typeArgument = cls.typeParameters[1].bound.typeArguments[0]; 1204 TypeRef typeArgument = cls.typeParameters[1].bound.typeArguments[0];
1207 checkParamTypeRef(typeArgument, 2); 1205 checkParamTypeRef(typeArgument, 2);
1208 } 1206 }
1209 1207
1210 test_class_type_param_f_bound_self_ref() { 1208 test_class_type_param_f_bound_self_ref() {
1211 UnlinkedClass cls = serializeClassText('class C<T, U extends List<U>> {}'); 1209 UnlinkedClass cls = serializeClassText('class C<T, U extends List<U>> {}');
1212 UnlinkedTypeRef typeArgument = cls.typeParameters[1].bound.typeArguments[0]; 1210 TypeRef typeArgument = cls.typeParameters[1].bound.typeArguments[0];
1213 checkParamTypeRef(typeArgument, 1); 1211 checkParamTypeRef(typeArgument, 1);
1214 } 1212 }
1215 1213
1216 test_class_type_param_no_bound() { 1214 test_class_type_param_no_bound() {
1217 String text = 'class C<T> {}'; 1215 String text = 'class C<T> {}';
1218 UnlinkedClass cls = serializeClassText(text); 1216 UnlinkedClass cls = serializeClassText(text);
1219 expect(cls.typeParameters, hasLength(1)); 1217 expect(cls.typeParameters, hasLength(1));
1220 expect(cls.typeParameters[0].name, 'T'); 1218 expect(cls.typeParameters[0].name, 'T');
1221 expect(cls.typeParameters[0].nameOffset, text.indexOf('T')); 1219 expect(cls.typeParameters[0].nameOffset, text.indexOf('T'));
1222 expect(cls.typeParameters[0].bound, isNull); 1220 expect(cls.typeParameters[0].bound, isNull);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 } 1483 }
1486 const v = const C.named(); 1484 const v = const C.named();
1487 '''); 1485 ''');
1488 _assertUnlinkedConst(variable.constExpr, operators: [ 1486 _assertUnlinkedConst(variable.constExpr, operators: [
1489 UnlinkedConstOperation.invokeConstructor, 1487 UnlinkedConstOperation.invokeConstructor,
1490 ], ints: [ 1488 ], ints: [
1491 0 1489 0
1492 ], strings: [ 1490 ], strings: [
1493 'named' 1491 'named'
1494 ], referenceValidators: [ 1492 ], referenceValidators: [
1495 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C', 1493 (TypeRef r) => checkTypeRef(r, null, null, 'C',
1496 expectedKind: ReferenceKind.classOrEnum) 1494 expectedKind: ReferenceKind.classOrEnum)
1497 ]); 1495 ]);
1498 } 1496 }
1499 1497
1500 test_constExpr_invokeConstructor_named_imported() { 1498 test_constExpr_invokeConstructor_named_imported() {
1501 if (checkAstDerivedData) { 1499 if (checkAstDerivedData) {
1502 // TODO(scheglov) at the moment we cannot link class member references 1500 // TODO(scheglov) at the moment we cannot link class member references
1503 return; 1501 return;
1504 } 1502 }
1505 addNamedSource( 1503 addNamedSource(
1506 '/a.dart', 1504 '/a.dart',
1507 ''' 1505 '''
1508 class C { 1506 class C {
1509 const C.named(); 1507 const C.named();
1510 } 1508 }
1511 '''); 1509 ''');
1512 UnlinkedVariable variable = serializeVariableText(''' 1510 UnlinkedVariable variable = serializeVariableText('''
1513 import 'a.dart'; 1511 import 'a.dart';
1514 const v = const C.named(); 1512 const v = const C.named();
1515 '''); 1513 ''');
1516 _assertUnlinkedConst(variable.constExpr, operators: [ 1514 _assertUnlinkedConst(variable.constExpr, operators: [
1517 UnlinkedConstOperation.invokeConstructor, 1515 UnlinkedConstOperation.invokeConstructor,
1518 ], ints: [ 1516 ], ints: [
1519 0 1517 0
1520 ], strings: [ 1518 ], strings: [
1521 'named' 1519 'named'
1522 ], referenceValidators: [ 1520 ], referenceValidators: [
1523 (UnlinkedTypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C', 1521 (TypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C',
1524 expectedKind: ReferenceKind.classOrEnum) 1522 expectedKind: ReferenceKind.classOrEnum)
1525 ]); 1523 ]);
1526 } 1524 }
1527 1525
1528 test_constExpr_invokeConstructor_named_imported_withPrefix() { 1526 test_constExpr_invokeConstructor_named_imported_withPrefix() {
1529 addNamedSource( 1527 addNamedSource(
1530 '/a.dart', 1528 '/a.dart',
1531 ''' 1529 '''
1532 class C { 1530 class C {
1533 const C.named(); 1531 const C.named();
1534 } 1532 }
1535 '''); 1533 ''');
1536 UnlinkedVariable variable = serializeVariableText(''' 1534 UnlinkedVariable variable = serializeVariableText('''
1537 import 'a.dart' as p; 1535 import 'a.dart' as p;
1538 const v = const p.C.named(); 1536 const v = const p.C.named();
1539 '''); 1537 ''');
1540 _assertUnlinkedConst(variable.constExpr, operators: [ 1538 _assertUnlinkedConst(variable.constExpr, operators: [
1541 UnlinkedConstOperation.invokeConstructor, 1539 UnlinkedConstOperation.invokeConstructor,
1542 ], ints: [ 1540 ], ints: [
1543 0 1541 0
1544 ], strings: [ 1542 ], strings: [
1545 'named' 1543 'named'
1546 ], referenceValidators: [ 1544 ], referenceValidators: [
1547 (UnlinkedTypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C', 1545 (TypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C',
1548 expectedKind: ReferenceKind.classOrEnum, expectedPrefix: 'p') 1546 expectedKind: ReferenceKind.classOrEnum, expectedPrefix: 'p')
1549 ]); 1547 ]);
1550 } 1548 }
1551 1549
1552 test_constExpr_invokeConstructor_unnamed() { 1550 test_constExpr_invokeConstructor_unnamed() {
1553 UnlinkedVariable variable = serializeVariableText(''' 1551 UnlinkedVariable variable = serializeVariableText('''
1554 class C { 1552 class C {
1555 const C(int a, String b); 1553 const C(int a, String b);
1556 } 1554 }
1557 const v = const C(42, 'sss'); 1555 const v = const C(42, 'sss');
1558 '''); 1556 ''');
1559 _assertUnlinkedConst(variable.constExpr, operators: [ 1557 _assertUnlinkedConst(variable.constExpr, operators: [
1560 UnlinkedConstOperation.pushInt, 1558 UnlinkedConstOperation.pushInt,
1561 UnlinkedConstOperation.pushString, 1559 UnlinkedConstOperation.pushString,
1562 UnlinkedConstOperation.invokeConstructor, 1560 UnlinkedConstOperation.invokeConstructor,
1563 ], ints: [ 1561 ], ints: [
1564 42, 1562 42,
1565 2 1563 2
1566 ], strings: [ 1564 ], strings: [
1567 'sss', 1565 'sss',
1568 '' 1566 ''
1569 ], referenceValidators: [ 1567 ], referenceValidators: [
1570 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C', 1568 (TypeRef r) => checkTypeRef(r, null, null, 'C',
1571 expectedKind: ReferenceKind.classOrEnum) 1569 expectedKind: ReferenceKind.classOrEnum)
1572 ]); 1570 ]);
1573 } 1571 }
1574 1572
1575 test_constExpr_length() { 1573 test_constExpr_length() {
1576 UnlinkedVariable variable = 1574 UnlinkedVariable variable =
1577 serializeVariableText('const v = "abc".length;'); 1575 serializeVariableText('const v = "abc".length;');
1578 _assertUnlinkedConst(variable.constExpr, operators: [ 1576 _assertUnlinkedConst(variable.constExpr,
1579 UnlinkedConstOperation.pushString, 1577 operators:
1580 UnlinkedConstOperation.length 1578 [UnlinkedConstOperation.pushString, UnlinkedConstOperation.length],
1581 ], strings: [ 1579 strings: ['abc']);
1582 'abc'
1583 ]);
1584 } 1580 }
1585 1581
1586 test_constExpr_makeList_typed() { 1582 test_constExpr_makeList_typed() {
1587 UnlinkedVariable variable = 1583 UnlinkedVariable variable =
1588 serializeVariableText('const v = const <int>[11, 22, 33];'); 1584 serializeVariableText('const v = const <int>[11, 22, 33];');
1589 _assertUnlinkedConst(variable.constExpr, operators: [ 1585 _assertUnlinkedConst(variable.constExpr, operators: [
1590 UnlinkedConstOperation.pushInt, 1586 UnlinkedConstOperation.pushInt,
1591 UnlinkedConstOperation.pushInt, 1587 UnlinkedConstOperation.pushInt,
1592 UnlinkedConstOperation.pushInt, 1588 UnlinkedConstOperation.pushInt,
1593 UnlinkedConstOperation.makeList 1589 UnlinkedConstOperation.makeList
1594 ], ints: [ 1590 ], ints: [
1595 11, 1591 11,
1596 22, 1592 22,
1597 33, 1593 33,
1598 3 1594 3
1599 ], referenceValidators: [ 1595 ], referenceValidators: [
1600 (UnlinkedTypeRef r) => checkTypeRef(r, 'dart:core', 'dart:core', 'int', 1596 (TypeRef r) => checkTypeRef(r, 'dart:core', 'dart:core', 'int',
1601 expectedKind: ReferenceKind.classOrEnum) 1597 expectedKind: ReferenceKind.classOrEnum)
1602 ]); 1598 ]);
1603 } 1599 }
1604 1600
1605 test_constExpr_makeList_untyped() { 1601 test_constExpr_makeList_untyped() {
1606 UnlinkedVariable variable = 1602 UnlinkedVariable variable =
1607 serializeVariableText('const v = const [11, 22, 33];'); 1603 serializeVariableText('const v = const [11, 22, 33];');
1608 _assertUnlinkedConst(variable.constExpr, operators: [ 1604 _assertUnlinkedConst(variable.constExpr, operators: [
1609 UnlinkedConstOperation.pushInt, 1605 UnlinkedConstOperation.pushInt,
1610 UnlinkedConstOperation.pushInt, 1606 UnlinkedConstOperation.pushInt,
1611 UnlinkedConstOperation.pushInt, 1607 UnlinkedConstOperation.pushInt,
1612 UnlinkedConstOperation.makeList 1608 UnlinkedConstOperation.makeList
1613 ], ints: [ 1609 ], ints: [
1614 11, 1610 11,
1615 22, 1611 22,
1616 33, 1612 33,
1617 3 1613 3
1618 ], referenceValidators: [ 1614 ], referenceValidators: [
1619 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, '', 1615 (TypeRef r) => checkTypeRef(r, null, null, '',
1620 expectedKind: ReferenceKind.classOrEnum) 1616 expectedKind: ReferenceKind.classOrEnum)
1621 ]); 1617 ]);
1622 } 1618 }
1623 1619
1624 test_constExpr_makeMap_typed() { 1620 test_constExpr_makeMap_typed() {
1625 UnlinkedVariable variable = serializeVariableText( 1621 UnlinkedVariable variable = serializeVariableText(
1626 'const v = const <int, String>{11: "aaa", 22: "bbb", 33: "ccc"};'); 1622 'const v = const <int, String>{11: "aaa", 22: "bbb", 33: "ccc"};');
1627 _assertUnlinkedConst(variable.constExpr, operators: [ 1623 _assertUnlinkedConst(variable.constExpr, operators: [
1628 UnlinkedConstOperation.pushInt, 1624 UnlinkedConstOperation.pushInt,
1629 UnlinkedConstOperation.pushString, 1625 UnlinkedConstOperation.pushString,
1630 UnlinkedConstOperation.pushInt, 1626 UnlinkedConstOperation.pushInt,
1631 UnlinkedConstOperation.pushString, 1627 UnlinkedConstOperation.pushString,
1632 UnlinkedConstOperation.pushInt, 1628 UnlinkedConstOperation.pushInt,
1633 UnlinkedConstOperation.pushString, 1629 UnlinkedConstOperation.pushString,
1634 UnlinkedConstOperation.makeMap 1630 UnlinkedConstOperation.makeMap
1635 ], ints: [ 1631 ], ints: [
1636 11, 1632 11,
1637 22, 1633 22,
1638 33, 1634 33,
1639 3 1635 3
1640 ], strings: [ 1636 ], strings: [
1641 'aaa', 1637 'aaa',
1642 'bbb', 1638 'bbb',
1643 'ccc' 1639 'ccc'
1644 ], referenceValidators: [ 1640 ], referenceValidators: [
1645 (UnlinkedTypeRef r) => checkTypeRef(r, 'dart:core', 'dart:core', 'int', 1641 (TypeRef r) => checkTypeRef(r, 'dart:core', 'dart:core', 'int',
1646 expectedKind: ReferenceKind.classOrEnum), 1642 expectedKind: ReferenceKind.classOrEnum),
1647 (UnlinkedTypeRef r) => checkTypeRef(r, 'dart:core', 'dart:core', 'String', 1643 (TypeRef r) => checkTypeRef(r, 'dart:core', 'dart:core', 'String',
1648 expectedKind: ReferenceKind.classOrEnum) 1644 expectedKind: ReferenceKind.classOrEnum)
1649 ]); 1645 ]);
1650 } 1646 }
1651 1647
1652 test_constExpr_makeMap_untyped() { 1648 test_constExpr_makeMap_untyped() {
1653 UnlinkedVariable variable = serializeVariableText( 1649 UnlinkedVariable variable = serializeVariableText(
1654 'const v = const {11: "aaa", 22: "bbb", 33: "ccc"};'); 1650 'const v = const {11: "aaa", 22: "bbb", 33: "ccc"};');
1655 _assertUnlinkedConst(variable.constExpr, operators: [ 1651 _assertUnlinkedConst(variable.constExpr, operators: [
1656 UnlinkedConstOperation.pushInt, 1652 UnlinkedConstOperation.pushInt,
1657 UnlinkedConstOperation.pushString, 1653 UnlinkedConstOperation.pushString,
1658 UnlinkedConstOperation.pushInt, 1654 UnlinkedConstOperation.pushInt,
1659 UnlinkedConstOperation.pushString, 1655 UnlinkedConstOperation.pushString,
1660 UnlinkedConstOperation.pushInt, 1656 UnlinkedConstOperation.pushInt,
1661 UnlinkedConstOperation.pushString, 1657 UnlinkedConstOperation.pushString,
1662 UnlinkedConstOperation.makeMap 1658 UnlinkedConstOperation.makeMap
1663 ], ints: [ 1659 ], ints: [
1664 11, 1660 11,
1665 22, 1661 22,
1666 33, 1662 33,
1667 3 1663 3
1668 ], strings: [ 1664 ], strings: [
1669 'aaa', 1665 'aaa',
1670 'bbb', 1666 'bbb',
1671 'ccc' 1667 'ccc'
1672 ], referenceValidators: [ 1668 ], referenceValidators: [
1673 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, '', 1669 (TypeRef r) => checkTypeRef(r, null, null, '',
1674 expectedKind: ReferenceKind.classOrEnum), 1670 expectedKind: ReferenceKind.classOrEnum),
1675 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, '', 1671 (TypeRef r) => checkTypeRef(r, null, null, '',
1676 expectedKind: ReferenceKind.classOrEnum) 1672 expectedKind: ReferenceKind.classOrEnum)
1677 ]); 1673 ]);
1678 } 1674 }
1679 1675
1680 test_constExpr_makeSymbol() { 1676 test_constExpr_makeSymbol() {
1681 UnlinkedVariable variable = serializeVariableText('const v = #a.bb.ccc;'); 1677 UnlinkedVariable variable = serializeVariableText('const v = #a.bb.ccc;');
1682 _assertUnlinkedConst(variable.constExpr, operators: [ 1678 _assertUnlinkedConst(variable.constExpr, operators: [
1683 UnlinkedConstOperation.pushString, 1679 UnlinkedConstOperation.pushString,
1684 UnlinkedConstOperation.makeSymbol 1680 UnlinkedConstOperation.makeSymbol
1685 ], strings: [ 1681 ], strings: [
(...skipping 11 matching lines...) Expand all
1697 UnlinkedConstOperation.multiply, 1693 UnlinkedConstOperation.multiply,
1698 ], ints: [ 1694 ], ints: [
1699 1, 1695 1,
1700 2, 1696 2,
1701 3 1697 3
1702 ]); 1698 ]);
1703 } 1699 }
1704 1700
1705 test_constExpr_prefix_complement() { 1701 test_constExpr_prefix_complement() {
1706 UnlinkedVariable variable = serializeVariableText('const v = ~2;'); 1702 UnlinkedVariable variable = serializeVariableText('const v = ~2;');
1707 _assertUnlinkedConst(variable.constExpr, operators: [ 1703 _assertUnlinkedConst(variable.constExpr,
1708 UnlinkedConstOperation.pushInt, 1704 operators:
1709 UnlinkedConstOperation.complement 1705 [UnlinkedConstOperation.pushInt, UnlinkedConstOperation.complement],
1710 ], ints: [ 1706 ints: [2]);
1711 2
1712 ]);
1713 } 1707 }
1714 1708
1715 test_constExpr_prefix_negate() { 1709 test_constExpr_prefix_negate() {
1716 UnlinkedVariable variable = serializeVariableText('const v = -(2);'); 1710 UnlinkedVariable variable = serializeVariableText('const v = -(2);');
1717 _assertUnlinkedConst(variable.constExpr, operators: [ 1711 _assertUnlinkedConst(variable.constExpr,
1718 UnlinkedConstOperation.pushInt, 1712 operators:
1719 UnlinkedConstOperation.negate 1713 [UnlinkedConstOperation.pushInt, UnlinkedConstOperation.negate],
1720 ], ints: [ 1714 ints: [2]);
1721 2
1722 ]);
1723 } 1715 }
1724 1716
1725 test_constExpr_prefix_not() { 1717 test_constExpr_prefix_not() {
1726 UnlinkedVariable variable = serializeVariableText('const v = !true;'); 1718 UnlinkedVariable variable = serializeVariableText('const v = !true;');
1727 _assertUnlinkedConst(variable.constExpr, operators: [ 1719 _assertUnlinkedConst(variable.constExpr, operators:
1728 UnlinkedConstOperation.pushTrue, 1720 [UnlinkedConstOperation.pushTrue, UnlinkedConstOperation.not]);
1729 UnlinkedConstOperation.not
1730 ]);
1731 } 1721 }
1732 1722
1733 test_constExpr_pushDouble() { 1723 test_constExpr_pushDouble() {
1734 UnlinkedVariable variable = serializeVariableText('const v = 123.4567;'); 1724 UnlinkedVariable variable = serializeVariableText('const v = 123.4567;');
1735 _assertUnlinkedConst(variable.constExpr, 1725 _assertUnlinkedConst(variable.constExpr,
1736 operators: [UnlinkedConstOperation.pushDouble], doubles: [123.4567]); 1726 operators: [UnlinkedConstOperation.pushDouble], doubles: [123.4567]);
1737 } 1727 }
1738 1728
1739 test_constExpr_pushFalse() { 1729 test_constExpr_pushFalse() {
1740 UnlinkedVariable variable = serializeVariableText('const v = false;'); 1730 UnlinkedVariable variable = serializeVariableText('const v = false;');
(...skipping 14 matching lines...) Expand all
1755 } 1745 }
1756 1746
1757 test_constExpr_pushReference_class() { 1747 test_constExpr_pushReference_class() {
1758 UnlinkedVariable variable = serializeVariableText(''' 1748 UnlinkedVariable variable = serializeVariableText('''
1759 class C {} 1749 class C {}
1760 const v = C; 1750 const v = C;
1761 '''); 1751 ''');
1762 _assertUnlinkedConst(variable.constExpr, operators: [ 1752 _assertUnlinkedConst(variable.constExpr, operators: [
1763 UnlinkedConstOperation.pushReference 1753 UnlinkedConstOperation.pushReference
1764 ], referenceValidators: [ 1754 ], referenceValidators: [
1765 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C', 1755 (TypeRef r) => checkTypeRef(r, null, null, 'C',
1766 expectedKind: ReferenceKind.classOrEnum) 1756 expectedKind: ReferenceKind.classOrEnum)
1767 ]); 1757 ]);
1768 } 1758 }
1769 1759
1770 test_constExpr_pushReference_class_field() { 1760 test_constExpr_pushReference_class_field() {
1771 // TODO(scheglov) Not sure for to represent a field reference 1761 // TODO(scheglov) Not sure for to represent a field reference
1772 // using UnlinkedTypeRef. 1762 // using TypeRef.
1773 // UnlinkedVariable variable = serializeVariableText(''' 1763 // UnlinkedVariable variable = serializeVariableText('''
1774 //class C { 1764 //class C {
1775 // static const int F = 1; 1765 // static const int F = 1;
1776 //} 1766 //}
1777 //const v = C.F; 1767 //const v = C.F;
1778 //'''); 1768 //''');
1779 // _assertUnlinkedConst(variable.constExpr, operators: [ 1769 // _assertUnlinkedConst(variable.constExpr, operators: [
1780 // UnlinkedConstOperation.pushReference 1770 // UnlinkedConstOperation.pushReference
1781 // ], references: [ 1771 // ], references: [
1782 // (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'F', 1772 // (TypeRef r) => checkTypeRef(r, null, null, 'F',
1783 // expectedKind: ReferenceKind.classOrEnum, expectedPrefix: 'C') 1773 // expectedKind: ReferenceKind.classOrEnum, expectedPrefix: 'C')
1784 // ]); 1774 // ]);
1785 } 1775 }
1786 1776
1787 test_constExpr_pushReference_enum() { 1777 test_constExpr_pushReference_enum() {
1788 UnlinkedVariable variable = serializeVariableText(''' 1778 UnlinkedVariable variable = serializeVariableText('''
1789 enum C {V1, V2, V3} 1779 enum C {V1, V2, V3}
1790 const v = C; 1780 const v = C;
1791 '''); 1781 ''');
1792 _assertUnlinkedConst(variable.constExpr, operators: [ 1782 _assertUnlinkedConst(variable.constExpr, operators: [
1793 UnlinkedConstOperation.pushReference 1783 UnlinkedConstOperation.pushReference
1794 ], referenceValidators: [ 1784 ], referenceValidators: [
1795 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C', 1785 (TypeRef r) => checkTypeRef(r, null, null, 'C',
1796 expectedKind: ReferenceKind.classOrEnum) 1786 expectedKind: ReferenceKind.classOrEnum)
1797 ]); 1787 ]);
1798 } 1788 }
1799 1789
1800 test_constExpr_pushReference_topLevelVariable_imported() { 1790 test_constExpr_pushReference_topLevelVariable_imported() {
1801 addNamedSource('/a.dart', 'const int a = 1;'); 1791 addNamedSource('/a.dart', 'const int a = 1;');
1802 UnlinkedVariable variable = serializeVariableText(''' 1792 UnlinkedVariable variable = serializeVariableText('''
1803 import 'a.dart'; 1793 import 'a.dart';
1804 const v = a; 1794 const v = a;
1805 '''); 1795 ''');
1806 _assertUnlinkedConst(variable.constExpr, operators: [ 1796 _assertUnlinkedConst(variable.constExpr, operators: [
1807 UnlinkedConstOperation.pushReference 1797 UnlinkedConstOperation.pushReference
1808 ], referenceValidators: [ 1798 ], referenceValidators: [
1809 (UnlinkedTypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a', 1799 (TypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a',
1810 expectedKind: ReferenceKind.topLevelPropertyAccessor) 1800 expectedKind: ReferenceKind.topLevelPropertyAccessor)
1811 ]); 1801 ]);
1812 } 1802 }
1813 1803
1814 test_constExpr_pushReference_topLevelVariable_imported_withPrefix() { 1804 test_constExpr_pushReference_topLevelVariable_imported_withPrefix() {
1815 addNamedSource('/a.dart', 'const int a = 1;'); 1805 addNamedSource('/a.dart', 'const int a = 1;');
1816 UnlinkedVariable variable = serializeVariableText(''' 1806 UnlinkedVariable variable = serializeVariableText('''
1817 import 'a.dart' as p; 1807 import 'a.dart' as p;
1818 const v = p.a; 1808 const v = p.a;
1819 '''); 1809 ''');
1820 _assertUnlinkedConst(variable.constExpr, operators: [ 1810 _assertUnlinkedConst(variable.constExpr, operators: [
1821 UnlinkedConstOperation.pushReference 1811 UnlinkedConstOperation.pushReference
1822 ], referenceValidators: [ 1812 ], referenceValidators: [
1823 (UnlinkedTypeRef r) { 1813 (TypeRef r) {
1824 return checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a', 1814 return checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a',
1825 expectedKind: ReferenceKind.topLevelPropertyAccessor, 1815 expectedKind: ReferenceKind.topLevelPropertyAccessor,
1826 expectedPrefix: 'p'); 1816 expectedPrefix: 'p');
1827 } 1817 }
1828 ]); 1818 ]);
1829 } 1819 }
1830 1820
1831 test_constExpr_pushReference_topLevelVariable_local() { 1821 test_constExpr_pushReference_topLevelVariable_local() {
1832 // TODO(scheglov) use `a + b` 1822 // TODO(scheglov) use `a + b`
1833 UnlinkedVariable variable = serializeVariableText(''' 1823 UnlinkedVariable variable = serializeVariableText('''
1834 const int a = 1; 1824 const int a = 1;
1835 const v = a; 1825 const v = a;
1836 '''); 1826 ''');
1837 _assertUnlinkedConst(variable.constExpr, operators: [ 1827 _assertUnlinkedConst(variable.constExpr, operators: [
1838 UnlinkedConstOperation.pushReference 1828 UnlinkedConstOperation.pushReference
1839 ], referenceValidators: [ 1829 ], referenceValidators: [
1840 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'a', 1830 (TypeRef r) => checkTypeRef(r, null, null, 'a',
1841 expectedKind: ReferenceKind.topLevelPropertyAccessor) 1831 expectedKind: ReferenceKind.topLevelPropertyAccessor)
1842 ]); 1832 ]);
1843 } 1833 }
1844 1834
1845 test_constExpr_pushString_adjacent() { 1835 test_constExpr_pushString_adjacent() {
1846 UnlinkedVariable variable = 1836 UnlinkedVariable variable =
1847 serializeVariableText('const v = "aaa" "b" "ccc";'); 1837 serializeVariableText('const v = "aaa" "b" "ccc";');
1848 _assertUnlinkedConst(variable.constExpr, 1838 _assertUnlinkedConst(variable.constExpr,
1849 operators: [UnlinkedConstOperation.pushString], strings: ['aaabccc']); 1839 operators: [UnlinkedConstOperation.pushString], strings: ['aaabccc']);
1850 } 1840 }
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
2558 expect(executable.isConst, false); 2548 expect(executable.isConst, false);
2559 expect(executable.isFactory, false); 2549 expect(executable.isFactory, false);
2560 expect(executable.isStatic, false); 2550 expect(executable.isStatic, false);
2561 expect(executable.parameters, hasLength(1)); 2551 expect(executable.parameters, hasLength(1));
2562 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool'); 2552 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool');
2563 expect(executable.typeParameters, isEmpty); 2553 expect(executable.typeParameters, isEmpty);
2564 } 2554 }
2565 2555
2566 test_executable_operator_index_set() { 2556 test_executable_operator_index_set() {
2567 UnlinkedExecutable executable = serializeClassText( 2557 UnlinkedExecutable executable = serializeClassText(
2568 'class C { void operator[]=(int i, bool v) => null; }') 2558 'class C { void operator[]=(int i, bool v) => null; }').executables[0];
2569 .executables[0];
2570 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 2559 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
2571 expect(executable.name, '[]='); 2560 expect(executable.name, '[]=');
2572 expect(executable.hasImplicitReturnType, false); 2561 expect(executable.hasImplicitReturnType, false);
2573 expect(executable.isAbstract, false); 2562 expect(executable.isAbstract, false);
2574 expect(executable.isConst, false); 2563 expect(executable.isConst, false);
2575 expect(executable.isFactory, false); 2564 expect(executable.isFactory, false);
2576 expect(executable.isStatic, false); 2565 expect(executable.isStatic, false);
2577 expect(executable.parameters, hasLength(2)); 2566 expect(executable.parameters, hasLength(2));
2578 expect(executable.returnType, isNull); 2567 expect(executable.returnType, isNull);
2579 expect(executable.typeParameters, isEmpty); 2568 expect(executable.typeParameters, isEmpty);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
2754 2743
2755 test_executable_static() { 2744 test_executable_static() {
2756 UnlinkedExecutable executable = 2745 UnlinkedExecutable executable =
2757 serializeClassText('class C { static f() {} }').executables[0]; 2746 serializeClassText('class C { static f() {} }').executables[0];
2758 expect(executable.isStatic, isTrue); 2747 expect(executable.isStatic, isTrue);
2759 } 2748 }
2760 2749
2761 test_executable_type_param_f_bound_function() { 2750 test_executable_type_param_f_bound_function() {
2762 UnlinkedExecutable ex = 2751 UnlinkedExecutable ex =
2763 serializeExecutableText('void f<T, U extends List<T>>() {}'); 2752 serializeExecutableText('void f<T, U extends List<T>>() {}');
2764 UnlinkedTypeRef typeArgument = ex.typeParameters[1].bound.typeArguments[0]; 2753 TypeRef typeArgument = ex.typeParameters[1].bound.typeArguments[0];
2765 checkParamTypeRef(typeArgument, 2); 2754 checkParamTypeRef(typeArgument, 2);
2766 } 2755 }
2767 2756
2768 test_executable_type_param_f_bound_method() { 2757 test_executable_type_param_f_bound_method() {
2769 UnlinkedExecutable ex = 2758 UnlinkedExecutable ex =
2770 serializeMethodText('void f<T, U extends List<T>>() {}'); 2759 serializeMethodText('void f<T, U extends List<T>>() {}');
2771 UnlinkedTypeRef typeArgument = ex.typeParameters[1].bound.typeArguments[0]; 2760 TypeRef typeArgument = ex.typeParameters[1].bound.typeArguments[0];
2772 checkParamTypeRef(typeArgument, 2); 2761 checkParamTypeRef(typeArgument, 2);
2773 } 2762 }
2774 2763
2775 test_executable_type_param_f_bound_self_ref_function() { 2764 test_executable_type_param_f_bound_self_ref_function() {
2776 UnlinkedExecutable ex = 2765 UnlinkedExecutable ex =
2777 serializeExecutableText('void f<T, U extends List<U>>() {}'); 2766 serializeExecutableText('void f<T, U extends List<U>>() {}');
2778 UnlinkedTypeRef typeArgument = ex.typeParameters[1].bound.typeArguments[0]; 2767 TypeRef typeArgument = ex.typeParameters[1].bound.typeArguments[0];
2779 checkParamTypeRef(typeArgument, 1); 2768 checkParamTypeRef(typeArgument, 1);
2780 } 2769 }
2781 2770
2782 test_executable_type_param_f_bound_self_ref_method() { 2771 test_executable_type_param_f_bound_self_ref_method() {
2783 UnlinkedExecutable ex = 2772 UnlinkedExecutable ex =
2784 serializeMethodText('void f<T, U extends List<U>>() {}'); 2773 serializeMethodText('void f<T, U extends List<U>>() {}');
2785 UnlinkedTypeRef typeArgument = ex.typeParameters[1].bound.typeArguments[0]; 2774 TypeRef typeArgument = ex.typeParameters[1].bound.typeArguments[0];
2786 checkParamTypeRef(typeArgument, 1); 2775 checkParamTypeRef(typeArgument, 1);
2787 } 2776 }
2788 2777
2789 test_executable_type_param_in_parameter_function() { 2778 test_executable_type_param_in_parameter_function() {
2790 UnlinkedExecutable ex = serializeExecutableText('void f<T>(T t) {}'); 2779 UnlinkedExecutable ex = serializeExecutableText('void f<T>(T t) {}');
2791 checkParamTypeRef(ex.parameters[0].type, 1); 2780 checkParamTypeRef(ex.parameters[0].type, 1);
2792 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 1); 2781 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 1);
2793 } 2782 }
2794 2783
2795 test_executable_type_param_in_parameter_method() { 2784 test_executable_type_param_in_parameter_method() {
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
3336 checkUnresolvedTypeRef( 3325 checkUnresolvedTypeRef(
3337 serializeTypeText('dynamic.T', allowErrors: true), 'dynamic', 'T'); 3326 serializeTypeText('dynamic.T', allowErrors: true), 'dynamic', 'T');
3338 } 3327 }
3339 3328
3340 test_invalid_prefix_type_parameter() { 3329 test_invalid_prefix_type_parameter() {
3341 if (checkAstDerivedData) { 3330 if (checkAstDerivedData) {
3342 // TODO(paulberry): get this to work properly. 3331 // TODO(paulberry): get this to work properly.
3343 return; 3332 return;
3344 } 3333 }
3345 checkUnresolvedTypeRef( 3334 checkUnresolvedTypeRef(
3346 serializeClassText('class C<T> { T.U x; }', allowErrors: true) 3335 serializeClassText('class C<T> { T.U x; }', allowErrors: true).fields[0]
3347 .fields[0]
3348 .type, 3336 .type,
3349 'T', 3337 'T',
3350 'U'); 3338 'U');
3351 } 3339 }
3352 3340
3353 test_invalid_prefix_void() { 3341 test_invalid_prefix_void() {
3354 if (checkAstDerivedData) { 3342 if (checkAstDerivedData) {
3355 // TODO(paulberry): get this to work properly. 3343 // TODO(paulberry): get this to work properly.
3356 return; 3344 return;
3357 } 3345 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
3471 /** 3459 /**
3472 * Docs 3460 * Docs
3473 */ 3461 */
3474 void set f(value) {}'''; 3462 void set f(value) {}''';
3475 UnlinkedExecutable executable = serializeExecutableText(text, 'f='); 3463 UnlinkedExecutable executable = serializeExecutableText(text, 'f=');
3476 expect(executable.documentationComment, isNotNull); 3464 expect(executable.documentationComment, isNotNull);
3477 checkDocumentationComment(executable.documentationComment, text); 3465 checkDocumentationComment(executable.documentationComment, text);
3478 } 3466 }
3479 3467
3480 test_type_arguments_explicit() { 3468 test_type_arguments_explicit() {
3481 UnlinkedTypeRef typeRef = serializeTypeText('List<int>'); 3469 TypeRef typeRef = serializeTypeText('List<int>');
3482 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List', 3470 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List',
3483 allowTypeParameters: true, numTypeParameters: 1); 3471 allowTypeParameters: true, numTypeParameters: 1);
3484 expect(typeRef.typeArguments, hasLength(1)); 3472 expect(typeRef.typeArguments, hasLength(1));
3485 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int'); 3473 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int');
3486 } 3474 }
3487 3475
3488 test_type_arguments_explicit_dynamic() { 3476 test_type_arguments_explicit_dynamic() {
3489 UnlinkedTypeRef typeRef = serializeTypeText('List<dynamic>'); 3477 TypeRef typeRef = serializeTypeText('List<dynamic>');
3490 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List', 3478 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List',
3491 allowTypeParameters: true, numTypeParameters: 1); 3479 allowTypeParameters: true, numTypeParameters: 1);
3492 expect(typeRef.typeArguments, isEmpty); 3480 expect(typeRef.typeArguments, isEmpty);
3493 } 3481 }
3494 3482
3495 test_type_arguments_explicit_dynamic_dynamic() { 3483 test_type_arguments_explicit_dynamic_dynamic() {
3496 UnlinkedTypeRef typeRef = serializeTypeText('Map<dynamic, dynamic>'); 3484 TypeRef typeRef = serializeTypeText('Map<dynamic, dynamic>');
3497 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'Map', 3485 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'Map',
3498 allowTypeParameters: true, numTypeParameters: 2); 3486 allowTypeParameters: true, numTypeParameters: 2);
3499 // Trailing type arguments of type `dynamic` are omitted. 3487 // Trailing type arguments of type `dynamic` are omitted.
3500 expect(typeRef.typeArguments, isEmpty); 3488 expect(typeRef.typeArguments, isEmpty);
3501 } 3489 }
3502 3490
3503 test_type_arguments_explicit_dynamic_int() { 3491 test_type_arguments_explicit_dynamic_int() {
3504 UnlinkedTypeRef typeRef = serializeTypeText('Map<dynamic, int>'); 3492 TypeRef typeRef = serializeTypeText('Map<dynamic, int>');
3505 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'Map', 3493 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'Map',
3506 allowTypeParameters: true, numTypeParameters: 2); 3494 allowTypeParameters: true, numTypeParameters: 2);
3507 // Leading type arguments of type `dynamic` are not omitted. 3495 // Leading type arguments of type `dynamic` are not omitted.
3508 expect(typeRef.typeArguments.length, 2); 3496 expect(typeRef.typeArguments.length, 2);
3509 checkDynamicTypeRef(typeRef.typeArguments[0]); 3497 checkDynamicTypeRef(typeRef.typeArguments[0]);
3510 checkTypeRef(typeRef.typeArguments[1], 'dart:core', 'dart:core', 'int'); 3498 checkTypeRef(typeRef.typeArguments[1], 'dart:core', 'dart:core', 'int');
3511 } 3499 }
3512 3500
3513 test_type_arguments_explicit_dynamic_typedef() { 3501 test_type_arguments_explicit_dynamic_typedef() {
3514 UnlinkedTypeRef typeRef = 3502 TypeRef typeRef =
3515 serializeTypeText('F<dynamic>', otherDeclarations: 'typedef T F<T>();'); 3503 serializeTypeText('F<dynamic>', otherDeclarations: 'typedef T F<T>();');
3516 checkTypeRef(typeRef, null, null, 'F', 3504 checkTypeRef(typeRef, null, null, 'F',
3517 allowTypeParameters: true, 3505 allowTypeParameters: true,
3518 expectedKind: ReferenceKind.typedef, 3506 expectedKind: ReferenceKind.typedef,
3519 numTypeParameters: 1); 3507 numTypeParameters: 1);
3520 expect(typeRef.typeArguments, isEmpty); 3508 expect(typeRef.typeArguments, isEmpty);
3521 } 3509 }
3522 3510
3523 test_type_arguments_explicit_String_dynamic() { 3511 test_type_arguments_explicit_String_dynamic() {
3524 UnlinkedTypeRef typeRef = serializeTypeText('Map<String, dynamic>'); 3512 TypeRef typeRef = serializeTypeText('Map<String, dynamic>');
3525 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'Map', 3513 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'Map',
3526 allowTypeParameters: true, numTypeParameters: 2); 3514 allowTypeParameters: true, numTypeParameters: 2);
3527 // Trailing type arguments of type `dynamic` are omitted. 3515 // Trailing type arguments of type `dynamic` are omitted.
3528 expect(typeRef.typeArguments.length, 1); 3516 expect(typeRef.typeArguments.length, 1);
3529 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'String'); 3517 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'String');
3530 } 3518 }
3531 3519
3532 test_type_arguments_explicit_String_int() { 3520 test_type_arguments_explicit_String_int() {
3533 UnlinkedTypeRef typeRef = serializeTypeText('Map<String, int>'); 3521 TypeRef typeRef = serializeTypeText('Map<String, int>');
3534 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'Map', 3522 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'Map',
3535 allowTypeParameters: true, numTypeParameters: 2); 3523 allowTypeParameters: true, numTypeParameters: 2);
3536 expect(typeRef.typeArguments.length, 2); 3524 expect(typeRef.typeArguments.length, 2);
3537 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'String'); 3525 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'String');
3538 checkTypeRef(typeRef.typeArguments[1], 'dart:core', 'dart:core', 'int'); 3526 checkTypeRef(typeRef.typeArguments[1], 'dart:core', 'dart:core', 'int');
3539 } 3527 }
3540 3528
3541 test_type_arguments_explicit_typedef() { 3529 test_type_arguments_explicit_typedef() {
3542 UnlinkedTypeRef typeRef = 3530 TypeRef typeRef =
3543 serializeTypeText('F<int>', otherDeclarations: 'typedef T F<T>();'); 3531 serializeTypeText('F<int>', otherDeclarations: 'typedef T F<T>();');
3544 checkTypeRef(typeRef, null, null, 'F', 3532 checkTypeRef(typeRef, null, null, 'F',
3545 allowTypeParameters: true, 3533 allowTypeParameters: true,
3546 expectedKind: ReferenceKind.typedef, 3534 expectedKind: ReferenceKind.typedef,
3547 numTypeParameters: 1); 3535 numTypeParameters: 1);
3548 expect(typeRef.typeArguments, hasLength(1)); 3536 expect(typeRef.typeArguments, hasLength(1));
3549 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int'); 3537 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int');
3550 } 3538 }
3551 3539
3552 test_type_arguments_implicit() { 3540 test_type_arguments_implicit() {
3553 UnlinkedTypeRef typeRef = serializeTypeText('List'); 3541 TypeRef typeRef = serializeTypeText('List');
3554 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List', 3542 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List',
3555 allowTypeParameters: true, numTypeParameters: 1); 3543 allowTypeParameters: true, numTypeParameters: 1);
3556 expect(typeRef.typeArguments, isEmpty); 3544 expect(typeRef.typeArguments, isEmpty);
3557 } 3545 }
3558 3546
3559 test_type_arguments_implicit_typedef() { 3547 test_type_arguments_implicit_typedef() {
3560 UnlinkedTypeRef typeRef = 3548 TypeRef typeRef =
3561 serializeTypeText('F', otherDeclarations: 'typedef T F<T>();'); 3549 serializeTypeText('F', otherDeclarations: 'typedef T F<T>();');
3562 checkTypeRef(typeRef, null, null, 'F', 3550 checkTypeRef(typeRef, null, null, 'F',
3563 allowTypeParameters: true, 3551 allowTypeParameters: true,
3564 expectedKind: ReferenceKind.typedef, 3552 expectedKind: ReferenceKind.typedef,
3565 numTypeParameters: 1); 3553 numTypeParameters: 1);
3566 expect(typeRef.typeArguments, isEmpty); 3554 expect(typeRef.typeArguments, isEmpty);
3567 } 3555 }
3568 3556
3569 test_type_arguments_order() { 3557 test_type_arguments_order() {
3570 UnlinkedTypeRef typeRef = serializeTypeText('Map<int, Object>'); 3558 TypeRef typeRef = serializeTypeText('Map<int, Object>');
3571 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'Map', 3559 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'Map',
3572 allowTypeParameters: true, numTypeParameters: 2); 3560 allowTypeParameters: true, numTypeParameters: 2);
3573 expect(typeRef.typeArguments, hasLength(2)); 3561 expect(typeRef.typeArguments, hasLength(2));
3574 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int'); 3562 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int');
3575 checkTypeRef(typeRef.typeArguments[1], 'dart:core', 'dart:core', 'Object'); 3563 checkTypeRef(typeRef.typeArguments[1], 'dart:core', 'dart:core', 'Object');
3576 } 3564 }
3577 3565
3578 test_type_dynamic() { 3566 test_type_dynamic() {
3579 checkDynamicTypeRef(serializeTypeText('dynamic')); 3567 checkDynamicTypeRef(serializeTypeText('dynamic'));
3580 } 3568 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
3671 checkTypeRef(findVariable('v', variables: unlinkedUnits[1].variables).type, 3659 checkTypeRef(findVariable('v', variables: unlinkedUnits[1].variables).type,
3672 absUri('/a.dart'), 'a.dart', 'C', 3660 absUri('/a.dart'), 'a.dart', 'C',
3673 expectedPrefix: 'a', 3661 expectedPrefix: 'a',
3674 linkedSourceUnit: linked.units[1], 3662 linkedSourceUnit: linked.units[1],
3675 unlinkedSourceUnit: unlinkedUnits[1]); 3663 unlinkedSourceUnit: unlinkedUnits[1]);
3676 } 3664 }
3677 3665
3678 test_type_reference_to_class_argument() { 3666 test_type_reference_to_class_argument() {
3679 UnlinkedClass cls = serializeClassText('class C<T, U> { T t; U u; }'); 3667 UnlinkedClass cls = serializeClassText('class C<T, U> { T t; U u; }');
3680 { 3668 {
3681 UnlinkedTypeRef typeRef = 3669 TypeRef typeRef =
3682 findVariable('t', variables: cls.fields, failIfAbsent: true).type; 3670 findVariable('t', variables: cls.fields, failIfAbsent: true).type;
3683 checkParamTypeRef(typeRef, 2); 3671 checkParamTypeRef(typeRef, 2);
3684 } 3672 }
3685 { 3673 {
3686 UnlinkedTypeRef typeRef = 3674 TypeRef typeRef =
3687 findVariable('u', variables: cls.fields, failIfAbsent: true).type; 3675 findVariable('u', variables: cls.fields, failIfAbsent: true).type;
3688 checkParamTypeRef(typeRef, 1); 3676 checkParamTypeRef(typeRef, 1);
3689 } 3677 }
3690 } 3678 }
3691 3679
3692 test_type_reference_to_import_of_export() { 3680 test_type_reference_to_import_of_export() {
3693 addNamedSource('/a.dart', 'library a; export "b.dart";'); 3681 addNamedSource('/a.dart', 'library a; export "b.dart";');
3694 addNamedSource('/b.dart', 'library b; class C {}'); 3682 addNamedSource('/b.dart', 'library b; class C {}');
3695 checkTypeRef(serializeTypeText('C', otherDeclarations: 'import "a.dart";'), 3683 checkTypeRef(serializeTypeText('C', otherDeclarations: 'import "a.dart";'),
3696 absUri('/b.dart'), 'b.dart', 'C'); 3684 absUri('/b.dart'), 'b.dart', 'C');
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
3763 } 3751 }
3764 3752
3765 test_type_reference_to_nonexistent_file_via_prefix() { 3753 test_type_reference_to_nonexistent_file_via_prefix() {
3766 if (!checkAstDerivedData) { 3754 if (!checkAstDerivedData) {
3767 // TODO(paulberry): this test currently fails because there is not enough 3755 // TODO(paulberry): this test currently fails because there is not enough
3768 // information in the element model to figure out that the unresolved 3756 // information in the element model to figure out that the unresolved
3769 // reference `p.C` uses the prefix `p`. 3757 // reference `p.C` uses the prefix `p`.
3770 return; 3758 return;
3771 } 3759 }
3772 allowMissingFiles = true; 3760 allowMissingFiles = true;
3773 UnlinkedTypeRef typeRef = serializeTypeText('p.C', 3761 TypeRef typeRef = serializeTypeText('p.C',
3774 otherDeclarations: 'import "foo.dart" as p;', allowErrors: true); 3762 otherDeclarations: 'import "foo.dart" as p;', allowErrors: true);
3775 checkUnresolvedTypeRef(typeRef, 'p', 'C'); 3763 checkUnresolvedTypeRef(typeRef, 'p', 'C');
3776 } 3764 }
3777 3765
3778 test_type_reference_to_part() { 3766 test_type_reference_to_part() {
3779 addNamedSource('/a.dart', 'part of foo; class C { C(); }'); 3767 addNamedSource('/a.dart', 'part of foo; class C { C(); }');
3780 serializeLibraryText('library foo; part "a.dart"; C c;'); 3768 serializeLibraryText('library foo; part "a.dart"; C c;');
3781 checkTypeRef(unlinkedUnits[0].variables.single.type, null, null, 'C', 3769 checkTypeRef(unlinkedUnits[0].variables.single.type, null, null, 'C',
3782 expectedKind: ReferenceKind.classOrEnum, expectedTargetUnit: 1); 3770 expectedKind: ReferenceKind.classOrEnum, expectedTargetUnit: 1);
3783 } 3771 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3816 test_type_reference_to_typedef() { 3804 test_type_reference_to_typedef() {
3817 checkTypeRef(serializeTypeText('F', otherDeclarations: 'typedef void F();'), 3805 checkTypeRef(serializeTypeText('F', otherDeclarations: 'typedef void F();'),
3818 null, null, 'F', 3806 null, null, 'F',
3819 expectedKind: ReferenceKind.typedef); 3807 expectedKind: ReferenceKind.typedef);
3820 } 3808 }
3821 3809
3822 test_type_unit_counts_unreferenced_units() { 3810 test_type_unit_counts_unreferenced_units() {
3823 addNamedSource('/a.dart', 'library a; part "b.dart"; part "c.dart";'); 3811 addNamedSource('/a.dart', 'library a; part "b.dart"; part "c.dart";');
3824 addNamedSource('/b.dart', 'part of a;'); 3812 addNamedSource('/b.dart', 'part of a;');
3825 addNamedSource('/c.dart', 'part of a; class C {}'); 3813 addNamedSource('/c.dart', 'part of a; class C {}');
3826 UnlinkedTypeRef typeRef = 3814 TypeRef typeRef =
3827 serializeTypeText('C', otherDeclarations: 'import "a.dart";'); 3815 serializeTypeText('C', otherDeclarations: 'import "a.dart";');
3828 // The referenced unit should be 2, since unit 0 is a.dart and unit 1 is 3816 // The referenced unit should be 2, since unit 0 is a.dart and unit 1 is
3829 // b.dart. a.dart and b.dart are counted even though nothing is imported 3817 // b.dart. a.dart and b.dart are counted even though nothing is imported
3830 // from them. 3818 // from them.
3831 checkTypeRef(typeRef, absUri('/a.dart'), 'a.dart', 'C', 3819 checkTypeRef(typeRef, absUri('/a.dart'), 'a.dart', 'C',
3832 expectedTargetUnit: 2); 3820 expectedTargetUnit: 2);
3833 } 3821 }
3834 3822
3835 test_type_unresolved() { 3823 test_type_unresolved() {
3836 UnlinkedTypeRef typeRef = serializeTypeText('Foo', allowErrors: true); 3824 TypeRef typeRef = serializeTypeText('Foo', allowErrors: true);
3837 checkUnresolvedTypeRef(typeRef, null, 'Foo'); 3825 checkUnresolvedTypeRef(typeRef, null, 'Foo');
3838 } 3826 }
3839 3827
3840 test_typedef_documented() { 3828 test_typedef_documented() {
3841 String text = ''' 3829 String text = '''
3842 // Extra comment so doc comment offset != 0 3830 // Extra comment so doc comment offset != 0
3843 /** 3831 /**
3844 * Docs 3832 * Docs
3845 */ 3833 */
3846 typedef F();'''; 3834 typedef F();''';
(...skipping 25 matching lines...) Expand all
3872 expect(type.parameters[0].name, 'x'); 3860 expect(type.parameters[0].name, 'x');
3873 expect(type.parameters[1].name, 'y'); 3861 expect(type.parameters[1].name, 'y');
3874 } 3862 }
3875 3863
3876 test_typedef_private() { 3864 test_typedef_private() {
3877 serializeTypedefText('typedef _F();', '_F'); 3865 serializeTypedefText('typedef _F();', '_F');
3878 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); 3866 expect(unlinkedUnits[0].publicNamespace.names, isEmpty);
3879 } 3867 }
3880 3868
3881 test_typedef_reference_generic() { 3869 test_typedef_reference_generic() {
3882 UnlinkedTypeRef typeRef = 3870 TypeRef typeRef =
3883 serializeTypeText('F', otherDeclarations: 'typedef void F<A, B>();'); 3871 serializeTypeText('F', otherDeclarations: 'typedef void F<A, B>();');
3884 checkTypeRef(typeRef, null, null, 'F', 3872 checkTypeRef(typeRef, null, null, 'F',
3885 numTypeParameters: 2, expectedKind: ReferenceKind.typedef); 3873 numTypeParameters: 2, expectedKind: ReferenceKind.typedef);
3886 } 3874 }
3887 3875
3888 test_typedef_reference_generic_imported() { 3876 test_typedef_reference_generic_imported() {
3889 addNamedSource('/lib.dart', 'typedef void F<A, B>();'); 3877 addNamedSource('/lib.dart', 'typedef void F<A, B>();');
3890 UnlinkedTypeRef typeRef = 3878 TypeRef typeRef =
3891 serializeTypeText('F', otherDeclarations: 'import "lib.dart";'); 3879 serializeTypeText('F', otherDeclarations: 'import "lib.dart";');
3892 checkTypeRef(typeRef, absUri('/lib.dart'), 'lib.dart', 'F', 3880 checkTypeRef(typeRef, absUri('/lib.dart'), 'lib.dart', 'F',
3893 numTypeParameters: 2, expectedKind: ReferenceKind.typedef); 3881 numTypeParameters: 2, expectedKind: ReferenceKind.typedef);
3894 } 3882 }
3895 3883
3896 test_typedef_return_type_explicit() { 3884 test_typedef_return_type_explicit() {
3897 UnlinkedTypedef type = serializeTypedefText('typedef int F();'); 3885 UnlinkedTypedef type = serializeTypedefText('typedef int F();');
3898 checkTypeRef(type.returnType, 'dart:core', 'dart:core', 'int'); 3886 checkTypeRef(type.returnType, 'dart:core', 'dart:core', 'int');
3899 } 3887 }
3900 3888
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
4028 UnlinkedVariable variable = 4016 UnlinkedVariable variable =
4029 serializeVariableText('int i;', variableName: 'i'); 4017 serializeVariableText('int i;', variableName: 'i');
4030 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); 4018 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int');
4031 } 4019 }
4032 4020
4033 void _assertUnlinkedConst(UnlinkedConst constExpr, 4021 void _assertUnlinkedConst(UnlinkedConst constExpr,
4034 {List<UnlinkedConstOperation> operators, 4022 {List<UnlinkedConstOperation> operators,
4035 List<int> ints: const <int>[], 4023 List<int> ints: const <int>[],
4036 List<double> doubles: const <double>[], 4024 List<double> doubles: const <double>[],
4037 List<String> strings: const <String>[], 4025 List<String> strings: const <String>[],
4038 List<_UnlinkedTypeRefValidator> referenceValidators: 4026 List<_TypeRefValidator> referenceValidators:
4039 const <_UnlinkedTypeRefValidator>[]}) { 4027 const <_TypeRefValidator>[]}) {
4040 expect(constExpr, isNotNull); 4028 expect(constExpr, isNotNull);
4041 expect(constExpr.operations, operators); 4029 expect(constExpr.operations, operators);
4042 expect(constExpr.ints, ints); 4030 expect(constExpr.ints, ints);
4043 expect(constExpr.doubles, doubles); 4031 expect(constExpr.doubles, doubles);
4044 expect(constExpr.strings, strings); 4032 expect(constExpr.strings, strings);
4045 expect(constExpr.references, hasLength(referenceValidators.length)); 4033 expect(constExpr.references, hasLength(referenceValidators.length));
4046 for (int i = 0; i < referenceValidators.length; i++) { 4034 for (int i = 0; i < referenceValidators.length; i++) {
4047 referenceValidators[i](constExpr.references[i]); 4035 referenceValidators[i](constExpr.references[i]);
4048 } 4036 }
4049 } 4037 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
4129 CompilationUnit _parseText(String text) { 4117 CompilationUnit _parseText(String text) {
4130 CharSequenceReader reader = new CharSequenceReader(text); 4118 CharSequenceReader reader = new CharSequenceReader(text);
4131 Scanner scanner = 4119 Scanner scanner =
4132 new Scanner(null, reader, AnalysisErrorListener.NULL_LISTENER); 4120 new Scanner(null, reader, AnalysisErrorListener.NULL_LISTENER);
4133 Token token = scanner.tokenize(); 4121 Token token = scanner.tokenize();
4134 Parser parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER); 4122 Parser parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER);
4135 parser.parseGenericMethods = true; 4123 parser.parseGenericMethods = true;
4136 return parser.parseCompilationUnit(token); 4124 return parser.parseCompilationUnit(token);
4137 } 4125 }
4138 } 4126 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_elements.dart ('k') | pkg/analyzer/tool/summary/idl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698