| OLD | NEW |
| 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/dart/element/element.dart'; | 7 import 'package:analyzer/dart/element/element.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/error.dart'; | 10 import 'package:analyzer/src/generated/error.dart'; |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 checkDependency(referenceResolution.dependency, absoluteUri, relativeUri); | 361 checkDependency(referenceResolution.dependency, absoluteUri, relativeUri); |
| 362 } | 362 } |
| 363 if (!allowTypeParameters) { | 363 if (!allowTypeParameters) { |
| 364 expect(typeRef.typeArguments, isEmpty); | 364 expect(typeRef.typeArguments, isEmpty); |
| 365 } | 365 } |
| 366 if (expectedName == null) { | 366 if (expectedName == null) { |
| 367 expect(reference.name, isEmpty); | 367 expect(reference.name, isEmpty); |
| 368 } else { | 368 } else { |
| 369 expect(reference.name, expectedName); | 369 expect(reference.name, expectedName); |
| 370 } | 370 } |
| 371 if (checkAstDerivedData) { | 371 if (expectedPrefix == null) { |
| 372 if (expectedPrefix == null) { | 372 expect(reference.prefixReference, 0); |
| 373 expect(reference.prefixReference, 0); | 373 } else { |
| 374 } else { | 374 checkPrefix(reference.prefixReference, expectedPrefix); |
| 375 checkPrefix(reference.prefixReference, expectedPrefix); | |
| 376 } | |
| 377 } | 375 } |
| 378 expect(referenceResolution.kind, expectedKind); | 376 expect(referenceResolution.kind, expectedKind); |
| 379 expect(referenceResolution.unit, expectedTargetUnit); | 377 expect(referenceResolution.unit, expectedTargetUnit); |
| 380 expect(referenceResolution.numTypeParameters, numTypeParameters); | 378 expect(referenceResolution.numTypeParameters, numTypeParameters); |
| 381 } | 379 } |
| 382 | 380 |
| 383 /** | 381 /** |
| 384 * Verify that the given [typeRef] represents a reference to an unresolved | 382 * Verify that the given [typeRef] represents a reference to an unresolved |
| 385 * type. | 383 * type. |
| 386 */ | 384 */ |
| (...skipping 25 matching lines...) Expand all Loading... |
| 412 // the element model, so we can't pass this test. | 410 // the element model, so we can't pass this test. |
| 413 // Unresolved imports are included since this is necessary for proper | 411 // Unresolved imports are included since this is necessary for proper |
| 414 // dependency tracking. | 412 // dependency tracking. |
| 415 serializeLibraryText('import "foo.dart";', allowErrors: true); | 413 serializeLibraryText('import "foo.dart";', allowErrors: true); |
| 416 // Second import is the implicit import of dart:core | 414 // Second import is the implicit import of dart:core |
| 417 expect(unlinkedUnits[0].imports, hasLength(2)); | 415 expect(unlinkedUnits[0].imports, hasLength(2)); |
| 418 checkDependency( | 416 checkDependency( |
| 419 prelinked.importDependencies[0], absUri('/foo.dart'), 'foo.dart'); | 417 prelinked.importDependencies[0], absUri('/foo.dart'), 'foo.dart'); |
| 420 } | 418 } |
| 421 | 419 |
| 420 fail_type_reference_to_nonexistent_file_via_prefix() { |
| 421 // TODO(paulberry): this test currently fails because there is not enough |
| 422 // information in the element model to figure out that the unresolved |
| 423 // reference `p.C` uses the prefix `p`. |
| 424 UnlinkedTypeRef typeRef = serializeTypeText('p.C', |
| 425 otherDeclarations: 'import "foo.dart" as p;', allowErrors: true); |
| 426 checkUnresolvedTypeRef(typeRef, 'p', 'C'); |
| 427 } |
| 428 |
| 429 fail_type_reference_to_type_visible_via_multiple_import_prefixes() { |
| 430 // TODO(paulberry): this test currently fails because the element model |
| 431 // doesn't record enough information to track which prefix is used to refer |
| 432 // to a type. |
| 433 addNamedSource('/lib1.dart', 'class C'); |
| 434 addNamedSource('/lib2.dart', 'export "lib1.dart";'); |
| 435 addNamedSource('/lib3.dart', 'export "lib1.dart";'); |
| 436 addNamedSource('/lib4.dart', 'export "lib1.dart";'); |
| 437 serializeLibraryText(''' |
| 438 import 'lib2.dart'; |
| 439 import 'lib3.dart' as a; |
| 440 import 'lib4.dart' as b; |
| 441 C c2; |
| 442 a.C c3; |
| 443 b.C c4;'''); |
| 444 // Note: it is important that each reference to class C records the prefix |
| 445 // used to find it; otherwise it's possible that relinking might produce an |
| 446 // incorrect result after a change to lib2.dart, lib3.dart, or lib4.dart. |
| 447 checkTypeRef( |
| 448 findVariable('c2').type, absUri('/lib1.dart'), 'lib1.dart', 'C'); |
| 449 checkTypeRef( |
| 450 findVariable('c3').type, absUri('/lib1.dart'), 'lib1.dart', 'C', |
| 451 expectedPrefix: 'a'); |
| 452 checkTypeRef( |
| 453 findVariable('c4').type, absUri('/lib1.dart'), 'lib1.dart', 'C', |
| 454 expectedPrefix: 'b'); |
| 455 } |
| 456 |
| 422 /** | 457 /** |
| 423 * Find the class with the given [className] in the summary, and return its | 458 * Find the class with the given [className] in the summary, and return its |
| 424 * [UnlinkedClass] data structure. If [unit] is not given, the class is | 459 * [UnlinkedClass] data structure. If [unit] is not given, the class is |
| 425 * looked for in the defining compilation unit. | 460 * looked for in the defining compilation unit. |
| 426 */ | 461 */ |
| 427 UnlinkedClass findClass(String className, | 462 UnlinkedClass findClass(String className, |
| 428 {bool failIfAbsent: false, UnlinkedUnit unit}) { | 463 {bool failIfAbsent: false, UnlinkedUnit unit}) { |
| 429 unit ??= unlinkedUnits[0]; | 464 unit ??= unlinkedUnits[0]; |
| 430 UnlinkedClass result; | 465 UnlinkedClass result; |
| 431 for (UnlinkedClass cls in unit.classes) { | 466 for (UnlinkedClass cls in unit.classes) { |
| (...skipping 1996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2428 addNamedSource('/a.dart', 'part of my.lib; class C {}'); | 2463 addNamedSource('/a.dart', 'part of my.lib; class C {}'); |
| 2429 checkTypeRef( | 2464 checkTypeRef( |
| 2430 serializeTypeText('C', | 2465 serializeTypeText('C', |
| 2431 otherDeclarations: 'library my.lib; part "a.dart";'), | 2466 otherDeclarations: 'library my.lib; part "a.dart";'), |
| 2432 null, | 2467 null, |
| 2433 null, | 2468 null, |
| 2434 'C', | 2469 'C', |
| 2435 expectedTargetUnit: 1); | 2470 expectedTargetUnit: 1); |
| 2436 } | 2471 } |
| 2437 | 2472 |
| 2438 test_type_reference_to_nonexistent_file_via_prefix() { | |
| 2439 UnlinkedTypeRef typeRef = serializeTypeText('p.C', | |
| 2440 otherDeclarations: 'import "foo.dart" as p;', allowErrors: true); | |
| 2441 checkUnresolvedTypeRef(typeRef, 'p', 'C'); | |
| 2442 } | |
| 2443 | |
| 2444 test_type_reference_to_part() { | 2473 test_type_reference_to_part() { |
| 2445 addNamedSource('/a.dart', 'part of foo; class C { C(); }'); | 2474 addNamedSource('/a.dart', 'part of foo; class C { C(); }'); |
| 2446 serializeLibraryText('library foo; part "a.dart"; C c;'); | 2475 serializeLibraryText('library foo; part "a.dart"; C c;'); |
| 2447 checkTypeRef(unlinkedUnits[0].variables.single.type, null, null, 'C', | 2476 checkTypeRef(unlinkedUnits[0].variables.single.type, null, null, 'C', |
| 2448 expectedKind: PrelinkedReferenceKind.classOrEnum, | 2477 expectedKind: PrelinkedReferenceKind.classOrEnum, |
| 2449 expectedTargetUnit: 1); | 2478 expectedTargetUnit: 1); |
| 2450 } | 2479 } |
| 2451 | 2480 |
| 2452 test_type_reference_to_typedef() { | 2481 test_type_reference_to_typedef() { |
| 2453 checkTypeRef(serializeTypeText('F', otherDeclarations: 'typedef void F();'), | 2482 checkTypeRef(serializeTypeText('F', otherDeclarations: 'typedef void F();'), |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2659 UnlinkedVariable variable = | 2688 UnlinkedVariable variable = |
| 2660 serializeVariableText('int i;', variableName: 'i'); | 2689 serializeVariableText('int i;', variableName: 'i'); |
| 2661 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); | 2690 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); |
| 2662 } | 2691 } |
| 2663 | 2692 |
| 2664 test_varible_private() { | 2693 test_varible_private() { |
| 2665 serializeVariableText('int _i;', variableName: '_i'); | 2694 serializeVariableText('int _i;', variableName: '_i'); |
| 2666 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); | 2695 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); |
| 2667 } | 2696 } |
| 2668 } | 2697 } |
| OLD | NEW |