| 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 analyzer.src.generated.testing.test_type_provider; | 5 library analyzer.src.generated.testing.test_type_provider; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.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/src/dart/element/element.dart'; | 11 import 'package:analyzer/src/dart/element/element.dart'; |
| 12 import 'package:analyzer/src/dart/element/type.dart'; | 12 import 'package:analyzer/src/dart/element/type.dart'; |
| 13 import 'package:analyzer/src/generated/constant.dart'; | 13 import 'package:analyzer/src/generated/constant.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; | 14 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; |
| 15 import 'package:analyzer/src/generated/resolver.dart'; | 15 import 'package:analyzer/src/generated/resolver.dart'; |
| 16 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; | 16 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; |
| 17 import 'package:analyzer/src/generated/source.dart' show Source; | 17 import 'package:analyzer/src/generated/source.dart' show Source; |
| 18 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 18 import 'package:analyzer/src/generated/testing/ast_test_factory.dart'; |
| 19 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 19 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * A type provider that can be used by tests without creating the element model | 22 * A type provider that can be used by tests without creating the element model |
| 23 * for the core library. | 23 * for the core library. |
| 24 */ | 24 */ |
| 25 class TestTypeProvider extends TypeProviderBase { | 25 class TestTypeProvider extends TypeProviderBase { |
| 26 /** | 26 /** |
| 27 * The type representing the built-in type 'bool'. | 27 * The type representing the built-in type 'bool'. |
| 28 */ | 28 */ |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 InterfaceType get boolType { | 165 InterfaceType get boolType { |
| 166 if (_boolType == null) { | 166 if (_boolType == null) { |
| 167 ClassElementImpl boolElement = ElementFactory.classElement2("bool"); | 167 ClassElementImpl boolElement = ElementFactory.classElement2("bool"); |
| 168 _boolType = boolElement.type; | 168 _boolType = boolElement.type; |
| 169 ConstructorElementImpl fromEnvironment = ElementFactory | 169 ConstructorElementImpl fromEnvironment = ElementFactory |
| 170 .constructorElement(boolElement, "fromEnvironment", true); | 170 .constructorElement(boolElement, "fromEnvironment", true); |
| 171 fromEnvironment.parameters = <ParameterElement>[ | 171 fromEnvironment.parameters = <ParameterElement>[ |
| 172 ElementFactory.requiredParameter2("name", stringType), | 172 ElementFactory.requiredParameter2("name", stringType), |
| 173 ElementFactory.namedParameter3("defaultValue", | 173 ElementFactory.namedParameter3("defaultValue", |
| 174 type: _boolType, | 174 type: _boolType, |
| 175 initializer: AstFactory.booleanLiteral(false), | 175 initializer: AstTestFactory.booleanLiteral(false), |
| 176 initializerCode: 'false') | 176 initializerCode: 'false') |
| 177 ]; | 177 ]; |
| 178 fromEnvironment.factory = true; | 178 fromEnvironment.factory = true; |
| 179 fromEnvironment.isCycleFree = true; | 179 fromEnvironment.isCycleFree = true; |
| 180 boolElement.constructors = <ConstructorElement>[fromEnvironment]; | 180 boolElement.constructors = <ConstructorElement>[fromEnvironment]; |
| 181 } | 181 } |
| 182 return _boolType; | 182 return _boolType; |
| 183 } | 183 } |
| 184 | 184 |
| 185 @override | 185 @override |
| (...skipping 12 matching lines...) Expand all Loading... |
| 198 FieldElementImpl expiresField = ElementFactory.fieldElement( | 198 FieldElementImpl expiresField = ElementFactory.fieldElement( |
| 199 'expires', false, true, false, stringType); | 199 'expires', false, true, false, stringType); |
| 200 deprecatedElement.fields = <FieldElement>[expiresField]; | 200 deprecatedElement.fields = <FieldElement>[expiresField]; |
| 201 deprecatedElement.accessors = <PropertyAccessorElement>[ | 201 deprecatedElement.accessors = <PropertyAccessorElement>[ |
| 202 expiresField.getter | 202 expiresField.getter |
| 203 ]; | 203 ]; |
| 204 ConstructorElementImpl constructor = ElementFactory | 204 ConstructorElementImpl constructor = ElementFactory |
| 205 .constructorElement(deprecatedElement, '', true, [stringType]); | 205 .constructorElement(deprecatedElement, '', true, [stringType]); |
| 206 (constructor.parameters[0] as ParameterElementImpl).name = 'expires'; | 206 (constructor.parameters[0] as ParameterElementImpl).name = 'expires'; |
| 207 ConstructorFieldInitializer expiresInit = | 207 ConstructorFieldInitializer expiresInit = |
| 208 AstFactory.constructorFieldInitializer( | 208 AstTestFactory.constructorFieldInitializer( |
| 209 true, 'expires', AstFactory.identifier3('expires')); | 209 true, 'expires', AstTestFactory.identifier3('expires')); |
| 210 expiresInit.fieldName.staticElement = expiresField; | 210 expiresInit.fieldName.staticElement = expiresField; |
| 211 (expiresInit.expression as SimpleIdentifier).staticElement = | 211 (expiresInit.expression as SimpleIdentifier).staticElement = |
| 212 constructor.parameters[0]; | 212 constructor.parameters[0]; |
| 213 constructor.constantInitializers = <ConstructorInitializer>[expiresInit]; | 213 constructor.constantInitializers = <ConstructorInitializer>[expiresInit]; |
| 214 deprecatedElement.constructors = <ConstructorElement>[constructor]; | 214 deprecatedElement.constructors = <ConstructorElement>[constructor]; |
| 215 _deprecatedType = deprecatedElement.type; | 215 _deprecatedType = deprecatedElement.type; |
| 216 } | 216 } |
| 217 return _deprecatedType; | 217 return _deprecatedType; |
| 218 } | 218 } |
| 219 | 219 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 262 } |
| 263 | 263 |
| 264 @override | 264 @override |
| 265 InterfaceType get futureType { | 265 InterfaceType get futureType { |
| 266 if (_futureType == null) { | 266 if (_futureType == null) { |
| 267 Source asyncSource = _context.sourceFactory.forUri(DartSdk.DART_ASYNC); | 267 Source asyncSource = _context.sourceFactory.forUri(DartSdk.DART_ASYNC); |
| 268 _context.setContents(asyncSource, ""); | 268 _context.setContents(asyncSource, ""); |
| 269 CompilationUnitElementImpl asyncUnit = | 269 CompilationUnitElementImpl asyncUnit = |
| 270 new CompilationUnitElementImpl("async.dart"); | 270 new CompilationUnitElementImpl("async.dart"); |
| 271 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( | 271 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( |
| 272 _context, AstFactory.libraryIdentifier2(["dart.async"])); | 272 _context, AstTestFactory.libraryIdentifier2(["dart.async"])); |
| 273 asyncLibrary.definingCompilationUnit = asyncUnit; | 273 asyncLibrary.definingCompilationUnit = asyncUnit; |
| 274 asyncUnit.librarySource = asyncUnit.source = asyncSource; | 274 asyncUnit.librarySource = asyncUnit.source = asyncSource; |
| 275 | 275 |
| 276 ClassElementImpl future = ElementFactory.classElement2("Future", ["T"]); | 276 ClassElementImpl future = ElementFactory.classElement2("Future", ["T"]); |
| 277 _futureType = future.type; | 277 _futureType = future.type; |
| 278 asyncUnit.types = <ClassElement>[future]; | 278 asyncUnit.types = <ClassElement>[future]; |
| 279 } | 279 } |
| 280 return _futureType; | 280 return _futureType; |
| 281 } | 281 } |
| 282 | 282 |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 ElementFactory.constructorElement(numElement, null, false) | 613 ElementFactory.constructorElement(numElement, null, false) |
| 614 ..isSynthetic = true | 614 ..isSynthetic = true |
| 615 ]; | 615 ]; |
| 616 intElement.constructors = <ConstructorElement>[fromEnvironment]; | 616 intElement.constructors = <ConstructorElement>[fromEnvironment]; |
| 617 doubleElement.constructors = <ConstructorElement>[ | 617 doubleElement.constructors = <ConstructorElement>[ |
| 618 ElementFactory.constructorElement(doubleElement, null, false) | 618 ElementFactory.constructorElement(doubleElement, null, false) |
| 619 ..isSynthetic = true | 619 ..isSynthetic = true |
| 620 ]; | 620 ]; |
| 621 ConstFieldElementImpl varINFINITY = ElementFactory.fieldElement( | 621 ConstFieldElementImpl varINFINITY = ElementFactory.fieldElement( |
| 622 "INFINITY", true, false, true, _doubleType, | 622 "INFINITY", true, false, true, _doubleType, |
| 623 initializer: AstFactory.doubleLiteral(double.INFINITY)); | 623 initializer: AstTestFactory.doubleLiteral(double.INFINITY)); |
| 624 varINFINITY.constantInitializer = AstFactory.binaryExpression( | 624 varINFINITY.constantInitializer = AstTestFactory.binaryExpression( |
| 625 AstFactory.integer(1), TokenType.SLASH, AstFactory.integer(0)); | 625 AstTestFactory.integer(1), TokenType.SLASH, AstTestFactory.integer(0)); |
| 626 List<FieldElement> fields = <FieldElement>[ | 626 List<FieldElement> fields = <FieldElement>[ |
| 627 ElementFactory.fieldElement("NAN", true, false, true, _doubleType, | 627 ElementFactory.fieldElement("NAN", true, false, true, _doubleType, |
| 628 initializer: AstFactory.doubleLiteral(double.NAN)), | 628 initializer: AstTestFactory.doubleLiteral(double.NAN)), |
| 629 varINFINITY, | 629 varINFINITY, |
| 630 ElementFactory.fieldElement( | 630 ElementFactory.fieldElement( |
| 631 "NEGATIVE_INFINITY", true, false, true, _doubleType, | 631 "NEGATIVE_INFINITY", true, false, true, _doubleType, |
| 632 initializer: AstFactory.doubleLiteral(double.NEGATIVE_INFINITY)), | 632 initializer: AstTestFactory.doubleLiteral(double.NEGATIVE_INFINITY)), |
| 633 ElementFactory.fieldElement( | 633 ElementFactory.fieldElement( |
| 634 "MIN_POSITIVE", true, false, true, _doubleType, | 634 "MIN_POSITIVE", true, false, true, _doubleType, |
| 635 initializer: AstFactory.doubleLiteral(double.MIN_POSITIVE)), | 635 initializer: AstTestFactory.doubleLiteral(double.MIN_POSITIVE)), |
| 636 ElementFactory.fieldElement("MAX_FINITE", true, false, true, _doubleType, | 636 ElementFactory.fieldElement("MAX_FINITE", true, false, true, _doubleType, |
| 637 initializer: AstFactory.doubleLiteral(double.MAX_FINITE)) | 637 initializer: AstTestFactory.doubleLiteral(double.MAX_FINITE)) |
| 638 ]; | 638 ]; |
| 639 doubleElement.fields = fields; | 639 doubleElement.fields = fields; |
| 640 int fieldCount = fields.length; | 640 int fieldCount = fields.length; |
| 641 List<PropertyAccessorElement> accessors = | 641 List<PropertyAccessorElement> accessors = |
| 642 new List<PropertyAccessorElement>(fieldCount); | 642 new List<PropertyAccessorElement>(fieldCount); |
| 643 for (int i = 0; i < fieldCount; i++) { | 643 for (int i = 0; i < fieldCount; i++) { |
| 644 accessors[i] = fields[i].getter; | 644 accessors[i] = fields[i].getter; |
| 645 } | 645 } |
| 646 doubleElement.accessors = accessors; | 646 doubleElement.accessors = accessors; |
| 647 doubleElement.methods = <MethodElement>[ | 647 doubleElement.methods = <MethodElement>[ |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 * and also set the fields to those that correspond to the accessors. | 681 * and also set the fields to those that correspond to the accessors. |
| 682 */ | 682 */ |
| 683 void _setAccessors( | 683 void _setAccessors( |
| 684 ClassElementImpl element, List<PropertyAccessorElement> accessors) { | 684 ClassElementImpl element, List<PropertyAccessorElement> accessors) { |
| 685 element.accessors = accessors; | 685 element.accessors = accessors; |
| 686 element.fields = accessors | 686 element.fields = accessors |
| 687 .map((PropertyAccessorElement accessor) => accessor.variable) | 687 .map((PropertyAccessorElement accessor) => accessor.variable) |
| 688 .toList(); | 688 .toList(); |
| 689 } | 689 } |
| 690 } | 690 } |
| OLD | NEW |