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

Unified Diff: lib/compiler/implementation/elements/elements.dart

Issue 10310040: Sort the output (for now just the classes and instance members). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/compiler/implementation/emitter.dart » ('j') | lib/compiler/implementation/emitter.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/elements/elements.dart
diff --git a/lib/compiler/implementation/elements/elements.dart b/lib/compiler/implementation/elements/elements.dart
index 0b9fca1014c852c45d5715f9bc5717251d906b35..5b7d44a8cf864a98fb83b98061e87280bd83addf 100644
--- a/lib/compiler/implementation/elements/elements.dart
+++ b/lib/compiler/implementation/elements/elements.dart
@@ -96,7 +96,7 @@ class ElementKind {
toString() => id;
}
-class Element implements Hashable {
+class Element implements Comparable, Hashable {
final SourceString name;
final ElementKind kind;
final Element enclosingElement;
@@ -156,6 +156,23 @@ class Element implements Hashable {
// the same hash code. Replace this with a simple id in the element?
int hashCode() => name.hashCode();
+ /** Two elements are compared first according to their library name, then
+ * by their position in the source. */
+ int compareTo(Element other) {
+ SourceString lib1Name = this.getLibrary().name;
+ SourceString lib2Name = other.getLibrary().name;
+ int libComparison = lib1Name.compareTo(lib2Name);
+ if (libComparison != 0) return libComparison;
+ SourceString compilationUnitName1 = this.getCompilationUnit().name;
+ SourceString compilationUnitName2 = other.getCompilationUnit().name;
+ int compilationUnitComparison =
+ compilationUnitName1.compareTo(compilationUnitName2);
+ if (compilationUnitComparison != 0) return compilationUnitComparison;
+ int charOffset1 = this.position().charOffset;
+ int charOffset2 = other.position().charOffset;
+ return charOffset1.compareTo(charOffset2);
+ }
+
CompilationUnitElement getCompilationUnit() {
Element element = this;
while (element !== null && !element.isCompilationUnit()) {
« no previous file with comments | « no previous file | lib/compiler/implementation/emitter.dart » ('j') | lib/compiler/implementation/emitter.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698