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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 // | 120 // |
121 // dart:core | 121 // dart:core |
122 // | 122 // |
123 TestTypeProvider provider = new TestTypeProvider(); | 123 TestTypeProvider provider = new TestTypeProvider(); |
124 CompilationUnitElementImpl coreUnit = | 124 CompilationUnitElementImpl coreUnit = |
125 new CompilationUnitElementImpl("core.dart"); | 125 new CompilationUnitElementImpl("core.dart"); |
126 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); | 126 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); |
127 coreContext.setContents(coreSource, ""); | 127 coreContext.setContents(coreSource, ""); |
128 coreUnit.librarySource = coreUnit.source = coreSource; | 128 coreUnit.librarySource = coreUnit.source = coreSource; |
129 ClassElementImpl proxyClassElement = ElementFactory.classElement2("_Proxy"); | 129 ClassElementImpl proxyClassElement = ElementFactory.classElement2("_Proxy"); |
| 130 ClassElement objectClassElement = provider.objectType.element; |
130 coreUnit.types = <ClassElement>[ | 131 coreUnit.types = <ClassElement>[ |
131 provider.boolType.element, | 132 provider.boolType.element, |
132 provider.deprecatedType.element, | 133 provider.deprecatedType.element, |
133 provider.doubleType.element, | 134 provider.doubleType.element, |
134 provider.functionType.element, | 135 provider.functionType.element, |
135 provider.intType.element, | 136 provider.intType.element, |
136 provider.iterableType.element, | 137 provider.iterableType.element, |
137 provider.iteratorType.element, | 138 provider.iteratorType.element, |
138 provider.listType.element, | 139 provider.listType.element, |
139 provider.mapType.element, | 140 provider.mapType.element, |
140 provider.nullType.element, | 141 provider.nullType.element, |
141 provider.numType.element, | 142 provider.numType.element, |
142 provider.objectType.element, | 143 objectClassElement, |
143 proxyClassElement, | 144 proxyClassElement, |
144 provider.stackTraceType.element, | 145 provider.stackTraceType.element, |
145 provider.stringType.element, | 146 provider.stringType.element, |
146 provider.symbolType.element, | 147 provider.symbolType.element, |
147 provider.typeType.element | 148 provider.typeType.element |
148 ]; | 149 ]; |
149 coreUnit.functions = <FunctionElement>[ | 150 coreUnit.functions = <FunctionElement>[ |
150 ElementFactory.functionElement3("identical", provider.boolType.element, | 151 ElementFactory.functionElement3("identical", provider.boolType.element, |
151 <ClassElement>[ | 152 <ClassElement>[objectClassElement, objectClassElement], null), |
152 provider.objectType.element, | |
153 provider.objectType.element | |
154 ], null), | |
155 ElementFactory.functionElement3("print", VoidTypeImpl.instance.element, | 153 ElementFactory.functionElement3("print", VoidTypeImpl.instance.element, |
156 <ClassElement>[provider.objectType.element], null) | 154 <ClassElement>[objectClassElement], null) |
157 ]; | 155 ]; |
158 TopLevelVariableElement proxyTopLevelVariableElt = ElementFactory | 156 TopLevelVariableElement proxyTopLevelVariableElt = ElementFactory |
159 .topLevelVariableElement3("proxy", true, false, proxyClassElement.type); | 157 .topLevelVariableElement3("proxy", true, false, proxyClassElement.type); |
160 TopLevelVariableElement deprecatedTopLevelVariableElt = ElementFactory | 158 ConstTopLevelVariableElementImpl deprecatedTopLevelVariableElt = |
161 .topLevelVariableElement3( | 159 ElementFactory.topLevelVariableElement3( |
162 "deprecated", true, false, provider.deprecatedType); | 160 "deprecated", true, false, provider.deprecatedType); |
| 161 deprecatedTopLevelVariableElt.constantInitializer = AstFactory |
| 162 .instanceCreationExpression2(Keyword.CONST, |
| 163 AstFactory.typeName(provider.deprecatedType.element), |
| 164 [AstFactory.string2('next release')]); |
163 coreUnit.accessors = <PropertyAccessorElement>[ | 165 coreUnit.accessors = <PropertyAccessorElement>[ |
164 proxyTopLevelVariableElt.getter, | 166 proxyTopLevelVariableElt.getter, |
165 deprecatedTopLevelVariableElt.getter | 167 deprecatedTopLevelVariableElt.getter |
166 ]; | 168 ]; |
167 coreUnit.topLevelVariables = <TopLevelVariableElement>[ | 169 coreUnit.topLevelVariables = <TopLevelVariableElement>[ |
168 proxyTopLevelVariableElt, | 170 proxyTopLevelVariableElt, |
169 deprecatedTopLevelVariableElt | 171 deprecatedTopLevelVariableElt |
170 ]; | 172 ]; |
171 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( | 173 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( |
172 coreContext, AstFactory.libraryIdentifier2(["dart", "core"])); | 174 coreContext, AstFactory.libraryIdentifier2(["dart", "core"])); |
(...skipping 7818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7991 reset(); | 7993 reset(); |
7992 } | 7994 } |
7993 | 7995 |
7994 @override | 7996 @override |
7995 void tearDown() { | 7997 void tearDown() { |
7996 analysisContext2 = null; | 7998 analysisContext2 = null; |
7997 super.tearDown(); | 7999 super.tearDown(); |
7998 } | 8000 } |
7999 | 8001 |
8000 /** | 8002 /** |
8001 * Verify that all of the identifiers in the compilation units associated with
the given sources | 8003 * Verify that all of the identifiers in the compilation units associated with |
8002 * have been resolved. | 8004 * the given [sources] have been resolved. |
8003 * | |
8004 * @param resolvedElementMap a table mapping the AST nodes that have been reso
lved to the element | |
8005 * to which they were resolved | |
8006 * @param sources the sources identifying the compilation units to be verified | |
8007 * @throws Exception if the contents of the compilation unit cannot be accesse
d | |
8008 */ | 8005 */ |
8009 void verify(List<Source> sources) { | 8006 void verify(List<Source> sources) { |
8010 ResolutionVerifier verifier = new ResolutionVerifier(); | 8007 ResolutionVerifier verifier = new ResolutionVerifier(); |
8011 for (Source source in sources) { | 8008 for (Source source in sources) { |
8012 analysisContext2.parseCompilationUnit(source).accept(verifier); | 8009 List<Source> libraries = analysisContext2.getLibrariesContaining(source); |
| 8010 for (Source library in libraries) { |
| 8011 analysisContext2 |
| 8012 .resolveCompilationUnit2(source, library) |
| 8013 .accept(verifier); |
| 8014 } |
8013 } | 8015 } |
8014 verifier.assertResolved(); | 8016 verifier.assertResolved(); |
8015 } | 8017 } |
8016 | 8018 |
8017 /** | 8019 /** |
8018 * Create a source object representing a file with the given name and give it
an empty content. | 8020 * Create a source object representing a file with the given [fileName] and |
8019 * | 8021 * give it an empty content. Return the source that was created. |
8020 * @param fileName the name of the file for which a source is to be created | |
8021 * @return the source that was created | |
8022 */ | 8022 */ |
8023 FileBasedSource _createNamedSource(String fileName) { | 8023 FileBasedSource _createNamedSource(String fileName) { |
8024 FileBasedSource source = | 8024 FileBasedSource source = |
8025 new FileBasedSource(FileUtilities2.createFile(fileName)); | 8025 new FileBasedSource(FileUtilities2.createFile(fileName)); |
8026 analysisContext2.setContents(source, ""); | 8026 analysisContext2.setContents(source, ""); |
8027 return source; | 8027 return source; |
8028 } | 8028 } |
8029 } | 8029 } |
8030 | 8030 |
8031 class Scope_EnclosedScopeTest_test_define_duplicate extends Scope { | 8031 class Scope_EnclosedScopeTest_test_define_duplicate extends Scope { |
(...skipping 5837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13869 // check propagated type | 13869 // check propagated type |
13870 FunctionType propagatedType = node.propagatedType as FunctionType; | 13870 FunctionType propagatedType = node.propagatedType as FunctionType; |
13871 expect(propagatedType.returnType, test.typeProvider.stringType); | 13871 expect(propagatedType.returnType, test.typeProvider.stringType); |
13872 } on AnalysisException catch (e, stackTrace) { | 13872 } on AnalysisException catch (e, stackTrace) { |
13873 thrownException[0] = new CaughtException(e, stackTrace); | 13873 thrownException[0] = new CaughtException(e, stackTrace); |
13874 } | 13874 } |
13875 } | 13875 } |
13876 return null; | 13876 return null; |
13877 } | 13877 } |
13878 } | 13878 } |
OLD | NEW |