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.element; | 5 library analyzer.src.dart.element.element; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'dart:math' show min; | 8 import 'dart:math' show min; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 } | 1201 } |
1202 // Build explicit property accessors and implicit fields. | 1202 // Build explicit property accessors and implicit fields. |
1203 var explicitAccessors = <PropertyAccessorElement>[]; | 1203 var explicitAccessors = <PropertyAccessorElement>[]; |
1204 var implicitFields = <String, FieldElementImpl>{}; | 1204 var implicitFields = <String, FieldElementImpl>{}; |
1205 for (UnlinkedExecutable e in _unlinkedClass.executables) { | 1205 for (UnlinkedExecutable e in _unlinkedClass.executables) { |
1206 if (e.kind == UnlinkedExecutableKind.getter || | 1206 if (e.kind == UnlinkedExecutableKind.getter || |
1207 e.kind == UnlinkedExecutableKind.setter) { | 1207 e.kind == UnlinkedExecutableKind.setter) { |
1208 PropertyAccessorElementImpl accessor = | 1208 PropertyAccessorElementImpl accessor = |
1209 new PropertyAccessorElementImpl.forSerialized(e, this); | 1209 new PropertyAccessorElementImpl.forSerialized(e, this); |
1210 explicitAccessors.add(accessor); | 1210 explicitAccessors.add(accessor); |
1211 // Prepare the field type. | |
1212 DartType fieldType; | |
1213 if (e.kind == UnlinkedExecutableKind.getter) { | |
1214 fieldType = accessor.returnType; | |
1215 } else { | |
1216 List<ParameterElement> parameters = accessor.parameters; | |
1217 fieldType = parameters.isNotEmpty | |
1218 ? parameters[0].type | |
1219 : DynamicTypeImpl.instance; | |
1220 } | |
1221 // Create or update the implicit field. | 1211 // Create or update the implicit field. |
1222 String fieldName = accessor.displayName; | 1212 String fieldName = accessor.displayName; |
1223 FieldElementImpl field = implicitFields[fieldName]; | 1213 FieldElementImpl field = implicitFields[fieldName]; |
1224 if (field == null) { | 1214 if (field == null) { |
1225 field = new FieldElementImpl(fieldName, -1); | 1215 field = new FieldElementImpl(fieldName, -1); |
1226 implicitFields[fieldName] = field; | 1216 implicitFields[fieldName] = field; |
1227 field.enclosingElement = this; | 1217 field.enclosingElement = this; |
1228 field.isSynthetic = true; | 1218 field.isSynthetic = true; |
1229 field.isFinal = e.kind == UnlinkedExecutableKind.getter; | 1219 field.isFinal = e.kind == UnlinkedExecutableKind.getter; |
1230 field.type = fieldType; | |
1231 field.isStatic = e.isStatic; | 1220 field.isStatic = e.isStatic; |
1232 } else { | 1221 } else { |
1233 field.isFinal = false; | 1222 field.isFinal = false; |
1234 } | 1223 } |
1235 accessor.variable = field; | 1224 accessor.variable = field; |
1236 if (e.kind == UnlinkedExecutableKind.getter) { | 1225 if (e.kind == UnlinkedExecutableKind.getter) { |
1237 field.getter = accessor; | 1226 field.getter = accessor; |
1238 } else { | 1227 } else { |
1239 field.setter = accessor; | 1228 field.setter = accessor; |
1240 } | 1229 } |
(...skipping 5659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6900 DartType get type { | 6889 DartType get type { |
6901 if (_unlinkedVariable != null && _declaredType == null && _type == null) { | 6890 if (_unlinkedVariable != null && _declaredType == null && _type == null) { |
6902 _type = enclosingUnit.resynthesizerContext.resolveLinkedType( | 6891 _type = enclosingUnit.resynthesizerContext.resolveLinkedType( |
6903 _unlinkedVariable.inferredTypeSlot, typeParameterContext); | 6892 _unlinkedVariable.inferredTypeSlot, typeParameterContext); |
6904 _declaredType = enclosingUnit.resynthesizerContext | 6893 _declaredType = enclosingUnit.resynthesizerContext |
6905 .resolveTypeRef(_unlinkedVariable.type, typeParameterContext); | 6894 .resolveTypeRef(_unlinkedVariable.type, typeParameterContext); |
6906 } | 6895 } |
6907 return super.type; | 6896 return super.type; |
6908 } | 6897 } |
6909 | 6898 |
| 6899 @override |
6910 void set type(DartType type) { | 6900 void set type(DartType type) { |
6911 _assertNotResynthesized(_unlinkedVariable); | 6901 _assertNotResynthesized(_unlinkedVariable); |
6912 _type = type; | 6902 _type = type; |
6913 } | 6903 } |
6914 | 6904 |
6915 /** | 6905 /** |
6916 * Subclasses need this getter, see [ConstVariableElement._unlinkedConst]. | 6906 * Subclasses need this getter, see [ConstVariableElement._unlinkedConst]. |
6917 */ | 6907 */ |
6918 UnlinkedExpr get _unlinkedConst => _unlinkedVariable?.initializer?.bodyExpr; | 6908 UnlinkedExpr get _unlinkedConst => _unlinkedVariable?.initializer?.bodyExpr; |
6919 } | 6909 } |
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7880 _propagatedType = enclosingUnit.resynthesizerContext.resolveLinkedType( | 7870 _propagatedType = enclosingUnit.resynthesizerContext.resolveLinkedType( |
7881 _unlinkedVariable.propagatedTypeSlot, typeParameterContext); | 7871 _unlinkedVariable.propagatedTypeSlot, typeParameterContext); |
7882 } | 7872 } |
7883 return _propagatedType; | 7873 return _propagatedType; |
7884 } | 7874 } |
7885 | 7875 |
7886 void set propagatedType(DartType propagatedType) { | 7876 void set propagatedType(DartType propagatedType) { |
7887 _assertNotResynthesized(_unlinkedVariable); | 7877 _assertNotResynthesized(_unlinkedVariable); |
7888 _propagatedType = propagatedType; | 7878 _propagatedType = propagatedType; |
7889 } | 7879 } |
| 7880 |
| 7881 @override |
| 7882 DartType get type { |
| 7883 if (isSynthetic && _type == null) { |
| 7884 if (getter != null) { |
| 7885 _type = getter.returnType; |
| 7886 } else if (setter != null) { |
| 7887 List<ParameterElement> parameters = setter.parameters; |
| 7888 _type = parameters.isNotEmpty |
| 7889 ? parameters[0].type |
| 7890 : DynamicTypeImpl.instance; |
| 7891 } else { |
| 7892 _type = DynamicTypeImpl.instance; |
| 7893 } |
| 7894 } |
| 7895 return super.type; |
| 7896 } |
7890 } | 7897 } |
7891 | 7898 |
7892 /** | 7899 /** |
7893 * The context in which elements are resynthesized. | 7900 * The context in which elements are resynthesized. |
7894 */ | 7901 */ |
7895 abstract class ResynthesizerContext { | 7902 abstract class ResynthesizerContext { |
7896 bool get isStrongMode; | 7903 bool get isStrongMode; |
7897 | 7904 |
7898 /** | 7905 /** |
7899 * Build [ElementAnnotationImpl] for the given [UnlinkedExpr]. | 7906 * Build [ElementAnnotationImpl] for the given [UnlinkedExpr]. |
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8625 | 8632 |
8626 @override | 8633 @override |
8627 void visitElement(Element element) { | 8634 void visitElement(Element element) { |
8628 int offset = element.nameOffset; | 8635 int offset = element.nameOffset; |
8629 if (offset != -1) { | 8636 if (offset != -1) { |
8630 map[offset] = element; | 8637 map[offset] = element; |
8631 } | 8638 } |
8632 super.visitElement(element); | 8639 super.visitElement(element); |
8633 } | 8640 } |
8634 } | 8641 } |
OLD | NEW |