Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:collection'; | 5 import 'dart:collection'; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 * Instances of the class `InheritanceManager` manage the knowledge of where cla ss members | 21 * Instances of the class `InheritanceManager` manage the knowledge of where cla ss members |
| 22 * (methods, getters & setters) are inherited from. | 22 * (methods, getters & setters) are inherited from. |
| 23 */ | 23 */ |
| 24 class InheritanceManager { | 24 class InheritanceManager { |
| 25 /** | 25 /** |
| 26 * The [LibraryElement] that is managed by this manager. | 26 * The [LibraryElement] that is managed by this manager. |
| 27 */ | 27 */ |
| 28 LibraryElement _library; | 28 LibraryElement _library; |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * A flag indicating whether abstract methods should be included when looking | |
| 32 * up the superclass chain. | |
| 33 */ | |
| 34 bool _includeAbstractFromSuperclasses; | |
| 35 | |
| 36 /** | |
| 31 * This is a mapping between each [ClassElement] and a map between the [String ] member | 37 * This is a mapping between each [ClassElement] and a map between the [String ] member |
| 32 * names and the associated [ExecutableElement] in the mixin and superclass ch ain. | 38 * names and the associated [ExecutableElement] in the mixin and superclass ch ain. |
| 33 */ | 39 */ |
| 34 Map<ClassElement, Map<String, ExecutableElement>> _classLookup; | 40 Map<ClassElement, Map<String, ExecutableElement>> _classLookup; |
| 35 | 41 |
| 36 /** | 42 /** |
| 37 * This is a mapping between each [ClassElement] and a map between the [String ] member | 43 * This is a mapping between each [ClassElement] and a map between the [String ] member |
| 38 * names and the associated [ExecutableElement] in the interface set. | 44 * names and the associated [ExecutableElement] in the interface set. |
| 39 */ | 45 */ |
| 40 Map<ClassElement, Map<String, ExecutableElement>> _interfaceLookup; | 46 Map<ClassElement, Map<String, ExecutableElement>> _interfaceLookup; |
| 41 | 47 |
| 42 /** | 48 /** |
| 43 * A map between each visited [ClassElement] and the set of [AnalysisError]s f ound on | 49 * A map between each visited [ClassElement] and the set of [AnalysisError]s f ound on |
| 44 * the class element. | 50 * the class element. |
| 45 */ | 51 */ |
| 46 Map<ClassElement, Set<AnalysisError>> _errorsInClassElement = | 52 Map<ClassElement, Set<AnalysisError>> _errorsInClassElement = |
| 47 new HashMap<ClassElement, Set<AnalysisError>>(); | 53 new HashMap<ClassElement, Set<AnalysisError>>(); |
| 48 | 54 |
| 49 /** | 55 /** |
| 50 * Initialize a newly created inheritance manager. | 56 * Initialize a newly created inheritance manager. |
| 51 * | 57 * |
| 52 * @param library the library element context that the inheritance mappings ar e being generated | 58 * @param library the library element context that the inheritance mappings ar e being generated |
| 53 */ | 59 */ |
| 54 InheritanceManager(LibraryElement library) { | 60 InheritanceManager(LibraryElement library, |
| 61 {bool includeAbstractFromSuperclasses: false}) { | |
|
scheglov
2016/08/10 01:23:38
At some point we discussed a possible optimization
| |
| 55 this._library = library; | 62 this._library = library; |
| 63 _includeAbstractFromSuperclasses = includeAbstractFromSuperclasses; | |
| 56 _classLookup = new HashMap<ClassElement, Map<String, ExecutableElement>>(); | 64 _classLookup = new HashMap<ClassElement, Map<String, ExecutableElement>>(); |
| 57 _interfaceLookup = | 65 _interfaceLookup = |
| 58 new HashMap<ClassElement, Map<String, ExecutableElement>>(); | 66 new HashMap<ClassElement, Map<String, ExecutableElement>>(); |
| 59 } | 67 } |
| 60 | 68 |
| 61 /** | 69 /** |
| 62 * Set the new library element context. | 70 * Set the new library element context. |
| 63 * | 71 * |
| 64 * @param library the new library element | 72 * @param library the new library element |
| 65 */ | 73 */ |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 try { | 283 try { |
| 276 resultMap = new Map<String, ExecutableElement>.from( | 284 resultMap = new Map<String, ExecutableElement>.from( |
| 277 _computeClassChainLookupMap(superclassElt, visitedClasses)); | 285 _computeClassChainLookupMap(superclassElt, visitedClasses)); |
| 278 // | 286 // |
| 279 // Substitute the super types down the hierarchy. | 287 // Substitute the super types down the hierarchy. |
| 280 // | 288 // |
| 281 _substituteTypeParametersDownHierarchy(supertype, resultMap); | 289 _substituteTypeParametersDownHierarchy(supertype, resultMap); |
| 282 // | 290 // |
| 283 // Include the members from the superclass in the resultMap. | 291 // Include the members from the superclass in the resultMap. |
| 284 // | 292 // |
| 285 _recordMapWithClassMembers(resultMap, supertype, false); | 293 _recordMapWithClassMembers( |
| 294 resultMap, supertype, _includeAbstractFromSuperclasses); | |
| 286 } finally { | 295 } finally { |
| 287 visitedClasses.remove(superclassElt); | 296 visitedClasses.remove(superclassElt); |
| 288 } | 297 } |
| 289 } else { | 298 } else { |
| 290 // This case happens only when the superclass was previously visited and | 299 // This case happens only when the superclass was previously visited and |
| 291 // not in the lookup, meaning this is meant to shorten the compute for | 300 // not in the lookup, meaning this is meant to shorten the compute for |
| 292 // recursive cases. | 301 // recursive cases. |
| 293 _classLookup[superclassElt] = resultMap; | 302 _classLookup[superclassElt] = resultMap; |
| 294 return resultMap; | 303 return resultMap; |
| 295 } | 304 } |
| 296 } | 305 } |
| 297 // | 306 // |
| 298 // Include the members from the mixins in the resultMap. If there are | 307 // Include the members from the mixins in the resultMap. If there are |
| 299 // multiple mixins, visit them in the order listed so that methods in later | 308 // multiple mixins, visit them in the order listed so that methods in later |
| 300 // mixins will overwrite identically-named methods in earlier mixins. | 309 // mixins will overwrite identically-named methods in earlier mixins. |
| 301 // | 310 // |
| 302 List<InterfaceType> mixins = classElt.mixins; | 311 List<InterfaceType> mixins = classElt.mixins; |
| 303 for (InterfaceType mixin in mixins) { | 312 for (InterfaceType mixin in mixins) { |
| 304 ClassElement mixinElement = mixin.element; | 313 ClassElement mixinElement = mixin.element; |
| 305 if (mixinElement != null) { | 314 if (mixinElement != null) { |
| 306 if (!visitedClasses.contains(mixinElement)) { | 315 if (!visitedClasses.contains(mixinElement)) { |
| 307 visitedClasses.add(mixinElement); | 316 visitedClasses.add(mixinElement); |
| 308 try { | 317 try { |
| 309 Map<String, ExecutableElement> map = | 318 Map<String, ExecutableElement> map = |
| 310 new Map<String, ExecutableElement>(); | 319 new Map<String, ExecutableElement>(); |
| 311 // | 320 // |
| 312 // Include the members from the mixin in the resultMap. | 321 // Include the members from the mixin in the resultMap. |
| 313 // | 322 // |
| 314 _recordMapWithClassMembers(map, mixin, false); | 323 _recordMapWithClassMembers( |
| 324 map, mixin, _includeAbstractFromSuperclasses); | |
| 315 // | 325 // |
| 316 // Add the members from map into result map. | 326 // Add the members from map into result map. |
| 317 // | 327 // |
| 318 for (String memberName in map.keys) { | 328 for (String memberName in map.keys) { |
| 319 ExecutableElement value = map[memberName]; | 329 ExecutableElement value = map[memberName]; |
| 320 ClassElement definingClass = value | 330 ClassElement definingClass = value |
| 321 .getAncestor((Element element) => element is ClassElement); | 331 .getAncestor((Element element) => element is ClassElement); |
| 322 if (!definingClass.type.isObject) { | 332 if (!definingClass.type.isObject) { |
| 323 ExecutableElement existingValue = resultMap[memberName]; | 333 ExecutableElement existingValue = resultMap[memberName]; |
| 324 if (existingValue == null || | 334 if (existingValue == null || |
| (...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1230 } | 1240 } |
| 1231 | 1241 |
| 1232 /** | 1242 /** |
| 1233 * Initializes [keys] and [values]. | 1243 * Initializes [keys] and [values]. |
| 1234 */ | 1244 */ |
| 1235 void _initArrays(int initialCapacity) { | 1245 void _initArrays(int initialCapacity) { |
| 1236 _keys = new List<String>(initialCapacity); | 1246 _keys = new List<String>(initialCapacity); |
| 1237 _values = new List<ExecutableElement>(initialCapacity); | 1247 _values = new List<ExecutableElement>(initialCapacity); |
| 1238 } | 1248 } |
| 1239 } | 1249 } |
| OLD | NEW |