| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 engine.resolver_test; | 5 library engine.resolver_test; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/context/context.dart' as newContext; | 9 import 'package:analyzer/src/context/context.dart' as newContext; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 _listener.assertNoErrors(); | 1295 _listener.assertNoErrors(); |
| 1296 } | 1296 } |
| 1297 | 1297 |
| 1298 void fail_visitRedirectingConstructorInvocation() { | 1298 void fail_visitRedirectingConstructorInvocation() { |
| 1299 fail("Not yet tested"); | 1299 fail("Not yet tested"); |
| 1300 _listener.assertNoErrors(); | 1300 _listener.assertNoErrors(); |
| 1301 } | 1301 } |
| 1302 | 1302 |
| 1303 @override | 1303 @override |
| 1304 void setUp() { | 1304 void setUp() { |
| 1305 super.setUp(); |
| 1305 _listener = new GatheringErrorListener(); | 1306 _listener = new GatheringErrorListener(); |
| 1306 _typeProvider = new TestTypeProvider(); | 1307 _typeProvider = new TestTypeProvider(); |
| 1307 _resolver = _createResolver(); | 1308 _resolver = _createResolver(); |
| 1308 } | 1309 } |
| 1309 | 1310 |
| 1310 void test_lookUpMethodInInterfaces() { | 1311 void test_lookUpMethodInInterfaces() { |
| 1311 InterfaceType intType = _typeProvider.intType; | 1312 InterfaceType intType = _typeProvider.intType; |
| 1312 // | 1313 // |
| 1313 // abstract class A { int operator[](int index); } | 1314 // abstract class A { int operator[](int index); } |
| 1314 // | 1315 // |
| (...skipping 3518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4833 } | 4834 } |
| 4834 }'''); | 4835 }'''); |
| 4835 computeLibrarySourceErrors(source); | 4836 computeLibrarySourceErrors(source); |
| 4836 assertErrors( | 4837 assertErrors( |
| 4837 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); | 4838 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); |
| 4838 verify([source]); | 4839 verify([source]); |
| 4839 } | 4840 } |
| 4840 } | 4841 } |
| 4841 | 4842 |
| 4842 @reflectiveTest | 4843 @reflectiveTest |
| 4843 class InheritanceManagerTest extends EngineTestCase { | 4844 class InheritanceManagerTest { |
| 4844 /** | 4845 /** |
| 4845 * The type provider used to access the types. | 4846 * The type provider used to access the types. |
| 4846 */ | 4847 */ |
| 4847 TestTypeProvider _typeProvider; | 4848 TestTypeProvider _typeProvider; |
| 4848 | 4849 |
| 4849 /** | 4850 /** |
| 4850 * The library containing the code being resolved. | 4851 * The library containing the code being resolved. |
| 4851 */ | 4852 */ |
| 4852 LibraryElementImpl _definingLibrary; | 4853 LibraryElementImpl _definingLibrary; |
| 4853 | 4854 |
| 4854 /** | 4855 /** |
| 4855 * The inheritance manager being tested. | 4856 * The inheritance manager being tested. |
| 4856 */ | 4857 */ |
| 4857 InheritanceManager _inheritanceManager; | 4858 InheritanceManager _inheritanceManager; |
| 4858 | 4859 |
| 4859 /** | 4860 /** |
| 4860 * The number of members that Object implements (as determined by [TestTypePro
vider]). | 4861 * The number of members that Object implements (as determined by [TestTypePro
vider]). |
| 4861 */ | 4862 */ |
| 4862 int _numOfMembersInObject = 0; | 4863 int _numOfMembersInObject = 0; |
| 4863 | 4864 |
| 4864 @override | |
| 4865 void setUp() { | 4865 void setUp() { |
| 4866 _typeProvider = new TestTypeProvider(); | 4866 _typeProvider = new TestTypeProvider(); |
| 4867 _inheritanceManager = _createInheritanceManager(); | 4867 _inheritanceManager = _createInheritanceManager(); |
| 4868 InterfaceType objectType = _typeProvider.objectType; | 4868 InterfaceType objectType = _typeProvider.objectType; |
| 4869 _numOfMembersInObject = | 4869 _numOfMembersInObject = |
| 4870 objectType.methods.length + objectType.accessors.length; | 4870 objectType.methods.length + objectType.accessors.length; |
| 4871 } | 4871 } |
| 4872 | 4872 |
| 4873 void test_getMapOfMembersInheritedFromClasses_accessor_extends() { | 4873 void test_getMapOfMembersInheritedFromClasses_accessor_extends() { |
| 4874 // class A { int get g; } | 4874 // class A { int get g; } |
| (...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6058 new CompilationUnitElementImpl("test.dart"); | 6058 new CompilationUnitElementImpl("test.dart"); |
| 6059 definingCompilationUnit.librarySource = | 6059 definingCompilationUnit.librarySource = |
| 6060 definingCompilationUnit.source = source; | 6060 definingCompilationUnit.source = source; |
| 6061 _definingLibrary = ElementFactory.library(context, "test"); | 6061 _definingLibrary = ElementFactory.library(context, "test"); |
| 6062 _definingLibrary.definingCompilationUnit = definingCompilationUnit; | 6062 _definingLibrary.definingCompilationUnit = definingCompilationUnit; |
| 6063 return new InheritanceManager(_definingLibrary); | 6063 return new InheritanceManager(_definingLibrary); |
| 6064 } | 6064 } |
| 6065 } | 6065 } |
| 6066 | 6066 |
| 6067 @reflectiveTest | 6067 @reflectiveTest |
| 6068 class LibraryElementBuilderTest extends EngineTestCase { | 6068 class LibraryElementBuilderTest { |
| 6069 /** | 6069 /** |
| 6070 * The analysis context used to analyze sources. | 6070 * The analysis context used to analyze sources. |
| 6071 */ | 6071 */ |
| 6072 InternalAnalysisContext _context; | 6072 InternalAnalysisContext _context; |
| 6073 | 6073 |
| 6074 /** | 6074 /** |
| 6075 * Add a source file to the content provider. The file path should be absolute
. | 6075 * Add a source file to the content provider. The file path should be absolute
. |
| 6076 * | 6076 * |
| 6077 * @param filePath the path of the file being added | 6077 * @param filePath the path of the file being added |
| 6078 * @param contents the contents to be returned by the content provider for the
specified file | 6078 * @param contents the contents to be returned by the content provider for the
specified file |
| 6079 * @return the source object representing the added file | 6079 * @return the source object representing the added file |
| 6080 */ | 6080 */ |
| 6081 Source addSource(String filePath, String contents) { | 6081 Source addSource(String filePath, String contents) { |
| 6082 Source source = new FileBasedSource(FileUtilities2.createFile(filePath)); | 6082 Source source = new FileBasedSource(FileUtilities2.createFile(filePath)); |
| 6083 _context.setContents(source, contents); | 6083 _context.setContents(source, contents); |
| 6084 return source; | 6084 return source; |
| 6085 } | 6085 } |
| 6086 | 6086 |
| 6087 @override | |
| 6088 void setUp() { | 6087 void setUp() { |
| 6089 _context = AnalysisContextFactory.contextWithCore(); | 6088 _context = AnalysisContextFactory.contextWithCore(); |
| 6090 } | 6089 } |
| 6091 | 6090 |
| 6092 @override | |
| 6093 void tearDown() { | 6091 void tearDown() { |
| 6094 _context = null; | 6092 _context = null; |
| 6095 super.tearDown(); | |
| 6096 } | 6093 } |
| 6097 | 6094 |
| 6098 void test_accessorsAcrossFiles() { | 6095 void test_accessorsAcrossFiles() { |
| 6099 Source librarySource = addSource( | 6096 Source librarySource = addSource( |
| 6100 "/lib.dart", | 6097 "/lib.dart", |
| 6101 r''' | 6098 r''' |
| 6102 library lib; | 6099 library lib; |
| 6103 part 'first.dart'; | 6100 part 'first.dart'; |
| 6104 part 'second.dart';'''); | 6101 part 'second.dart';'''); |
| 6105 addSource( | 6102 addSource( |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6583 | 6580 |
| 6584 void test_getErrorListener() { | 6581 void test_getErrorListener() { |
| 6585 LibraryElement definingLibrary = createDefaultTestLibrary(); | 6582 LibraryElement definingLibrary = createDefaultTestLibrary(); |
| 6586 GatheringErrorListener errorListener = new GatheringErrorListener(); | 6583 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 6587 LibraryScope scope = new LibraryScope(definingLibrary, errorListener); | 6584 LibraryScope scope = new LibraryScope(definingLibrary, errorListener); |
| 6588 expect(scope.errorListener, errorListener); | 6585 expect(scope.errorListener, errorListener); |
| 6589 } | 6586 } |
| 6590 } | 6587 } |
| 6591 | 6588 |
| 6592 @reflectiveTest | 6589 @reflectiveTest |
| 6593 class LibraryTest extends EngineTestCase { | 6590 class LibraryTest { |
| 6594 /** | 6591 /** |
| 6595 * The error listener to which all errors will be reported. | 6592 * The error listener to which all errors will be reported. |
| 6596 */ | 6593 */ |
| 6597 GatheringErrorListener _errorListener; | 6594 GatheringErrorListener _errorListener; |
| 6598 | 6595 |
| 6599 /** | 6596 /** |
| 6600 * The analysis context to pass in to all libraries created by the tests. | 6597 * The analysis context to pass in to all libraries created by the tests. |
| 6601 */ | 6598 */ |
| 6602 InternalAnalysisContext _analysisContext; | 6599 InternalAnalysisContext _analysisContext; |
| 6603 | 6600 |
| 6604 /** | 6601 /** |
| 6605 * The library used by the tests. | 6602 * The library used by the tests. |
| 6606 */ | 6603 */ |
| 6607 Library _library; | 6604 Library _library; |
| 6608 | 6605 |
| 6609 @override | |
| 6610 void setUp() { | 6606 void setUp() { |
| 6611 _analysisContext = AnalysisContextFactory.contextWithCore(); | 6607 _analysisContext = AnalysisContextFactory.contextWithCore(); |
| 6612 _errorListener = new GatheringErrorListener(); | 6608 _errorListener = new GatheringErrorListener(); |
| 6613 _library = _createLibrary("/lib.dart"); | 6609 _library = _createLibrary("/lib.dart"); |
| 6614 } | 6610 } |
| 6615 | 6611 |
| 6616 @override | |
| 6617 void tearDown() { | 6612 void tearDown() { |
| 6618 _errorListener = null; | 6613 _errorListener = null; |
| 6619 _analysisContext = null; | 6614 _analysisContext = null; |
| 6620 _library = null; | 6615 _library = null; |
| 6621 super.tearDown(); | |
| 6622 } | 6616 } |
| 6623 | 6617 |
| 6624 void test_getExplicitlyImportsCore() { | 6618 void test_getExplicitlyImportsCore() { |
| 6625 expect(_library.explicitlyImportsCore, isFalse); | 6619 expect(_library.explicitlyImportsCore, isFalse); |
| 6626 _errorListener.assertNoErrors(); | 6620 _errorListener.assertNoErrors(); |
| 6627 } | 6621 } |
| 6628 | 6622 |
| 6629 void test_getExports() { | 6623 void test_getExports() { |
| 6630 expect(_library.exports, hasLength(0)); | 6624 expect(_library.exports, hasLength(0)); |
| 6631 _errorListener.assertNoErrors(); | 6625 _errorListener.assertNoErrors(); |
| (...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8419 | 8413 |
| 8420 void resolveWithErrors(List<String> strSources, List<ErrorCode> codes) { | 8414 void resolveWithErrors(List<String> strSources, List<ErrorCode> codes) { |
| 8421 // Analysis and assertions | 8415 // Analysis and assertions |
| 8422 Source source = resolveSources(strSources); | 8416 Source source = resolveSources(strSources); |
| 8423 assertErrors(source, codes); | 8417 assertErrors(source, codes); |
| 8424 verify([source]); | 8418 verify([source]); |
| 8425 } | 8419 } |
| 8426 | 8420 |
| 8427 @override | 8421 @override |
| 8428 void setUp() { | 8422 void setUp() { |
| 8423 super.setUp(); |
| 8429 reset(); | 8424 reset(); |
| 8430 } | 8425 } |
| 8431 | 8426 |
| 8432 @override | 8427 @override |
| 8433 void tearDown() { | 8428 void tearDown() { |
| 8434 analysisContext2 = null; | 8429 analysisContext2 = null; |
| 8435 super.tearDown(); | 8430 super.tearDown(); |
| 8436 } | 8431 } |
| 8437 | 8432 |
| 8438 /** | 8433 /** |
| (...skipping 1916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10355 _listener.assertNoErrors(); | 10350 _listener.assertNoErrors(); |
| 10356 } | 10351 } |
| 10357 | 10352 |
| 10358 void fail_visitSimpleIdentifier() { | 10353 void fail_visitSimpleIdentifier() { |
| 10359 fail("Not yet tested"); | 10354 fail("Not yet tested"); |
| 10360 _listener.assertNoErrors(); | 10355 _listener.assertNoErrors(); |
| 10361 } | 10356 } |
| 10362 | 10357 |
| 10363 @override | 10358 @override |
| 10364 void setUp() { | 10359 void setUp() { |
| 10360 super.setUp(); |
| 10365 _listener = new GatheringErrorListener(); | 10361 _listener = new GatheringErrorListener(); |
| 10366 _typeProvider = new TestTypeProvider(); | 10362 _typeProvider = new TestTypeProvider(); |
| 10367 _analyzer = _createAnalyzer(); | 10363 _analyzer = _createAnalyzer(); |
| 10368 } | 10364 } |
| 10369 | 10365 |
| 10370 void test_flatten_derived() { | 10366 void test_flatten_derived() { |
| 10371 // class Derived<T> extends Future<T> { ... } | 10367 // class Derived<T> extends Future<T> { ... } |
| 10372 ClassElementImpl derivedClass = | 10368 ClassElementImpl derivedClass = |
| 10373 ElementFactory.classElement2('Derived', ['T']); | 10369 ElementFactory.classElement2('Derived', ['T']); |
| 10374 derivedClass.supertype = _typeProvider.futureType | 10370 derivedClass.supertype = _typeProvider.futureType |
| (...skipping 2297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12672 v; // marker | 12668 v; // marker |
| 12673 } | 12669 } |
| 12674 int x = 3; | 12670 int x = 3; |
| 12675 '''; | 12671 '''; |
| 12676 _assertPropagatedAssignedType(code, typeProvider.intType, null); | 12672 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 12677 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 12673 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 12678 } | 12674 } |
| 12679 } | 12675 } |
| 12680 | 12676 |
| 12681 @reflectiveTest | 12677 @reflectiveTest |
| 12682 class SubtypeManagerTest extends EngineTestCase { | 12678 class SubtypeManagerTest { |
| 12683 /** | 12679 /** |
| 12684 * The inheritance manager being tested. | 12680 * The inheritance manager being tested. |
| 12685 */ | 12681 */ |
| 12686 SubtypeManager _subtypeManager; | 12682 SubtypeManager _subtypeManager; |
| 12687 | 12683 |
| 12688 /** | 12684 /** |
| 12689 * The compilation unit element containing all of the types setup in each test
. | 12685 * The compilation unit element containing all of the types setup in each test
. |
| 12690 */ | 12686 */ |
| 12691 CompilationUnitElementImpl _definingCompilationUnit; | 12687 CompilationUnitElementImpl _definingCompilationUnit; |
| 12692 | 12688 |
| 12693 @override | |
| 12694 void setUp() { | 12689 void setUp() { |
| 12695 super.setUp(); | |
| 12696 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | 12690 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 12697 FileBasedSource source = | 12691 FileBasedSource source = |
| 12698 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | 12692 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 12699 _definingCompilationUnit = new CompilationUnitElementImpl("test.dart"); | 12693 _definingCompilationUnit = new CompilationUnitElementImpl("test.dart"); |
| 12700 _definingCompilationUnit.librarySource = | 12694 _definingCompilationUnit.librarySource = |
| 12701 _definingCompilationUnit.source = source; | 12695 _definingCompilationUnit.source = source; |
| 12702 LibraryElementImpl definingLibrary = | 12696 LibraryElementImpl definingLibrary = |
| 12703 ElementFactory.library(context, "test"); | 12697 ElementFactory.library(context, "test"); |
| 12704 definingLibrary.definingCompilationUnit = _definingCompilationUnit; | 12698 definingLibrary.definingCompilationUnit = _definingCompilationUnit; |
| 12705 _subtypeManager = new SubtypeManager(); | 12699 _subtypeManager = new SubtypeManager(); |
| (...skipping 1865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14571 } | 14565 } |
| 14572 element.typeParameters = typeParameters; | 14566 element.typeParameters = typeParameters; |
| 14573 type.typeArguments = typeArguments; | 14567 type.typeArguments = typeArguments; |
| 14574 } | 14568 } |
| 14575 } | 14569 } |
| 14576 return element; | 14570 return element; |
| 14577 } | 14571 } |
| 14578 } | 14572 } |
| 14579 | 14573 |
| 14580 @reflectiveTest | 14574 @reflectiveTest |
| 14581 class TypeResolverVisitorTest extends EngineTestCase { | 14575 class TypeResolverVisitorTest { |
| 14582 /** | 14576 /** |
| 14583 * The error listener to which errors will be reported. | 14577 * The error listener to which errors will be reported. |
| 14584 */ | 14578 */ |
| 14585 GatheringErrorListener _listener; | 14579 GatheringErrorListener _listener; |
| 14586 | 14580 |
| 14587 /** | 14581 /** |
| 14588 * The object representing the information about the library in which the type
s are being | 14582 * The object representing the information about the library in which the type
s are being |
| 14589 * resolved. | 14583 * resolved. |
| 14590 */ | 14584 */ |
| 14591 Library _library; | 14585 Library _library; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 14613 void fail_visitVariableDeclaration() { | 14607 void fail_visitVariableDeclaration() { |
| 14614 fail("Not yet tested"); | 14608 fail("Not yet tested"); |
| 14615 ClassElement type = ElementFactory.classElement2("A"); | 14609 ClassElement type = ElementFactory.classElement2("A"); |
| 14616 VariableDeclaration node = AstFactory.variableDeclaration("a"); | 14610 VariableDeclaration node = AstFactory.variableDeclaration("a"); |
| 14617 AstFactory.variableDeclarationList(null, AstFactory.typeName(type), [node]); | 14611 AstFactory.variableDeclarationList(null, AstFactory.typeName(type), [node]); |
| 14618 //resolve(node); | 14612 //resolve(node); |
| 14619 expect(node.name.staticType, same(type.type)); | 14613 expect(node.name.staticType, same(type.type)); |
| 14620 _listener.assertNoErrors(); | 14614 _listener.assertNoErrors(); |
| 14621 } | 14615 } |
| 14622 | 14616 |
| 14623 @override | |
| 14624 void setUp() { | 14617 void setUp() { |
| 14625 _listener = new GatheringErrorListener(); | 14618 _listener = new GatheringErrorListener(); |
| 14626 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | 14619 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 14627 Source librarySource = | 14620 Source librarySource = |
| 14628 new FileBasedSource(FileUtilities2.createFile("/lib.dart")); | 14621 new FileBasedSource(FileUtilities2.createFile("/lib.dart")); |
| 14629 _library = new Library(context, _listener, librarySource); | 14622 _library = new Library(context, _listener, librarySource); |
| 14630 LibraryElementImpl element = new LibraryElementImpl.forNode( | 14623 LibraryElementImpl element = new LibraryElementImpl.forNode( |
| 14631 context, AstFactory.libraryIdentifier2(["lib"])); | 14624 context, AstFactory.libraryIdentifier2(["lib"])); |
| 14632 element.definingCompilationUnit = | 14625 element.definingCompilationUnit = |
| 14633 new CompilationUnitElementImpl("lib.dart"); | 14626 new CompilationUnitElementImpl("lib.dart"); |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15278 | 15271 |
| 15279 void _resolveTestUnit(String code) { | 15272 void _resolveTestUnit(String code) { |
| 15280 testCode = code; | 15273 testCode = code; |
| 15281 testSource = addSource(testCode); | 15274 testSource = addSource(testCode); |
| 15282 LibraryElement library = resolve2(testSource); | 15275 LibraryElement library = resolve2(testSource); |
| 15283 assertNoErrors(testSource); | 15276 assertNoErrors(testSource); |
| 15284 verify([testSource]); | 15277 verify([testSource]); |
| 15285 testUnit = resolveCompilationUnit(testSource, library); | 15278 testUnit = resolveCompilationUnit(testSource, library); |
| 15286 } | 15279 } |
| 15287 } | 15280 } |
| OLD | NEW |