| 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/member.dart'; | 14 import 'package:analyzer/src/dart/element/member.dart'; |
| 15 import 'package:analyzer/src/dart/element/type.dart'; | 15 import 'package:analyzer/src/dart/element/type.dart'; |
| 16 import 'package:analyzer/src/generated/constant.dart'; |
| 16 import 'package:analyzer/src/generated/element_handle.dart'; | 17 import 'package:analyzer/src/generated/element_handle.dart'; |
| 17 import 'package:analyzer/src/generated/engine.dart'; | 18 import 'package:analyzer/src/generated/engine.dart'; |
| 18 import 'package:analyzer/src/generated/resolver.dart'; | 19 import 'package:analyzer/src/generated/resolver.dart'; |
| 19 import 'package:analyzer/src/generated/source_io.dart'; | 20 import 'package:analyzer/src/generated/source_io.dart'; |
| 20 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 21 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 21 import 'package:analyzer/src/generated/testing/token_factory.dart'; | 22 import 'package:analyzer/src/generated/testing/token_factory.dart'; |
| 22 import 'package:analyzer/src/generated/utilities_dart.dart'; | 23 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 23 import 'package:analyzer/src/summary/idl.dart'; | 24 import 'package:analyzer/src/summary/idl.dart'; |
| 24 | 25 |
| 25 /** | 26 /** |
| (...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 assert(!isCoreLibrary); | 1020 assert(!isCoreLibrary); |
| 1020 ClassElementImpl classElement = | 1021 ClassElementImpl classElement = |
| 1021 new ClassElementImpl(serializedEnum.name, serializedEnum.nameOffset); | 1022 new ClassElementImpl(serializedEnum.name, serializedEnum.nameOffset); |
| 1022 classElement.enum2 = true; | 1023 classElement.enum2 = true; |
| 1023 InterfaceType enumType = new InterfaceTypeImpl(classElement); | 1024 InterfaceType enumType = new InterfaceTypeImpl(classElement); |
| 1024 classElement.type = enumType; | 1025 classElement.type = enumType; |
| 1025 classElement.supertype = summaryResynthesizer.typeProvider.objectType; | 1026 classElement.supertype = summaryResynthesizer.typeProvider.objectType; |
| 1026 buildDocumentation(classElement, serializedEnum.documentationComment); | 1027 buildDocumentation(classElement, serializedEnum.documentationComment); |
| 1027 buildAnnotations(classElement, serializedEnum.annotations); | 1028 buildAnnotations(classElement, serializedEnum.annotations); |
| 1028 ElementHolder memberHolder = new ElementHolder(); | 1029 ElementHolder memberHolder = new ElementHolder(); |
| 1030 // Build the 'index' field. |
| 1029 FieldElementImpl indexField = new FieldElementImpl('index', -1); | 1031 FieldElementImpl indexField = new FieldElementImpl('index', -1); |
| 1030 indexField.final2 = true; | 1032 indexField.final2 = true; |
| 1031 indexField.synthetic = true; | 1033 indexField.synthetic = true; |
| 1032 indexField.type = summaryResynthesizer.typeProvider.intType; | 1034 indexField.type = summaryResynthesizer.typeProvider.intType; |
| 1033 memberHolder.addField(indexField); | 1035 memberHolder.addField(indexField); |
| 1034 buildImplicitAccessors(indexField, memberHolder); | 1036 buildImplicitAccessors(indexField, memberHolder); |
| 1037 // Build the 'values' field. |
| 1035 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); | 1038 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); |
| 1036 valuesField.synthetic = true; | 1039 valuesField.synthetic = true; |
| 1037 valuesField.const3 = true; | 1040 valuesField.const3 = true; |
| 1038 valuesField.static = true; | 1041 valuesField.static = true; |
| 1039 valuesField.type = summaryResynthesizer.typeProvider.listType | 1042 valuesField.type = summaryResynthesizer.typeProvider.listType |
| 1040 .substitute4(<DartType>[enumType]); | 1043 .substitute4(<DartType>[enumType]); |
| 1041 memberHolder.addField(valuesField); | 1044 memberHolder.addField(valuesField); |
| 1042 buildImplicitAccessors(valuesField, memberHolder); | 1045 buildImplicitAccessors(valuesField, memberHolder); |
| 1043 for (UnlinkedEnumValue serializedEnumValue in serializedEnum.values) { | 1046 // Build fields for all enum constants. |
| 1044 ConstFieldElementImpl valueField = new ConstFieldElementImpl( | 1047 List<DartObjectImpl> constantValues = <DartObjectImpl>[]; |
| 1045 serializedEnumValue.name, serializedEnumValue.nameOffset); | 1048 for (int i = 0; i < serializedEnum.values.length; i++) { |
| 1046 buildDocumentation(valueField, serializedEnumValue.documentationComment); | 1049 UnlinkedEnumValue serializedEnumValue = serializedEnum.values[i]; |
| 1047 valueField.const3 = true; | 1050 String fieldName = serializedEnumValue.name; |
| 1048 valueField.static = true; | 1051 ConstFieldElementImpl field = |
| 1049 valueField.type = enumType; | 1052 new ConstFieldElementImpl(fieldName, serializedEnumValue.nameOffset); |
| 1050 memberHolder.addField(valueField); | 1053 buildDocumentation(field, serializedEnumValue.documentationComment); |
| 1051 buildImplicitAccessors(valueField, memberHolder); | 1054 field.const3 = true; |
| 1055 field.static = true; |
| 1056 field.type = enumType; |
| 1057 // Create a value for the constant. |
| 1058 Map<String, DartObjectImpl> fieldMap = <String, DartObjectImpl>{ |
| 1059 fieldName: new DartObjectImpl( |
| 1060 summaryResynthesizer.typeProvider.intType, new IntState(i)) |
| 1061 }; |
| 1062 DartObjectImpl value = |
| 1063 new DartObjectImpl(enumType, new GenericState(fieldMap)); |
| 1064 constantValues.add(value); |
| 1065 field.evaluationResult = new EvaluationResultImpl(value); |
| 1066 // Add the field. |
| 1067 memberHolder.addField(field); |
| 1068 buildImplicitAccessors(field, memberHolder); |
| 1052 } | 1069 } |
| 1070 // Build the value of the 'values' field. |
| 1071 valuesField.evaluationResult = new EvaluationResultImpl( |
| 1072 new DartObjectImpl(valuesField.type, new ListState(constantValues))); |
| 1073 // done |
| 1053 classElement.fields = memberHolder.fields; | 1074 classElement.fields = memberHolder.fields; |
| 1054 classElement.accessors = memberHolder.accessors; | 1075 classElement.accessors = memberHolder.accessors; |
| 1055 classElement.constructors = <ConstructorElement>[]; | 1076 classElement.constructors = <ConstructorElement>[]; |
| 1056 unitHolder.addEnum(classElement); | 1077 unitHolder.addEnum(classElement); |
| 1057 } | 1078 } |
| 1058 | 1079 |
| 1059 /** | 1080 /** |
| 1060 * Resynthesize an [ExecutableElement] and place it in the given [holder]. | 1081 * Resynthesize an [ExecutableElement] and place it in the given [holder]. |
| 1061 */ | 1082 */ |
| 1062 void buildExecutable(UnlinkedExecutable serializedExecutable, | 1083 void buildExecutable(UnlinkedExecutable serializedExecutable, |
| (...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2243 } | 2264 } |
| 2244 : () => this.element; | 2265 : () => this.element; |
| 2245 // TODO(paulberry): Is it a bug that we have to pass `false` for | 2266 // TODO(paulberry): Is it a bug that we have to pass `false` for |
| 2246 // isInstantiated? | 2267 // isInstantiated? |
| 2247 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); | 2268 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); |
| 2248 } else { | 2269 } else { |
| 2249 return null; | 2270 return null; |
| 2250 } | 2271 } |
| 2251 } | 2272 } |
| 2252 } | 2273 } |
| OLD | NEW |