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

Unified Diff: pkg/analysis_server/lib/src/services/correction/sort_members.dart

Issue 1131523005: Sort imports by package names, then by file paths. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 | pkg/analysis_server/test/services/correction/sort_members_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/correction/sort_members.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/sort_members.dart b/pkg/analysis_server/lib/src/services/correction/sort_members.dart
index 62a19aeb54e2aa726f82d74e9738b67c80034256..e6acec706cc56e86c5893f345613a47de662f5e6 100644
--- a/pkg/analysis_server/lib/src/services/correction/sort_members.dart
+++ b/pkg/analysis_server/lib/src/services/correction/sort_members.dart
@@ -195,7 +195,7 @@ class MemberSorter {
int offset = directive.offset;
int length = directive.length;
String text = code.substring(offset, offset + length);
- directives.add(new _DirectiveInfo(directive, kind, text));
+ directives.add(new _DirectiveInfo(directive, kind, uriContent, text));
}
}
// nothing to do
@@ -360,20 +360,42 @@ class MemberSorter {
class _DirectiveInfo implements Comparable<_DirectiveInfo> {
final Directive directive;
final _DirectivePriority priority;
+ final String uri;
final String text;
- _DirectiveInfo(this.directive, this.priority, this.text);
+ _DirectiveInfo(this.directive, this.priority, this.uri, this.text);
@override
int compareTo(_DirectiveInfo other) {
if (priority == other.priority) {
- return text.compareTo(other.text);
+ return _compareUri(uri, other.uri);
}
return priority.ordinal - other.priority.ordinal;
}
@override
String toString() => '(priority=$priority; text=$text)';
+
+ static int _compareUri(String a, String b) {
+ List<String> aList = _splitUri(a);
+ List<String> bList = _splitUri(b);
+ int result;
+ if ((result = aList[0].compareTo(bList[0])) != 0) return result;
+ if ((result = aList[1].compareTo(bList[1])) != 0) return result;
+ return 0;
+ }
+
+ /**
+ * Split the given [uri] like `package:some.name/and/path.dart` into a list
+ * like `[package:some.name, and/path.dart]`.
+ */
+ static List<String> _splitUri(String uri) {
+ int index = uri.indexOf('/');
+ if (index == -1) {
+ return <String>[uri, ''];
+ }
+ return <String>[uri.substring(0, index), uri.substring(index + 1)];
+ }
}
class _DirectivePriority {
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/correction/sort_members_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698