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 Names, Uris; | 9 import '../common/names.dart' show Names, Uris; |
10 import '../core_types.dart' show CoreClasses; | 10 import '../core_types.dart' show CoreClasses; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 @override | 81 @override |
82 bool get isMalformed => false; | 82 bool get isMalformed => false; |
83 | 83 |
84 @override | 84 @override |
85 bool get isWarnOnUse => kind == ElementKind.WARN_ON_USE; | 85 bool get isWarnOnUse => kind == ElementKind.WARN_ON_USE; |
86 | 86 |
87 @override | 87 @override |
88 bool get impliesType => (kind.category & ElementCategory.IMPLIES_TYPE) != 0; | 88 bool get impliesType => (kind.category & ElementCategory.IMPLIES_TYPE) != 0; |
89 | 89 |
90 @override | 90 @override |
| 91 bool get isAssignable { |
| 92 if (isFinal || isConst) return false; |
| 93 if (isFunction || isConstructor) return false; |
| 94 return true; |
| 95 } |
| 96 |
| 97 @override |
91 Element get declaration => this; | 98 Element get declaration => this; |
92 | 99 |
93 @override | 100 @override |
94 Element get implementation => this; | 101 Element get implementation => this; |
95 | 102 |
96 @override | 103 @override |
97 bool get isDeclaration => true; | 104 bool get isDeclaration => true; |
98 | 105 |
99 @override | 106 @override |
100 bool get isPatched => false; | 107 bool get isPatched => false; |
(...skipping 22 matching lines...) Expand all Loading... |
123 ClassElement cls; | 130 ClassElement cls; |
124 for (Element e = this; e != null; e = e.enclosingElement) { | 131 for (Element e = this; e != null; e = e.enclosingElement) { |
125 if (e.isClass) { | 132 if (e.isClass) { |
126 // Record [e] instead of returning it directly. We need the last class | 133 // Record [e] instead of returning it directly. We need the last class |
127 // in the chain since the first classes might be closure classes. | 134 // in the chain since the first classes might be closure classes. |
128 cls = e.declaration; | 135 cls = e.declaration; |
129 } | 136 } |
130 } | 137 } |
131 return cls; | 138 return cls; |
132 } | 139 } |
| 140 |
| 141 @override |
| 142 Element get outermostEnclosingMemberOrTopLevel { |
| 143 // TODO(lrn): Why is this called "Outermost"? |
| 144 // TODO(johnniwinther): Clean up this method: This method does not return |
| 145 // the outermost for elements in closure classses, but some call-sites rely |
| 146 // on that behavior. |
| 147 for (Element e = this; e != null; e = e.enclosingElement) { |
| 148 if (e.isClassMember || e.isTopLevel) { |
| 149 return e; |
| 150 } |
| 151 } |
| 152 return null; |
| 153 } |
133 } | 154 } |
134 | 155 |
135 abstract class LibraryElementCommon implements LibraryElement { | 156 abstract class LibraryElementCommon implements LibraryElement { |
136 @override | 157 @override |
137 bool get isDartCore => canonicalUri == Uris.dart_core; | 158 bool get isDartCore => canonicalUri == Uris.dart_core; |
138 | 159 |
139 @override | 160 @override |
140 bool get isPlatformLibrary => canonicalUri.scheme == 'dart'; | 161 bool get isPlatformLibrary => canonicalUri.scheme == 'dart'; |
141 | 162 |
142 @override | 163 @override |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 469 |
449 abstract class FunctionSignatureCommon implements FunctionSignature { | 470 abstract class FunctionSignatureCommon implements FunctionSignature { |
450 void forEachRequiredParameter(void function(Element parameter)) { | 471 void forEachRequiredParameter(void function(Element parameter)) { |
451 requiredParameters.forEach(function); | 472 requiredParameters.forEach(function); |
452 } | 473 } |
453 | 474 |
454 void forEachOptionalParameter(void function(Element parameter)) { | 475 void forEachOptionalParameter(void function(Element parameter)) { |
455 optionalParameters.forEach(function); | 476 optionalParameters.forEach(function); |
456 } | 477 } |
457 | 478 |
458 Element get firstOptionalParameter => optionalParameters.first; | |
459 | |
460 void forEachParameter(void function(Element parameter)) { | 479 void forEachParameter(void function(Element parameter)) { |
461 forEachRequiredParameter(function); | 480 forEachRequiredParameter(function); |
462 forEachOptionalParameter(function); | 481 forEachOptionalParameter(function); |
463 } | 482 } |
464 | 483 |
465 void orderedForEachParameter(void function(Element parameter)) { | 484 void orderedForEachParameter(void function(Element parameter)) { |
466 forEachRequiredParameter(function); | 485 forEachRequiredParameter(function); |
467 orderedOptionalParameters.forEach(function); | 486 orderedOptionalParameters.forEach(function); |
468 } | 487 } |
469 | 488 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 | 550 |
532 @override | 551 @override |
533 void forEachLocalMember(void f(Element member)) { | 552 void forEachLocalMember(void f(Element member)) { |
534 constructors.forEach(f); | 553 constructors.forEach(f); |
535 if (mixin != null) | 554 if (mixin != null) |
536 mixin.forEachLocalMember((Element mixedInElement) { | 555 mixin.forEachLocalMember((Element mixedInElement) { |
537 if (mixedInElement.isInstanceMember) f(mixedInElement); | 556 if (mixedInElement.isInstanceMember) f(mixedInElement); |
538 }); | 557 }); |
539 } | 558 } |
540 } | 559 } |
OLD | NEW |