| 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.dart.element.builder; | 5 library analyzer.src.dart.element.builder; |
| 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'; |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 enumElement.metadata = _createElementAnnotations(node.metadata); | 614 enumElement.metadata = _createElementAnnotations(node.metadata); |
| 615 enumElement.enum2 = true; | 615 enumElement.enum2 = true; |
| 616 setElementDocumentationComment(enumElement, node); | 616 setElementDocumentationComment(enumElement, node); |
| 617 InterfaceTypeImpl enumType = new InterfaceTypeImpl(enumElement); | 617 InterfaceTypeImpl enumType = new InterfaceTypeImpl(enumElement); |
| 618 enumElement.type = enumType; | 618 enumElement.type = enumType; |
| 619 // The equivalent code for enums in the spec shows a single constructor, | 619 // The equivalent code for enums in the spec shows a single constructor, |
| 620 // but that constructor is not callable (since it is a compile-time error | 620 // but that constructor is not callable (since it is a compile-time error |
| 621 // to subclass, mix-in, implement, or explicitly instantiate an enum). So | 621 // to subclass, mix-in, implement, or explicitly instantiate an enum). So |
| 622 // we represent this as having no constructors. | 622 // we represent this as having no constructors. |
| 623 enumElement.constructors = ConstructorElement.EMPTY_LIST; | 623 enumElement.constructors = ConstructorElement.EMPTY_LIST; |
| 624 // |
| 625 // Build the elements for the constants. These are minimal elements; the |
| 626 // rest of the constant elements (and elements for other fields) must be |
| 627 // built later after we can access the type provider. |
| 628 // |
| 629 List<FieldElement> fields = new List<FieldElement>(); |
| 630 NodeList<EnumConstantDeclaration> constants = node.constants; |
| 631 for (EnumConstantDeclaration constant in constants) { |
| 632 SimpleIdentifier constantName = constant.name; |
| 633 FieldElementImpl constantField = |
| 634 new ConstFieldElementImpl.forNode(constantName); |
| 635 constantField.static = true; |
| 636 constantField.const3 = true; |
| 637 constantField.type = enumType; |
| 638 setElementDocumentationComment(constantField, constant); |
| 639 fields.add(constantField); |
| 640 _createGetter(constantField); |
| 641 constantName.staticElement = constantField; |
| 642 } |
| 643 enumElement.fields = fields; |
| 644 |
| 624 _currentHolder.addEnum(enumElement); | 645 _currentHolder.addEnum(enumElement); |
| 625 enumName.staticElement = enumElement; | 646 enumName.staticElement = enumElement; |
| 626 return super.visitEnumDeclaration(node); | 647 return super.visitEnumDeclaration(node); |
| 627 } | 648 } |
| 628 | 649 |
| 629 @override | 650 @override |
| 630 Object visitExportDirective(ExportDirective node) { | 651 Object visitExportDirective(ExportDirective node) { |
| 631 List<ElementAnnotation> annotations = | 652 List<ElementAnnotation> annotations = |
| 632 _createElementAnnotations(node.metadata); | 653 _createElementAnnotations(node.metadata); |
| 633 compilationUnitElement.setAnnotations(node.offset, annotations); | 654 compilationUnitElement.setAnnotations(node.offset, annotations); |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1309 } | 1330 } |
| 1310 return annotations.map((Annotation a) { | 1331 return annotations.map((Annotation a) { |
| 1311 ElementAnnotationImpl elementAnnotation = | 1332 ElementAnnotationImpl elementAnnotation = |
| 1312 new ElementAnnotationImpl(compilationUnitElement); | 1333 new ElementAnnotationImpl(compilationUnitElement); |
| 1313 a.elementAnnotation = elementAnnotation; | 1334 a.elementAnnotation = elementAnnotation; |
| 1314 return elementAnnotation; | 1335 return elementAnnotation; |
| 1315 }).toList(); | 1336 }).toList(); |
| 1316 } | 1337 } |
| 1317 | 1338 |
| 1318 /** | 1339 /** |
| 1340 * Create a getter that corresponds to the given [field]. |
| 1341 */ |
| 1342 void _createGetter(FieldElementImpl field) { |
| 1343 PropertyAccessorElementImpl getter = |
| 1344 new PropertyAccessorElementImpl.forVariable(field); |
| 1345 getter.getter = true; |
| 1346 getter.returnType = field.type; |
| 1347 getter.type = new FunctionTypeImpl(getter); |
| 1348 field.getter = getter; |
| 1349 } |
| 1350 |
| 1351 /** |
| 1319 * Create the types associated with the given type parameters, setting the typ
e of each type | 1352 * Create the types associated with the given type parameters, setting the typ
e of each type |
| 1320 * parameter, and return an array of types corresponding to the given paramete
rs. | 1353 * parameter, and return an array of types corresponding to the given paramete
rs. |
| 1321 * | 1354 * |
| 1322 * @param typeParameters the type parameters for which types are to be created | 1355 * @param typeParameters the type parameters for which types are to be created |
| 1323 * @return an array of types corresponding to the given parameters | 1356 * @return an array of types corresponding to the given parameters |
| 1324 */ | 1357 */ |
| 1325 List<DartType> _createTypeParameterTypes( | 1358 List<DartType> _createTypeParameterTypes( |
| 1326 List<TypeParameterElement> typeParameters) { | 1359 List<TypeParameterElement> typeParameters) { |
| 1327 int typeParameterCount = typeParameters.length; | 1360 int typeParameterCount = typeParameters.length; |
| 1328 List<DartType> typeArguments = new List<DartType>(typeParameterCount); | 1361 List<DartType> typeArguments = new List<DartType>(typeParameterCount); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 return null; | 1489 return null; |
| 1457 } | 1490 } |
| 1458 | 1491 |
| 1459 /** | 1492 /** |
| 1460 * Return the lexical identifiers associated with the given [identifiers]. | 1493 * Return the lexical identifiers associated with the given [identifiers]. |
| 1461 */ | 1494 */ |
| 1462 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { | 1495 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { |
| 1463 return identifiers.map((identifier) => identifier.name).toList(); | 1496 return identifiers.map((identifier) => identifier.name).toList(); |
| 1464 } | 1497 } |
| 1465 } | 1498 } |
| OLD | NEW |