| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.generated.resolver_test_case; | 5 library analyzer.test.generated.resolver_test_case; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/visitor.dart'; | 8 import 'package:analyzer/dart/ast/visitor.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| 11 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 11 import 'package:analyzer/src/dart/element/element.dart'; | 12 import 'package:analyzer/src/dart/element/element.dart'; |
| 12 import 'package:analyzer/src/dart/element/type.dart'; | 13 import 'package:analyzer/src/dart/element/type.dart'; |
| 13 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 14 import 'package:analyzer/src/generated/error.dart'; | 15 import 'package:analyzer/src/generated/error.dart'; |
| 15 import 'package:analyzer/src/generated/java_core.dart'; | 16 import 'package:analyzer/src/generated/java_core.dart'; |
| 16 import 'package:analyzer/src/generated/java_engine.dart'; | 17 import 'package:analyzer/src/generated/java_engine.dart'; |
| 17 import 'package:analyzer/src/generated/java_engine_io.dart'; | |
| 18 import 'package:analyzer/src/generated/resolver.dart'; | 18 import 'package:analyzer/src/generated/resolver.dart'; |
| 19 import 'package:analyzer/src/generated/source_io.dart'; | 19 import 'package:analyzer/src/generated/source_io.dart'; |
| 20 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 20 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 21 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 21 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 22 import 'package:unittest/unittest.dart'; | 22 import 'package:unittest/unittest.dart'; |
| 23 | 23 |
| 24 import 'analysis_context_factory.dart'; | 24 import 'analysis_context_factory.dart'; |
| 25 import 'test_support.dart'; | 25 import 'test_support.dart'; |
| 26 | 26 |
| 27 /** | 27 /** |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 void assertTypeOfMarkedExpression(String code, DartType expectedStaticType, | 466 void assertTypeOfMarkedExpression(String code, DartType expectedStaticType, |
| 467 DartType expectedPropagatedType) { | 467 DartType expectedPropagatedType) { |
| 468 SimpleIdentifier identifier = findMarkedIdentifier(code, "; // marker"); | 468 SimpleIdentifier identifier = findMarkedIdentifier(code, "; // marker"); |
| 469 if (expectedStaticType != null) { | 469 if (expectedStaticType != null) { |
| 470 expect(identifier.staticType, expectedStaticType); | 470 expect(identifier.staticType, expectedStaticType); |
| 471 } | 471 } |
| 472 expect(identifier.propagatedType, expectedPropagatedType); | 472 expect(identifier.propagatedType, expectedPropagatedType); |
| 473 } | 473 } |
| 474 | 474 |
| 475 /** | 475 /** |
| 476 * Cache the source file content in the source factory but don't add the sourc
e to the analysis | 476 * Cache the [contents] for the file at the given [filePath] but don't add the |
| 477 * context. The file path should be absolute. | 477 * source to the analysis context. The file path must be absolute. |
| 478 * | |
| 479 * @param filePath the path of the file being cached | |
| 480 * @param contents the contents to be returned by the content provider for the
specified file | |
| 481 * @return the source object representing the cached file | |
| 482 */ | 478 */ |
| 483 Source cacheSource(String filePath, String contents) { | 479 Source cacheSource(String filePath, String contents) { |
| 484 Source source = new FileBasedSource(FileUtilities2.createFile(filePath)); | 480 Source source = |
| 481 PhysicalResourceProvider.INSTANCE.getFile(filePath).createSource(); |
| 485 analysisContext2.setContents(source, contents); | 482 analysisContext2.setContents(source, contents); |
| 486 return source; | 483 return source; |
| 487 } | 484 } |
| 488 | 485 |
| 489 /** | 486 /** |
| 490 * Change the contents of the given [source] to the given [contents]. | 487 * Change the contents of the given [source] to the given [contents]. |
| 491 */ | 488 */ |
| 492 void changeSource(Source source, String contents) { | 489 void changeSource(Source source, String contents) { |
| 493 analysisContext2.setContents(source, contents); | 490 analysisContext2.setContents(source, contents); |
| 494 ChangeSet changeSet = new ChangeSet(); | 491 ChangeSet changeSet = new ChangeSet(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 511 * | 508 * |
| 512 * @return the library element that was created | 509 * @return the library element that was created |
| 513 */ | 510 */ |
| 514 LibraryElementImpl createDefaultTestLibrary() => | 511 LibraryElementImpl createDefaultTestLibrary() => |
| 515 createTestLibrary(AnalysisContextFactory.contextWithCore(), "test"); | 512 createTestLibrary(AnalysisContextFactory.contextWithCore(), "test"); |
| 516 | 513 |
| 517 /** | 514 /** |
| 518 * Create a source object representing a file with the given [fileName] and | 515 * Create a source object representing a file with the given [fileName] and |
| 519 * give it an empty content. Return the source that was created. | 516 * give it an empty content. Return the source that was created. |
| 520 */ | 517 */ |
| 521 FileBasedSource createNamedSource(String fileName) { | 518 Source createNamedSource(String fileName) { |
| 522 FileBasedSource source = | 519 Source source = |
| 523 new FileBasedSource(FileUtilities2.createFile(fileName)); | 520 PhysicalResourceProvider.INSTANCE.getFile(fileName).createSource(); |
| 524 analysisContext2.setContents(source, ""); | 521 analysisContext2.setContents(source, ''); |
| 525 return source; | 522 return source; |
| 526 } | 523 } |
| 527 | 524 |
| 528 /** | 525 /** |
| 529 * Create a library element that represents a library with the given name cont
aining a single | 526 * Create a library element that represents a library with the given name cont
aining a single |
| 530 * empty compilation unit. | 527 * empty compilation unit. |
| 531 * | 528 * |
| 532 * @param libraryName the name of the library to be created | 529 * @param libraryName the name of the library to be created |
| 533 * @return the library element that was created | 530 * @return the library element that was created |
| 534 */ | 531 */ |
| 535 LibraryElementImpl createTestLibrary( | 532 LibraryElementImpl createTestLibrary( |
| 536 AnalysisContext context, String libraryName, | 533 AnalysisContext context, String libraryName, |
| 537 [List<String> typeNames]) { | 534 [List<String> typeNames]) { |
| 538 String fileName = "$libraryName.dart"; | 535 String fileName = "/test/$libraryName.dart"; |
| 539 FileBasedSource definingCompilationUnitSource = createNamedSource(fileName); | 536 Source definingCompilationUnitSource = createNamedSource(fileName); |
| 540 List<CompilationUnitElement> sourcedCompilationUnits; | 537 List<CompilationUnitElement> sourcedCompilationUnits; |
| 541 if (typeNames == null) { | 538 if (typeNames == null) { |
| 542 sourcedCompilationUnits = CompilationUnitElement.EMPTY_LIST; | 539 sourcedCompilationUnits = CompilationUnitElement.EMPTY_LIST; |
| 543 } else { | 540 } else { |
| 544 int count = typeNames.length; | 541 int count = typeNames.length; |
| 545 sourcedCompilationUnits = new List<CompilationUnitElement>(count); | 542 sourcedCompilationUnits = new List<CompilationUnitElement>(count); |
| 546 for (int i = 0; i < count; i++) { | 543 for (int i = 0; i < count; i++) { |
| 547 String typeName = typeNames[i]; | 544 String typeName = typeNames[i]; |
| 548 ClassElementImpl type = | 545 ClassElementImpl type = |
| 549 new ClassElementImpl.forNode(AstFactory.identifier3(typeName)); | 546 new ClassElementImpl.forNode(AstFactory.identifier3(typeName)); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 String typeArgs: '[]', | 754 String typeArgs: '[]', |
| 758 String typeFormals: '[]'}) { | 755 String typeFormals: '[]'}) { |
| 759 typeParameters(Element element) { | 756 typeParameters(Element element) { |
| 760 if (element is ExecutableElement) { | 757 if (element is ExecutableElement) { |
| 761 return element.typeParameters; | 758 return element.typeParameters; |
| 762 } else if (element is ParameterElement) { | 759 } else if (element is ParameterElement) { |
| 763 return element.typeParameters; | 760 return element.typeParameters; |
| 764 } | 761 } |
| 765 fail('Wrong element type: ${element.runtimeType}'); | 762 fail('Wrong element type: ${element.runtimeType}'); |
| 766 } | 763 } |
| 764 |
| 767 SimpleIdentifier identifier = findIdentifier(name); | 765 SimpleIdentifier identifier = findIdentifier(name); |
| 768 // Element is either ExecutableElement or ParameterElement. | 766 // Element is either ExecutableElement or ParameterElement. |
| 769 Element element = identifier.staticElement; | 767 Element element = identifier.staticElement; |
| 770 FunctionTypeImpl functionType = identifier.staticType; | 768 FunctionTypeImpl functionType = identifier.staticType; |
| 771 expect(functionType.toString(), type); | 769 expect(functionType.toString(), type); |
| 772 expect(typeParameters(element).toString(), elementTypeParams); | 770 expect(typeParameters(element).toString(), elementTypeParams); |
| 773 expect(functionType.typeParameters.toString(), typeParams); | 771 expect(functionType.typeParameters.toString(), typeParams); |
| 774 expect(functionType.typeArguments.toString(), typeArgs); | 772 expect(functionType.typeArguments.toString(), typeArgs); |
| 775 expect(functionType.typeFormals.toString(), typeFormals); | 773 expect(functionType.typeFormals.toString(), typeFormals); |
| 776 } | 774 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 * text. Otherwise, [expected] is used directly a [Matcher] to match the type. | 835 * text. Otherwise, [expected] is used directly a [Matcher] to match the type. |
| 838 */ | 836 */ |
| 839 _expectType(DartType type, expected) { | 837 _expectType(DartType type, expected) { |
| 840 if (expected is String) { | 838 if (expected is String) { |
| 841 expect(type.toString(), expected); | 839 expect(type.toString(), expected); |
| 842 } else { | 840 } else { |
| 843 expect(type, expected); | 841 expect(type, expected); |
| 844 } | 842 } |
| 845 } | 843 } |
| 846 } | 844 } |
| OLD | NEW |