| 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_common; | 5 library analyzer.test.src.summary.summary_common; |
| 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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 void checkInferredTypeSlot( | 320 void checkInferredTypeSlot( |
| 321 int slotId, String absoluteUri, String relativeUri, String expectedName, | 321 int slotId, String absoluteUri, String relativeUri, String expectedName, |
| 322 {bool allowTypeParameters: false, | 322 {bool allowTypeParameters: false, |
| 323 ReferenceKind expectedKind: ReferenceKind.classOrEnum, | 323 ReferenceKind expectedKind: ReferenceKind.classOrEnum, |
| 324 int expectedTargetUnit: 0, | 324 int expectedTargetUnit: 0, |
| 325 LinkedUnit linkedSourceUnit, | 325 LinkedUnit linkedSourceUnit, |
| 326 UnlinkedUnit unlinkedSourceUnit, | 326 UnlinkedUnit unlinkedSourceUnit, |
| 327 int numTypeParameters: 0}) { | 327 int numTypeParameters: 0}) { |
| 328 if (strongMode) { | 328 if (strongMode) { |
| 329 checkLinkedTypeSlot(slotId, absoluteUri, relativeUri, expectedName, | 329 checkLinkedTypeSlot(slotId, absoluteUri, relativeUri, expectedName, |
| 330 allowTypeParameters: allowTypeParameters, | 330 allowTypeArguments: allowTypeParameters, |
| 331 expectedKind: expectedKind, | 331 expectedKind: expectedKind, |
| 332 expectedTargetUnit: expectedTargetUnit, | 332 expectedTargetUnit: expectedTargetUnit, |
| 333 linkedSourceUnit: linkedSourceUnit, | 333 linkedSourceUnit: linkedSourceUnit, |
| 334 unlinkedSourceUnit: unlinkedSourceUnit, | 334 unlinkedSourceUnit: unlinkedSourceUnit, |
| 335 numTypeParameters: numTypeParameters); | 335 numTypeParameters: numTypeParameters); |
| 336 } else { | 336 } else { |
| 337 // A slot id should have been assigned but it should not be associated | 337 // A slot id should have been assigned but it should not be associated |
| 338 // with any type. | 338 // with any type. |
| 339 expect(slotId, isNot(0)); | 339 expect(slotId, isNot(0)); |
| 340 expect(getTypeRefForSlot(slotId, linkedSourceUnit: linkedSourceUnit), | 340 expect(getTypeRefForSlot(slotId, linkedSourceUnit: linkedSourceUnit), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 356 for (LinkedDependency dep in linked.dependencies) { | 356 for (LinkedDependency dep in linked.dependencies) { |
| 357 if (dep.uri == relativeUri) { | 357 if (dep.uri == relativeUri) { |
| 358 fail('Unexpected dependency found: $relativeUri'); | 358 fail('Unexpected dependency found: $relativeUri'); |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 } | 361 } |
| 362 | 362 |
| 363 /** | 363 /** |
| 364 * Verify that the given [typeRef] represents a reference to a type declared | 364 * Verify that the given [typeRef] represents a reference to a type declared |
| 365 * in a file reachable via [absoluteUri] and [relativeUri], having name | 365 * in a file reachable via [absoluteUri] and [relativeUri], having name |
| 366 * [expectedName]. If [allowTypeParameters] is true, allow the type | 366 * [expectedName]. If [allowTypeArguments] is true, allow the type |
| 367 * reference to supply type parameters. [expectedKind] is the kind of object | 367 * reference to supply type arguments. [expectedKind] is the kind of object |
| 368 * referenced. [linkedSourceUnit] and [unlinkedSourceUnit] refer to the | 368 * referenced. [linkedSourceUnit] and [unlinkedSourceUnit] refer to the |
| 369 * compilation unit within which the [typeRef] appears; if not specified they | 369 * compilation unit within which the [typeRef] appears; if not specified they |
| 370 * are assumed to refer to the defining compilation unit. | 370 * are assumed to refer to the defining compilation unit. |
| 371 * [expectedTargetUnit] is the index of the compilation unit in which the | 371 * [expectedTargetUnit] is the index of the compilation unit in which the |
| 372 * target of the [typeRef] is expected to appear; if not specified it is | 372 * target of the [typeRef] is expected to appear; if not specified it is |
| 373 * assumed to be the defining compilation unit. [numTypeParameters] is the | 373 * assumed to be the defining compilation unit. [numTypeParameters] is the |
| 374 * number of type parameters of the thing being referred to. | 374 * number of type parameters of the thing being referred to. |
| 375 */ | 375 */ |
| 376 void checkLinkedTypeRef(EntityRef typeRef, String absoluteUri, | 376 void checkLinkedTypeRef(EntityRef typeRef, String absoluteUri, |
| 377 String relativeUri, String expectedName, | 377 String relativeUri, String expectedName, |
| 378 {bool allowTypeParameters: false, | 378 {bool allowTypeArguments: false, |
| 379 ReferenceKind expectedKind: ReferenceKind.classOrEnum, | 379 ReferenceKind expectedKind: ReferenceKind.classOrEnum, |
| 380 int expectedTargetUnit: 0, | 380 int expectedTargetUnit: 0, |
| 381 LinkedUnit linkedSourceUnit, | 381 LinkedUnit linkedSourceUnit, |
| 382 UnlinkedUnit unlinkedSourceUnit, | 382 UnlinkedUnit unlinkedSourceUnit, |
| 383 int numTypeParameters: 0}) { | 383 int numTypeParameters: 0}) { |
| 384 linkedSourceUnit ??= definingUnit; | 384 linkedSourceUnit ??= definingUnit; |
| 385 expect(typeRef, isNotNull, | 385 expect(typeRef, isNotNull, |
| 386 reason: 'No entry in linkedSourceUnit.types matching slotId'); | 386 reason: 'No entry in linkedSourceUnit.types matching slotId'); |
| 387 expect(typeRef.paramReference, 0); | 387 expect(typeRef.paramReference, 0); |
| 388 int index = typeRef.reference; | 388 int index = typeRef.reference; |
| 389 if (!allowTypeParameters) { | 389 if (!allowTypeArguments) { |
| 390 expect(typeRef.typeArguments, isEmpty); | 390 expect(typeRef.typeArguments, isEmpty); |
| 391 } | 391 } |
| 392 checkReferenceIndex(index, absoluteUri, relativeUri, expectedName, | 392 checkReferenceIndex(index, absoluteUri, relativeUri, expectedName, |
| 393 expectedKind: expectedKind, | 393 expectedKind: expectedKind, |
| 394 expectedTargetUnit: expectedTargetUnit, | 394 expectedTargetUnit: expectedTargetUnit, |
| 395 linkedSourceUnit: linkedSourceUnit, | 395 linkedSourceUnit: linkedSourceUnit, |
| 396 unlinkedSourceUnit: unlinkedSourceUnit, | 396 unlinkedSourceUnit: unlinkedSourceUnit, |
| 397 numTypeParameters: numTypeParameters); | 397 numTypeParameters: numTypeParameters); |
| 398 } | 398 } |
| 399 | 399 |
| 400 /** | 400 /** |
| 401 * Verify that the given [slotId] represents a reference to a type declared | 401 * Verify that the given [slotId] represents a reference to a type declared |
| 402 * in a file reachable via [absoluteUri] and [relativeUri], having name | 402 * in a file reachable via [absoluteUri] and [relativeUri], having name |
| 403 * [expectedName]. If [allowTypeParameters] is true, allow the type | 403 * [expectedName]. If [allowTypeArguments] is true, allow the type |
| 404 * reference to supply type parameters. [expectedKind] is the kind of object | 404 * reference to supply type arguments. [expectedKind] is the kind of object |
| 405 * referenced. [linkedSourceUnit] and [unlinkedSourceUnit] refer to the | 405 * referenced. [linkedSourceUnit] and [unlinkedSourceUnit] refer to the |
| 406 * compilation unit within which the [typeRef] appears; if not specified they | 406 * compilation unit within which the [typeRef] appears; if not specified they |
| 407 * are assumed to refer to the defining compilation unit. | 407 * are assumed to refer to the defining compilation unit. |
| 408 * [expectedTargetUnit] is the index of the compilation unit in which the | 408 * [expectedTargetUnit] is the index of the compilation unit in which the |
| 409 * target of the [typeRef] is expected to appear; if not specified it is | 409 * target of the [typeRef] is expected to appear; if not specified it is |
| 410 * assumed to be the defining compilation unit. [numTypeParameters] is the | 410 * assumed to be the defining compilation unit. [numTypeParameters] is the |
| 411 * number of type parameters of the thing being referred to. | 411 * number of type parameters of the thing being referred to. |
| 412 */ | 412 */ |
| 413 void checkLinkedTypeSlot( | 413 void checkLinkedTypeSlot( |
| 414 int slotId, String absoluteUri, String relativeUri, String expectedName, | 414 int slotId, String absoluteUri, String relativeUri, String expectedName, |
| 415 {bool allowTypeParameters: false, | 415 {bool allowTypeArguments: false, |
| 416 ReferenceKind expectedKind: ReferenceKind.classOrEnum, | 416 ReferenceKind expectedKind: ReferenceKind.classOrEnum, |
| 417 int expectedTargetUnit: 0, | 417 int expectedTargetUnit: 0, |
| 418 LinkedUnit linkedSourceUnit, | 418 LinkedUnit linkedSourceUnit, |
| 419 UnlinkedUnit unlinkedSourceUnit, | 419 UnlinkedUnit unlinkedSourceUnit, |
| 420 int numTypeParameters: 0}) { | 420 int numTypeParameters: 0}) { |
| 421 // Slot ids should be nonzero, since zero means "no associated slot". | 421 // Slot ids should be nonzero, since zero means "no associated slot". |
| 422 expect(slotId, isNot(0)); | 422 expect(slotId, isNot(0)); |
| 423 if (skipFullyLinkedData) { | 423 if (skipFullyLinkedData) { |
| 424 return; | 424 return; |
| 425 } | 425 } |
| 426 linkedSourceUnit ??= definingUnit; | 426 linkedSourceUnit ??= definingUnit; |
| 427 checkLinkedTypeRef( | 427 checkLinkedTypeRef( |
| 428 getTypeRefForSlot(slotId, linkedSourceUnit: linkedSourceUnit), | 428 getTypeRefForSlot(slotId, linkedSourceUnit: linkedSourceUnit), |
| 429 absoluteUri, | 429 absoluteUri, |
| 430 relativeUri, | 430 relativeUri, |
| 431 expectedName, | 431 expectedName, |
| 432 allowTypeParameters: allowTypeParameters, | 432 allowTypeArguments: allowTypeArguments, |
| 433 expectedKind: expectedKind, | 433 expectedKind: expectedKind, |
| 434 expectedTargetUnit: expectedTargetUnit, | 434 expectedTargetUnit: expectedTargetUnit, |
| 435 linkedSourceUnit: linkedSourceUnit, | 435 linkedSourceUnit: linkedSourceUnit, |
| 436 unlinkedSourceUnit: unlinkedSourceUnit, | 436 unlinkedSourceUnit: unlinkedSourceUnit, |
| 437 numTypeParameters: numTypeParameters); | 437 numTypeParameters: numTypeParameters); |
| 438 } | 438 } |
| 439 | 439 |
| 440 /** | 440 /** |
| 441 * Verify that the given [typeRef] represents a reference to a type parameter | 441 * Verify that the given [typeRef] represents a reference to a type parameter |
| 442 * having the given [deBruijnIndex]. | 442 * having the given [deBruijnIndex]. |
| (...skipping 4249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4692 if (!strongMode || skipFullyLinkedData) { | 4692 if (!strongMode || skipFullyLinkedData) { |
| 4693 return; | 4693 return; |
| 4694 } | 4694 } |
| 4695 UnlinkedClass cls = serializeClassText( | 4695 UnlinkedClass cls = serializeClassText( |
| 4696 'class C<T> extends D<int, T> { var v; }' | 4696 'class C<T> extends D<int, T> { var v; }' |
| 4697 ' abstract class D<U, V> { Map<V, U> get v; }', | 4697 ' abstract class D<U, V> { Map<V, U> get v; }', |
| 4698 className: 'C'); | 4698 className: 'C'); |
| 4699 EntityRef type = getTypeRefForSlot(cls.fields[0].inferredTypeSlot); | 4699 EntityRef type = getTypeRefForSlot(cls.fields[0].inferredTypeSlot); |
| 4700 // Check that v has inferred type Map<T, int>. | 4700 // Check that v has inferred type Map<T, int>. |
| 4701 checkLinkedTypeRef(type, 'dart:core', 'dart:core', 'Map', | 4701 checkLinkedTypeRef(type, 'dart:core', 'dart:core', 'Map', |
| 4702 allowTypeParameters: true, numTypeParameters: 2); | 4702 allowTypeArguments: true, numTypeParameters: 2); |
| 4703 checkParamTypeRef(type.typeArguments[0], 1); | 4703 checkParamTypeRef(type.typeArguments[0], 1); |
| 4704 checkLinkedTypeRef(type.typeArguments[1], 'dart:core', 'dart:core', 'int'); | 4704 checkLinkedTypeRef(type.typeArguments[1], 'dart:core', 'dart:core', 'int'); |
| 4705 } | 4705 } |
| 4706 | 4706 |
| 4707 test_inferred_type_refers_to_function_typed_parameter_type_generic_class() { | 4707 test_inferred_type_refers_to_function_typed_parameter_type_generic_class() { |
| 4708 if (!strongMode || skipFullyLinkedData) { | 4708 if (!strongMode || skipFullyLinkedData) { |
| 4709 return; | 4709 return; |
| 4710 } | 4710 } |
| 4711 UnlinkedClass cls = serializeClassText( | 4711 UnlinkedClass cls = serializeClassText( |
| 4712 'class C<T, U> extends D<U, int> { void f(int x, g) {} }' | 4712 'class C<T, U> extends D<U, int> { void f(int x, g) {} }' |
| (...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6013 greaterThanOrEqualTo(unlinkedUnits[0].references.length)); | 6013 greaterThanOrEqualTo(unlinkedUnits[0].references.length)); |
| 6014 } | 6014 } |
| 6015 | 6015 |
| 6016 test_variable_propagated_type_omit_dynamic() { | 6016 test_variable_propagated_type_omit_dynamic() { |
| 6017 if (skipFullyLinkedData) { | 6017 if (skipFullyLinkedData) { |
| 6018 return; | 6018 return; |
| 6019 } | 6019 } |
| 6020 UnlinkedVariable v = serializeVariableText('final v = <int, dynamic>{};'); | 6020 UnlinkedVariable v = serializeVariableText('final v = <int, dynamic>{};'); |
| 6021 EntityRef type = getTypeRefForSlot(v.propagatedTypeSlot); | 6021 EntityRef type = getTypeRefForSlot(v.propagatedTypeSlot); |
| 6022 checkLinkedTypeRef(type, 'dart:core', 'dart:core', 'Map', | 6022 checkLinkedTypeRef(type, 'dart:core', 'dart:core', 'Map', |
| 6023 allowTypeParameters: true, numTypeParameters: 2); | 6023 allowTypeArguments: true, numTypeParameters: 2); |
| 6024 expect(type.typeArguments, hasLength(1)); | 6024 expect(type.typeArguments, hasLength(1)); |
| 6025 checkLinkedTypeRef(type.typeArguments[0], 'dart:core', 'dart:core', 'int'); | 6025 checkLinkedTypeRef(type.typeArguments[0], 'dart:core', 'dart:core', 'int'); |
| 6026 } | 6026 } |
| 6027 | 6027 |
| 6028 test_variable_propagatedTypeSlot_const() { | 6028 test_variable_propagatedTypeSlot_const() { |
| 6029 // Const variables are propagable so they have a nonzero | 6029 // Const variables are propagable so they have a nonzero |
| 6030 // propagatedTypeSlot. | 6030 // propagatedTypeSlot. |
| 6031 UnlinkedVariable variable = serializeVariableText('const v = 0;'); | 6031 UnlinkedVariable variable = serializeVariableText('const v = 0;'); |
| 6032 expect(variable.propagatedTypeSlot, isNot(0)); | 6032 expect(variable.propagatedTypeSlot, isNot(0)); |
| 6033 } | 6033 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6125 final String absoluteUri; | 6125 final String absoluteUri; |
| 6126 final String relativeUri; | 6126 final String relativeUri; |
| 6127 final int numTypeParameters; | 6127 final int numTypeParameters; |
| 6128 | 6128 |
| 6129 _PrefixExpectation(this.kind, this.name, | 6129 _PrefixExpectation(this.kind, this.name, |
| 6130 {this.inLibraryDefiningUnit: false, | 6130 {this.inLibraryDefiningUnit: false, |
| 6131 this.absoluteUri, | 6131 this.absoluteUri, |
| 6132 this.relativeUri, | 6132 this.relativeUri, |
| 6133 this.numTypeParameters: 0}); | 6133 this.numTypeParameters: 0}); |
| 6134 } | 6134 } |
| OLD | NEW |