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.analysis_context_factory; | 5 library analyzer.test.generated.analysis_context_factory; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
11 import 'package:analyzer/dart/element/element.dart'; | 11 import 'package:analyzer/dart/element/element.dart'; |
12 import 'package:analyzer/dart/element/type.dart'; | 12 import 'package:analyzer/dart/element/type.dart'; |
13 import 'package:analyzer/file_system/file_system.dart'; | 13 import 'package:analyzer/file_system/file_system.dart'; |
14 import 'package:analyzer/file_system/memory_file_system.dart'; | 14 import 'package:analyzer/file_system/memory_file_system.dart'; |
15 import 'package:analyzer/file_system/physical_file_system.dart'; | 15 import 'package:analyzer/file_system/physical_file_system.dart'; |
16 import 'package:analyzer/src/context/context.dart'; | 16 import 'package:analyzer/src/context/context.dart'; |
17 import 'package:analyzer/src/dart/element/element.dart'; | 17 import 'package:analyzer/src/dart/element/element.dart'; |
18 import 'package:analyzer/src/dart/element/type.dart'; | 18 import 'package:analyzer/src/dart/element/type.dart'; |
19 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 19 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
20 import 'package:analyzer/src/generated/engine.dart'; | 20 import 'package:analyzer/src/generated/engine.dart'; |
21 import 'package:analyzer/src/generated/resolver.dart'; | 21 import 'package:analyzer/src/generated/resolver.dart'; |
22 import 'package:analyzer/src/generated/sdk.dart'; | 22 import 'package:analyzer/src/generated/sdk.dart'; |
23 import 'package:analyzer/src/generated/source_io.dart'; | 23 import 'package:analyzer/src/generated/source_io.dart'; |
24 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 24 import 'package:analyzer/src/generated/testing/ast_test_factory.dart'; |
25 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 25 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
26 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; | 26 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; |
27 import 'package:analyzer/src/generated/utilities_dart.dart'; | 27 import 'package:analyzer/src/generated/utilities_dart.dart'; |
28 import 'package:analyzer/src/string_source.dart'; | 28 import 'package:analyzer/src/string_source.dart'; |
29 import 'package:test/test.dart'; | 29 import 'package:test/test.dart'; |
30 | 30 |
31 /** | 31 /** |
32 * The class `AnalysisContextFactory` defines utility methods used to create ana
lysis contexts | 32 * The class `AnalysisContextFactory` defines utility methods used to create ana
lysis contexts |
33 * for testing purposes. | 33 * for testing purposes. |
34 */ | 34 */ |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 TopLevelVariableElement proxyTopLevelVariableElt = ElementFactory | 149 TopLevelVariableElement proxyTopLevelVariableElt = ElementFactory |
150 .topLevelVariableElement3("proxy", true, false, proxyClassElement.type); | 150 .topLevelVariableElement3("proxy", true, false, proxyClassElement.type); |
151 ConstTopLevelVariableElementImpl deprecatedTopLevelVariableElt = | 151 ConstTopLevelVariableElementImpl deprecatedTopLevelVariableElt = |
152 ElementFactory.topLevelVariableElement3( | 152 ElementFactory.topLevelVariableElement3( |
153 "deprecated", true, false, provider.deprecatedType); | 153 "deprecated", true, false, provider.deprecatedType); |
154 TopLevelVariableElement overrideTopLevelVariableElt = | 154 TopLevelVariableElement overrideTopLevelVariableElt = |
155 ElementFactory.topLevelVariableElement3( | 155 ElementFactory.topLevelVariableElement3( |
156 "override", true, false, overrideClassElement.type); | 156 "override", true, false, overrideClassElement.type); |
157 { | 157 { |
158 ClassElement deprecatedElement = provider.deprecatedType.element; | 158 ClassElement deprecatedElement = provider.deprecatedType.element; |
159 InstanceCreationExpression initializer = AstFactory | 159 InstanceCreationExpression initializer = AstTestFactory |
160 .instanceCreationExpression2( | 160 .instanceCreationExpression2( |
161 Keyword.CONST, | 161 Keyword.CONST, |
162 AstFactory.typeName(deprecatedElement), | 162 AstTestFactory.typeName(deprecatedElement), |
163 [AstFactory.string2('next release')]); | 163 [AstTestFactory.string2('next release')]); |
164 ConstructorElement constructor = deprecatedElement.constructors.single; | 164 ConstructorElement constructor = deprecatedElement.constructors.single; |
165 initializer.staticElement = constructor; | 165 initializer.staticElement = constructor; |
166 initializer.constructorName.staticElement = constructor; | 166 initializer.constructorName.staticElement = constructor; |
167 deprecatedTopLevelVariableElt.constantInitializer = initializer; | 167 deprecatedTopLevelVariableElt.constantInitializer = initializer; |
168 } | 168 } |
169 coreUnit.accessors = <PropertyAccessorElement>[ | 169 coreUnit.accessors = <PropertyAccessorElement>[ |
170 deprecatedTopLevelVariableElt.getter, | 170 deprecatedTopLevelVariableElt.getter, |
171 overrideTopLevelVariableElt.getter, | 171 overrideTopLevelVariableElt.getter, |
172 proxyTopLevelVariableElt.getter | 172 proxyTopLevelVariableElt.getter |
173 ]; | 173 ]; |
174 coreUnit.topLevelVariables = <TopLevelVariableElement>[ | 174 coreUnit.topLevelVariables = <TopLevelVariableElement>[ |
175 deprecatedTopLevelVariableElt, | 175 deprecatedTopLevelVariableElt, |
176 overrideTopLevelVariableElt, | 176 overrideTopLevelVariableElt, |
177 proxyTopLevelVariableElt | 177 proxyTopLevelVariableElt |
178 ]; | 178 ]; |
179 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( | 179 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( |
180 coreContext, AstFactory.libraryIdentifier2(["dart", "core"])); | 180 coreContext, AstTestFactory.libraryIdentifier2(["dart", "core"])); |
181 coreLibrary.definingCompilationUnit = coreUnit; | 181 coreLibrary.definingCompilationUnit = coreUnit; |
182 // | 182 // |
183 // dart:async | 183 // dart:async |
184 // | 184 // |
185 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( | 185 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( |
186 coreContext, AstFactory.libraryIdentifier2(["dart", "async"])); | 186 coreContext, AstTestFactory.libraryIdentifier2(["dart", "async"])); |
187 CompilationUnitElementImpl asyncUnit = | 187 CompilationUnitElementImpl asyncUnit = |
188 new CompilationUnitElementImpl("async.dart"); | 188 new CompilationUnitElementImpl("async.dart"); |
189 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); | 189 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); |
190 coreContext.setContents(asyncSource, ""); | 190 coreContext.setContents(asyncSource, ""); |
191 asyncUnit.librarySource = asyncUnit.source = asyncSource; | 191 asyncUnit.librarySource = asyncUnit.source = asyncSource; |
192 asyncLibrary.definingCompilationUnit = asyncUnit; | 192 asyncLibrary.definingCompilationUnit = asyncUnit; |
193 // Future | 193 // Future |
194 ClassElementImpl futureElement = | 194 ClassElementImpl futureElement = |
195 ElementFactory.classElement2("Future", ["T"]); | 195 ElementFactory.classElement2("Future", ["T"]); |
196 futureElement.enclosingElement = asyncUnit; | 196 futureElement.enclosingElement = asyncUnit; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 ]; | 321 ]; |
322 htmlUnit.functions = <FunctionElement>[ | 322 htmlUnit.functions = <FunctionElement>[ |
323 ElementFactory.functionElement3("query", elementElement, | 323 ElementFactory.functionElement3("query", elementElement, |
324 <ClassElement>[provider.stringType.element], ClassElement.EMPTY_LIST) | 324 <ClassElement>[provider.stringType.element], ClassElement.EMPTY_LIST) |
325 ]; | 325 ]; |
326 TopLevelVariableElementImpl document = | 326 TopLevelVariableElementImpl document = |
327 ElementFactory.topLevelVariableElement3( | 327 ElementFactory.topLevelVariableElement3( |
328 "document", false, true, htmlDocumentElement.type); | 328 "document", false, true, htmlDocumentElement.type); |
329 htmlUnit.topLevelVariables = <TopLevelVariableElement>[document]; | 329 htmlUnit.topLevelVariables = <TopLevelVariableElement>[document]; |
330 htmlUnit.accessors = <PropertyAccessorElement>[document.getter]; | 330 htmlUnit.accessors = <PropertyAccessorElement>[document.getter]; |
331 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode( | 331 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode(coreContext, |
332 coreContext, AstFactory.libraryIdentifier2(["dart", "dom", "html"])); | 332 AstTestFactory.libraryIdentifier2(["dart", "dom", "html"])); |
333 htmlLibrary.definingCompilationUnit = htmlUnit; | 333 htmlLibrary.definingCompilationUnit = htmlUnit; |
334 // | 334 // |
335 // dart:math | 335 // dart:math |
336 // | 336 // |
337 CompilationUnitElementImpl mathUnit = | 337 CompilationUnitElementImpl mathUnit = |
338 new CompilationUnitElementImpl("math.dart"); | 338 new CompilationUnitElementImpl("math.dart"); |
339 Source mathSource = sourceFactory.forUri(_DART_MATH); | 339 Source mathSource = sourceFactory.forUri(_DART_MATH); |
340 coreContext.setContents(mathSource, ""); | 340 coreContext.setContents(mathSource, ""); |
341 mathUnit.librarySource = mathUnit.source = mathSource; | 341 mathUnit.librarySource = mathUnit.source = mathSource; |
342 FunctionElement cosElement = ElementFactory.functionElement3( | 342 FunctionElement cosElement = ElementFactory.functionElement3( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 maxElement, | 383 maxElement, |
384 sinElement, | 384 sinElement, |
385 sqrtElement | 385 sqrtElement |
386 ]; | 386 ]; |
387 mathUnit.topLevelVariables = <TopLevelVariableElement>[ | 387 mathUnit.topLevelVariables = <TopLevelVariableElement>[ |
388 ln10Element, | 388 ln10Element, |
389 piElement | 389 piElement |
390 ]; | 390 ]; |
391 mathUnit.types = <ClassElement>[randomElement]; | 391 mathUnit.types = <ClassElement>[randomElement]; |
392 LibraryElementImpl mathLibrary = new LibraryElementImpl.forNode( | 392 LibraryElementImpl mathLibrary = new LibraryElementImpl.forNode( |
393 coreContext, AstFactory.libraryIdentifier2(["dart", "math"])); | 393 coreContext, AstTestFactory.libraryIdentifier2(["dart", "math"])); |
394 mathLibrary.definingCompilationUnit = mathUnit; | 394 mathLibrary.definingCompilationUnit = mathUnit; |
395 // | 395 // |
396 // Set empty sources for the rest of the libraries. | 396 // Set empty sources for the rest of the libraries. |
397 // | 397 // |
398 Source source = sourceFactory.forUri(_DART_INTERCEPTORS); | 398 Source source = sourceFactory.forUri(_DART_INTERCEPTORS); |
399 coreContext.setContents(source, ""); | 399 coreContext.setContents(source, ""); |
400 source = sourceFactory.forUri(_DART_JS_HELPER); | 400 source = sourceFactory.forUri(_DART_JS_HELPER); |
401 coreContext.setContents(source, ""); | 401 coreContext.setContents(source, ""); |
402 // | 402 // |
403 // Record the elements. | 403 // Record the elements. |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 | 571 |
572 void _addLibrary(LibraryMap map, String uri, bool isInternal, String path) { | 572 void _addLibrary(LibraryMap map, String uri, bool isInternal, String path) { |
573 SdkLibraryImpl library = new SdkLibraryImpl(uri); | 573 SdkLibraryImpl library = new SdkLibraryImpl(uri); |
574 if (isInternal) { | 574 if (isInternal) { |
575 library.category = "Internal"; | 575 library.category = "Internal"; |
576 } | 576 } |
577 library.path = path; | 577 library.path = path; |
578 map.setLibrary(uri, library); | 578 map.setLibrary(uri, library); |
579 } | 579 } |
580 } | 580 } |
OLD | NEW |