OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 elements; | 5 library elements; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../common/resolution.dart' show Resolution; | 8 import '../common/resolution.dart' show Resolution; |
9 import '../compiler.dart' show Compiler; | 9 import '../compiler.dart' show Compiler; |
10 import '../constants/constructors.dart'; | 10 import '../constants/constructors.dart'; |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 /// `true` if this element is a method, getter, setter or field that | 322 /// `true` if this element is a method, getter, setter or field that |
323 /// is declared `static`. | 323 /// is declared `static`. |
324 bool get isStatic; | 324 bool get isStatic; |
325 | 325 |
326 /// `true` if this element is local element, that is, a local variable, | 326 /// `true` if this element is local element, that is, a local variable, |
327 /// local function or parameter. | 327 /// local function or parameter. |
328 bool get isLocal; | 328 bool get isLocal; |
329 | 329 |
330 bool get impliesType; | 330 bool get impliesType; |
331 | 331 |
| 332 /// The character offset of the declaration of this element within its |
| 333 /// compilation unit, if available. |
| 334 /// |
| 335 /// This is used to sort the elements. |
| 336 int get sourceOffset; |
| 337 |
332 // TODO(johnniwinther): Remove this. | 338 // TODO(johnniwinther): Remove this. |
333 Token get position; | 339 Token get position; |
334 | 340 |
335 /// The position of the declaration of this element, if available. | 341 /// The position of the declaration of this element, if available. |
336 SourceSpan get sourcePosition; | 342 SourceSpan get sourcePosition; |
337 | 343 |
338 CompilationUnitElement get compilationUnit; | 344 CompilationUnitElement get compilationUnit; |
339 LibraryElement get library; | 345 LibraryElement get library; |
340 LibraryElement get implementationLibrary; | 346 LibraryElement get implementationLibrary; |
341 ClassElement get enclosingClass; | 347 ClassElement get enclosingClass; |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 } | 682 } |
677 | 683 |
678 /// A `compareTo` function that places [Element]s in a consistent order based | 684 /// A `compareTo` function that places [Element]s in a consistent order based |
679 /// on the source code order. | 685 /// on the source code order. |
680 static int compareByPosition(Element a, Element b) { | 686 static int compareByPosition(Element a, Element b) { |
681 if (identical(a, b)) return 0; | 687 if (identical(a, b)) return 0; |
682 int r = a.library.compareTo(b.library); | 688 int r = a.library.compareTo(b.library); |
683 if (r != 0) return r; | 689 if (r != 0) return r; |
684 r = a.compilationUnit.compareTo(b.compilationUnit); | 690 r = a.compilationUnit.compareTo(b.compilationUnit); |
685 if (r != 0) return r; | 691 if (r != 0) return r; |
686 Token positionA = a.position; | 692 int offsetA = a.sourceOffset ?? -1; |
687 Token positionB = b.position; | 693 int offsetB = b.sourceOffset ?? -1; |
688 int offsetA = positionA == null ? -1 : positionA.charOffset; | |
689 int offsetB = positionB == null ? -1 : positionB.charOffset; | |
690 r = offsetA.compareTo(offsetB); | 694 r = offsetA.compareTo(offsetB); |
691 if (r != 0) return r; | 695 if (r != 0) return r; |
692 r = a.name.compareTo(b.name); | 696 r = a.name.compareTo(b.name); |
693 if (r != 0) return r; | 697 if (r != 0) return r; |
694 // Same file, position and name. If this happens, we should find out why | 698 // Same file, position and name. If this happens, we should find out why |
695 // and make the order total and independent of hashCode. | 699 // and make the order total and independent of hashCode. |
696 return a.hashCode.compareTo(b.hashCode); | 700 return a.hashCode.compareTo(b.hashCode); |
697 } | 701 } |
698 | 702 |
699 static List<Element> sortedByPosition(Iterable<Element> elements) { | 703 static List<Element> sortedByPosition(Iterable<Element> elements) { |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 /// A local function or closure (anonymous local function). | 1225 /// A local function or closure (anonymous local function). |
1222 abstract class LocalFunctionElement extends FunctionElement | 1226 abstract class LocalFunctionElement extends FunctionElement |
1223 implements LocalElement {} | 1227 implements LocalElement {} |
1224 | 1228 |
1225 /// A constructor. | 1229 /// A constructor. |
1226 abstract class ConstructorElement extends FunctionElement | 1230 abstract class ConstructorElement extends FunctionElement |
1227 implements MemberElement { | 1231 implements MemberElement { |
1228 /// The effective target of this constructor, that is the non-redirecting | 1232 /// The effective target of this constructor, that is the non-redirecting |
1229 /// constructor that is called on invocation of this constructor. | 1233 /// constructor that is called on invocation of this constructor. |
1230 /// | 1234 /// |
1231 /// Consider for instance this hierachy: | 1235 /// Consider for instance this hierarchy: |
1232 /// | 1236 /// |
1233 /// class C { factory C.c() = D.d; } | 1237 /// class C { factory C.c() = D.d; } |
1234 /// class D { factory D.d() = E.e2; } | 1238 /// class D { factory D.d() = E.e2; } |
1235 /// class E { E.e1(); | 1239 /// class E { E.e1(); |
1236 /// E.e2() : this.e1(); } | 1240 /// E.e2() : this.e1(); } |
1237 /// | 1241 /// |
1238 /// The effective target of both `C.c`, `D.d`, and `E.e2` is `E.e2`, and the | 1242 /// The effective target of both `C.c`, `D.d`, and `E.e2` is `E.e2`, and the |
1239 /// effective target of `E.e1` is `E.e1` itself. | 1243 /// effective target of `E.e1` is `E.e1` itself. |
1240 ConstructorElement get effectiveTarget; | 1244 ConstructorElement get effectiveTarget; |
1241 | 1245 |
1242 /// The immediate redirection target of a redirecting factory constructor. | 1246 /// The immediate redirection target of a redirecting factory constructor. |
1243 /// | 1247 /// |
1244 /// Consider for instance this hierachy: | 1248 /// Consider for instance this hierarchy: |
1245 /// | 1249 /// |
1246 /// class C { factory C() = D; } | 1250 /// class C { factory C() = D; } |
1247 /// class D { factory D() = E; } | 1251 /// class D { factory D() = E; } |
1248 /// class E { E(); } | 1252 /// class E { E(); } |
1249 /// | 1253 /// |
1250 /// The immediate redirection target of `C` is `D` and the immediate | 1254 /// The immediate redirection target of `C` is `D` and the immediate |
1251 /// redirection target of `D` is `E`. `E` is not a redirecting factory | 1255 /// redirection target of `D` is `E`. `E` is not a redirecting factory |
1252 /// constructor so its immediate redirection target is `null`. | 1256 /// constructor so its immediate redirection target is `null`. |
1253 ConstructorElement get immediateRedirectionTarget; | 1257 ConstructorElement get immediateRedirectionTarget; |
1254 | 1258 |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1797 /// by a field. | 1801 /// by a field. |
1798 bool get isDeclaredByField; | 1802 bool get isDeclaredByField; |
1799 | 1803 |
1800 /// Returns `true` if this member is abstract. | 1804 /// Returns `true` if this member is abstract. |
1801 bool get isAbstract; | 1805 bool get isAbstract; |
1802 | 1806 |
1803 /// If abstract, [implementation] points to the overridden concrete member, | 1807 /// If abstract, [implementation] points to the overridden concrete member, |
1804 /// if any. Otherwise [implementation] points to the member itself. | 1808 /// if any. Otherwise [implementation] points to the member itself. |
1805 Member get implementation; | 1809 Member get implementation; |
1806 } | 1810 } |
OLD | NEW |