| 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 | 7 |
| 8 import 'modelx.dart'; | 8 import 'modelx.dart'; |
| 9 import '../tree/tree.dart'; | 9 import '../tree/tree.dart'; |
| 10 import '../util/util.dart'; | 10 import '../util/util.dart'; |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 | 490 |
| 491 /// A `compareTo` function that places [Element]s in a consistent order based | 491 /// A `compareTo` function that places [Element]s in a consistent order based |
| 492 /// on the source code order. | 492 /// on the source code order. |
| 493 static int compareByPosition(Element a, Element b) { | 493 static int compareByPosition(Element a, Element b) { |
| 494 int r = a.getLibrary().compareTo(b.getLibrary()); | 494 int r = a.getLibrary().compareTo(b.getLibrary()); |
| 495 if (r != 0) return r; | 495 if (r != 0) return r; |
| 496 r = a.getCompilationUnit().compareTo(b.getCompilationUnit()); | 496 r = a.getCompilationUnit().compareTo(b.getCompilationUnit()); |
| 497 if (r != 0) return r; | 497 if (r != 0) return r; |
| 498 Token positionA = a.position(); | 498 Token positionA = a.position(); |
| 499 Token positionB = b.position(); | 499 Token positionB = b.position(); |
| 500 r = positionA.charOffset.compareTo(positionB.charOffset); | 500 int offsetA = positionA == null ? -1 : positionA.charOffset; |
| 501 int offsetB = positionB == null ? -1 : positionB.charOffset; |
| 502 r = offsetA.compareTo(offsetB); |
| 501 if (r != 0) return r; | 503 if (r != 0) return r; |
| 502 r = a.name.slowToString().compareTo(b.name.slowToString()); | 504 r = a.name.slowToString().compareTo(b.name.slowToString()); |
| 503 if (r != 0) return r; | 505 if (r != 0) return r; |
| 504 // Same file, position and name. If this happens, we should find out why | 506 // Same file, position and name. If this happens, we should find out why |
| 505 // and make the order total and independent of hashCode. | 507 // and make the order total and independent of hashCode. |
| 506 return a.hashCode.compareTo(b.hashCode); | 508 return a.hashCode.compareTo(b.hashCode); |
| 507 } | 509 } |
| 508 | 510 |
| 509 static List<Element> sortedByPosition(Iterable<Element> elements) { | 511 static List<Element> sortedByPosition(Iterable<Element> elements) { |
| 510 return elements.toList()..sort(compareByPosition); | 512 return elements.toList()..sort(compareByPosition); |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 int get resolutionState; | 937 int get resolutionState; |
| 936 Token get beginToken; | 938 Token get beginToken; |
| 937 Token get endToken; | 939 Token get endToken; |
| 938 | 940 |
| 939 // TODO(kasperl): Try to get rid of these. | 941 // TODO(kasperl): Try to get rid of these. |
| 940 void set annotatedElement(Element value); | 942 void set annotatedElement(Element value); |
| 941 void set resolutionState(int value); | 943 void set resolutionState(int value); |
| 942 | 944 |
| 943 MetadataAnnotation ensureResolved(Compiler compiler); | 945 MetadataAnnotation ensureResolved(Compiler compiler); |
| 944 } | 946 } |
| OLD | NEW |