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

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

Issue 1530503002: Organize summary declarations by unit rather than by library. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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/src/generated/element.dart'; 7 import 'package:analyzer/src/generated/element.dart';
8 import 'package:analyzer/src/generated/engine.dart'; 8 import 'package:analyzer/src/generated/engine.dart';
9 import 'package:analyzer/src/generated/java_engine_io.dart'; 9 import 'package:analyzer/src/generated/java_engine_io.dart';
10 import 'package:analyzer/src/generated/source.dart'; 10 import 'package:analyzer/src/generated/source.dart';
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 53
54 @override 54 @override
55 void serializeLibraryText(String text, {bool allowErrors: false}) { 55 void serializeLibraryText(String text, {bool allowErrors: false}) {
56 Source source = addSource(text); 56 Source source = addSource(text);
57 LibraryElement library = resolve2(source); 57 LibraryElement library = resolve2(source);
58 if (!allowErrors) { 58 if (!allowErrors) {
59 assertNoErrors(source); 59 assertNoErrors(source);
60 } 60 }
61 serializeLibraryElement(library); 61 serializeLibraryElement(library);
62 expect(unlinked.imports.length, lib.importDependencies.length); 62 expect(definingUnit.unlinked.imports.length, lib.importDependencies.length);
63 expect(unlinked.references.length, lib.references.length); 63 expect(unlinked.references.length, lib.references.length);
64 } 64 }
65 65
66 @override 66 @override
67 void setUp() { 67 void setUp() {
68 super.setUp(); 68 super.setUp();
69 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 69 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
70 options.enableGenericMethods = true; 70 options.enableGenericMethods = true;
71 resetWithOptions(options); 71 resetWithOptions(options);
72 } 72 }
(...skipping 18 matching lines...) Expand all
91 91
92 /** 92 /**
93 * `true` if the summary was created directly from the AST (and hence 93 * `true` if the summary was created directly from the AST (and hence
94 * contains information that is not obtainable from the element model alone). 94 * contains information that is not obtainable from the element model alone).
95 * TODO(paulberry): modify the element model so that it contains all the data 95 * TODO(paulberry): modify the element model so that it contains all the data
96 * that summaries need, so that this flag is no longer needed. 96 * that summaries need, so that this flag is no longer needed.
97 */ 97 */
98 bool get checkAstDerivedData; 98 bool get checkAstDerivedData;
99 99
100 /** 100 /**
101 * Get access to the prelinked defining compilation unit.
102 */
103 PrelinkedUnit get definingUnit => lib.units[0];
104
105 /**
101 * Get access to the "unlinked" section of the summary. 106 * Get access to the "unlinked" section of the summary.
102 */ 107 */
103 UnlinkedLibrary get unlinked => lib.unlinked; 108 UnlinkedLibrary get unlinked => lib.unlinked;
104 109
105 /** 110 /**
106 * Convert [path] to a suitably formatted absolute path URI for the current 111 * Convert [path] to a suitably formatted absolute path URI for the current
107 * platform. 112 * platform.
108 */ 113 */
109 String absUri(String path) { 114 String absUri(String path) {
110 return FileUtilities2.createFile(path).toURI().toString(); 115 return FileUtilities2.createFile(path).toURI().toString();
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 expectedKind: PrelinkedReferenceKind.unresolved); 259 expectedKind: PrelinkedReferenceKind.unresolved);
255 } 260 }
256 261
257 fail_test_import_missing() { 262 fail_test_import_missing() {
258 // TODO(paulberry): At the moment unresolved imports are not included in 263 // TODO(paulberry): At the moment unresolved imports are not included in
259 // the element model, so we can't pass this test. 264 // the element model, so we can't pass this test.
260 // Unresolved imports are included since this is necessary for proper 265 // Unresolved imports are included since this is necessary for proper
261 // dependency tracking. 266 // dependency tracking.
262 serializeLibraryText('import "foo.dart";', allowErrors: true); 267 serializeLibraryText('import "foo.dart";', allowErrors: true);
263 // Second import is the implicit import of dart:core 268 // Second import is the implicit import of dart:core
264 expect(unlinked.imports, hasLength(2)); 269 expect(definingUnit.unlinked.imports, hasLength(2));
265 checkDependency(lib.importDependencies[0], absUri('/foo.dart'), 'foo.dart'); 270 checkDependency(lib.importDependencies[0], absUri('/foo.dart'), 'foo.dart');
266 } 271 }
267 272
268 /** 273 /**
269 * Find the class with the given [className] in the summary, and return its 274 * Find the class with the given [className] in the summary, and return its
270 * [UnlinkedClass] data structure. 275 * [UnlinkedClass] data structure. If [unit] is not given, the class is
276 * looked for in the defining compilation unit.
271 */ 277 */
272 UnlinkedClass findClass(String className, {bool failIfAbsent: false}) { 278 UnlinkedClass findClass(String className,
279 {bool failIfAbsent: false, PrelinkedUnit unit}) {
280 unit ??= definingUnit;
273 UnlinkedClass result; 281 UnlinkedClass result;
274 for (UnlinkedClass cls in unlinked.classes) { 282 for (UnlinkedClass cls in unit.unlinked.classes) {
275 if (cls.name == className) { 283 if (cls.name == className) {
276 if (result != null) { 284 if (result != null) {
277 fail('Duplicate class $className'); 285 fail('Duplicate class $className');
278 } 286 }
279 result = cls; 287 result = cls;
280 } 288 }
281 } 289 }
282 if (result == null && failIfAbsent) { 290 if (result == null && failIfAbsent) {
283 fail('Class $className not found in serialized output'); 291 fail('Class $className not found in serialized output');
284 } 292 }
285 return result; 293 return result;
286 } 294 }
287 295
288 /** 296 /**
289 * Find the enum with the given [enumName] in the summary, and return its 297 * Find the enum with the given [enumName] in the summary, and return its
290 * [UnlinkedEnum] data structure. 298 * [UnlinkedEnum] data structure. If [unit] is not given, the enum is looked
299 * for in the defining compilation unit.
291 */ 300 */
292 UnlinkedEnum findEnum(String enumName, {bool failIfAbsent: false}) { 301 UnlinkedEnum findEnum(String enumName,
302 {bool failIfAbsent: false, PrelinkedUnit unit}) {
303 unit ??= definingUnit;
293 UnlinkedEnum result; 304 UnlinkedEnum result;
294 for (UnlinkedEnum e in unlinked.enums) { 305 for (UnlinkedEnum e in unit.unlinked.enums) {
295 if (e.name == enumName) { 306 if (e.name == enumName) {
296 if (result != null) { 307 if (result != null) {
297 fail('Duplicate enum $enumName'); 308 fail('Duplicate enum $enumName');
298 } 309 }
299 result = e; 310 result = e;
300 } 311 }
301 } 312 }
302 if (result == null && failIfAbsent) { 313 if (result == null && failIfAbsent) {
303 fail('Enum $enumName not found in serialized output'); 314 fail('Enum $enumName not found in serialized output');
304 } 315 }
305 return result; 316 return result;
306 } 317 }
307 318
308 /** 319 /**
309 * Find the executable with the given [executableName] in the summary, and 320 * Find the executable with the given [executableName] in the summary, and
310 * return its [UnlinkedExecutable] data structure. 321 * return its [UnlinkedExecutable] data structure. If [executables] is not
322 * given, then the executable is searched for in the defining compilation
323 * unit.
311 */ 324 */
312 UnlinkedExecutable findExecutable(String executableName, 325 UnlinkedExecutable findExecutable(String executableName,
313 {UnlinkedClass cls, bool failIfAbsent: false}) { 326 {List<UnlinkedExecutable> executables, bool failIfAbsent: false}) {
314 List<UnlinkedExecutable> executables; 327 executables ??= definingUnit.unlinked.executables;
315 if (cls == null) {
316 executables = unlinked.executables;
317 } else {
318 executables = cls.executables;
319 }
320 UnlinkedExecutable result; 328 UnlinkedExecutable result;
321 for (UnlinkedExecutable executable in executables) { 329 for (UnlinkedExecutable executable in executables) {
322 if (executable.name == executableName) { 330 if (executable.name == executableName) {
323 if (result != null) { 331 if (result != null) {
324 fail('Duplicate executable $executableName'); 332 fail('Duplicate executable $executableName');
325 } 333 }
326 result = executable; 334 result = executable;
327 } 335 }
328 } 336 }
329 if (result == null && failIfAbsent) { 337 if (result == null && failIfAbsent) {
330 fail('Executable $executableName not found in serialized output'); 338 fail('Executable $executableName not found in serialized output');
331 } 339 }
332 return result; 340 return result;
333 } 341 }
334 342
335 /** 343 /**
336 * Find the typedef with the given [typedefName] in the summary, and return 344 * Find the typedef with the given [typedefName] in the summary, and return
337 * its [UnlinkedTypedef] data structure. 345 * its [UnlinkedTypedef] data structure. If [unit] is not given, the typedef
346 * is looked for in the defining compilation unit.
338 */ 347 */
339 UnlinkedTypedef findTypedef(String typedefName, {bool failIfAbsent: false}) { 348 UnlinkedTypedef findTypedef(String typedefName,
349 {bool failIfAbsent: false, PrelinkedUnit unit}) {
350 unit ??= definingUnit;
340 UnlinkedTypedef result; 351 UnlinkedTypedef result;
341 for (UnlinkedTypedef type in unlinked.typedefs) { 352 for (UnlinkedTypedef type in unit.unlinked.typedefs) {
342 if (type.name == typedefName) { 353 if (type.name == typedefName) {
343 if (result != null) { 354 if (result != null) {
344 fail('Duplicate typedef $typedefName'); 355 fail('Duplicate typedef $typedefName');
345 } 356 }
346 result = type; 357 result = type;
347 } 358 }
348 } 359 }
349 if (result == null && failIfAbsent) { 360 if (result == null && failIfAbsent) {
350 fail('Typedef $typedefName not found in serialized output'); 361 fail('Typedef $typedefName not found in serialized output');
351 } 362 }
352 return result; 363 return result;
353 } 364 }
354 365
355 /** 366 /**
356 * Find the top level variable with the given [variableName] in the summary, 367 * Find the top level variable with the given [variableName] in the summary,
357 * and return its [UnlinkedVariable] data structure. 368 * and return its [UnlinkedVariable] data structure. If [variables] is not
369 * specified, the variable is looked for in the defining compilation unit.
358 */ 370 */
359 UnlinkedVariable findVariable(String variableName, 371 UnlinkedVariable findVariable(String variableName,
360 {UnlinkedClass cls, bool failIfAbsent: false}) { 372 {List<UnlinkedVariable> variables, bool failIfAbsent: false}) {
361 List<UnlinkedVariable> variables; 373 variables ??= definingUnit.unlinked.variables;
362 if (cls == null) {
363 variables = unlinked.variables;
364 } else {
365 variables = cls.fields;
366 }
367 UnlinkedVariable result; 374 UnlinkedVariable result;
368 for (UnlinkedVariable variable in variables) { 375 for (UnlinkedVariable variable in variables) {
369 if (variable.name == variableName) { 376 if (variable.name == variableName) {
370 if (result != null) { 377 if (result != null) {
371 fail('Duplicate variable $variableName'); 378 fail('Duplicate variable $variableName');
372 } 379 }
373 result = variable; 380 result = variable;
374 } 381 }
375 } 382 }
376 if (result == null && failIfAbsent) { 383 if (result == null && failIfAbsent) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 void serializeLibraryText(String text, {bool allowErrors: false}); 421 void serializeLibraryText(String text, {bool allowErrors: false});
415 422
416 /** 423 /**
417 * Serialize the given method [text] and return the summary of the executable 424 * Serialize the given method [text] and return the summary of the executable
418 * with the given [executableName]. 425 * with the given [executableName].
419 */ 426 */
420 UnlinkedExecutable serializeMethodText(String text, 427 UnlinkedExecutable serializeMethodText(String text,
421 [String executableName = 'f']) { 428 [String executableName = 'f']) {
422 serializeLibraryText('class C { $text }'); 429 serializeLibraryText('class C { $text }');
423 return findExecutable(executableName, 430 return findExecutable(executableName,
424 cls: findClass('C', failIfAbsent: true), failIfAbsent: true); 431 executables: findClass('C', failIfAbsent: true).executables,
432 failIfAbsent: true);
425 } 433 }
426 434
427 /** 435 /**
428 * Serialize the given library [text] and return the summary of the typedef 436 * Serialize the given library [text] and return the summary of the typedef
429 * with the given [typedefName]. 437 * with the given [typedefName].
430 */ 438 */
431 UnlinkedTypedef serializeTypedefText(String text, 439 UnlinkedTypedef serializeTypedefText(String text,
432 [String typedefName = 'F']) { 440 [String typedefName = 'F']) {
433 serializeLibraryText(text); 441 serializeLibraryText(text);
434 return findTypedef(typedefName, failIfAbsent: true); 442 return findTypedef(typedefName, failIfAbsent: true);
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 '''); 687 ''');
680 expect(cls.mixins, hasLength(2)); 688 expect(cls.mixins, hasLength(2));
681 checkTypeRef(cls.mixins[0], null, null, 'D'); 689 checkTypeRef(cls.mixins[0], null, null, 'D');
682 checkTypeRef(cls.mixins[1], null, null, 'E'); 690 checkTypeRef(cls.mixins[1], null, null, 'E');
683 } 691 }
684 692
685 test_class_name() { 693 test_class_name() {
686 var classText = 'class C {}'; 694 var classText = 'class C {}';
687 UnlinkedClass cls = serializeClassText(classText); 695 UnlinkedClass cls = serializeClassText(classText);
688 expect(cls.name, 'C'); 696 expect(cls.name, 'C');
689 expect(cls.unit, 0);
690 } 697 }
691 698
692 test_class_no_flags() { 699 test_class_no_flags() {
693 UnlinkedClass cls = serializeClassText('class C {}'); 700 UnlinkedClass cls = serializeClassText('class C {}');
694 expect(cls.isAbstract, false); 701 expect(cls.isAbstract, false);
695 expect(cls.isMixinApplication, false); 702 expect(cls.isMixinApplication, false);
696 } 703 }
697 704
698 test_class_no_interface() { 705 test_class_no_interface() {
699 UnlinkedClass cls = serializeClassText('class C {}'); 706 UnlinkedClass cls = serializeClassText('class C {}');
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 } 755 }
749 756
750 test_class_type_param_no_bound() { 757 test_class_type_param_no_bound() {
751 UnlinkedClass cls = serializeClassText('class C<T> {}'); 758 UnlinkedClass cls = serializeClassText('class C<T> {}');
752 expect(cls.typeParameters, hasLength(1)); 759 expect(cls.typeParameters, hasLength(1));
753 expect(cls.typeParameters[0].name, 'T'); 760 expect(cls.typeParameters[0].name, 'T');
754 expect(cls.typeParameters[0].bound, isNull); 761 expect(cls.typeParameters[0].bound, isNull);
755 } 762 }
756 763
757 test_constructor() { 764 test_constructor() {
758 UnlinkedExecutable executable = 765 UnlinkedExecutable executable = findExecutable('',
759 findExecutable('', cls: serializeClassText('class C { C(); }')); 766 executables: serializeClassText('class C { C(); }').executables);
760 expect(executable.kind, UnlinkedExecutableKind.constructor); 767 expect(executable.kind, UnlinkedExecutableKind.constructor);
761 expect(executable.hasImplicitReturnType, isFalse); 768 expect(executable.hasImplicitReturnType, isFalse);
762 } 769 }
763 770
764 test_constructor_anonymous() { 771 test_constructor_anonymous() {
765 UnlinkedExecutable executable = 772 UnlinkedExecutable executable = findExecutable('',
766 findExecutable('', cls: serializeClassText('class C { C(); }')); 773 executables: serializeClassText('class C { C(); }').executables);
767 expect(executable.name, isEmpty); 774 expect(executable.name, isEmpty);
768 } 775 }
769 776
770 test_constructor_const() { 777 test_constructor_const() {
771 UnlinkedExecutable executable = 778 UnlinkedExecutable executable = findExecutable('',
772 findExecutable('', cls: serializeClassText('class C { const C(); }')); 779 executables: serializeClassText('class C { const C(); }').executables);
773 expect(executable.isConst, isTrue); 780 expect(executable.isConst, isTrue);
774 } 781 }
775 782
776 test_constructor_factory() { 783 test_constructor_factory() {
777 UnlinkedExecutable executable = findExecutable('', 784 UnlinkedExecutable executable = findExecutable('',
778 cls: serializeClassText('class C { factory C() => null; }')); 785 executables:
786 serializeClassText('class C { factory C() => null; }').executables);
779 expect(executable.isFactory, isTrue); 787 expect(executable.isFactory, isTrue);
780 } 788 }
781 789
782 test_constructor_implicit() { 790 test_constructor_implicit() {
783 // Implicit constructors are not serialized. 791 // Implicit constructors are not serialized.
784 UnlinkedExecutable executable = findExecutable(null, 792 UnlinkedExecutable executable = findExecutable(null,
785 cls: serializeClassText('class C { C(); }'), failIfAbsent: false); 793 executables: serializeClassText('class C { C(); }').executables,
794 failIfAbsent: false);
786 expect(executable, isNull); 795 expect(executable, isNull);
787 } 796 }
788 797
789 test_constructor_initializing_formal() { 798 test_constructor_initializing_formal() {
790 UnlinkedExecutable executable = findExecutable('', 799 UnlinkedExecutable executable = findExecutable('',
791 cls: serializeClassText('class C { C(this.x); final x; }')); 800 executables:
801 serializeClassText('class C { C(this.x); final x; }').executables);
792 UnlinkedParam parameter = executable.parameters[0]; 802 UnlinkedParam parameter = executable.parameters[0];
793 expect(parameter.isInitializingFormal, isTrue); 803 expect(parameter.isInitializingFormal, isTrue);
794 } 804 }
795 805
796 test_constructor_initializing_formal_explicit_type() { 806 test_constructor_initializing_formal_explicit_type() {
797 UnlinkedExecutable executable = findExecutable('', 807 UnlinkedExecutable executable = findExecutable('',
798 cls: serializeClassText('class C { C(int this.x); final x; }')); 808 executables: serializeClassText('class C { C(int this.x); final x; }')
809 .executables);
799 UnlinkedParam parameter = executable.parameters[0]; 810 UnlinkedParam parameter = executable.parameters[0];
800 checkTypeRef(parameter.type, 'dart:core', 'dart:core', 'int'); 811 checkTypeRef(parameter.type, 'dart:core', 'dart:core', 'int');
801 } 812 }
802 813
803 test_constructor_initializing_formal_function_typed() { 814 test_constructor_initializing_formal_function_typed() {
804 UnlinkedExecutable executable = findExecutable('', 815 UnlinkedExecutable executable = findExecutable('',
805 cls: serializeClassText('class C { C(this.x()); final x; }')); 816 executables: serializeClassText('class C { C(this.x()); final x; }')
817 .executables);
806 UnlinkedParam parameter = executable.parameters[0]; 818 UnlinkedParam parameter = executable.parameters[0];
807 expect(parameter.isFunctionTyped, isTrue); 819 expect(parameter.isFunctionTyped, isTrue);
808 } 820 }
809 821
810 test_constructor_initializing_formal_function_typed_explicit_return_type() { 822 test_constructor_initializing_formal_function_typed_explicit_return_type() {
811 UnlinkedExecutable executable = findExecutable('', 823 UnlinkedExecutable executable = findExecutable('',
812 cls: serializeClassText('class C { C(int this.x()); Function x; }')); 824 executables:
825 serializeClassText('class C { C(int this.x()); Function x; }')
826 .executables);
813 UnlinkedParam parameter = executable.parameters[0]; 827 UnlinkedParam parameter = executable.parameters[0];
814 checkTypeRef(parameter.type, 'dart:core', 'dart:core', 'int'); 828 checkTypeRef(parameter.type, 'dart:core', 'dart:core', 'int');
815 } 829 }
816 830
817 test_constructor_initializing_formal_function_typed_implicit_return_type() { 831 test_constructor_initializing_formal_function_typed_implicit_return_type() {
818 UnlinkedExecutable executable = findExecutable('', 832 UnlinkedExecutable executable = findExecutable('',
819 cls: serializeClassText('class C { C(this.x()); Function x; }')); 833 executables: serializeClassText('class C { C(this.x()); Function x; }')
834 .executables);
820 UnlinkedParam parameter = executable.parameters[0]; 835 UnlinkedParam parameter = executable.parameters[0];
821 // Since the parameter is function-typed it is considered to have an 836 // Since the parameter is function-typed it is considered to have an
822 // explicit type, even though that explicit type itself has an implicit 837 // explicit type, even though that explicit type itself has an implicit
823 // return type. 838 // return type.
824 expect(parameter.hasImplicitType, isFalse); 839 expect(parameter.hasImplicitType, isFalse);
825 checkDynamicTypeRef(parameter.type); 840 checkDynamicTypeRef(parameter.type);
826 } 841 }
827 842
828 test_constructor_initializing_formal_function_typed_no_prameters() { 843 test_constructor_initializing_formal_function_typed_no_prameters() {
829 UnlinkedExecutable executable = findExecutable('', 844 UnlinkedExecutable executable = findExecutable('',
830 cls: serializeClassText('class C { C(this.x()); final x; }')); 845 executables: serializeClassText('class C { C(this.x()); final x; }')
846 .executables);
831 UnlinkedParam parameter = executable.parameters[0]; 847 UnlinkedParam parameter = executable.parameters[0];
832 expect(parameter.parameters, isEmpty); 848 expect(parameter.parameters, isEmpty);
833 } 849 }
834 850
835 test_constructor_initializing_formal_function_typed_prameter() { 851 test_constructor_initializing_formal_function_typed_prameter() {
836 UnlinkedExecutable executable = findExecutable('', 852 UnlinkedExecutable executable = findExecutable('',
837 cls: serializeClassText('class C { C(this.x(a)); final x; }')); 853 executables: serializeClassText('class C { C(this.x(a)); final x; }')
854 .executables);
838 UnlinkedParam parameter = executable.parameters[0]; 855 UnlinkedParam parameter = executable.parameters[0];
839 expect(parameter.parameters, hasLength(1)); 856 expect(parameter.parameters, hasLength(1));
840 } 857 }
841 858
842 test_constructor_initializing_formal_function_typed_prameter_order() { 859 test_constructor_initializing_formal_function_typed_prameter_order() {
843 UnlinkedExecutable executable = findExecutable('', 860 UnlinkedExecutable executable = findExecutable('',
844 cls: serializeClassText('class C { C(this.x(a, b)); final x; }')); 861 executables: serializeClassText('class C { C(this.x(a, b)); final x; }')
862 .executables);
845 UnlinkedParam parameter = executable.parameters[0]; 863 UnlinkedParam parameter = executable.parameters[0];
846 expect(parameter.parameters, hasLength(2)); 864 expect(parameter.parameters, hasLength(2));
847 expect(parameter.parameters[0].name, 'a'); 865 expect(parameter.parameters[0].name, 'a');
848 expect(parameter.parameters[1].name, 'b'); 866 expect(parameter.parameters[1].name, 'b');
849 } 867 }
850 868
851 test_constructor_initializing_formal_implicit_type() { 869 test_constructor_initializing_formal_implicit_type() {
852 // Note: the implicit type of an initializing formal is the type of the 870 // Note: the implicit type of an initializing formal is the type of the
853 // field. 871 // field.
854 UnlinkedExecutable executable = findExecutable('', 872 UnlinkedExecutable executable = findExecutable('',
855 cls: serializeClassText('class C { C(this.x); int x; }')); 873 executables:
874 serializeClassText('class C { C(this.x); int x; }').executables);
856 UnlinkedParam parameter = executable.parameters[0]; 875 UnlinkedParam parameter = executable.parameters[0];
857 checkTypeRef(parameter.type, 'dart:core', 'dart:core', 'int'); 876 checkTypeRef(parameter.type, 'dart:core', 'dart:core', 'int');
858 expect(parameter.hasImplicitType, isTrue); 877 expect(parameter.hasImplicitType, isTrue);
859 } 878 }
860 879
861 test_constructor_initializing_formal_name() { 880 test_constructor_initializing_formal_name() {
862 UnlinkedExecutable executable = findExecutable('', 881 UnlinkedExecutable executable = findExecutable('',
863 cls: serializeClassText('class C { C(this.x); final x; }')); 882 executables:
883 serializeClassText('class C { C(this.x); final x; }').executables);
864 UnlinkedParam parameter = executable.parameters[0]; 884 UnlinkedParam parameter = executable.parameters[0];
865 expect(parameter.name, 'x'); 885 expect(parameter.name, 'x');
866 } 886 }
867 887
868 test_constructor_initializing_formal_named() { 888 test_constructor_initializing_formal_named() {
869 // TODO(paulberry): also test default value 889 // TODO(paulberry): also test default value
870 UnlinkedExecutable executable = findExecutable('', 890 UnlinkedExecutable executable = findExecutable('',
871 cls: serializeClassText('class C { C({this.x}); final x; }')); 891 executables: serializeClassText('class C { C({this.x}); final x; }')
892 .executables);
872 UnlinkedParam parameter = executable.parameters[0]; 893 UnlinkedParam parameter = executable.parameters[0];
873 expect(parameter.kind, UnlinkedParamKind.named); 894 expect(parameter.kind, UnlinkedParamKind.named);
874 } 895 }
875 896
876 test_constructor_initializing_formal_non_function_typed() { 897 test_constructor_initializing_formal_non_function_typed() {
877 UnlinkedExecutable executable = findExecutable('', 898 UnlinkedExecutable executable = findExecutable('',
878 cls: serializeClassText('class C { C(this.x); final x; }')); 899 executables:
900 serializeClassText('class C { C(this.x); final x; }').executables);
879 UnlinkedParam parameter = executable.parameters[0]; 901 UnlinkedParam parameter = executable.parameters[0];
880 expect(parameter.isFunctionTyped, isFalse); 902 expect(parameter.isFunctionTyped, isFalse);
881 } 903 }
882 904
883 test_constructor_initializing_formal_positional() { 905 test_constructor_initializing_formal_positional() {
884 // TODO(paulberry): also test default value 906 // TODO(paulberry): also test default value
885 UnlinkedExecutable executable = findExecutable('', 907 UnlinkedExecutable executable = findExecutable('',
886 cls: serializeClassText('class C { C([this.x]); final x; }')); 908 executables: serializeClassText('class C { C([this.x]); final x; }')
909 .executables);
887 UnlinkedParam parameter = executable.parameters[0]; 910 UnlinkedParam parameter = executable.parameters[0];
888 expect(parameter.kind, UnlinkedParamKind.positional); 911 expect(parameter.kind, UnlinkedParamKind.positional);
889 } 912 }
890 913
891 test_constructor_initializing_formal_required() { 914 test_constructor_initializing_formal_required() {
892 UnlinkedExecutable executable = findExecutable('', 915 UnlinkedExecutable executable = findExecutable('',
893 cls: serializeClassText('class C { C(this.x); final x; }')); 916 executables:
917 serializeClassText('class C { C(this.x); final x; }').executables);
894 UnlinkedParam parameter = executable.parameters[0]; 918 UnlinkedParam parameter = executable.parameters[0];
895 expect(parameter.kind, UnlinkedParamKind.required); 919 expect(parameter.kind, UnlinkedParamKind.required);
896 } 920 }
897 921
898 test_constructor_named() { 922 test_constructor_named() {
899 UnlinkedExecutable executable = 923 UnlinkedExecutable executable = findExecutable('foo',
900 findExecutable('foo', cls: serializeClassText('class C { C.foo(); }')); 924 executables: serializeClassText('class C { C.foo(); }').executables);
901 expect(executable.name, 'foo'); 925 expect(executable.name, 'foo');
902 } 926 }
903 927
904 test_constructor_non_const() { 928 test_constructor_non_const() {
905 UnlinkedExecutable executable = 929 UnlinkedExecutable executable = findExecutable('',
906 findExecutable('', cls: serializeClassText('class C { C(); }')); 930 executables: serializeClassText('class C { C(); }').executables);
907 expect(executable.isConst, isFalse); 931 expect(executable.isConst, isFalse);
908 } 932 }
909 933
910 test_constructor_non_factory() { 934 test_constructor_non_factory() {
911 UnlinkedExecutable executable = 935 UnlinkedExecutable executable = findExecutable('',
912 findExecutable('', cls: serializeClassText('class C { C(); }')); 936 executables: serializeClassText('class C { C(); }').executables);
913 expect(executable.isFactory, isFalse); 937 expect(executable.isFactory, isFalse);
914 } 938 }
915 939
916 test_constructor_return_type() { 940 test_constructor_return_type() {
917 UnlinkedExecutable executable = 941 UnlinkedExecutable executable = findExecutable('',
918 findExecutable('', cls: serializeClassText('class C { C(); }')); 942 executables: serializeClassText('class C { C(); }').executables);
919 checkTypeRef(executable.returnType, null, null, 'C'); 943 checkTypeRef(executable.returnType, null, null, 'C');
920 } 944 }
921 945
922 test_constructor_return_type_parameterized() { 946 test_constructor_return_type_parameterized() {
923 UnlinkedExecutable executable = 947 UnlinkedExecutable executable = findExecutable('',
924 findExecutable('', cls: serializeClassText('class C<T, U> { C(); }')); 948 executables: serializeClassText('class C<T, U> { C(); }').executables);
925 checkTypeRef(executable.returnType, null, null, 'C', 949 checkTypeRef(executable.returnType, null, null, 'C',
926 allowTypeParameters: true); 950 allowTypeParameters: true);
927 expect(executable.returnType.typeArguments, hasLength(2)); 951 expect(executable.returnType.typeArguments, hasLength(2));
928 { 952 {
929 UnlinkedTypeRef typeRef = executable.returnType.typeArguments[0]; 953 UnlinkedTypeRef typeRef = executable.returnType.typeArguments[0];
930 checkParamTypeRef(typeRef, 2); 954 checkParamTypeRef(typeRef, 2);
931 } 955 }
932 { 956 {
933 UnlinkedTypeRef typeRef = executable.returnType.typeArguments[1]; 957 UnlinkedTypeRef typeRef = executable.returnType.typeArguments[1];
934 checkParamTypeRef(typeRef, 1); 958 checkParamTypeRef(typeRef, 1);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 ''' 1048 '''
1025 part of my.lib; 1049 part of my.lib;
1026 1050
1027 class C {} 1051 class C {}
1028 enum E { v } 1052 enum E { v }
1029 var v; 1053 var v;
1030 f() {} 1054 f() {}
1031 typedef F(); 1055 typedef F();
1032 '''); 1056 ''');
1033 serializeLibraryText('library my.lib; part "part1.dart";'); 1057 serializeLibraryText('library my.lib; part "part1.dart";');
1034 expect(findClass('C', failIfAbsent: true).unit, 1); 1058 PrelinkedUnit unit = lib.units[1];
1035 expect(findEnum('E', failIfAbsent: true).unit, 1); 1059 expect(findClass('C', unit: unit), isNotNull);
1036 expect(findVariable('v', failIfAbsent: true).unit, 1); 1060 expect(findEnum('E', unit: unit), isNotNull);
1037 expect(findExecutable('f', failIfAbsent: true).unit, 1); 1061 expect(findVariable('v', variables: unit.unlinked.variables), isNotNull);
1038 expect(findTypedef('F', failIfAbsent: true).unit, 1); 1062 expect(
1063 findExecutable('f', executables: unit.unlinked.executables), isNotNull);
1064 expect(findTypedef('F', unit: unit), isNotNull);
1039 } 1065 }
1040 1066
1041 test_enum() { 1067 test_enum() {
1042 UnlinkedEnum e = serializeEnumText('enum E { v1 }'); 1068 UnlinkedEnum e = serializeEnumText('enum E { v1 }');
1043 expect(e.name, 'E'); 1069 expect(e.name, 'E');
1044 expect(e.values, hasLength(1)); 1070 expect(e.values, hasLength(1));
1045 expect(e.values[0].name, 'v1'); 1071 expect(e.values[0].name, 'v1');
1046 expect(e.unit, 0);
1047 } 1072 }
1048 1073
1049 test_enum_order() { 1074 test_enum_order() {
1050 UnlinkedEnum e = serializeEnumText('enum E { v1, v2 }'); 1075 UnlinkedEnum e = serializeEnumText('enum E { v1, v2 }');
1051 expect(e.values, hasLength(2)); 1076 expect(e.values, hasLength(2));
1052 expect(e.values[0].name, 'v1'); 1077 expect(e.values[0].name, 'v1');
1053 expect(e.values[1].name, 'v2'); 1078 expect(e.values[1].name, 'v2');
1054 } 1079 }
1055 1080
1056 test_executable_abstract() { 1081 test_executable_abstract() {
1057 UnlinkedExecutable executable = 1082 UnlinkedExecutable executable =
1058 serializeClassText('abstract class C { f(); }').executables[0]; 1083 serializeClassText('abstract class C { f(); }').executables[0];
1059 expect(executable.isAbstract, isTrue); 1084 expect(executable.isAbstract, isTrue);
1060 } 1085 }
1061 1086
1062 test_executable_concrete() { 1087 test_executable_concrete() {
1063 UnlinkedExecutable executable = 1088 UnlinkedExecutable executable =
1064 serializeClassText('abstract class C { f() {} }').executables[0]; 1089 serializeClassText('abstract class C { f() {} }').executables[0];
1065 expect(executable.isAbstract, isFalse); 1090 expect(executable.isAbstract, isFalse);
1066 } 1091 }
1067 1092
1068 test_executable_function() { 1093 test_executable_function() {
1069 UnlinkedExecutable executable = serializeExecutableText('f() {}'); 1094 UnlinkedExecutable executable = serializeExecutableText('f() {}');
1070 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 1095 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
1071 expect(executable.unit, 0);
1072 expect(executable.hasImplicitReturnType, isTrue); 1096 expect(executable.hasImplicitReturnType, isTrue);
1073 checkDynamicTypeRef(executable.returnType); 1097 checkDynamicTypeRef(executable.returnType);
1074 } 1098 }
1075 1099
1076 test_executable_function_explicit_return() { 1100 test_executable_function_explicit_return() {
1077 UnlinkedExecutable executable = 1101 UnlinkedExecutable executable =
1078 serializeExecutableText('dynamic f() => null;'); 1102 serializeExecutableText('dynamic f() => null;');
1079 expect(executable.hasImplicitReturnType, isFalse); 1103 expect(executable.hasImplicitReturnType, isFalse);
1080 checkDynamicTypeRef(executable.returnType); 1104 checkDynamicTypeRef(executable.returnType);
1081 } 1105 }
(...skipping 13 matching lines...) Expand all
1095 } 1119 }
1096 1120
1097 test_executable_getter_type_implicit() { 1121 test_executable_getter_type_implicit() {
1098 UnlinkedExecutable executable = serializeExecutableText('get f => 1;'); 1122 UnlinkedExecutable executable = serializeExecutableText('get f => 1;');
1099 checkDynamicTypeRef(executable.returnType); 1123 checkDynamicTypeRef(executable.returnType);
1100 expect(executable.hasImplicitReturnType, isTrue); 1124 expect(executable.hasImplicitReturnType, isTrue);
1101 expect(executable.parameters, isEmpty); 1125 expect(executable.parameters, isEmpty);
1102 } 1126 }
1103 1127
1104 test_executable_member_function() { 1128 test_executable_member_function() {
1105 UnlinkedExecutable executable = 1129 UnlinkedExecutable executable = findExecutable('f',
1106 findExecutable('f', cls: serializeClassText('class C { f() {} }')); 1130 executables: serializeClassText('class C { f() {} }').executables);
1107 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 1131 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
1108 expect(executable.hasImplicitReturnType, isTrue); 1132 expect(executable.hasImplicitReturnType, isTrue);
1109 } 1133 }
1110 1134
1111 test_executable_member_function_explicit_return() { 1135 test_executable_member_function_explicit_return() {
1112 UnlinkedExecutable executable = findExecutable('f', 1136 UnlinkedExecutable executable = findExecutable('f',
1113 cls: serializeClassText('class C { dynamic f() => null; }')); 1137 executables:
1138 serializeClassText('class C { dynamic f() => null; }').executables);
1114 expect(executable.hasImplicitReturnType, isFalse); 1139 expect(executable.hasImplicitReturnType, isFalse);
1115 } 1140 }
1116 1141
1117 test_executable_member_getter() { 1142 test_executable_member_getter() {
1118 UnlinkedClass cls = serializeClassText('class C { int get f => 1; }'); 1143 UnlinkedClass cls = serializeClassText('class C { int get f => 1; }');
1119 UnlinkedExecutable executable = 1144 UnlinkedExecutable executable =
1120 findExecutable('f', cls: cls, failIfAbsent: true); 1145 findExecutable('f', executables: cls.executables, failIfAbsent: true);
1121 expect(executable.kind, UnlinkedExecutableKind.getter); 1146 expect(executable.kind, UnlinkedExecutableKind.getter);
1122 expect(executable.hasImplicitReturnType, isFalse); 1147 expect(executable.hasImplicitReturnType, isFalse);
1123 expect(findVariable('f', cls: cls), isNull); 1148 expect(findVariable('f', variables: cls.fields), isNull);
1124 expect(findExecutable('f=', cls: cls), isNull); 1149 expect(findExecutable('f=', executables: cls.executables), isNull);
1125 } 1150 }
1126 1151
1127 test_executable_member_setter() { 1152 test_executable_member_setter() {
1128 UnlinkedClass cls = serializeClassText('class C { void set f(value) {} }'); 1153 UnlinkedClass cls = serializeClassText('class C { void set f(value) {} }');
1129 UnlinkedExecutable executable = 1154 UnlinkedExecutable executable =
1130 findExecutable('f=', cls: cls, failIfAbsent: true); 1155 findExecutable('f=', executables: cls.executables, failIfAbsent: true);
1131 expect(executable.kind, UnlinkedExecutableKind.setter); 1156 expect(executable.kind, UnlinkedExecutableKind.setter);
1132 // For setters, hasImplicitReturnType is always false. 1157 // For setters, hasImplicitReturnType is always false.
1133 expect(executable.hasImplicitReturnType, isFalse); 1158 expect(executable.hasImplicitReturnType, isFalse);
1134 expect(findVariable('f', cls: cls), isNull); 1159 expect(findVariable('f', variables: cls.fields), isNull);
1135 expect(findExecutable('f', cls: cls), isNull); 1160 expect(findExecutable('f', executables: cls.executables), isNull);
1136 } 1161 }
1137 1162
1138 test_executable_member_setter_implicit_return() { 1163 test_executable_member_setter_implicit_return() {
1139 UnlinkedClass cls = serializeClassText('class C { set f(value) {} }'); 1164 UnlinkedClass cls = serializeClassText('class C { set f(value) {} }');
1140 UnlinkedExecutable executable = 1165 UnlinkedExecutable executable =
1141 findExecutable('f=', cls: cls, failIfAbsent: true); 1166 findExecutable('f=', executables: cls.executables, failIfAbsent: true);
1142 expect(executable.hasImplicitReturnType, isFalse); 1167 expect(executable.hasImplicitReturnType, isFalse);
1143 checkDynamicTypeRef(executable.returnType); 1168 checkDynamicTypeRef(executable.returnType);
1144 } 1169 }
1145 1170
1146 test_executable_name() { 1171 test_executable_name() {
1147 UnlinkedExecutable executable = serializeExecutableText('f() {}'); 1172 UnlinkedExecutable executable = serializeExecutableText('f() {}');
1148 expect(executable.name, 'f'); 1173 expect(executable.name, 'f');
1149 } 1174 }
1150 1175
1151 test_executable_no_flags() { 1176 test_executable_no_flags() {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 } 1370 }
1346 1371
1347 test_executable_type_param_in_return_type() { 1372 test_executable_type_param_in_return_type() {
1348 // TODO(paulberry): also test top level executables. 1373 // TODO(paulberry): also test top level executables.
1349 UnlinkedExecutable ex = serializeMethodText('T f<T>() => null;'); 1374 UnlinkedExecutable ex = serializeMethodText('T f<T>() => null;');
1350 checkParamTypeRef(ex.returnType, 1); 1375 checkParamTypeRef(ex.returnType, 1);
1351 } 1376 }
1352 1377
1353 test_export_hide_order() { 1378 test_export_hide_order() {
1354 serializeLibraryText('export "dart:async" hide Future, Stream;'); 1379 serializeLibraryText('export "dart:async" hide Future, Stream;');
1355 expect(unlinked.exports, hasLength(1)); 1380 expect(definingUnit.unlinked.exports, hasLength(1));
1356 expect(unlinked.exports[0].combinators, hasLength(1)); 1381 expect(definingUnit.unlinked.exports[0].combinators, hasLength(1));
1357 expect(unlinked.exports[0].combinators[0].shows, isEmpty); 1382 expect(definingUnit.unlinked.exports[0].combinators[0].shows, isEmpty);
1358 expect(unlinked.exports[0].combinators[0].hides, hasLength(2)); 1383 expect(definingUnit.unlinked.exports[0].combinators[0].hides, hasLength(2));
1359 checkCombinatorName(unlinked.exports[0].combinators[0].hides[0], 'Future'); 1384 checkCombinatorName(
1360 checkCombinatorName(unlinked.exports[0].combinators[0].hides[1], 'Stream'); 1385 definingUnit.unlinked.exports[0].combinators[0].hides[0], 'Future');
1386 checkCombinatorName(
1387 definingUnit.unlinked.exports[0].combinators[0].hides[1], 'Stream');
1361 } 1388 }
1362 1389
1363 test_export_no_combinators() { 1390 test_export_no_combinators() {
1364 serializeLibraryText('export "dart:async";'); 1391 serializeLibraryText('export "dart:async";');
1365 expect(unlinked.exports, hasLength(1)); 1392 expect(definingUnit.unlinked.exports, hasLength(1));
1366 expect(unlinked.exports[0].combinators, isEmpty); 1393 expect(definingUnit.unlinked.exports[0].combinators, isEmpty);
1367 } 1394 }
1368 1395
1369 test_export_show_order() { 1396 test_export_show_order() {
1370 serializeLibraryText('export "dart:async" show Future, Stream;'); 1397 serializeLibraryText('export "dart:async" show Future, Stream;');
1371 expect(unlinked.exports, hasLength(1)); 1398 expect(definingUnit.unlinked.exports, hasLength(1));
1372 expect(unlinked.exports[0].combinators, hasLength(1)); 1399 expect(definingUnit.unlinked.exports[0].combinators, hasLength(1));
1373 expect(unlinked.exports[0].combinators[0].shows, hasLength(2)); 1400 expect(definingUnit.unlinked.exports[0].combinators[0].shows, hasLength(2));
1374 expect(unlinked.exports[0].combinators[0].hides, isEmpty); 1401 expect(definingUnit.unlinked.exports[0].combinators[0].hides, isEmpty);
1375 checkCombinatorName(unlinked.exports[0].combinators[0].shows[0], 'Future'); 1402 checkCombinatorName(
1376 checkCombinatorName(unlinked.exports[0].combinators[0].shows[1], 'Stream'); 1403 definingUnit.unlinked.exports[0].combinators[0].shows[0], 'Future');
1404 checkCombinatorName(
1405 definingUnit.unlinked.exports[0].combinators[0].shows[1], 'Stream');
1377 } 1406 }
1378 1407
1379 test_export_uri() { 1408 test_export_uri() {
1380 addNamedSource('/a.dart', 'library my.lib;'); 1409 addNamedSource('/a.dart', 'library my.lib;');
1381 String uriString = '"a.dart"'; 1410 String uriString = '"a.dart"';
1382 String libraryText = 'export $uriString;'; 1411 String libraryText = 'export $uriString;';
1383 serializeLibraryText(libraryText); 1412 serializeLibraryText(libraryText);
1384 expect(unlinked.exports, hasLength(1)); 1413 expect(definingUnit.unlinked.exports, hasLength(1));
1385 expect(unlinked.exports[0].uri, 'a.dart'); 1414 expect(definingUnit.unlinked.exports[0].uri, 'a.dart');
1386 } 1415 }
1387 1416
1388 test_field() { 1417 test_field() {
1389 UnlinkedClass cls = serializeClassText('class C { int i; }'); 1418 UnlinkedClass cls = serializeClassText('class C { int i; }');
1390 expect(findVariable('i', cls: cls), isNotNull); 1419 expect(findVariable('i', variables: cls.fields), isNotNull);
1391 expect(findExecutable('i', cls: cls), isNull); 1420 expect(findExecutable('i', executables: cls.executables), isNull);
1392 expect(findExecutable('i=', cls: cls), isNull); 1421 expect(findExecutable('i=', executables: cls.executables), isNull);
1393 } 1422 }
1394 1423
1395 test_field_final() { 1424 test_field_final() {
1396 UnlinkedVariable variable = 1425 UnlinkedVariable variable =
1397 serializeClassText('class C { final int i = 0; }').fields[0]; 1426 serializeClassText('class C { final int i = 0; }').fields[0];
1398 expect(variable.isFinal, isTrue); 1427 expect(variable.isFinal, isTrue);
1399 } 1428 }
1400 1429
1401 test_field_non_final() { 1430 test_field_non_final() {
1402 UnlinkedVariable variable = 1431 UnlinkedVariable variable =
1403 serializeClassText('class C { int i; }').fields[0]; 1432 serializeClassText('class C { int i; }').fields[0];
1404 expect(variable.isFinal, isFalse); 1433 expect(variable.isFinal, isFalse);
1405 } 1434 }
1406 1435
1407 test_generic_method_in_generic_class() { 1436 test_generic_method_in_generic_class() {
1408 UnlinkedClass cls = serializeClassText( 1437 UnlinkedClass cls = serializeClassText(
1409 'class C<T, U> { void m<V, W>(T t, U u, V v, W w) {} }'); 1438 'class C<T, U> { void m<V, W>(T t, U u, V v, W w) {} }');
1410 List<UnlinkedParam> params = cls.executables[0].parameters; 1439 List<UnlinkedParam> params = cls.executables[0].parameters;
1411 checkParamTypeRef(params[0].type, 4); 1440 checkParamTypeRef(params[0].type, 4);
1412 checkParamTypeRef(params[1].type, 3); 1441 checkParamTypeRef(params[1].type, 3);
1413 checkParamTypeRef(params[2].type, 2); 1442 checkParamTypeRef(params[2].type, 2);
1414 checkParamTypeRef(params[3].type, 1); 1443 checkParamTypeRef(params[3].type, 1);
1415 } 1444 }
1416 1445
1417 test_import_deferred() { 1446 test_import_deferred() {
1418 serializeLibraryText( 1447 serializeLibraryText(
1419 'import "dart:async" deferred as a; main() { print(a.Future); }'); 1448 'import "dart:async" deferred as a; main() { print(a.Future); }');
1420 expect(unlinked.imports[0].isDeferred, isTrue); 1449 expect(definingUnit.unlinked.imports[0].isDeferred, isTrue);
1421 } 1450 }
1422 1451
1423 test_import_dependency() { 1452 test_import_dependency() {
1424 serializeLibraryText('import "dart:async"; Future x;'); 1453 serializeLibraryText('import "dart:async"; Future x;');
1425 // Second import is the implicit import of dart:core 1454 // Second import is the implicit import of dart:core
1426 expect(unlinked.imports, hasLength(2)); 1455 expect(definingUnit.unlinked.imports, hasLength(2));
1427 checkDependency(lib.importDependencies[0], 'dart:async', 'dart:async'); 1456 checkDependency(lib.importDependencies[0], 'dart:async', 'dart:async');
1428 } 1457 }
1429 1458
1430 test_import_explicit() { 1459 test_import_explicit() {
1431 serializeLibraryText('import "dart:core"; int i;'); 1460 serializeLibraryText('import "dart:core"; int i;');
1432 expect(unlinked.imports, hasLength(1)); 1461 expect(definingUnit.unlinked.imports, hasLength(1));
1433 expect(unlinked.imports[0].isImplicit, isFalse); 1462 expect(definingUnit.unlinked.imports[0].isImplicit, isFalse);
1434 } 1463 }
1435 1464
1436 test_import_hide_order() { 1465 test_import_hide_order() {
1437 serializeLibraryText( 1466 serializeLibraryText(
1438 'import "dart:async" hide Future, Stream; Completer c;'); 1467 'import "dart:async" hide Future, Stream; Completer c;');
1439 // Second import is the implicit import of dart:core 1468 // Second import is the implicit import of dart:core
1440 expect(unlinked.imports, hasLength(2)); 1469 expect(definingUnit.unlinked.imports, hasLength(2));
1441 expect(unlinked.imports[0].combinators, hasLength(1)); 1470 expect(definingUnit.unlinked.imports[0].combinators, hasLength(1));
1442 expect(unlinked.imports[0].combinators[0].shows, isEmpty); 1471 expect(definingUnit.unlinked.imports[0].combinators[0].shows, isEmpty);
1443 expect(unlinked.imports[0].combinators[0].hides, hasLength(2)); 1472 expect(definingUnit.unlinked.imports[0].combinators[0].hides, hasLength(2));
1444 checkCombinatorName(unlinked.imports[0].combinators[0].hides[0], 'Future'); 1473 checkCombinatorName(
1445 checkCombinatorName(unlinked.imports[0].combinators[0].hides[1], 'Stream'); 1474 definingUnit.unlinked.imports[0].combinators[0].hides[0], 'Future');
1475 checkCombinatorName(
1476 definingUnit.unlinked.imports[0].combinators[0].hides[1], 'Stream');
1446 } 1477 }
1447 1478
1448 test_import_implicit() { 1479 test_import_implicit() {
1449 // The implicit import of dart:core is represented in the model. 1480 // The implicit import of dart:core is represented in the model.
1450 serializeLibraryText(''); 1481 serializeLibraryText('');
1451 expect(unlinked.imports, hasLength(1)); 1482 expect(definingUnit.unlinked.imports, hasLength(1));
1452 checkDependency(lib.importDependencies[0], 'dart:core', 'dart:core'); 1483 checkDependency(lib.importDependencies[0], 'dart:core', 'dart:core');
1453 expect(unlinked.imports[0].uri, isEmpty); 1484 expect(definingUnit.unlinked.imports[0].uri, isEmpty);
1454 expect(unlinked.imports[0].prefix, 0); 1485 expect(definingUnit.unlinked.imports[0].prefix, 0);
1455 expect(unlinked.imports[0].combinators, isEmpty); 1486 expect(definingUnit.unlinked.imports[0].combinators, isEmpty);
1456 expect(unlinked.imports[0].isImplicit, isTrue); 1487 expect(definingUnit.unlinked.imports[0].isImplicit, isTrue);
1457 } 1488 }
1458 1489
1459 test_import_no_combinators() { 1490 test_import_no_combinators() {
1460 serializeLibraryText('import "dart:async"; Future x;'); 1491 serializeLibraryText('import "dart:async"; Future x;');
1461 // Second import is the implicit import of dart:core 1492 // Second import is the implicit import of dart:core
1462 expect(unlinked.imports, hasLength(2)); 1493 expect(definingUnit.unlinked.imports, hasLength(2));
1463 expect(unlinked.imports[0].combinators, isEmpty); 1494 expect(definingUnit.unlinked.imports[0].combinators, isEmpty);
1464 } 1495 }
1465 1496
1466 test_import_no_flags() { 1497 test_import_no_flags() {
1467 serializeLibraryText('import "dart:async"; Future x;'); 1498 serializeLibraryText('import "dart:async"; Future x;');
1468 expect(unlinked.imports[0].isImplicit, isFalse); 1499 expect(definingUnit.unlinked.imports[0].isImplicit, isFalse);
1469 expect(unlinked.imports[0].isDeferred, isFalse); 1500 expect(definingUnit.unlinked.imports[0].isDeferred, isFalse);
1470 } 1501 }
1471 1502
1472 test_import_non_deferred() { 1503 test_import_non_deferred() {
1473 serializeLibraryText( 1504 serializeLibraryText(
1474 'import "dart:async" as a; main() { print(a.Future); }'); 1505 'import "dart:async" as a; main() { print(a.Future); }');
1475 expect(unlinked.imports[0].isDeferred, isFalse); 1506 expect(definingUnit.unlinked.imports[0].isDeferred, isFalse);
1476 } 1507 }
1477 1508
1478 test_import_of_file_with_missing_part() { 1509 test_import_of_file_with_missing_part() {
1479 // Other references in foo.dart should be resolved even though foo.dart's 1510 // Other references in foo.dart should be resolved even though foo.dart's
1480 // part declaration for bar.dart refers to a non-existent file. 1511 // part declaration for bar.dart refers to a non-existent file.
1481 addNamedSource('/foo.dart', 'part "bar.dart"; class C {}'); 1512 addNamedSource('/foo.dart', 'part "bar.dart"; class C {}');
1482 serializeLibraryText('import "foo.dart"; C x;'); 1513 serializeLibraryText('import "foo.dart"; C x;');
1483 checkTypeRef(findVariable('x').type, absUri('/foo.dart'), 'foo.dart', 'C'); 1514 checkTypeRef(findVariable('x').type, absUri('/foo.dart'), 'foo.dart', 'C');
1484 } 1515 }
1485 1516
1486 test_import_of_missing_export() { 1517 test_import_of_missing_export() {
1487 // Other references in foo.dart should be resolved even though foo.dart's 1518 // Other references in foo.dart should be resolved even though foo.dart's
1488 // re-export of bar.dart refers to a non-existent file. 1519 // re-export of bar.dart refers to a non-existent file.
1489 addNamedSource('/foo.dart', 'export "bar.dart"; class C {}'); 1520 addNamedSource('/foo.dart', 'export "bar.dart"; class C {}');
1490 serializeLibraryText('import "foo.dart"; C x;'); 1521 serializeLibraryText('import "foo.dart"; C x;');
1491 checkTypeRef(findVariable('x').type, absUri('/foo.dart'), 'foo.dart', 'C'); 1522 checkTypeRef(findVariable('x').type, absUri('/foo.dart'), 'foo.dart', 'C');
1492 } 1523 }
1493 1524
1494 test_import_offset() { 1525 test_import_offset() {
1495 String libraryText = ' import "dart:async"; Future x;'; 1526 String libraryText = ' import "dart:async"; Future x;';
1496 serializeLibraryText(libraryText); 1527 serializeLibraryText(libraryText);
1497 expect(unlinked.imports[0].offset, libraryText.indexOf('import')); 1528 expect(
1529 definingUnit.unlinked.imports[0].offset, libraryText.indexOf('import'));
1498 } 1530 }
1499 1531
1500 test_import_prefix_name() { 1532 test_import_prefix_name() {
1501 String libraryText = 'import "dart:async" as a; a.Future x;'; 1533 String libraryText = 'import "dart:async" as a; a.Future x;';
1502 serializeLibraryText(libraryText); 1534 serializeLibraryText(libraryText);
1503 // Second import is the implicit import of dart:core 1535 // Second import is the implicit import of dart:core
1504 expect(unlinked.imports, hasLength(2)); 1536 expect(definingUnit.unlinked.imports, hasLength(2));
1505 expect(unlinked.imports[0].prefix, isNot(0)); 1537 expect(definingUnit.unlinked.imports[0].prefix, isNot(0));
1506 expect(unlinked.prefixes[unlinked.imports[0].prefix].name, 'a'); 1538 expect(
1539 unlinked.prefixes[definingUnit.unlinked.imports[0].prefix].name, 'a');
1507 } 1540 }
1508 1541
1509 test_import_prefix_none() { 1542 test_import_prefix_none() {
1510 serializeLibraryText('import "dart:async"; Future x;'); 1543 serializeLibraryText('import "dart:async"; Future x;');
1511 // Second import is the implicit import of dart:core 1544 // Second import is the implicit import of dart:core
1512 expect(unlinked.imports, hasLength(2)); 1545 expect(definingUnit.unlinked.imports, hasLength(2));
1513 expect(unlinked.imports[0].prefix, 0); 1546 expect(definingUnit.unlinked.imports[0].prefix, 0);
1514 expect(unlinked.prefixes[unlinked.imports[0].prefix].name, isEmpty); 1547 expect(unlinked.prefixes[definingUnit.unlinked.imports[0].prefix].name,
1548 isEmpty);
1515 } 1549 }
1516 1550
1517 test_import_prefix_reference() { 1551 test_import_prefix_reference() {
1518 UnlinkedVariable variable = 1552 UnlinkedVariable variable =
1519 serializeVariableText('import "dart:async" as a; a.Future v;'); 1553 serializeVariableText('import "dart:async" as a; a.Future v;');
1520 checkTypeRef(variable.type, 'dart:async', 'dart:async', 'Future', 1554 checkTypeRef(variable.type, 'dart:async', 'dart:async', 'Future',
1521 expectedPrefix: 'a'); 1555 expectedPrefix: 'a');
1522 } 1556 }
1523 1557
1524 test_import_reference() { 1558 test_import_reference() {
(...skipping 26 matching lines...) Expand all
1551 expectedPrefix: 'a'); 1585 expectedPrefix: 'a');
1552 checkTypeRef(findVariable('s').type, 'dart:async', 'dart:async', 'Stream', 1586 checkTypeRef(findVariable('s').type, 'dart:async', 'dart:async', 'Stream',
1553 expectedPrefix: 'a'); 1587 expectedPrefix: 'a');
1554 } 1588 }
1555 1589
1556 test_import_show_order() { 1590 test_import_show_order() {
1557 String libraryText = 1591 String libraryText =
1558 'import "dart:async" show Future, Stream; Future x; Stream y;'; 1592 'import "dart:async" show Future, Stream; Future x; Stream y;';
1559 serializeLibraryText(libraryText); 1593 serializeLibraryText(libraryText);
1560 // Second import is the implicit import of dart:core 1594 // Second import is the implicit import of dart:core
1561 expect(unlinked.imports, hasLength(2)); 1595 expect(definingUnit.unlinked.imports, hasLength(2));
1562 expect(unlinked.imports[0].combinators, hasLength(1)); 1596 expect(definingUnit.unlinked.imports[0].combinators, hasLength(1));
1563 expect(unlinked.imports[0].combinators[0].shows, hasLength(2)); 1597 expect(definingUnit.unlinked.imports[0].combinators[0].shows, hasLength(2));
1564 expect(unlinked.imports[0].combinators[0].hides, isEmpty); 1598 expect(definingUnit.unlinked.imports[0].combinators[0].hides, isEmpty);
1565 checkCombinatorName(unlinked.imports[0].combinators[0].shows[0], 'Future'); 1599 checkCombinatorName(
1566 checkCombinatorName(unlinked.imports[0].combinators[0].shows[1], 'Stream'); 1600 definingUnit.unlinked.imports[0].combinators[0].shows[0], 'Future');
1601 checkCombinatorName(
1602 definingUnit.unlinked.imports[0].combinators[0].shows[1], 'Stream');
1567 } 1603 }
1568 1604
1569 test_import_uri() { 1605 test_import_uri() {
1570 String uriString = '"dart:async"'; 1606 String uriString = '"dart:async"';
1571 String libraryText = 'import $uriString; Future x;'; 1607 String libraryText = 'import $uriString; Future x;';
1572 serializeLibraryText(libraryText); 1608 serializeLibraryText(libraryText);
1573 // Second import is the implicit import of dart:core 1609 // Second import is the implicit import of dart:core
1574 expect(unlinked.imports, hasLength(2)); 1610 expect(definingUnit.unlinked.imports, hasLength(2));
1575 expect(unlinked.imports[0].uri, 'dart:async'); 1611 expect(definingUnit.unlinked.imports[0].uri, 'dart:async');
1576 } 1612 }
1577 1613
1578 test_library_named() { 1614 test_library_named() {
1579 String text = 'library foo.bar;'; 1615 String text = 'library foo.bar;';
1580 serializeLibraryText(text); 1616 serializeLibraryText(text);
1581 expect(unlinked.name, 'foo.bar'); 1617 expect(definingUnit.unlinked.libraryName, 'foo.bar');
1582 } 1618 }
1583 1619
1584 test_library_unnamed() { 1620 test_library_unnamed() {
1585 serializeLibraryText(''); 1621 serializeLibraryText('');
1586 expect(unlinked.name, isEmpty); 1622 expect(definingUnit.unlinked.libraryName, isEmpty);
1587 }
1588
1589 test_nested_elements_have_no_part() {
1590 addNamedSource(
1591 '/part1.dart',
1592 '''
1593 part of my.lib;
1594
1595 class C {
1596 var v;
1597 f() {}
1598 }
1599 ''');
1600 serializeLibraryText('library my.lib; part "part1.dart";');
1601 UnlinkedClass cls = findClass('C');
1602 expect(findVariable('v', cls: cls).unit, 0);
1603 expect(findExecutable('f', cls: cls).unit, 0);
1604 } 1623 }
1605 1624
1606 test_parts_defining_compilation_unit() { 1625 test_parts_defining_compilation_unit() {
1607 serializeLibraryText(''); 1626 serializeLibraryText('');
1608 expect(unlinked.units, hasLength(1)); 1627 expect(lib.units, hasLength(1));
1609 expect(unlinked.units[0].uri, isEmpty); 1628 expect(definingUnit.unlinked.parts, isEmpty);
1610 } 1629 }
1611 1630
1612 test_parts_included() { 1631 test_parts_included() {
1613 addNamedSource('/part1.dart', 'part of my.lib;'); 1632 addNamedSource('/part1.dart', 'part of my.lib;');
1614 String partString = '"part1.dart"'; 1633 String partString = '"part1.dart"';
1615 String libraryText = 'library my.lib; part $partString;'; 1634 String libraryText = 'library my.lib; part $partString;';
1616 serializeLibraryText(libraryText); 1635 serializeLibraryText(libraryText);
1617 expect(unlinked.units, hasLength(2)); 1636 expect(lib.units, hasLength(2));
1618 expect(unlinked.units[1].uri, 'part1.dart'); 1637 expect(definingUnit.unlinked.parts, hasLength(1));
1638 expect(definingUnit.unlinked.parts[0].uri, 'part1.dart');
1619 } 1639 }
1620 1640
1621 test_type_arguments_explicit() { 1641 test_type_arguments_explicit() {
1622 UnlinkedTypeRef typeRef = serializeTypeText('List<int>'); 1642 UnlinkedTypeRef typeRef = serializeTypeText('List<int>');
1623 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List', 1643 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List',
1624 allowTypeParameters: true); 1644 allowTypeParameters: true);
1625 expect(typeRef.typeArguments, hasLength(1)); 1645 expect(typeRef.typeArguments, hasLength(1));
1626 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int'); 1646 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int');
1627 } 1647 }
1628 1648
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 } 1698 }
1679 1699
1680 test_type_dynamic() { 1700 test_type_dynamic() {
1681 checkDynamicTypeRef(serializeTypeText('dynamic')); 1701 checkDynamicTypeRef(serializeTypeText('dynamic'));
1682 } 1702 }
1683 1703
1684 test_type_reference_to_class_argument() { 1704 test_type_reference_to_class_argument() {
1685 UnlinkedClass cls = serializeClassText('class C<T, U> { T t; U u; }'); 1705 UnlinkedClass cls = serializeClassText('class C<T, U> { T t; U u; }');
1686 { 1706 {
1687 UnlinkedTypeRef typeRef = 1707 UnlinkedTypeRef typeRef =
1688 findVariable('t', cls: cls, failIfAbsent: true).type; 1708 findVariable('t', variables: cls.fields, failIfAbsent: true).type;
1689 checkParamTypeRef(typeRef, 2); 1709 checkParamTypeRef(typeRef, 2);
1690 } 1710 }
1691 { 1711 {
1692 UnlinkedTypeRef typeRef = 1712 UnlinkedTypeRef typeRef =
1693 findVariable('u', cls: cls, failIfAbsent: true).type; 1713 findVariable('u', variables: cls.fields, failIfAbsent: true).type;
1694 checkParamTypeRef(typeRef, 1); 1714 checkParamTypeRef(typeRef, 1);
1695 } 1715 }
1696 } 1716 }
1697 1717
1698 test_type_reference_to_import_of_export() { 1718 test_type_reference_to_import_of_export() {
1699 addNamedSource('/a.dart', 'library a; export "b.dart";'); 1719 addNamedSource('/a.dart', 'library a; export "b.dart";');
1700 addNamedSource('/b.dart', 'library b; class C {}'); 1720 addNamedSource('/b.dart', 'library b; class C {}');
1701 checkTypeRef(serializeTypeText('C', otherDeclarations: 'import "a.dart";'), 1721 checkTypeRef(serializeTypeText('C', otherDeclarations: 'import "a.dart";'),
1702 absUri('/b.dart'), 'b.dart', 'C'); 1722 absUri('/b.dart'), 'b.dart', 'C');
1703 } 1723 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 } 1813 }
1794 1814
1795 test_type_unresolved() { 1815 test_type_unresolved() {
1796 UnlinkedTypeRef typeRef = serializeTypeText('Foo', allowErrors: true); 1816 UnlinkedTypeRef typeRef = serializeTypeText('Foo', allowErrors: true);
1797 checkUnresolvedTypeRef(typeRef, null, 'Foo'); 1817 checkUnresolvedTypeRef(typeRef, null, 'Foo');
1798 } 1818 }
1799 1819
1800 test_typedef_name() { 1820 test_typedef_name() {
1801 UnlinkedTypedef type = serializeTypedefText('typedef F();'); 1821 UnlinkedTypedef type = serializeTypedefText('typedef F();');
1802 expect(type.name, 'F'); 1822 expect(type.name, 'F');
1803 expect(type.unit, 0);
1804 } 1823 }
1805 1824
1806 test_typedef_param_none() { 1825 test_typedef_param_none() {
1807 UnlinkedTypedef type = serializeTypedefText('typedef F();'); 1826 UnlinkedTypedef type = serializeTypedefText('typedef F();');
1808 expect(type.parameters, isEmpty); 1827 expect(type.parameters, isEmpty);
1809 } 1828 }
1810 1829
1811 test_typedef_param_order() { 1830 test_typedef_param_order() {
1812 UnlinkedTypedef type = serializeTypedefText('typedef F(x, y);'); 1831 UnlinkedTypedef type = serializeTypedefText('typedef F(x, y);');
1813 expect(type.parameters, hasLength(2)); 1832 expect(type.parameters, hasLength(2));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 test_variable_implicit_dynamic() { 1888 test_variable_implicit_dynamic() {
1870 UnlinkedVariable variable = serializeVariableText('var v;'); 1889 UnlinkedVariable variable = serializeVariableText('var v;');
1871 checkDynamicTypeRef(variable.type); 1890 checkDynamicTypeRef(variable.type);
1872 expect(variable.hasImplicitType, isTrue); 1891 expect(variable.hasImplicitType, isTrue);
1873 } 1892 }
1874 1893
1875 test_variable_name() { 1894 test_variable_name() {
1876 UnlinkedVariable variable = 1895 UnlinkedVariable variable =
1877 serializeVariableText('int i;', variableName: 'i'); 1896 serializeVariableText('int i;', variableName: 'i');
1878 expect(variable.name, 'i'); 1897 expect(variable.name, 'i');
1879 expect(variable.unit, 0);
1880 } 1898 }
1881 1899
1882 test_variable_no_flags() { 1900 test_variable_no_flags() {
1883 UnlinkedVariable variable = 1901 UnlinkedVariable variable =
1884 serializeVariableText('int i;', variableName: 'i'); 1902 serializeVariableText('int i;', variableName: 'i');
1885 expect(variable.isStatic, isFalse); 1903 expect(variable.isStatic, isFalse);
1886 expect(variable.isConst, isFalse); 1904 expect(variable.isConst, isFalse);
1887 expect(variable.isFinal, isFalse); 1905 expect(variable.isFinal, isFalse);
1888 } 1906 }
1889 1907
(...skipping 27 matching lines...) Expand all
1917 serializeClassText('class C { static int i; }').fields[0]; 1935 serializeClassText('class C { static int i; }').fields[0];
1918 expect(variable.isStatic, isTrue); 1936 expect(variable.isStatic, isTrue);
1919 } 1937 }
1920 1938
1921 test_variable_type() { 1939 test_variable_type() {
1922 UnlinkedVariable variable = 1940 UnlinkedVariable variable =
1923 serializeVariableText('int i;', variableName: 'i'); 1941 serializeVariableText('int i;', variableName: 'i');
1924 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); 1942 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int');
1925 } 1943 }
1926 } 1944 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698