Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(520)

Side by Side Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 2038153003: Create ClassElement.type lazily in ClassElementImpl and EnumElementImpl. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 * this class. 42 * this class.
43 */ 43 */
44 List<PropertyAccessorElement> _accessors; 44 List<PropertyAccessorElement> _accessors;
45 45
46 /** 46 /**
47 * A list containing all of the fields contained in this class. 47 * A list containing all of the fields contained in this class.
48 */ 48 */
49 List<FieldElement> _fields; 49 List<FieldElement> _fields;
50 50
51 /** 51 /**
52 * The type defined by the class.
53 */
54 @override
55 InterfaceType type;
56
57 /**
58 * Initialize a newly created class element to have the given [name] at the 52 * Initialize a newly created class element to have the given [name] at the
59 * given [offset] in the file that contains the declaration of this element. 53 * given [offset] in the file that contains the declaration of this element.
60 */ 54 */
61 AbstractClassElementImpl(String name, int offset) : super(name, offset); 55 AbstractClassElementImpl(String name, int offset) : super(name, offset);
62 56
63 /** 57 /**
64 * Initialize a newly created class element to have the given [name]. 58 * Initialize a newly created class element to have the given [name].
65 */ 59 */
66 AbstractClassElementImpl.forNode(Identifier name) : super.forNode(name); 60 AbstractClassElementImpl.forNode(Identifier name) : super.forNode(name);
67 61
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 * A list containing all of the type parameters defined for this class. 428 * A list containing all of the type parameters defined for this class.
435 */ 429 */
436 List<TypeParameterElement> _typeParameters = TypeParameterElement.EMPTY_LIST; 430 List<TypeParameterElement> _typeParameters = TypeParameterElement.EMPTY_LIST;
437 431
438 /** 432 /**
439 * The superclass of the class, or `null` for [Object]. 433 * The superclass of the class, or `null` for [Object].
440 */ 434 */
441 InterfaceType _supertype; 435 InterfaceType _supertype;
442 436
443 /** 437 /**
438 * The type defined by the class.
439 */
440 InterfaceType _type;
441
442 /**
444 * A list containing all of the mixins that are applied to the class being 443 * A list containing all of the mixins that are applied to the class being
445 * extended in order to derive the superclass of this class. 444 * extended in order to derive the superclass of this class.
446 */ 445 */
447 List<InterfaceType> _mixins; 446 List<InterfaceType> _mixins;
448 447
449 /** 448 /**
450 * A list containing all of the interfaces that are implemented by this class. 449 * A list containing all of the interfaces that are implemented by this class.
451 */ 450 */
452 List<InterfaceType> _interfaces; 451 List<InterfaceType> _interfaces;
453 452
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 } 869 }
871 return _supertype; 870 return _supertype;
872 } 871 }
873 872
874 void set supertype(InterfaceType supertype) { 873 void set supertype(InterfaceType supertype) {
875 assert(_unlinkedClass == null); 874 assert(_unlinkedClass == null);
876 _supertype = supertype; 875 _supertype = supertype;
877 } 876 }
878 877
879 @override 878 @override
879 InterfaceType get type {
880 if (_type == null) {
881 InterfaceTypeImpl type = new InterfaceTypeImpl(this);
882 type.typeArguments = typeParameterTypes;
883 _type = type;
884 }
885 return _type;
886 }
887
888 @override
880 TypeParameterizedElementMixin get typeParameterContext => this; 889 TypeParameterizedElementMixin get typeParameterContext => this;
881 890
882 @override 891 @override
883 List<TypeParameterElement> get typeParameters { 892 List<TypeParameterElement> get typeParameters {
884 if (_unlinkedClass != null) { 893 if (_unlinkedClass != null) {
885 return super.typeParameters; 894 return super.typeParameters;
886 } 895 }
887 return _typeParameters; 896 return _typeParameters;
888 } 897 }
889 898
(...skipping 2231 matching lines...) Expand 10 before | Expand all | Expand 10 after
3121 /** 3130 /**
3122 * An [AbstractClassElementImpl] which is an enum. 3131 * An [AbstractClassElementImpl] which is an enum.
3123 */ 3132 */
3124 class EnumElementImpl extends AbstractClassElementImpl { 3133 class EnumElementImpl extends AbstractClassElementImpl {
3125 /** 3134 /**
3126 * The unlinked representation of the enum in the summary. 3135 * The unlinked representation of the enum in the summary.
3127 */ 3136 */
3128 final UnlinkedEnum _unlinkedEnum; 3137 final UnlinkedEnum _unlinkedEnum;
3129 3138
3130 /** 3139 /**
3140 * The type defined by the enum.
3141 */
3142 InterfaceType _type;
3143
3144 /**
3131 * Initialize a newly created class element to have the given [name] at the 3145 * Initialize a newly created class element to have the given [name] at the
3132 * given [offset] in the file that contains the declaration of this element. 3146 * given [offset] in the file that contains the declaration of this element.
3133 */ 3147 */
3134 EnumElementImpl(String name, int offset) 3148 EnumElementImpl(String name, int offset)
3135 : _unlinkedEnum = null, 3149 : _unlinkedEnum = null,
3136 super(name, offset); 3150 super(name, offset);
3137 3151
3138 /** 3152 /**
3139 * Initialize a newly created class element to have the given [name]. 3153 * Initialize a newly created class element to have the given [name].
3140 */ 3154 */
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
3261 if (_unlinkedEnum != null) { 3275 if (_unlinkedEnum != null) {
3262 return _unlinkedEnum.nameOffset; 3276 return _unlinkedEnum.nameOffset;
3263 } 3277 }
3264 return super.nameOffset; 3278 return super.nameOffset;
3265 } 3279 }
3266 3280
3267 @override 3281 @override
3268 InterfaceType get supertype => context.typeProvider.objectType; 3282 InterfaceType get supertype => context.typeProvider.objectType;
3269 3283
3270 @override 3284 @override
3285 InterfaceType get type {
3286 if (_type == null) {
3287 InterfaceTypeImpl type = new InterfaceTypeImpl(this);
3288 type.typeArguments = const <DartType>[];
3289 _type = type;
3290 }
3291 return _type;
3292 }
3293
3294 @override
3271 List<TypeParameterElement> get typeParameters => 3295 List<TypeParameterElement> get typeParameters =>
3272 const <TypeParameterElement>[]; 3296 const <TypeParameterElement>[];
3273 3297
3274 @override 3298 @override
3275 ConstructorElement get unnamedConstructor => null; 3299 ConstructorElement get unnamedConstructor => null;
3276 3300
3277 @override 3301 @override
3278 void appendTo(StringBuffer buffer) { 3302 void appendTo(StringBuffer buffer) {
3279 buffer.write('enum '); 3303 buffer.write('enum ');
3280 String name = displayName; 3304 String name = displayName;
(...skipping 4911 matching lines...) Expand 10 before | Expand all | Expand 10 after
8192 8216
8193 @override 8217 @override
8194 void visitElement(Element element) { 8218 void visitElement(Element element) {
8195 int offset = element.nameOffset; 8219 int offset = element.nameOffset;
8196 if (offset != -1) { 8220 if (offset != -1) {
8197 map[offset] = element; 8221 map[offset] = element;
8198 } 8222 }
8199 super.visitElement(element); 8223 super.visitElement(element);
8200 } 8224 }
8201 } 8225 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/builder.dart ('k') | pkg/analyzer/lib/src/generated/testing/element_factory.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698