| 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'; | 9 import 'package:analyzer/src/context/context.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 main() { | 37 main() { |
| 38 initializeTestEnvironment(); | 38 initializeTestEnvironment(); |
| 39 runReflectiveTests(AnalysisDeltaTest); | 39 runReflectiveTests(AnalysisDeltaTest); |
| 40 runReflectiveTests(ChangeSetTest); | 40 runReflectiveTests(ChangeSetTest); |
| 41 runReflectiveTests(EnclosedScopeTest); | 41 runReflectiveTests(EnclosedScopeTest); |
| 42 runReflectiveTests(LibraryImportScopeTest); | 42 runReflectiveTests(LibraryImportScopeTest); |
| 43 runReflectiveTests(LibraryScopeTest); | 43 runReflectiveTests(LibraryScopeTest); |
| 44 runReflectiveTests(ScopeTest); | 44 runReflectiveTests(ScopeTest); |
| 45 runReflectiveTests(ElementResolverTest); | 45 runReflectiveTests(ElementResolverTest); |
| 46 runReflectiveTests(InheritanceManagerTest); | 46 runReflectiveTests(InheritanceManagerTest); |
| 47 runReflectiveTests(LibraryTest); | |
| 48 runReflectiveTests(StaticTypeAnalyzerTest); | 47 runReflectiveTests(StaticTypeAnalyzerTest); |
| 49 runReflectiveTests(StaticTypeAnalyzer2Test); | 48 runReflectiveTests(StaticTypeAnalyzer2Test); |
| 50 runReflectiveTests(SubtypeManagerTest); | 49 runReflectiveTests(SubtypeManagerTest); |
| 51 runReflectiveTests(TypeOverrideManagerTest); | 50 runReflectiveTests(TypeOverrideManagerTest); |
| 52 runReflectiveTests(TypeProviderImplTest); | 51 runReflectiveTests(TypeProviderImplTest); |
| 53 runReflectiveTests(TypeResolverVisitorTest); | 52 runReflectiveTests(TypeResolverVisitorTest); |
| 54 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); | 53 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); |
| 55 runReflectiveTests(ErrorResolverTest); | 54 runReflectiveTests(ErrorResolverTest); |
| 56 runReflectiveTests(HintCodeTest); | 55 runReflectiveTests(HintCodeTest); |
| 57 runReflectiveTests(MemberMapTest); | 56 runReflectiveTests(MemberMapTest); |
| (...skipping 1901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1959 ElementResolver _createResolver() { | 1958 ElementResolver _createResolver() { |
| 1960 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | 1959 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 1961 FileBasedSource source = | 1960 FileBasedSource source = |
| 1962 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | 1961 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 1963 CompilationUnitElementImpl definingCompilationUnit = | 1962 CompilationUnitElementImpl definingCompilationUnit = |
| 1964 new CompilationUnitElementImpl("test.dart"); | 1963 new CompilationUnitElementImpl("test.dart"); |
| 1965 definingCompilationUnit.librarySource = | 1964 definingCompilationUnit.librarySource = |
| 1966 definingCompilationUnit.source = source; | 1965 definingCompilationUnit.source = source; |
| 1967 _definingLibrary = ElementFactory.library(context, "test"); | 1966 _definingLibrary = ElementFactory.library(context, "test"); |
| 1968 _definingLibrary.definingCompilationUnit = definingCompilationUnit; | 1967 _definingLibrary.definingCompilationUnit = definingCompilationUnit; |
| 1969 Library library = new Library(context, _listener, source); | |
| 1970 library.libraryElement = _definingLibrary; | |
| 1971 _visitor = new ResolverVisitor( | 1968 _visitor = new ResolverVisitor( |
| 1972 library.libraryElement, source, _typeProvider, library.errorListener, | 1969 _definingLibrary, source, _typeProvider, _listener, |
| 1973 nameScope: library.libraryScope, | 1970 nameScope: new LibraryScope(_definingLibrary, _listener)); |
| 1974 inheritanceManager: library.inheritanceManager); | |
| 1975 try { | 1971 try { |
| 1976 return _visitor.elementResolver; | 1972 return _visitor.elementResolver; |
| 1977 } catch (exception) { | 1973 } catch (exception) { |
| 1978 throw new IllegalArgumentException( | 1974 throw new IllegalArgumentException( |
| 1979 "Could not create resolver", exception); | 1975 "Could not create resolver", exception); |
| 1980 } | 1976 } |
| 1981 } | 1977 } |
| 1982 | 1978 |
| 1983 /** | 1979 /** |
| 1984 * Return the element associated with the label of [statement] after the | 1980 * Return the element associated with the label of [statement] after the |
| (...skipping 4252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6237 | 6233 |
| 6238 void test_getErrorListener() { | 6234 void test_getErrorListener() { |
| 6239 LibraryElement definingLibrary = createDefaultTestLibrary(); | 6235 LibraryElement definingLibrary = createDefaultTestLibrary(); |
| 6240 GatheringErrorListener errorListener = new GatheringErrorListener(); | 6236 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 6241 LibraryScope scope = new LibraryScope(definingLibrary, errorListener); | 6237 LibraryScope scope = new LibraryScope(definingLibrary, errorListener); |
| 6242 expect(scope.errorListener, errorListener); | 6238 expect(scope.errorListener, errorListener); |
| 6243 } | 6239 } |
| 6244 } | 6240 } |
| 6245 | 6241 |
| 6246 @reflectiveTest | 6242 @reflectiveTest |
| 6247 class LibraryTest { | |
| 6248 /** | |
| 6249 * The error listener to which all errors will be reported. | |
| 6250 */ | |
| 6251 GatheringErrorListener _errorListener; | |
| 6252 | |
| 6253 /** | |
| 6254 * The analysis context to pass in to all libraries created by the tests. | |
| 6255 */ | |
| 6256 InternalAnalysisContext _analysisContext; | |
| 6257 | |
| 6258 /** | |
| 6259 * The library used by the tests. | |
| 6260 */ | |
| 6261 Library _library; | |
| 6262 | |
| 6263 void setUp() { | |
| 6264 _analysisContext = AnalysisContextFactory.contextWithCore(); | |
| 6265 _errorListener = new GatheringErrorListener(); | |
| 6266 _library = _createLibrary("/lib.dart"); | |
| 6267 } | |
| 6268 | |
| 6269 void tearDown() { | |
| 6270 _errorListener = null; | |
| 6271 _analysisContext = null; | |
| 6272 _library = null; | |
| 6273 } | |
| 6274 | |
| 6275 void test_getExplicitlyImportsCore() { | |
| 6276 expect(_library.explicitlyImportsCore, isFalse); | |
| 6277 _errorListener.assertNoErrors(); | |
| 6278 } | |
| 6279 | |
| 6280 void test_getExports() { | |
| 6281 expect(_library.exports, hasLength(0)); | |
| 6282 _errorListener.assertNoErrors(); | |
| 6283 } | |
| 6284 | |
| 6285 void test_getImports() { | |
| 6286 expect(_library.imports, hasLength(0)); | |
| 6287 _errorListener.assertNoErrors(); | |
| 6288 } | |
| 6289 | |
| 6290 void test_getImportsAndExports() { | |
| 6291 _library.importedLibraries = <Library>[_createLibrary("/imported.dart")]; | |
| 6292 _library.exportedLibraries = <Library>[_createLibrary("/exported.dart")]; | |
| 6293 expect(_library.importsAndExports, hasLength(2)); | |
| 6294 _errorListener.assertNoErrors(); | |
| 6295 } | |
| 6296 | |
| 6297 void test_getLibraryScope() { | |
| 6298 LibraryElementImpl element = new LibraryElementImpl.forNode( | |
| 6299 _analysisContext, AstFactory.libraryIdentifier2(["lib"])); | |
| 6300 element.definingCompilationUnit = | |
| 6301 new CompilationUnitElementImpl("lib.dart"); | |
| 6302 _library.libraryElement = element; | |
| 6303 expect(_library.libraryScope, isNotNull); | |
| 6304 _errorListener.assertNoErrors(); | |
| 6305 } | |
| 6306 | |
| 6307 void test_getLibrarySource() { | |
| 6308 expect(_library.librarySource, isNotNull); | |
| 6309 } | |
| 6310 | |
| 6311 void test_setExplicitlyImportsCore() { | |
| 6312 _library.explicitlyImportsCore = true; | |
| 6313 expect(_library.explicitlyImportsCore, isTrue); | |
| 6314 _errorListener.assertNoErrors(); | |
| 6315 } | |
| 6316 | |
| 6317 void test_setExportedLibraries() { | |
| 6318 Library exportLibrary = _createLibrary("/exported.dart"); | |
| 6319 _library.exportedLibraries = <Library>[exportLibrary]; | |
| 6320 List<Library> exports = _library.exports; | |
| 6321 expect(exports, hasLength(1)); | |
| 6322 expect(exports[0], same(exportLibrary)); | |
| 6323 _errorListener.assertNoErrors(); | |
| 6324 } | |
| 6325 | |
| 6326 void test_setImportedLibraries() { | |
| 6327 Library importLibrary = _createLibrary("/imported.dart"); | |
| 6328 _library.importedLibraries = <Library>[importLibrary]; | |
| 6329 List<Library> imports = _library.imports; | |
| 6330 expect(imports, hasLength(1)); | |
| 6331 expect(imports[0], same(importLibrary)); | |
| 6332 _errorListener.assertNoErrors(); | |
| 6333 } | |
| 6334 | |
| 6335 void test_setLibraryElement() { | |
| 6336 LibraryElementImpl element = new LibraryElementImpl.forNode( | |
| 6337 _analysisContext, AstFactory.libraryIdentifier2(["lib"])); | |
| 6338 _library.libraryElement = element; | |
| 6339 expect(_library.libraryElement, same(element)); | |
| 6340 } | |
| 6341 | |
| 6342 Library _createLibrary(String definingCompilationUnitPath) => new Library( | |
| 6343 _analysisContext, | |
| 6344 _errorListener, | |
| 6345 new FileBasedSource( | |
| 6346 FileUtilities2.createFile(definingCompilationUnitPath))); | |
| 6347 } | |
| 6348 | |
| 6349 @reflectiveTest | |
| 6350 class MemberMapTest { | 6243 class MemberMapTest { |
| 6351 /** | 6244 /** |
| 6352 * The null type. | 6245 * The null type. |
| 6353 */ | 6246 */ |
| 6354 InterfaceType _nullType; | 6247 InterfaceType _nullType; |
| 6355 | 6248 |
| 6356 void setUp() { | 6249 void setUp() { |
| 6357 _nullType = new TestTypeProvider().nullType; | 6250 _nullType = new TestTypeProvider().nullType; |
| 6358 } | 6251 } |
| 6359 | 6252 |
| (...skipping 4860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11220 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | 11113 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 11221 FileBasedSource source = | 11114 FileBasedSource source = |
| 11222 new FileBasedSource(FileUtilities2.createFile("/lib.dart")); | 11115 new FileBasedSource(FileUtilities2.createFile("/lib.dart")); |
| 11223 CompilationUnitElementImpl definingCompilationUnit = | 11116 CompilationUnitElementImpl definingCompilationUnit = |
| 11224 new CompilationUnitElementImpl("lib.dart"); | 11117 new CompilationUnitElementImpl("lib.dart"); |
| 11225 definingCompilationUnit.librarySource = | 11118 definingCompilationUnit.librarySource = |
| 11226 definingCompilationUnit.source = source; | 11119 definingCompilationUnit.source = source; |
| 11227 LibraryElementImpl definingLibrary = | 11120 LibraryElementImpl definingLibrary = |
| 11228 new LibraryElementImpl.forNode(context, null); | 11121 new LibraryElementImpl.forNode(context, null); |
| 11229 definingLibrary.definingCompilationUnit = definingCompilationUnit; | 11122 definingLibrary.definingCompilationUnit = definingCompilationUnit; |
| 11230 Library library = new Library(context, _listener, source); | |
| 11231 library.libraryElement = definingLibrary; | |
| 11232 _visitor = new ResolverVisitor( | 11123 _visitor = new ResolverVisitor( |
| 11233 library.libraryElement, source, _typeProvider, library.errorListener, | 11124 definingLibrary, source, _typeProvider, _listener, |
| 11234 nameScope: library.libraryScope, | 11125 nameScope: new LibraryScope(definingLibrary, _listener)); |
| 11235 inheritanceManager: library.inheritanceManager); | |
| 11236 _visitor.overrideManager.enterScope(); | 11126 _visitor.overrideManager.enterScope(); |
| 11237 try { | 11127 try { |
| 11238 return _visitor.typeAnalyzer; | 11128 return _visitor.typeAnalyzer; |
| 11239 } catch (exception) { | 11129 } catch (exception) { |
| 11240 throw new IllegalArgumentException( | 11130 throw new IllegalArgumentException( |
| 11241 "Could not create analyzer", exception); | 11131 "Could not create analyzer", exception); |
| 11242 } | 11132 } |
| 11243 } | 11133 } |
| 11244 | 11134 |
| 11245 DartType _flatten(DartType type) => | 11135 DartType _flatten(DartType type) => |
| (...skipping 3858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15104 } | 14994 } |
| 15105 | 14995 |
| 15106 @reflectiveTest | 14996 @reflectiveTest |
| 15107 class TypeResolverVisitorTest { | 14997 class TypeResolverVisitorTest { |
| 15108 /** | 14998 /** |
| 15109 * The error listener to which errors will be reported. | 14999 * The error listener to which errors will be reported. |
| 15110 */ | 15000 */ |
| 15111 GatheringErrorListener _listener; | 15001 GatheringErrorListener _listener; |
| 15112 | 15002 |
| 15113 /** | 15003 /** |
| 15114 * The object representing the information about the library in which the type
s are being | |
| 15115 * resolved. | |
| 15116 */ | |
| 15117 Library _library; | |
| 15118 | |
| 15119 /** | |
| 15120 * The type provider used to access the types. | 15004 * The type provider used to access the types. |
| 15121 */ | 15005 */ |
| 15122 TestTypeProvider _typeProvider; | 15006 TestTypeProvider _typeProvider; |
| 15123 | 15007 |
| 15124 /** | 15008 /** |
| 15009 * The library scope in which types are to be resolved. |
| 15010 */ |
| 15011 LibraryScope libraryScope; |
| 15012 |
| 15013 /** |
| 15125 * The visitor used to resolve types needed to form the type hierarchy. | 15014 * The visitor used to resolve types needed to form the type hierarchy. |
| 15126 */ | 15015 */ |
| 15127 TypeResolverVisitor _visitor; | 15016 TypeResolverVisitor _visitor; |
| 15128 | 15017 |
| 15129 void fail_visitConstructorDeclaration() { | 15018 void fail_visitConstructorDeclaration() { |
| 15130 fail("Not yet tested"); | 15019 fail("Not yet tested"); |
| 15131 _listener.assertNoErrors(); | 15020 _listener.assertNoErrors(); |
| 15132 } | 15021 } |
| 15133 | 15022 |
| 15134 void fail_visitFunctionTypeAlias() { | 15023 void fail_visitFunctionTypeAlias() { |
| 15135 fail("Not yet tested"); | 15024 fail("Not yet tested"); |
| 15136 _listener.assertNoErrors(); | 15025 _listener.assertNoErrors(); |
| 15137 } | 15026 } |
| 15138 | 15027 |
| 15139 void fail_visitVariableDeclaration() { | 15028 void fail_visitVariableDeclaration() { |
| 15140 fail("Not yet tested"); | 15029 fail("Not yet tested"); |
| 15141 ClassElement type = ElementFactory.classElement2("A"); | 15030 ClassElement type = ElementFactory.classElement2("A"); |
| 15142 VariableDeclaration node = AstFactory.variableDeclaration("a"); | 15031 VariableDeclaration node = AstFactory.variableDeclaration("a"); |
| 15143 AstFactory.variableDeclarationList(null, AstFactory.typeName(type), [node]); | 15032 AstFactory.variableDeclarationList(null, AstFactory.typeName(type), [node]); |
| 15144 //resolve(node); | 15033 //resolve(node); |
| 15145 expect(node.name.staticType, same(type.type)); | 15034 expect(node.name.staticType, same(type.type)); |
| 15146 _listener.assertNoErrors(); | 15035 _listener.assertNoErrors(); |
| 15147 } | 15036 } |
| 15148 | 15037 |
| 15149 void setUp() { | 15038 void setUp() { |
| 15150 _listener = new GatheringErrorListener(); | 15039 _listener = new GatheringErrorListener(); |
| 15151 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | 15040 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 15152 Source librarySource = | 15041 Source librarySource = |
| 15153 new FileBasedSource(FileUtilities2.createFile("/lib.dart")); | 15042 new FileBasedSource(FileUtilities2.createFile("/lib.dart")); |
| 15154 _library = new Library(context, _listener, librarySource); | |
| 15155 LibraryElementImpl element = new LibraryElementImpl.forNode( | 15043 LibraryElementImpl element = new LibraryElementImpl.forNode( |
| 15156 context, AstFactory.libraryIdentifier2(["lib"])); | 15044 context, AstFactory.libraryIdentifier2(["lib"])); |
| 15157 element.definingCompilationUnit = | 15045 element.definingCompilationUnit = |
| 15158 new CompilationUnitElementImpl("lib.dart"); | 15046 new CompilationUnitElementImpl("lib.dart"); |
| 15159 _library.libraryElement = element; | |
| 15160 _typeProvider = new TestTypeProvider(); | 15047 _typeProvider = new TestTypeProvider(); |
| 15161 _visitor = new TypeResolverVisitor(_library.libraryElement, librarySource, | 15048 libraryScope = new LibraryScope(element, _listener); |
| 15162 _typeProvider, _library.errorListener, | 15049 _visitor = new TypeResolverVisitor( |
| 15163 nameScope: _library.libraryScope); | 15050 element, librarySource, _typeProvider, _listener, |
| 15051 nameScope: libraryScope); |
| 15164 } | 15052 } |
| 15165 | 15053 |
| 15166 void test_visitCatchClause_exception() { | 15054 void test_visitCatchClause_exception() { |
| 15167 // catch (e) | 15055 // catch (e) |
| 15168 CatchClause clause = AstFactory.catchClause("e"); | 15056 CatchClause clause = AstFactory.catchClause("e"); |
| 15169 SimpleIdentifier exceptionParameter = clause.exceptionParameter; | 15057 SimpleIdentifier exceptionParameter = clause.exceptionParameter; |
| 15170 exceptionParameter.staticElement = | 15058 exceptionParameter.staticElement = |
| 15171 new LocalVariableElementImpl.forNode(exceptionParameter); | 15059 new LocalVariableElementImpl.forNode(exceptionParameter); |
| 15172 _resolveCatchClause(clause, _typeProvider.dynamicType, null); | 15060 _resolveCatchClause(clause, _typeProvider.dynamicType, null); |
| 15173 _listener.assertNoErrors(); | 15061 _listener.assertNoErrors(); |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15713 * identifier. | 15601 * identifier. |
| 15714 * | 15602 * |
| 15715 * @param node the expression to be resolved | 15603 * @param node the expression to be resolved |
| 15716 * @param definedElements the elements that are to be defined in the scope in
which the element is | 15604 * @param definedElements the elements that are to be defined in the scope in
which the element is |
| 15717 * being resolved | 15605 * being resolved |
| 15718 * @return the element to which the expression was resolved | 15606 * @return the element to which the expression was resolved |
| 15719 */ | 15607 */ |
| 15720 void _resolveNode(AstNode node, [List<Element> definedElements]) { | 15608 void _resolveNode(AstNode node, [List<Element> definedElements]) { |
| 15721 if (definedElements != null) { | 15609 if (definedElements != null) { |
| 15722 for (Element element in definedElements) { | 15610 for (Element element in definedElements) { |
| 15723 _library.libraryScope.define(element); | 15611 libraryScope.define(element); |
| 15724 } | 15612 } |
| 15725 } | 15613 } |
| 15726 node.accept(_visitor); | 15614 node.accept(_visitor); |
| 15727 } | 15615 } |
| 15728 } | 15616 } |
| 15729 | 15617 |
| 15730 class _AnalysisContextFactory_initContextWithCore | 15618 class _AnalysisContextFactory_initContextWithCore |
| 15731 extends DirectoryBasedDartSdk { | 15619 extends DirectoryBasedDartSdk { |
| 15732 _AnalysisContextFactory_initContextWithCore(JavaFile arg0) : super(arg0); | 15620 _AnalysisContextFactory_initContextWithCore(JavaFile arg0) : super(arg0); |
| 15733 | 15621 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15803 | 15691 |
| 15804 void _resolveTestUnit(String code) { | 15692 void _resolveTestUnit(String code) { |
| 15805 testCode = code; | 15693 testCode = code; |
| 15806 testSource = addSource(testCode); | 15694 testSource = addSource(testCode); |
| 15807 LibraryElement library = resolve2(testSource); | 15695 LibraryElement library = resolve2(testSource); |
| 15808 assertNoErrors(testSource); | 15696 assertNoErrors(testSource); |
| 15809 verify([testSource]); | 15697 verify([testSource]); |
| 15810 testUnit = resolveCompilationUnit(testSource, library); | 15698 testUnit = resolveCompilationUnit(testSource, library); |
| 15811 } | 15699 } |
| 15812 } | 15700 } |
| OLD | NEW |