OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 summary_resynthesizer; | 5 library summary_resynthesizer; |
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/src/dart/element/element.dart'; | 13 import 'package:analyzer/src/dart/element/element.dart'; |
14 import 'package:analyzer/src/dart/element/handle.dart'; | 14 import 'package:analyzer/src/dart/element/handle.dart'; |
15 import 'package:analyzer/src/dart/element/member.dart'; | 15 import 'package:analyzer/src/dart/element/member.dart'; |
16 import 'package:analyzer/src/dart/element/type.dart'; | 16 import 'package:analyzer/src/dart/element/type.dart'; |
17 import 'package:analyzer/src/generated/constant.dart'; | |
18 import 'package:analyzer/src/generated/engine.dart'; | 17 import 'package:analyzer/src/generated/engine.dart'; |
19 import 'package:analyzer/src/generated/resolver.dart'; | 18 import 'package:analyzer/src/generated/resolver.dart'; |
20 import 'package:analyzer/src/generated/source_io.dart'; | 19 import 'package:analyzer/src/generated/source_io.dart'; |
21 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 20 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
22 import 'package:analyzer/src/generated/testing/token_factory.dart'; | 21 import 'package:analyzer/src/generated/testing/token_factory.dart'; |
23 import 'package:analyzer/src/summary/idl.dart'; | 22 import 'package:analyzer/src/summary/idl.dart'; |
24 | 23 |
25 /** | 24 /** |
26 * Implementation of [ElementResynthesizer] used when resynthesizing an element | 25 * Implementation of [ElementResynthesizer] used when resynthesizing an element |
27 * model from summaries. | 26 * model from summaries. |
(...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1522 } | 1521 } |
1523 | 1522 |
1524 /** | 1523 /** |
1525 * Resynthesize the [ClassElement] corresponding to an enum, along with the | 1524 * Resynthesize the [ClassElement] corresponding to an enum, along with the |
1526 * associated fields and implicit accessors. | 1525 * associated fields and implicit accessors. |
1527 */ | 1526 */ |
1528 void buildEnum(UnlinkedEnum serializedEnum) { | 1527 void buildEnum(UnlinkedEnum serializedEnum) { |
1529 assert(!libraryResynthesizer.isCoreLibrary); | 1528 assert(!libraryResynthesizer.isCoreLibrary); |
1530 EnumElementImpl classElement = | 1529 EnumElementImpl classElement = |
1531 new EnumElementImpl.forSerialized(serializedEnum, unit); | 1530 new EnumElementImpl.forSerialized(serializedEnum, unit); |
1532 InterfaceType enumType = classElement.type; | |
1533 ElementHolder memberHolder = new ElementHolder(); | |
1534 // Build the 'index' field. | |
1535 FieldElementImpl indexField = new FieldElementImpl('index', -1); | |
1536 indexField.final2 = true; | |
1537 indexField.synthetic = true; | |
1538 indexField.type = typeProvider.intType; | |
1539 memberHolder.addField(indexField); | |
1540 buildImplicitAccessors(indexField, memberHolder); | |
1541 // Build the 'values' field. | |
1542 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); | |
1543 valuesField.synthetic = true; | |
1544 valuesField.const3 = true; | |
1545 valuesField.static = true; | |
1546 valuesField.type = typeProvider.listType.instantiate(<DartType>[enumType]); | |
1547 memberHolder.addField(valuesField); | |
1548 buildImplicitAccessors(valuesField, memberHolder); | |
1549 // Build fields for all enum constants. | |
1550 List<DartObjectImpl> constantValues = <DartObjectImpl>[]; | |
1551 for (int i = 0; i < serializedEnum.values.length; i++) { | |
1552 UnlinkedEnumValue serializedEnumValue = serializedEnum.values[i]; | |
1553 String fieldName = serializedEnumValue.name; | |
1554 ConstFieldElementImpl field = | |
1555 new ConstFieldElementImpl(fieldName, serializedEnumValue.nameOffset); | |
1556 buildDocumentation(field, serializedEnumValue.documentationComment); | |
1557 field.const3 = true; | |
1558 field.static = true; | |
1559 field.type = enumType; | |
1560 // Create a value for the constant. | |
1561 Map<String, DartObjectImpl> fieldMap = <String, DartObjectImpl>{ | |
1562 fieldName: new DartObjectImpl(typeProvider.intType, new IntState(i)) | |
1563 }; | |
1564 DartObjectImpl value = | |
1565 new DartObjectImpl(enumType, new GenericState(fieldMap)); | |
1566 constantValues.add(value); | |
1567 field.evaluationResult = new EvaluationResultImpl(value); | |
1568 // Add the field. | |
1569 memberHolder.addField(field); | |
1570 buildImplicitAccessors(field, memberHolder); | |
1571 } | |
1572 // Build the value of the 'values' field. | |
1573 valuesField.evaluationResult = new EvaluationResultImpl( | |
1574 new DartObjectImpl(valuesField.type, new ListState(constantValues))); | |
1575 // done | |
1576 classElement.fields = memberHolder.fields; | |
1577 classElement.accessors = memberHolder.accessors; | |
1578 unitHolder.addEnum(classElement); | 1531 unitHolder.addEnum(classElement); |
1579 } | 1532 } |
1580 | 1533 |
1581 /** | 1534 /** |
1582 * Build the implicit getter and setter associated with [element], and place | 1535 * Build the implicit getter and setter associated with [element], and place |
1583 * them in [holder]. | 1536 * them in [holder]. |
1584 */ | 1537 */ |
1585 void buildImplicitAccessors( | 1538 void buildImplicitAccessors( |
1586 PropertyInducingElementImpl element, ElementHolder holder) { | 1539 PropertyInducingElementImpl element, ElementHolder holder) { |
1587 PropertyAccessorElementImpl getter = buildImplicitGetter(element); | 1540 PropertyAccessorElementImpl getter = buildImplicitGetter(element); |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 static String _getElementIdentifier(String name, ReferenceKind kind) { | 1891 static String _getElementIdentifier(String name, ReferenceKind kind) { |
1939 if (kind == ReferenceKind.topLevelPropertyAccessor || | 1892 if (kind == ReferenceKind.topLevelPropertyAccessor || |
1940 kind == ReferenceKind.propertyAccessor) { | 1893 kind == ReferenceKind.propertyAccessor) { |
1941 if (!name.endsWith('=')) { | 1894 if (!name.endsWith('=')) { |
1942 return name + '?'; | 1895 return name + '?'; |
1943 } | 1896 } |
1944 } | 1897 } |
1945 return name; | 1898 return name; |
1946 } | 1899 } |
1947 } | 1900 } |
OLD | NEW |