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

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 1898193004: TBR Revert "Remove MemberMap in favor of HashMap" (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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.generated.resolver; 5 library analyzer.src.generated.resolver;
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';
(...skipping 4825 matching lines...) Expand 10 before | Expand all | Expand 10 after
4836 class InheritanceManager { 4836 class InheritanceManager {
4837 /** 4837 /**
4838 * The [LibraryElement] that is managed by this manager. 4838 * The [LibraryElement] that is managed by this manager.
4839 */ 4839 */
4840 LibraryElement _library; 4840 LibraryElement _library;
4841 4841
4842 /** 4842 /**
4843 * This is a mapping between each [ClassElement] and a map between the [String ] member 4843 * This is a mapping between each [ClassElement] and a map between the [String ] member
4844 * names and the associated [ExecutableElement] in the mixin and superclass ch ain. 4844 * names and the associated [ExecutableElement] in the mixin and superclass ch ain.
4845 */ 4845 */
4846 Map<ClassElement, Map<String, ExecutableElement>> _classLookup; 4846 HashMap<ClassElement, MemberMap> _classLookup;
4847 4847
4848 /** 4848 /**
4849 * This is a mapping between each [ClassElement] and a map between the [String ] member 4849 * This is a mapping between each [ClassElement] and a map between the [String ] member
4850 * names and the associated [ExecutableElement] in the interface set. 4850 * names and the associated [ExecutableElement] in the interface set.
4851 */ 4851 */
4852 Map<ClassElement, Map<String, ExecutableElement>> _interfaceLookup; 4852 HashMap<ClassElement, MemberMap> _interfaceLookup;
4853 4853
4854 /** 4854 /**
4855 * A map between each visited [ClassElement] and the set of [AnalysisError]s f ound on 4855 * A map between each visited [ClassElement] and the set of [AnalysisError]s f ound on
4856 * the class element. 4856 * the class element.
4857 */ 4857 */
4858 Map<ClassElement, Set<AnalysisError>> _errorsInClassElement = 4858 HashMap<ClassElement, HashSet<AnalysisError>> _errorsInClassElement =
4859 new HashMap<ClassElement, Set<AnalysisError>>(); 4859 new HashMap<ClassElement, HashSet<AnalysisError>>();
4860 4860
4861 /** 4861 /**
4862 * Initialize a newly created inheritance manager. 4862 * Initialize a newly created inheritance manager.
4863 * 4863 *
4864 * @param library the library element context that the inheritance mappings ar e being generated 4864 * @param library the library element context that the inheritance mappings ar e being generated
4865 */ 4865 */
4866 InheritanceManager(LibraryElement library) { 4866 InheritanceManager(LibraryElement library) {
4867 this._library = library; 4867 this._library = library;
4868 _classLookup = new HashMap<ClassElement, Map<String, ExecutableElement>>(); 4868 _classLookup = new HashMap<ClassElement, MemberMap>();
4869 _interfaceLookup = 4869 _interfaceLookup = new HashMap<ClassElement, MemberMap>();
4870 new HashMap<ClassElement, Map<String, ExecutableElement>>();
4871 } 4870 }
4872 4871
4873 /** 4872 /**
4874 * Set the new library element context. 4873 * Set the new library element context.
4875 * 4874 *
4876 * @param library the new library element 4875 * @param library the new library element
4877 */ 4876 */
4878 void set libraryElement(LibraryElement library) { 4877 void set libraryElement(LibraryElement library) {
4879 this._library = library; 4878 this._library = library;
4880 } 4879 }
(...skipping 10 matching lines...) Expand all
4891 _errorsInClassElement[classElt]; 4890 _errorsInClassElement[classElt];
4892 4891
4893 /** 4892 /**
4894 * Get and return a mapping between the set of all string names of the members inherited from the 4893 * Get and return a mapping between the set of all string names of the members inherited from the
4895 * passed [ClassElement] superclass hierarchy, and the associated [ExecutableE lement]. 4894 * passed [ClassElement] superclass hierarchy, and the associated [ExecutableE lement].
4896 * 4895 *
4897 * @param classElt the class element to query 4896 * @param classElt the class element to query
4898 * @return a mapping between the set of all members inherited from the passed [ClassElement] 4897 * @return a mapping between the set of all members inherited from the passed [ClassElement]
4899 * superclass hierarchy, and the associated [ExecutableElement] 4898 * superclass hierarchy, and the associated [ExecutableElement]
4900 */ 4899 */
4901 Map<String, ExecutableElement> getMapOfMembersInheritedFromClasses( 4900 MemberMap getMapOfMembersInheritedFromClasses(ClassElement classElt) =>
4902 ClassElement classElt) =>
4903 _computeClassChainLookupMap(classElt, new HashSet<ClassElement>()); 4901 _computeClassChainLookupMap(classElt, new HashSet<ClassElement>());
4904 4902
4905 /** 4903 /**
4906 * Get and return a mapping between the set of all string names of the members inherited from the 4904 * Get and return a mapping between the set of all string names of the members inherited from the
4907 * passed [ClassElement] interface hierarchy, and the associated [ExecutableEl ement]. 4905 * passed [ClassElement] interface hierarchy, and the associated [ExecutableEl ement].
4908 * 4906 *
4909 * @param classElt the class element to query 4907 * @param classElt the class element to query
4910 * @return a mapping between the set of all string names of the members inheri ted from the passed 4908 * @return a mapping between the set of all string names of the members inheri ted from the passed
4911 * [ClassElement] interface hierarchy, and the associated [ExecutableE lement]. 4909 * [ClassElement] interface hierarchy, and the associated [ExecutableE lement].
4912 */ 4910 */
4913 Map<String, ExecutableElement> getMapOfMembersInheritedFromInterfaces( 4911 MemberMap getMapOfMembersInheritedFromInterfaces(ClassElement classElt) =>
4914 ClassElement classElt) =>
4915 _computeInterfaceLookupMap(classElt, new HashSet<ClassElement>()); 4912 _computeInterfaceLookupMap(classElt, new HashSet<ClassElement>());
4916 4913
4917 /** 4914 /**
4918 * Given some [ClassElement] and some member name, this returns the 4915 * Given some [ClassElement] and some member name, this returns the
4919 * [ExecutableElement] that the class inherits from the mixins, 4916 * [ExecutableElement] that the class inherits from the mixins,
4920 * superclasses or interfaces, that has the member name, if no member is inher ited `null` is 4917 * superclasses or interfaces, that has the member name, if no member is inher ited `null` is
4921 * returned. 4918 * returned.
4922 * 4919 *
4923 * @param classElt the class element to query 4920 * @param classElt the class element to query
4924 * @param memberName the name of the executable element to find and return 4921 * @param memberName the name of the executable element to find and return
4925 * @return the inherited executable element with the member name, or `null` if no such 4922 * @return the inherited executable element with the member name, or `null` if no such
4926 * member exists 4923 * member exists
4927 */ 4924 */
4928 ExecutableElement lookupInheritance( 4925 ExecutableElement lookupInheritance(
4929 ClassElement classElt, String memberName) { 4926 ClassElement classElt, String memberName) {
4930 if (memberName == null || memberName.isEmpty) { 4927 if (memberName == null || memberName.isEmpty) {
4931 return null; 4928 return null;
4932 } 4929 }
4933 ExecutableElement executable = _computeClassChainLookupMap( 4930 ExecutableElement executable =
4934 classElt, new HashSet<ClassElement>())[memberName]; 4931 _computeClassChainLookupMap(classElt, new HashSet<ClassElement>())
4932 .get(memberName);
4935 if (executable == null) { 4933 if (executable == null) {
4936 return _computeInterfaceLookupMap(classElt, new HashSet<ClassElement>())[ 4934 return _computeInterfaceLookupMap(classElt, new HashSet<ClassElement>())
4937 memberName]; 4935 .get(memberName);
4938 } 4936 }
4939 return executable; 4937 return executable;
4940 } 4938 }
4941 4939
4942 /** 4940 /**
4943 * Given some [ClassElement] and some member name, this returns the 4941 * Given some [ClassElement] and some member name, this returns the
4944 * [ExecutableElement] that the class either declares itself, or 4942 * [ExecutableElement] that the class either declares itself, or
4945 * inherits, that has the member name, if no member is inherited `null` is ret urned. 4943 * inherits, that has the member name, if no member is inherited `null` is ret urned.
4946 * 4944 *
4947 * @param classElt the class element to query 4945 * @param classElt the class element to query
(...skipping 18 matching lines...) Expand all
4966 * @param classElt the class to query 4964 * @param classElt the class to query
4967 * @param memberName the name of the class member to query 4965 * @param memberName the name of the class member to query
4968 * @return a list of overridden methods 4966 * @return a list of overridden methods
4969 */ 4967 */
4970 List<ExecutableElement> lookupOverrides( 4968 List<ExecutableElement> lookupOverrides(
4971 ClassElement classElt, String memberName) { 4969 ClassElement classElt, String memberName) {
4972 List<ExecutableElement> result = new List<ExecutableElement>(); 4970 List<ExecutableElement> result = new List<ExecutableElement>();
4973 if (memberName == null || memberName.isEmpty) { 4971 if (memberName == null || memberName.isEmpty) {
4974 return result; 4972 return result;
4975 } 4973 }
4976 List<Map<String, ExecutableElement>> interfaceMaps = 4974 List<MemberMap> interfaceMaps =
4977 _gatherInterfaceLookupMaps(classElt, new HashSet<ClassElement>()); 4975 _gatherInterfaceLookupMaps(classElt, new HashSet<ClassElement>());
4978 if (interfaceMaps != null) { 4976 if (interfaceMaps != null) {
4979 for (Map<String, ExecutableElement> interfaceMap in interfaceMaps) { 4977 for (MemberMap interfaceMap in interfaceMaps) {
4980 ExecutableElement overriddenElement = interfaceMap[memberName]; 4978 ExecutableElement overriddenElement = interfaceMap.get(memberName);
4981 if (overriddenElement != null) { 4979 if (overriddenElement != null) {
4982 if (overriddenElement is MultiplyInheritedExecutableElement) { 4980 if (overriddenElement is MultiplyInheritedExecutableElement) {
4983 MultiplyInheritedExecutableElement multiplyInheritedElement = 4981 MultiplyInheritedExecutableElement multiplyInheritedElement =
4984 overriddenElement; 4982 overriddenElement;
4985 for (ExecutableElement element 4983 for (ExecutableElement element
4986 in multiplyInheritedElement.inheritedElements) { 4984 in multiplyInheritedElement.inheritedElements) {
4987 result.add(element); 4985 result.add(element);
4988 } 4986 }
4989 } else { 4987 } else {
4990 result.add(overriddenElement); 4988 result.add(overriddenElement);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
5041 * Compute and return a mapping between the set of all string names of the mem bers inherited from 5039 * Compute and return a mapping between the set of all string names of the mem bers inherited from
5042 * the passed [ClassElement] superclass hierarchy, and the associated 5040 * the passed [ClassElement] superclass hierarchy, and the associated
5043 * [ExecutableElement]. 5041 * [ExecutableElement].
5044 * 5042 *
5045 * @param classElt the class element to query 5043 * @param classElt the class element to query
5046 * @param visitedClasses a set of visited classes passed back into this method when it calls 5044 * @param visitedClasses a set of visited classes passed back into this method when it calls
5047 * itself recursively 5045 * itself recursively
5048 * @return a mapping between the set of all string names of the members inheri ted from the passed 5046 * @return a mapping between the set of all string names of the members inheri ted from the passed
5049 * [ClassElement] superclass hierarchy, and the associated [Executable Element] 5047 * [ClassElement] superclass hierarchy, and the associated [Executable Element]
5050 */ 5048 */
5051 Map<String, ExecutableElement> _computeClassChainLookupMap( 5049 MemberMap _computeClassChainLookupMap(
5052 ClassElement classElt, HashSet<ClassElement> visitedClasses) { 5050 ClassElement classElt, HashSet<ClassElement> visitedClasses) {
5053 Map<String, ExecutableElement> resultMap = _classLookup[classElt]; 5051 MemberMap resultMap = _classLookup[classElt];
5054 if (resultMap != null) { 5052 if (resultMap != null) {
5055 return resultMap; 5053 return resultMap;
5056 } else { 5054 } else {
5057 resultMap = new HashMap<String, ExecutableElement>(); 5055 resultMap = new MemberMap();
5058 } 5056 }
5059 ClassElement superclassElt = null; 5057 ClassElement superclassElt = null;
5060 InterfaceType supertype = classElt.supertype; 5058 InterfaceType supertype = classElt.supertype;
5061 if (supertype != null) { 5059 if (supertype != null) {
5062 superclassElt = supertype.element; 5060 superclassElt = supertype.element;
5063 } else { 5061 } else {
5064 // classElt is Object 5062 // classElt is Object
5065 _classLookup[classElt] = resultMap; 5063 _classLookup[classElt] = resultMap;
5066 return resultMap; 5064 return resultMap;
5067 } 5065 }
5068 if (superclassElt != null) { 5066 if (superclassElt != null) {
5069 if (!visitedClasses.contains(superclassElt)) { 5067 if (!visitedClasses.contains(superclassElt)) {
5070 visitedClasses.add(superclassElt); 5068 visitedClasses.add(superclassElt);
5071 try { 5069 try {
5072 resultMap = new HashMap<String, ExecutableElement>.from( 5070 resultMap = new MemberMap.from(
5073 _computeClassChainLookupMap(superclassElt, visitedClasses)); 5071 _computeClassChainLookupMap(superclassElt, visitedClasses));
5074 // 5072 //
5075 // Substitute the super types down the hierarchy. 5073 // Substitute the super types down the hierarchy.
5076 // 5074 //
5077 _substituteTypeParametersDownHierarchy(supertype, resultMap); 5075 _substituteTypeParametersDownHierarchy(supertype, resultMap);
5078 // 5076 //
5079 // Include the members from the superclass in the resultMap. 5077 // Include the members from the superclass in the resultMap.
5080 // 5078 //
5081 _recordMapWithClassMembers(resultMap, supertype, false); 5079 _recordMapWithClassMembers(resultMap, supertype, false);
5082 } finally { 5080 } finally {
(...skipping 12 matching lines...) Expand all
5095 // multiple mixins, visit them in the order listed so that methods in later 5093 // multiple mixins, visit them in the order listed so that methods in later
5096 // mixins will overwrite identically-named methods in earlier mixins. 5094 // mixins will overwrite identically-named methods in earlier mixins.
5097 // 5095 //
5098 List<InterfaceType> mixins = classElt.mixins; 5096 List<InterfaceType> mixins = classElt.mixins;
5099 for (InterfaceType mixin in mixins) { 5097 for (InterfaceType mixin in mixins) {
5100 ClassElement mixinElement = mixin.element; 5098 ClassElement mixinElement = mixin.element;
5101 if (mixinElement != null) { 5099 if (mixinElement != null) {
5102 if (!visitedClasses.contains(mixinElement)) { 5100 if (!visitedClasses.contains(mixinElement)) {
5103 visitedClasses.add(mixinElement); 5101 visitedClasses.add(mixinElement);
5104 try { 5102 try {
5105 Map<String, ExecutableElement> map = 5103 MemberMap map = new MemberMap.from(
5106 new HashMap<String, ExecutableElement>.from( 5104 _computeClassChainLookupMap(mixinElement, visitedClasses));
5107 _computeClassChainLookupMap(mixinElement, visitedClasses));
5108 // 5105 //
5109 // Substitute the super types down the hierarchy. 5106 // Substitute the super types down the hierarchy.
5110 // 5107 //
5111 _substituteTypeParametersDownHierarchy(mixin, map); 5108 _substituteTypeParametersDownHierarchy(mixin, map);
5112 // 5109 //
5113 // Include the members from the superclass in the resultMap. 5110 // Include the members from the superclass in the resultMap.
5114 // 5111 //
5115 _recordMapWithClassMembers(map, mixin, false); 5112 _recordMapWithClassMembers(map, mixin, false);
5116 // 5113 //
5117 // Add the members from map into result map. 5114 // Add the members from map into result map.
5118 // 5115 //
5119 for (String memberName in map.keys) { 5116 for (int j = 0; j < map.size; j++) {
5120 ExecutableElement value = map[memberName]; 5117 String key = map.getKey(j);
5121 ClassElement definingClass = value 5118 ExecutableElement value = map.getValue(j);
5122 .getAncestor((Element element) => element is ClassElement); 5119 if (key != null) {
5123 if (!definingClass.type.isObject) { 5120 ClassElement definingClass = value
5124 ExecutableElement existingValue = resultMap[memberName]; 5121 .getAncestor((Element element) => element is ClassElement);
5125 if (existingValue == null || 5122 if (!definingClass.type.isObject) {
5126 (existingValue != null && !_isAbstract(value))) { 5123 ExecutableElement existingValue = resultMap.get(key);
5127 resultMap[memberName] = value; 5124 if (existingValue == null ||
5125 (existingValue != null && !_isAbstract(value))) {
5126 resultMap.put(key, value);
5127 }
5128 } 5128 }
5129 } 5129 }
5130 } 5130 }
5131 } finally { 5131 } finally {
5132 visitedClasses.remove(mixinElement); 5132 visitedClasses.remove(mixinElement);
5133 } 5133 }
5134 } else { 5134 } else {
5135 // This case happens only when the superclass was previously visited 5135 // This case happens only when the superclass was previously visited
5136 // and not in the lookup, meaning this is meant to shorten the compute 5136 // and not in the lookup, meaning this is meant to shorten the compute
5137 // for recursive cases. 5137 // for recursive cases.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
5212 * Compute and return a mapping between the set of all string names of the mem bers inherited from 5212 * Compute and return a mapping between the set of all string names of the mem bers inherited from
5213 * the passed [ClassElement] interface hierarchy, and the associated 5213 * the passed [ClassElement] interface hierarchy, and the associated
5214 * [ExecutableElement]. 5214 * [ExecutableElement].
5215 * 5215 *
5216 * @param classElt the class element to query 5216 * @param classElt the class element to query
5217 * @param visitedInterfaces a set of visited classes passed back into this met hod when it calls 5217 * @param visitedInterfaces a set of visited classes passed back into this met hod when it calls
5218 * itself recursively 5218 * itself recursively
5219 * @return a mapping between the set of all string names of the members inheri ted from the passed 5219 * @return a mapping between the set of all string names of the members inheri ted from the passed
5220 * [ClassElement] interface hierarchy, and the associated [ExecutableE lement] 5220 * [ClassElement] interface hierarchy, and the associated [ExecutableE lement]
5221 */ 5221 */
5222 Map<String, ExecutableElement> _computeInterfaceLookupMap( 5222 MemberMap _computeInterfaceLookupMap(
5223 ClassElement classElt, HashSet<ClassElement> visitedInterfaces) { 5223 ClassElement classElt, HashSet<ClassElement> visitedInterfaces) {
5224 Map<String, ExecutableElement> resultMap = _interfaceLookup[classElt]; 5224 MemberMap resultMap = _interfaceLookup[classElt];
5225 if (resultMap != null) { 5225 if (resultMap != null) {
5226 return resultMap; 5226 return resultMap;
5227 } 5227 }
5228 List<Map<String, ExecutableElement>> lookupMaps = 5228 List<MemberMap> lookupMaps =
5229 _gatherInterfaceLookupMaps(classElt, visitedInterfaces); 5229 _gatherInterfaceLookupMaps(classElt, visitedInterfaces);
5230 if (lookupMaps == null) { 5230 if (lookupMaps == null) {
5231 resultMap = new HashMap<String, ExecutableElement>(); 5231 resultMap = new MemberMap();
5232 } else { 5232 } else {
5233 Map<String, List<ExecutableElement>> unionMap = 5233 HashMap<String, List<ExecutableElement>> unionMap =
5234 _unionInterfaceLookupMaps(lookupMaps); 5234 _unionInterfaceLookupMaps(lookupMaps);
5235 resultMap = _resolveInheritanceLookup(classElt, unionMap); 5235 resultMap = _resolveInheritanceLookup(classElt, unionMap);
5236 } 5236 }
5237 _interfaceLookup[classElt] = resultMap; 5237 _interfaceLookup[classElt] = resultMap;
5238 return resultMap; 5238 return resultMap;
5239 } 5239 }
5240 5240
5241 /** 5241 /**
5242 * Collect a list of interface lookup maps whose elements correspond to all of the classes 5242 * Collect a list of interface lookup maps whose elements correspond to all of the classes
5243 * directly above [classElt] in the class hierarchy (the direct superclass if any, all 5243 * directly above [classElt] in the class hierarchy (the direct superclass if any, all
5244 * mixins, and all direct superinterfaces). Each item in the list is the inter face lookup map 5244 * mixins, and all direct superinterfaces). Each item in the list is the inter face lookup map
5245 * returned by [computeInterfaceLookupMap] for the corresponding super, except with type 5245 * returned by [computeInterfaceLookupMap] for the corresponding super, except with type
5246 * parameters appropriately substituted. 5246 * parameters appropriately substituted.
5247 * 5247 *
5248 * @param classElt the class element to query 5248 * @param classElt the class element to query
5249 * @param visitedInterfaces a set of visited classes passed back into this met hod when it calls 5249 * @param visitedInterfaces a set of visited classes passed back into this met hod when it calls
5250 * itself recursively 5250 * itself recursively
5251 * @return `null` if there was a problem (such as a loop in the class hierarch y) or if there 5251 * @return `null` if there was a problem (such as a loop in the class hierarch y) or if there
5252 * are no classes above this one in the class hierarchy. Otherwise, a list of interface 5252 * are no classes above this one in the class hierarchy. Otherwise, a list of interface
5253 * lookup maps. 5253 * lookup maps.
5254 */ 5254 */
5255 List<Map<String, ExecutableElement>> _gatherInterfaceLookupMaps( 5255 List<MemberMap> _gatherInterfaceLookupMaps(
5256 ClassElement classElt, HashSet<ClassElement> visitedInterfaces) { 5256 ClassElement classElt, HashSet<ClassElement> visitedInterfaces) {
5257 InterfaceType supertype = classElt.supertype; 5257 InterfaceType supertype = classElt.supertype;
5258 ClassElement superclassElement = 5258 ClassElement superclassElement =
5259 supertype != null ? supertype.element : null; 5259 supertype != null ? supertype.element : null;
5260 List<InterfaceType> mixins = classElt.mixins; 5260 List<InterfaceType> mixins = classElt.mixins;
5261 List<InterfaceType> interfaces = classElt.interfaces; 5261 List<InterfaceType> interfaces = classElt.interfaces;
5262 // Recursively collect the list of mappings from all of the interface types 5262 // Recursively collect the list of mappings from all of the interface types
5263 List<Map<String, ExecutableElement>> lookupMaps = 5263 List<MemberMap> lookupMaps = new List<MemberMap>();
5264 new List<Map<String, ExecutableElement>>();
5265 // 5264 //
5266 // Superclass element 5265 // Superclass element
5267 // 5266 //
5268 if (superclassElement != null) { 5267 if (superclassElement != null) {
5269 if (!visitedInterfaces.contains(superclassElement)) { 5268 if (!visitedInterfaces.contains(superclassElement)) {
5270 try { 5269 try {
5271 visitedInterfaces.add(superclassElement); 5270 visitedInterfaces.add(superclassElement);
5272 // 5271 //
5273 // Recursively compute the map for the super type. 5272 // Recursively compute the map for the super type.
5274 // 5273 //
5275 Map<String, ExecutableElement> map = 5274 MemberMap map =
5276 _computeInterfaceLookupMap(superclassElement, visitedInterfaces); 5275 _computeInterfaceLookupMap(superclassElement, visitedInterfaces);
5277 map = new HashMap<String, ExecutableElement>.from(map); 5276 map = new MemberMap.from(map);
5278 // 5277 //
5279 // Substitute the super type down the hierarchy. 5278 // Substitute the super type down the hierarchy.
5280 // 5279 //
5281 _substituteTypeParametersDownHierarchy(supertype, map); 5280 _substituteTypeParametersDownHierarchy(supertype, map);
5282 // 5281 //
5283 // Add any members from the super type into the map as well. 5282 // Add any members from the super type into the map as well.
5284 // 5283 //
5285 _recordMapWithClassMembers(map, supertype, true); 5284 _recordMapWithClassMembers(map, supertype, true);
5286 lookupMaps.add(map); 5285 lookupMaps.add(map);
5287 } finally { 5286 } finally {
5288 visitedInterfaces.remove(superclassElement); 5287 visitedInterfaces.remove(superclassElement);
5289 } 5288 }
5290 } else { 5289 } else {
5291 return null; 5290 return null;
5292 } 5291 }
5293 } 5292 }
5294 // 5293 //
5295 // Mixin elements 5294 // Mixin elements
5296 // 5295 //
5297 for (int i = mixins.length - 1; i >= 0; i--) { 5296 for (int i = mixins.length - 1; i >= 0; i--) {
5298 InterfaceType mixinType = mixins[i]; 5297 InterfaceType mixinType = mixins[i];
5299 ClassElement mixinElement = mixinType.element; 5298 ClassElement mixinElement = mixinType.element;
5300 if (mixinElement != null) { 5299 if (mixinElement != null) {
5301 if (!visitedInterfaces.contains(mixinElement)) { 5300 if (!visitedInterfaces.contains(mixinElement)) {
5302 try { 5301 try {
5303 visitedInterfaces.add(mixinElement); 5302 visitedInterfaces.add(mixinElement);
5304 // 5303 //
5305 // Recursively compute the map for the mixin. 5304 // Recursively compute the map for the mixin.
5306 // 5305 //
5307 Map<String, ExecutableElement> map = 5306 MemberMap map =
5308 _computeInterfaceLookupMap(mixinElement, visitedInterfaces); 5307 _computeInterfaceLookupMap(mixinElement, visitedInterfaces);
5309 map = new HashMap<String, ExecutableElement>.from(map); 5308 map = new MemberMap.from(map);
5310 // 5309 //
5311 // Substitute the mixin type down the hierarchy. 5310 // Substitute the mixin type down the hierarchy.
5312 // 5311 //
5313 _substituteTypeParametersDownHierarchy(mixinType, map); 5312 _substituteTypeParametersDownHierarchy(mixinType, map);
5314 // 5313 //
5315 // Add any members from the mixin type into the map as well. 5314 // Add any members from the mixin type into the map as well.
5316 // 5315 //
5317 _recordMapWithClassMembers(map, mixinType, true); 5316 _recordMapWithClassMembers(map, mixinType, true);
5318 lookupMaps.add(map); 5317 lookupMaps.add(map);
5319 } finally { 5318 } finally {
5320 visitedInterfaces.remove(mixinElement); 5319 visitedInterfaces.remove(mixinElement);
5321 } 5320 }
5322 } else { 5321 } else {
5323 return null; 5322 return null;
5324 } 5323 }
5325 } 5324 }
5326 } 5325 }
5327 // 5326 //
5328 // Interface elements 5327 // Interface elements
5329 // 5328 //
5330 for (InterfaceType interfaceType in interfaces) { 5329 for (InterfaceType interfaceType in interfaces) {
5331 ClassElement interfaceElement = interfaceType.element; 5330 ClassElement interfaceElement = interfaceType.element;
5332 if (interfaceElement != null) { 5331 if (interfaceElement != null) {
5333 if (!visitedInterfaces.contains(interfaceElement)) { 5332 if (!visitedInterfaces.contains(interfaceElement)) {
5334 try { 5333 try {
5335 visitedInterfaces.add(interfaceElement); 5334 visitedInterfaces.add(interfaceElement);
5336 // 5335 //
5337 // Recursively compute the map for the interfaces. 5336 // Recursively compute the map for the interfaces.
5338 // 5337 //
5339 Map<String, ExecutableElement> map = 5338 MemberMap map =
5340 _computeInterfaceLookupMap(interfaceElement, visitedInterfaces); 5339 _computeInterfaceLookupMap(interfaceElement, visitedInterfaces);
5341 map = new HashMap<String, ExecutableElement>.from(map); 5340 map = new MemberMap.from(map);
5342 // 5341 //
5343 // Substitute the supertypes down the hierarchy 5342 // Substitute the supertypes down the hierarchy
5344 // 5343 //
5345 _substituteTypeParametersDownHierarchy(interfaceType, map); 5344 _substituteTypeParametersDownHierarchy(interfaceType, map);
5346 // 5345 //
5347 // And add any members from the interface into the map as well. 5346 // And add any members from the interface into the map as well.
5348 // 5347 //
5349 _recordMapWithClassMembers(map, interfaceType, true); 5348 _recordMapWithClassMembers(map, interfaceType, true);
5350 lookupMaps.add(map); 5349 lookupMaps.add(map);
5351 } finally { 5350 } finally {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
5394 5393
5395 /** 5394 /**
5396 * Record the passed map with the set of all members (methods, getters and set ters) in the type 5395 * Record the passed map with the set of all members (methods, getters and set ters) in the type
5397 * into the passed map. 5396 * into the passed map.
5398 * 5397 *
5399 * @param map some non-`null` map to put the methods and accessors from the pa ssed 5398 * @param map some non-`null` map to put the methods and accessors from the pa ssed
5400 * [ClassElement] into 5399 * [ClassElement] into
5401 * @param type the type that will be recorded into the passed map 5400 * @param type the type that will be recorded into the passed map
5402 * @param doIncludeAbstract `true` if abstract members will be put into the ma p 5401 * @param doIncludeAbstract `true` if abstract members will be put into the ma p
5403 */ 5402 */
5404 void _recordMapWithClassMembers(Map<String, ExecutableElement> map, 5403 void _recordMapWithClassMembers(
5405 InterfaceType type, bool doIncludeAbstract) { 5404 MemberMap map, InterfaceType type, bool doIncludeAbstract) {
5406 List<MethodElement> methods = type.methods; 5405 List<MethodElement> methods = type.methods;
5407 for (MethodElement method in methods) { 5406 for (MethodElement method in methods) {
5408 if (method.isAccessibleIn(_library) && 5407 if (method.isAccessibleIn(_library) &&
5409 !method.isStatic && 5408 !method.isStatic &&
5410 (doIncludeAbstract || !method.isAbstract)) { 5409 (doIncludeAbstract || !method.isAbstract)) {
5411 map[method.name] = method; 5410 map.put(method.name, method);
5412 } 5411 }
5413 } 5412 }
5414 List<PropertyAccessorElement> accessors = type.accessors; 5413 List<PropertyAccessorElement> accessors = type.accessors;
5415 for (PropertyAccessorElement accessor in accessors) { 5414 for (PropertyAccessorElement accessor in accessors) {
5416 if (accessor.isAccessibleIn(_library) && 5415 if (accessor.isAccessibleIn(_library) &&
5417 !accessor.isStatic && 5416 !accessor.isStatic &&
5418 (doIncludeAbstract || !accessor.isAbstract)) { 5417 (doIncludeAbstract || !accessor.isAbstract)) {
5419 map[accessor.name] = accessor; 5418 map.put(accessor.name, accessor);
5420 } 5419 }
5421 } 5420 }
5422 } 5421 }
5423 5422
5424 /** 5423 /**
5425 * This method is used to report errors on when they are found computing inher itance information. 5424 * This method is used to report errors on when they are found computing inher itance information.
5426 * See [ErrorVerifier.checkForInconsistentMethodInheritance] to see where thes e generated 5425 * See [ErrorVerifier.checkForInconsistentMethodInheritance] to see where thes e generated
5427 * error codes are reported back into the analysis engine. 5426 * error codes are reported back into the analysis engine.
5428 * 5427 *
5429 * @param classElt the location of the source for which the exception occurred 5428 * @param classElt the location of the source for which the exception occurred
(...skipping 18 matching lines...) Expand all
5448 * apply the appropriate inheritance rules to determine those methods inherite d by or overridden 5447 * apply the appropriate inheritance rules to determine those methods inherite d by or overridden
5449 * by [classElt]. Also report static warnings 5448 * by [classElt]. Also report static warnings
5450 * [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE] and 5449 * [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE] and
5451 * [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD] if ap propriate. 5450 * [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD] if ap propriate.
5452 * 5451 *
5453 * @param classElt the class element to query. 5452 * @param classElt the class element to query.
5454 * @param unionMap a mapping from method name to the set of unique (in terms o f signature) methods 5453 * @param unionMap a mapping from method name to the set of unique (in terms o f signature) methods
5455 * defined in superclasses of [classElt]. 5454 * defined in superclasses of [classElt].
5456 * @return the inheritance lookup map for [classElt]. 5455 * @return the inheritance lookup map for [classElt].
5457 */ 5456 */
5458 Map<String, ExecutableElement> _resolveInheritanceLookup( 5457 MemberMap _resolveInheritanceLookup(ClassElement classElt,
5459 ClassElement classElt, Map<String, List<ExecutableElement>> unionMap) { 5458 HashMap<String, List<ExecutableElement>> unionMap) {
5460 Map<String, ExecutableElement> resultMap = 5459 MemberMap resultMap = new MemberMap();
5461 new HashMap<String, ExecutableElement>();
5462 unionMap.forEach((String key, List<ExecutableElement> list) { 5460 unionMap.forEach((String key, List<ExecutableElement> list) {
5463 int numOfEltsWithMatchingNames = list.length; 5461 int numOfEltsWithMatchingNames = list.length;
5464 if (numOfEltsWithMatchingNames == 1) { 5462 if (numOfEltsWithMatchingNames == 1) {
5465 // 5463 //
5466 // Example: class A inherits only 1 method named 'm'. 5464 // Example: class A inherits only 1 method named 'm'.
5467 // Since it is the only such method, it is inherited. 5465 // Since it is the only such method, it is inherited.
5468 // Another example: class A inherits 2 methods named 'm' from 2 5466 // Another example: class A inherits 2 methods named 'm' from 2
5469 // different interfaces, but they both have the same signature, so it is 5467 // different interfaces, but they both have the same signature, so it is
5470 // the method inherited. 5468 // the method inherited.
5471 // 5469 //
5472 resultMap[key] = list[0]; 5470 resultMap.put(key, list[0]);
5473 } else { 5471 } else {
5474 // 5472 //
5475 // Then numOfEltsWithMatchingNames > 1, check for the warning cases. 5473 // Then numOfEltsWithMatchingNames > 1, check for the warning cases.
5476 // 5474 //
5477 bool allMethods = true; 5475 bool allMethods = true;
5478 bool allSetters = true; 5476 bool allSetters = true;
5479 bool allGetters = true; 5477 bool allGetters = true;
5480 for (ExecutableElement executableElement in list) { 5478 for (ExecutableElement executableElement in list) {
5481 if (executableElement is PropertyAccessorElement) { 5479 if (executableElement is PropertyAccessorElement) {
5482 allMethods = false; 5480 allMethods = false;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
5534 // 5532 //
5535 if (subtypesOfAllOtherTypesIndexes.length == 1) { 5533 if (subtypesOfAllOtherTypesIndexes.length == 1) {
5536 // 5534 //
5537 // Example: class A inherited only 2 method named 'm'. 5535 // Example: class A inherited only 2 method named 'm'.
5538 // One has the function type '() -> dynamic' and one has the 5536 // One has the function type '() -> dynamic' and one has the
5539 // function type '([int]) -> dynamic'. Since the second method is a 5537 // function type '([int]) -> dynamic'. Since the second method is a
5540 // subtype of all the others, it is the inherited method. 5538 // subtype of all the others, it is the inherited method.
5541 // Tests: InheritanceManagerTest. 5539 // Tests: InheritanceManagerTest.
5542 // test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_* 5540 // test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_*
5543 // 5541 //
5544 resultMap[key] = elements[subtypesOfAllOtherTypesIndexes[0]]; 5542 resultMap.put(key, elements[subtypesOfAllOtherTypesIndexes[0]]);
5545 } else { 5543 } else {
5546 if (subtypesOfAllOtherTypesIndexes.isEmpty) { 5544 if (subtypesOfAllOtherTypesIndexes.isEmpty) {
5547 // 5545 //
5548 // Determine if the current class has a method or accessor with 5546 // Determine if the current class has a method or accessor with
5549 // the member name, if it does then then this class does not 5547 // the member name, if it does then then this class does not
5550 // "inherit" from any of the supertypes. See issue 16134. 5548 // "inherit" from any of the supertypes. See issue 16134.
5551 // 5549 //
5552 bool classHasMember = false; 5550 bool classHasMember = false;
5553 if (allMethods) { 5551 if (allMethods) {
5554 classHasMember = classElt.getMethod(key) != null; 5552 classHasMember = classElt.getMethod(key) != null;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
5588 // 5586 //
5589 List<ExecutableElement> elementArrayToMerge = 5587 List<ExecutableElement> elementArrayToMerge =
5590 new List<ExecutableElement>( 5588 new List<ExecutableElement>(
5591 subtypesOfAllOtherTypesIndexes.length); 5589 subtypesOfAllOtherTypesIndexes.length);
5592 for (int i = 0; i < elementArrayToMerge.length; i++) { 5590 for (int i = 0; i < elementArrayToMerge.length; i++) {
5593 elementArrayToMerge[i] = 5591 elementArrayToMerge[i] =
5594 elements[subtypesOfAllOtherTypesIndexes[i]]; 5592 elements[subtypesOfAllOtherTypesIndexes[i]];
5595 } 5593 }
5596 ExecutableElement mergedExecutableElement = 5594 ExecutableElement mergedExecutableElement =
5597 _computeMergedExecutableElement(elementArrayToMerge); 5595 _computeMergedExecutableElement(elementArrayToMerge);
5598 resultMap[key] = mergedExecutableElement; 5596 resultMap.put(key, mergedExecutableElement);
5599 } 5597 }
5600 } 5598 }
5601 } else { 5599 } else {
5602 _reportError( 5600 _reportError(
5603 classElt, 5601 classElt,
5604 classElt.nameOffset, 5602 classElt.nameOffset,
5605 classElt.nameLength, 5603 classElt.nameLength,
5606 StaticWarningCode 5604 StaticWarningCode
5607 .INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD, 5605 .INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD,
5608 [key]); 5606 [key]);
5609 } 5607 }
5610 } 5608 }
5611 }); 5609 });
5612 return resultMap; 5610 return resultMap;
5613 } 5611 }
5614 5612
5615 /** 5613 /**
5616 * Loop through all of the members in the given [map], and perform type 5614 * Loop through all of the members in some [MemberMap], performing type parame ter
5617 * parameter substitutions using a passed [supertype]. 5615 * substitutions using a passed supertype.
5616 *
5617 * @param superType the supertype to substitute into the members of the [Membe rMap]
5618 * @param map the MemberMap to perform the substitutions on
5618 */ 5619 */
5619 void _substituteTypeParametersDownHierarchy( 5620 void _substituteTypeParametersDownHierarchy(
5620 InterfaceType superType, Map<String, ExecutableElement> map) { 5621 InterfaceType superType, MemberMap map) {
5621 for (String memberName in map.keys) { 5622 for (int i = 0; i < map.size; i++) {
5622 ExecutableElement executableElement = map[memberName]; 5623 ExecutableElement executableElement = map.getValue(i);
5623 if (executableElement is MethodMember) { 5624 if (executableElement is MethodMember) {
5624 executableElement = 5625 executableElement =
5625 MethodMember.from(executableElement as MethodMember, superType); 5626 MethodMember.from(executableElement as MethodMember, superType);
5626 map[memberName] = executableElement; 5627 map.setValue(i, executableElement);
5627 } else if (executableElement is PropertyAccessorMember) { 5628 } else if (executableElement is PropertyAccessorMember) {
5628 executableElement = PropertyAccessorMember.from( 5629 executableElement = PropertyAccessorMember.from(
5629 executableElement as PropertyAccessorMember, superType); 5630 executableElement as PropertyAccessorMember, superType);
5630 map[memberName] = executableElement; 5631 map.setValue(i, executableElement);
5631 } 5632 }
5632 } 5633 }
5633 } 5634 }
5634 5635
5635 /** 5636 /**
5636 * Union all of the [lookupMaps] together into a single map, grouping the Exec utableElements 5637 * Union all of the [lookupMaps] together into a single map, grouping the Exec utableElements
5637 * into a list where none of the elements are equal where equality is determin ed by having equal 5638 * into a list where none of the elements are equal where equality is determin ed by having equal
5638 * function types. (We also take note too of the kind of the element: ()->int and () -> int may 5639 * function types. (We also take note too of the kind of the element: ()->int and () -> int may
5639 * not be equal if one is a getter and the other is a method.) 5640 * not be equal if one is a getter and the other is a method.)
5640 * 5641 *
5641 * @param lookupMaps the maps to be unioned together. 5642 * @param lookupMaps the maps to be unioned together.
5642 * @return the resulting union map. 5643 * @return the resulting union map.
5643 */ 5644 */
5644 Map<String, List<ExecutableElement>> _unionInterfaceLookupMaps( 5645 HashMap<String, List<ExecutableElement>> _unionInterfaceLookupMaps(
5645 List<Map<String, ExecutableElement>> lookupMaps) { 5646 List<MemberMap> lookupMaps) {
5646 Map<String, List<ExecutableElement>> unionMap = 5647 HashMap<String, List<ExecutableElement>> unionMap =
5647 new HashMap<String, List<ExecutableElement>>(); 5648 new HashMap<String, List<ExecutableElement>>();
5648 for (Map<String, ExecutableElement> lookupMap in lookupMaps) { 5649 for (MemberMap lookupMap in lookupMaps) {
5649 for (String memberName in lookupMap.keys) { 5650 int lookupMapSize = lookupMap.size;
5651 for (int i = 0; i < lookupMapSize; i++) {
5652 // Get the string key, if null, break.
5653 String key = lookupMap.getKey(i);
5654 if (key == null) {
5655 break;
5656 }
5650 // Get the list value out of the unionMap 5657 // Get the list value out of the unionMap
5651 List<ExecutableElement> list = unionMap[memberName]; 5658 List<ExecutableElement> list = unionMap[key];
5652 // If we haven't created such a map for this key yet, do create it and 5659 // If we haven't created such a map for this key yet, do create it and
5653 // put the list entry into the unionMap. 5660 // put the list entry into the unionMap.
5654 if (list == null) { 5661 if (list == null) {
5655 list = new List<ExecutableElement>(); 5662 list = new List<ExecutableElement>();
5656 unionMap[memberName] = list; 5663 unionMap[key] = list;
5657 } 5664 }
5658 // Fetch the entry out of this lookupMap 5665 // Fetch the entry out of this lookupMap
5659 ExecutableElement newExecutableElementEntry = lookupMap[memberName]; 5666 ExecutableElement newExecutableElementEntry = lookupMap.getValue(i);
5660 if (list.isEmpty) { 5667 if (list.isEmpty) {
5661 // If the list is empty, just the new value 5668 // If the list is empty, just the new value
5662 list.add(newExecutableElementEntry); 5669 list.add(newExecutableElementEntry);
5663 } else { 5670 } else {
5664 // Otherwise, only add the newExecutableElementEntry if it isn't 5671 // Otherwise, only add the newExecutableElementEntry if it isn't
5665 // already in the list, this covers situation where a class inherits 5672 // already in the list, this covers situation where a class inherits
5666 // two methods (or two getters) that are identical. 5673 // two methods (or two getters) that are identical.
5667 bool alreadyInList = false; 5674 bool alreadyInList = false;
5668 bool isMethod1 = newExecutableElementEntry is MethodElement; 5675 bool isMethod1 = newExecutableElementEntry is MethodElement;
5669 for (ExecutableElement executableElementInList in list) { 5676 for (ExecutableElement executableElementInList in list) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
5878 NOT_INIT, 5885 NOT_INIT,
5879 INIT_IN_DECLARATION, 5886 INIT_IN_DECLARATION,
5880 INIT_IN_FIELD_FORMAL, 5887 INIT_IN_FIELD_FORMAL,
5881 INIT_IN_INITIALIZERS 5888 INIT_IN_INITIALIZERS
5882 ]; 5889 ];
5883 5890
5884 const INIT_STATE(String name, int ordinal) : super(name, ordinal); 5891 const INIT_STATE(String name, int ordinal) : super(name, ordinal);
5885 } 5892 }
5886 5893
5887 /** 5894 /**
5895 * This class is used to replace uses of `HashMap<String, ExecutableElement>`
5896 * which are not as performant as this class.
5897 */
5898 class MemberMap {
5899 /**
5900 * The current size of this map.
5901 */
5902 int _size = 0;
5903
5904 /**
5905 * The array of keys.
5906 */
5907 List<String> _keys;
5908
5909 /**
5910 * The array of ExecutableElement values.
5911 */
5912 List<ExecutableElement> _values;
5913
5914 /**
5915 * Initialize a newly created member map to have the given [initialCapacity].
5916 * The map will grow if needed.
5917 */
5918 MemberMap([int initialCapacity = 10]) {
5919 _initArrays(initialCapacity);
5920 }
5921
5922 /**
5923 * Initialize a newly created member map to contain the same members as the
5924 * given [memberMap].
5925 */
5926 MemberMap.from(MemberMap memberMap) {
5927 _initArrays(memberMap._size + 5);
5928 for (int i = 0; i < memberMap._size; i++) {
5929 _keys[i] = memberMap._keys[i];
5930 _values[i] = memberMap._values[i];
5931 }
5932 _size = memberMap._size;
5933 }
5934
5935 /**
5936 * The size of the map.
5937 *
5938 * @return the size of the map.
5939 */
5940 int get size => _size;
5941
5942 /**
5943 * Given some key, return the ExecutableElement value from the map, if the key does not exist in
5944 * the map, `null` is returned.
5945 *
5946 * @param key some key to look up in the map
5947 * @return the associated ExecutableElement value from the map, if the key doe s not exist in the
5948 * map, `null` is returned
5949 */
5950 ExecutableElement get(String key) {
5951 for (int i = 0; i < _size; i++) {
5952 if (_keys[i] != null && _keys[i] == key) {
5953 return _values[i];
5954 }
5955 }
5956 return null;
5957 }
5958
5959 /**
5960 * Get and return the key at the specified location. If the key/value pair has been removed from
5961 * the set, then `null` is returned.
5962 *
5963 * @param i some non-zero value less than size
5964 * @return the key at the passed index
5965 * @throw ArrayIndexOutOfBoundsException this exception is thrown if the passe d index is less than
5966 * zero or greater than or equal to the capacity of the arrays
5967 */
5968 String getKey(int i) => _keys[i];
5969
5970 /**
5971 * Get and return the ExecutableElement at the specified location. If the key/ value pair has been
5972 * removed from the set, then then `null` is returned.
5973 *
5974 * @param i some non-zero value less than size
5975 * @return the key at the passed index
5976 * @throw ArrayIndexOutOfBoundsException this exception is thrown if the passe d index is less than
5977 * zero or greater than or equal to the capacity of the arrays
5978 */
5979 ExecutableElement getValue(int i) => _values[i];
5980
5981 /**
5982 * Given some key/value pair, store the pair in the map. If the key exists alr eady, then the new
5983 * value overrides the old value.
5984 *
5985 * @param key the key to store in the map
5986 * @param value the ExecutableElement value to store in the map
5987 */
5988 void put(String key, ExecutableElement value) {
5989 // If we already have a value with this key, override the value
5990 for (int i = 0; i < _size; i++) {
5991 if (_keys[i] != null && _keys[i] == key) {
5992 _values[i] = value;
5993 return;
5994 }
5995 }
5996 // If needed, double the size of our arrays and copy values over in both
5997 // arrays
5998 if (_size == _keys.length) {
5999 int newArrayLength = _size * 2;
6000 List<String> keys_new_array = new List<String>(newArrayLength);
6001 List<ExecutableElement> values_new_array =
6002 new List<ExecutableElement>(newArrayLength);
6003 for (int i = 0; i < _size; i++) {
6004 keys_new_array[i] = _keys[i];
6005 }
6006 for (int i = 0; i < _size; i++) {
6007 values_new_array[i] = _values[i];
6008 }
6009 _keys = keys_new_array;
6010 _values = values_new_array;
6011 }
6012 // Put new value at end of array
6013 _keys[_size] = key;
6014 _values[_size] = value;
6015 _size++;
6016 }
6017
6018 /**
6019 * Given some [String] key, this method replaces the associated key and value pair with
6020 * `null`. The size is not decremented with this call, instead it is expected that the users
6021 * check for `null`.
6022 *
6023 * @param key the key of the key/value pair to remove from the map
6024 */
6025 void remove(String key) {
6026 for (int i = 0; i < _size; i++) {
6027 if (_keys[i] == key) {
6028 _keys[i] = null;
6029 _values[i] = null;
6030 return;
6031 }
6032 }
6033 }
6034
6035 /**
6036 * Sets the ExecutableElement at the specified location.
6037 *
6038 * @param i some non-zero value less than size
6039 * @param value the ExecutableElement value to store in the map
6040 */
6041 void setValue(int i, ExecutableElement value) {
6042 _values[i] = value;
6043 }
6044
6045 /**
6046 * Initializes [keys] and [values].
6047 */
6048 void _initArrays(int initialCapacity) {
6049 _keys = new List<String>(initialCapacity);
6050 _values = new List<ExecutableElement>(initialCapacity);
6051 }
6052 }
6053
6054 /**
5888 * Instances of the class `OverrideVerifier` visit all of the declarations in a compilation 6055 * Instances of the class `OverrideVerifier` visit all of the declarations in a compilation
5889 * unit to verify that if they have an override annotation it is being used corr ectly. 6056 * unit to verify that if they have an override annotation it is being used corr ectly.
5890 */ 6057 */
5891 class OverrideVerifier extends RecursiveAstVisitor<Object> { 6058 class OverrideVerifier extends RecursiveAstVisitor<Object> {
5892 /** 6059 /**
5893 * The error reporter used to report errors. 6060 * The error reporter used to report errors.
5894 */ 6061 */
5895 final ErrorReporter _errorReporter; 6062 final ErrorReporter _errorReporter;
5896 6063
5897 /** 6064 /**
(...skipping 5884 matching lines...) Expand 10 before | Expand all | Expand 10 after
11782 nonFields.add(node); 11949 nonFields.add(node);
11783 return null; 11950 return null;
11784 } 11951 }
11785 11952
11786 @override 11953 @override
11787 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 11954 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
11788 11955
11789 @override 11956 @override
11790 Object visitWithClause(WithClause node) => null; 11957 Object visitWithClause(WithClause node) => null;
11791 } 11958 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/error_verifier.dart ('k') | pkg/analyzer/test/generated/inheritance_manager_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698