Chromium Code Reviews| 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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 return false; | 415 return false; |
| 416 } | 416 } |
| 417 } | 417 } |
| 418 return true; | 418 return true; |
| 419 } | 419 } |
| 420 | 420 |
| 421 @override | 421 @override |
| 422 ElementKind get kind => ElementKind.CLASS; | 422 ElementKind get kind => ElementKind.CLASS; |
| 423 | 423 |
| 424 @override | 424 @override |
| 425 List<ElementAnnotation> get metadata { | |
| 426 if (_unlinkedClass != null) { | |
| 427 _metadata ??= _unlinkedClass.annotations | |
| 428 .map(resynthesizerContext.buildAnnotation) | |
| 429 .toList(); | |
| 430 } | |
| 431 return _metadata ?? const <ElementAnnotation>[]; | |
|
Paul Berry
2016/05/17 20:45:33
To clarify that this is additional functionality w
scheglov
2016/05/17 21:17:41
Done.
| |
| 432 } | |
| 433 | |
| 434 @override | |
| 425 List<MethodElement> get methods => _methods; | 435 List<MethodElement> get methods => _methods; |
| 426 | 436 |
| 427 /** | 437 /** |
| 428 * Set the methods contained in this class to the given [methods]. | 438 * Set the methods contained in this class to the given [methods]. |
| 429 */ | 439 */ |
| 430 void set methods(List<MethodElement> methods) { | 440 void set methods(List<MethodElement> methods) { |
| 431 for (MethodElement method in methods) { | 441 for (MethodElement method in methods) { |
| 432 (method as MethodElementImpl).enclosingElement = this; | 442 (method as MethodElementImpl).enclosingElement = this; |
| 433 } | 443 } |
| 434 this._methods = methods; | 444 this._methods = methods; |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1231 @override | 1241 @override |
| 1232 CompilationUnit computeNode() => unit; | 1242 CompilationUnit computeNode() => unit; |
| 1233 | 1243 |
| 1234 /** | 1244 /** |
| 1235 * Return the annotations associated with the directive at the given [offset], | 1245 * Return the annotations associated with the directive at the given [offset], |
| 1236 * or an empty list if the directive has no annotations or if there is no | 1246 * or an empty list if the directive has no annotations or if there is no |
| 1237 * directive at the given offset. | 1247 * directive at the given offset. |
| 1238 */ | 1248 */ |
| 1239 List<ElementAnnotation> getAnnotations(int offset) { | 1249 List<ElementAnnotation> getAnnotations(int offset) { |
| 1240 if (annotationMap == null) { | 1250 if (annotationMap == null) { |
| 1241 return ElementAnnotation.EMPTY_LIST; | 1251 return const <ElementAnnotation>[]; |
| 1242 } | 1252 } |
| 1243 return annotationMap[offset] ?? ElementAnnotation.EMPTY_LIST; | 1253 return annotationMap[offset] ?? const <ElementAnnotation>[]; |
| 1244 } | 1254 } |
| 1245 | 1255 |
| 1246 @override | 1256 @override |
| 1247 ElementImpl getChild(String identifier) { | 1257 ElementImpl getChild(String identifier) { |
| 1248 // | 1258 // |
| 1249 // The casts in this method are safe because the set methods would have | 1259 // The casts in this method are safe because the set methods would have |
| 1250 // thrown a CCE if any of the elements in the arrays were not of the | 1260 // thrown a CCE if any of the elements in the arrays were not of the |
| 1251 // expected types. | 1261 // expected types. |
| 1252 // | 1262 // |
| 1253 for (PropertyAccessorElement accessor in _accessors) { | 1263 for (PropertyAccessorElement accessor in _accessors) { |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1871 int _nameOffset = 0; | 1881 int _nameOffset = 0; |
| 1872 | 1882 |
| 1873 /** | 1883 /** |
| 1874 * A bit-encoded form of the modifiers associated with this element. | 1884 * A bit-encoded form of the modifiers associated with this element. |
| 1875 */ | 1885 */ |
| 1876 int _modifiers = 0; | 1886 int _modifiers = 0; |
| 1877 | 1887 |
| 1878 /** | 1888 /** |
| 1879 * A list containing all of the metadata associated with this element. | 1889 * A list containing all of the metadata associated with this element. |
| 1880 */ | 1890 */ |
| 1881 List<ElementAnnotation> metadata = ElementAnnotation.EMPTY_LIST; | 1891 List<ElementAnnotation> _metadata; |
| 1882 | 1892 |
| 1883 /** | 1893 /** |
| 1884 * A cached copy of the calculated hashCode for this element. | 1894 * A cached copy of the calculated hashCode for this element. |
| 1885 */ | 1895 */ |
| 1886 int _cachedHashCode; | 1896 int _cachedHashCode; |
| 1887 | 1897 |
| 1888 /** | 1898 /** |
| 1889 * A cached copy of the calculated location for this element. | 1899 * A cached copy of the calculated location for this element. |
| 1890 */ | 1900 */ |
| 1891 ElementLocation _cachedLocation; | 1901 ElementLocation _cachedLocation; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2079 ElementLocation get location { | 2089 ElementLocation get location { |
| 2080 if (_cachedLocation == null) { | 2090 if (_cachedLocation == null) { |
| 2081 if (library == null) { | 2091 if (library == null) { |
| 2082 return new ElementLocationImpl.con1(this); | 2092 return new ElementLocationImpl.con1(this); |
| 2083 } | 2093 } |
| 2084 _cachedLocation = new ElementLocationImpl.con1(this); | 2094 _cachedLocation = new ElementLocationImpl.con1(this); |
| 2085 } | 2095 } |
| 2086 return _cachedLocation; | 2096 return _cachedLocation; |
| 2087 } | 2097 } |
| 2088 | 2098 |
| 2099 List<ElementAnnotation> get metadata { | |
| 2100 return _metadata ?? const <ElementAnnotation>[]; | |
| 2101 } | |
| 2102 | |
| 2103 void set metadata(List<ElementAnnotation> metadata) { | |
| 2104 assert(resynthesizerContext == null); | |
| 2105 _metadata = metadata; | |
| 2106 } | |
| 2107 | |
| 2089 @override | 2108 @override |
| 2090 String get name => _name; | 2109 String get name => _name; |
| 2091 | 2110 |
| 2092 /** | 2111 /** |
| 2093 * Changes the name of this element. | 2112 * Changes the name of this element. |
| 2094 * | 2113 * |
| 2095 * Throws [FrozenHashCodeException] if the hashCode can't be changed. | 2114 * Throws [FrozenHashCodeException] if the hashCode can't be changed. |
| 2096 */ | 2115 */ |
| 2097 void set name(String name) { | 2116 void set name(String name) { |
| 2098 this._name = name; | 2117 this._name = name; |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2701 * [variables]. | 2720 * [variables]. |
| 2702 */ | 2721 */ |
| 2703 void set localVariables(List<LocalVariableElement> variables) { | 2722 void set localVariables(List<LocalVariableElement> variables) { |
| 2704 for (LocalVariableElement variable in variables) { | 2723 for (LocalVariableElement variable in variables) { |
| 2705 (variable as LocalVariableElementImpl).enclosingElement = this; | 2724 (variable as LocalVariableElementImpl).enclosingElement = this; |
| 2706 } | 2725 } |
| 2707 this._localVariables = variables; | 2726 this._localVariables = variables; |
| 2708 } | 2727 } |
| 2709 | 2728 |
| 2710 @override | 2729 @override |
| 2730 List<ElementAnnotation> get metadata { | |
| 2731 if (serializedExecutable != null) { | |
| 2732 _metadata ??= serializedExecutable.annotations | |
| 2733 .map(resynthesizerContext.buildAnnotation) | |
| 2734 .toList(); | |
| 2735 } | |
| 2736 return _metadata ?? const <ElementAnnotation>[]; | |
|
Paul Berry
2016/05/17 20:45:33
Same suggestion here, and in two additional places
scheglov
2016/05/17 21:17:41
Done.
| |
| 2737 } | |
| 2738 | |
| 2739 @override | |
| 2711 String get name { | 2740 String get name { |
| 2712 if (serializedExecutable != null) { | 2741 if (serializedExecutable != null) { |
| 2713 return serializedExecutable.name; | 2742 return serializedExecutable.name; |
| 2714 } | 2743 } |
| 2715 return super.name; | 2744 return super.name; |
| 2716 } | 2745 } |
| 2717 | 2746 |
| 2718 @override | 2747 @override |
| 2719 int get nameOffset { | 2748 int get nameOffset { |
| 2720 if (serializedExecutable != null) { | 2749 if (serializedExecutable != null) { |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3191 } | 3220 } |
| 3192 | 3221 |
| 3193 @override | 3222 @override |
| 3194 CompilationUnitElement get enclosingElement => | 3223 CompilationUnitElement get enclosingElement => |
| 3195 super.enclosingElement as CompilationUnitElement; | 3224 super.enclosingElement as CompilationUnitElement; |
| 3196 | 3225 |
| 3197 @override | 3226 @override |
| 3198 ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS; | 3227 ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS; |
| 3199 | 3228 |
| 3200 @override | 3229 @override |
| 3230 List<ElementAnnotation> get metadata { | |
| 3231 if (_unlinkedTypedef != null) { | |
| 3232 _metadata ??= _unlinkedTypedef.annotations | |
| 3233 .map(resynthesizerContext.buildAnnotation) | |
| 3234 .toList(); | |
| 3235 } | |
| 3236 return _metadata ?? const <ElementAnnotation>[]; | |
| 3237 } | |
| 3238 | |
| 3239 @override | |
| 3201 String get name { | 3240 String get name { |
| 3202 if (_unlinkedTypedef != null) { | 3241 if (_unlinkedTypedef != null) { |
| 3203 return _unlinkedTypedef.name; | 3242 return _unlinkedTypedef.name; |
| 3204 } | 3243 } |
| 3205 return super.name; | 3244 return super.name; |
| 3206 } | 3245 } |
| 3207 | 3246 |
| 3208 @override | 3247 @override |
| 3209 int get nameOffset { | 3248 int get nameOffset { |
| 3210 if (_unlinkedTypedef != null) { | 3249 if (_unlinkedTypedef != null) { |
| (...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4434 @override | 4473 @override |
| 4435 ElementKind get kind => ElementKind.ERROR; | 4474 ElementKind get kind => ElementKind.ERROR; |
| 4436 | 4475 |
| 4437 @override | 4476 @override |
| 4438 LibraryElement get library => null; | 4477 LibraryElement get library => null; |
| 4439 | 4478 |
| 4440 @override | 4479 @override |
| 4441 ElementLocation get location => null; | 4480 ElementLocation get location => null; |
| 4442 | 4481 |
| 4443 @override | 4482 @override |
| 4444 List<ElementAnnotation> get metadata => ElementAnnotation.EMPTY_LIST; | 4483 List<ElementAnnotation> get metadata => const <ElementAnnotation>[]; |
| 4445 | 4484 |
| 4446 @override | 4485 @override |
| 4447 String get name => _name; | 4486 String get name => _name; |
| 4448 | 4487 |
| 4449 @override | 4488 @override |
| 4450 int get nameLength => displayName != null ? displayName.length : 0; | 4489 int get nameLength => displayName != null ? displayName.length : 0; |
| 4451 | 4490 |
| 4452 @override | 4491 @override |
| 4453 int get nameOffset => -1; | 4492 int get nameOffset => -1; |
| 4454 | 4493 |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5061 * Initialize a newly created element to have the given [name]. | 5100 * Initialize a newly created element to have the given [name]. |
| 5062 */ | 5101 */ |
| 5063 PropertyInducingElementImpl.forNode(Identifier name) : super.forNode(name); | 5102 PropertyInducingElementImpl.forNode(Identifier name) : super.forNode(name); |
| 5064 } | 5103 } |
| 5065 | 5104 |
| 5066 /** | 5105 /** |
| 5067 * The context in which elements are resynthesized. | 5106 * The context in which elements are resynthesized. |
| 5068 */ | 5107 */ |
| 5069 abstract class ResynthesizerContext { | 5108 abstract class ResynthesizerContext { |
| 5070 /** | 5109 /** |
| 5110 * Build [ElementAnnotationImpl] for the given [UnlinkedConst]. | |
| 5111 */ | |
| 5112 ElementAnnotationImpl buildAnnotation(UnlinkedConst uc); | |
| 5113 | |
| 5114 /** | |
| 5071 * Resolve an [EntityRef] into a type. If the reference is | 5115 * Resolve an [EntityRef] into a type. If the reference is |
| 5072 * unresolved, return [DynamicTypeImpl.instance]. | 5116 * unresolved, return [DynamicTypeImpl.instance]. |
| 5073 * | 5117 * |
| 5074 * TODO(paulberry): or should we have a class representing an | 5118 * TODO(paulberry): or should we have a class representing an |
| 5075 * unresolved type, for consistency with the full element model? | 5119 * unresolved type, for consistency with the full element model? |
| 5076 */ | 5120 */ |
| 5077 DartType resolveTypeRef( | 5121 DartType resolveTypeRef( |
| 5078 EntityRef type, TypeParameterizedElementMixin typeParameterContext, | 5122 EntityRef type, TypeParameterizedElementMixin typeParameterContext, |
| 5079 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true}); | 5123 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true}); |
| 5080 } | 5124 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5262 if (_unlinkedTypeParam != null) { | 5306 if (_unlinkedTypeParam != null) { |
| 5263 return _enclosingTypeParameterizedElement; | 5307 return _enclosingTypeParameterizedElement; |
| 5264 } | 5308 } |
| 5265 return super.enclosingElement; | 5309 return super.enclosingElement; |
| 5266 } | 5310 } |
| 5267 | 5311 |
| 5268 @override | 5312 @override |
| 5269 ElementKind get kind => ElementKind.TYPE_PARAMETER; | 5313 ElementKind get kind => ElementKind.TYPE_PARAMETER; |
| 5270 | 5314 |
| 5271 @override | 5315 @override |
| 5316 List<ElementAnnotation> get metadata { | |
| 5317 if (_unlinkedTypeParam != null) { | |
| 5318 _metadata ??= _unlinkedTypeParam.annotations | |
| 5319 .map(resynthesizerContext.buildAnnotation) | |
| 5320 .toList(); | |
| 5321 } | |
| 5322 return _metadata ?? const <ElementAnnotation>[]; | |
| 5323 } | |
| 5324 | |
| 5325 @override | |
| 5272 String get name { | 5326 String get name { |
| 5273 if (_unlinkedTypeParam != null) { | 5327 if (_unlinkedTypeParam != null) { |
| 5274 return _unlinkedTypeParam.name; | 5328 return _unlinkedTypeParam.name; |
| 5275 } | 5329 } |
| 5276 return super.name; | 5330 return super.name; |
| 5277 } | 5331 } |
| 5278 | 5332 |
| 5279 @override | 5333 @override |
| 5280 int get nameOffset { | 5334 int get nameOffset { |
| 5281 if (_unlinkedTypeParam != null) { | 5335 if (_unlinkedTypeParam != null) { |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5570 | 5624 |
| 5571 @override | 5625 @override |
| 5572 void visitElement(Element element) { | 5626 void visitElement(Element element) { |
| 5573 int offset = element.nameOffset; | 5627 int offset = element.nameOffset; |
| 5574 if (offset != -1) { | 5628 if (offset != -1) { |
| 5575 map[offset] = element; | 5629 map[offset] = element; |
| 5576 } | 5630 } |
| 5577 super.visitElement(element); | 5631 super.visitElement(element); |
| 5578 } | 5632 } |
| 5579 } | 5633 } |
| OLD | NEW |