| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Mixins that implement convenience methods on [Element] subclasses. | 5 /// Mixins that implement convenience methods on [Element] subclasses. |
| 6 | 6 |
| 7 library elements.common; | 7 library elements.common; |
| 8 | 8 |
| 9 import '../common/names.dart' show Identifiers, Names, Uris; | 9 import '../common/names.dart' show Identifiers, Names, Uris; |
| 10 import '../common_elements.dart' show CommonElements; | 10 import '../common_elements.dart' show CommonElements; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 /** | 210 /** |
| 211 * Find the first member in the class chain with the given [memberName]. | 211 * Find the first member in the class chain with the given [memberName]. |
| 212 * | 212 * |
| 213 * This method is NOT to be used for resolving | 213 * This method is NOT to be used for resolving |
| 214 * unqualified sends because it does not implement the scoping | 214 * unqualified sends because it does not implement the scoping |
| 215 * rules, where library scope comes before superclass scope. | 215 * rules, where library scope comes before superclass scope. |
| 216 * | 216 * |
| 217 * When called on the implementation element both members declared in the | 217 * When called on the implementation element both members declared in the |
| 218 * origin and the patch class are returned. | 218 * origin and the patch class are returned. |
| 219 */ | 219 */ |
| 220 Element lookupByName(Name memberName, {ClassElement stopAt}) { | 220 MemberElement lookupByName(Name memberName, {ClassElement stopAt}) { |
| 221 return internalLookupByName(memberName, | 221 return internalLookupByName(memberName, |
| 222 isSuperLookup: false, stopAtSuperclass: stopAt); | 222 isSuperLookup: false, stopAtSuperclass: stopAt); |
| 223 } | 223 } |
| 224 | 224 |
| 225 Element lookupSuperByName(Name memberName) { | 225 MemberElement lookupSuperByName(Name memberName) { |
| 226 return internalLookupByName(memberName, isSuperLookup: true); | 226 return internalLookupByName(memberName, isSuperLookup: true); |
| 227 } | 227 } |
| 228 | 228 |
| 229 Element internalLookupByName(Name memberName, | 229 MemberElement internalLookupByName(Name memberName, |
| 230 {bool isSuperLookup, ClassElement stopAtSuperclass}) { | 230 {bool isSuperLookup, ClassElement stopAtSuperclass}) { |
| 231 String name = memberName.text; | 231 String name = memberName.text; |
| 232 bool isPrivate = memberName.isPrivate; | 232 bool isPrivate = memberName.isPrivate; |
| 233 LibraryElement library = memberName.library; | 233 LibraryElement library = memberName.library; |
| 234 for (ClassElement current = isSuperLookup ? superclass : this; | 234 for (ClassElement current = isSuperLookup ? superclass : this; |
| 235 current != null && current != stopAtSuperclass; | 235 current != null && current != stopAtSuperclass; |
| 236 current = current.superclass) { | 236 current = current.superclass) { |
| 237 Element member = current.lookupLocalMember(name); | 237 Element member = current.lookupLocalMember(name); |
| 238 if (member == null && current.isPatched) { | 238 if (member == null && current.isPatched) { |
| 239 // Doing lookups on selectors is done after resolution, so it | 239 // Doing lookups on selectors is done after resolution, so it |
| 240 // is safe to look in the patch class. | 240 // is safe to look in the patch class. |
| 241 member = current.patch.lookupLocalMember(name); | 241 member = current.patch.lookupLocalMember(name); |
| 242 } | 242 } |
| 243 if (member == null) continue; | 243 if (member == null) continue; |
| 244 // Private members from a different library are not visible. | 244 // Private members from a different library are not visible. |
| 245 if (isPrivate && !identical(library, member.library)) continue; | 245 if (isPrivate && !identical(library, member.library)) continue; |
| 246 // Static members are not inherited. | 246 // Static members are not inherited. |
| 247 if (member.isStatic && !identical(this, current)) continue; | 247 if (member.isStatic && !identical(this, current)) continue; |
| 248 // If we find an abstract field we have to make sure that it has | 248 // If we find an abstract field we have to make sure that it has |
| 249 // the getter or setter part we're actually looking | 249 // the getter or setter part we're actually looking |
| 250 // for. Otherwise, we continue up the superclass chain. | 250 // for. Otherwise, we continue up the superclass chain. |
| 251 if (member.isAbstractField) { | 251 if (member.isAbstractField) { |
| 252 AbstractFieldElement field = member; | 252 AbstractFieldElement field = member; |
| 253 FunctionElement getter = field.getter; | 253 GetterElement getter = field.getter; |
| 254 FunctionElement setter = field.setter; | 254 SetterElement setter = field.setter; |
| 255 if (memberName.isSetter) { | 255 if (memberName.isSetter) { |
| 256 // Abstract members can be defined in a super class. | 256 // Abstract members can be defined in a super class. |
| 257 if (setter != null && !setter.isAbstract) { | 257 if (setter != null && !setter.isAbstract) { |
| 258 return setter; | 258 return setter; |
| 259 } | 259 } |
| 260 } else { | 260 } else { |
| 261 if (getter != null && !getter.isAbstract) { | 261 if (getter != null && !getter.isAbstract) { |
| 262 return getter; | 262 return getter; |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 // Abstract members can be defined in a super class. | 265 // Abstract members can be defined in a super class. |
| 266 } else if (!member.isAbstract) { | 266 } else if (!member.isAbstract && !member.isMalformed) { |
| 267 return member; | 267 return member; |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 return null; | 270 return null; |
| 271 } | 271 } |
| 272 | 272 |
| 273 /** | 273 /** |
| 274 * Find the first member in the class chain with the given | 274 * Find the first member in the class chain with the given |
| 275 * [memberName]. This method is NOT to be used for resolving | 275 * [memberName]. This method is NOT to be used for resolving |
| 276 * unqualified sends because it does not implement the scoping | 276 * unqualified sends because it does not implement the scoping |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 @override | 669 @override |
| 670 bool get isBoolFromEnvironmentConstructor { | 670 bool get isBoolFromEnvironmentConstructor { |
| 671 return fromEnvironmentState == _FromEnvironmentState.BOOL; | 671 return fromEnvironmentState == _FromEnvironmentState.BOOL; |
| 672 } | 672 } |
| 673 | 673 |
| 674 @override | 674 @override |
| 675 bool get isStringFromEnvironmentConstructor { | 675 bool get isStringFromEnvironmentConstructor { |
| 676 return fromEnvironmentState == _FromEnvironmentState.STRING; | 676 return fromEnvironmentState == _FromEnvironmentState.STRING; |
| 677 } | 677 } |
| 678 } | 678 } |
| OLD | NEW |