mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:27:43 +00:00
analysis_server: Fix OrganizeImports correction
Sort `a.dart` before `a/b.dart` Fixes https://github.com/dart-lang/sdk/issues/45321 Change-Id: Ic16cf3dc1d0651e450cc476bf02d86afa9abf3fa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214310 Auto-Submit: Kevin Moore <kevmoo@google.com> Commit-Queue: Kevin Moore <kevmoo@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
parent
1b3415b069
commit
22f1cee9d6
|
@ -350,23 +350,16 @@ class _DirectiveInfo implements Comparable<_DirectiveInfo> {
|
||||||
@override
|
@override
|
||||||
String toString() => '(priority=$priority; text=$text)';
|
String toString() => '(priority=$priority; text=$text)';
|
||||||
|
|
||||||
|
/// Should keep these in sync! Copied from
|
||||||
|
/// https://github.com/dart-lang/linter/blob/658f497eef/lib/src/rules/directives_ordering.dart#L380-L387
|
||||||
|
/// Consider finding a way to share this code!
|
||||||
static int _compareUri(String a, String b) {
|
static int _compareUri(String a, String b) {
|
||||||
var aList = _splitUri(a);
|
var indexA = a.indexOf('/');
|
||||||
var bList = _splitUri(b);
|
var indexB = b.indexOf('/');
|
||||||
int result;
|
if (indexA == -1 || indexB == -1) return a.compareTo(b);
|
||||||
if ((result = aList[0].compareTo(bList[0])) != 0) return result;
|
var result = a.substring(0, indexA).compareTo(b.substring(0, indexB));
|
||||||
if ((result = aList[1].compareTo(bList[1])) != 0) return result;
|
if (result != 0) return result;
|
||||||
return 0;
|
return a.substring(indexA + 1).compareTo(b.substring(indexB + 1));
|
||||||
}
|
|
||||||
|
|
||||||
/// 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) {
|
|
||||||
var index = uri.indexOf('/');
|
|
||||||
if (index == -1) {
|
|
||||||
return <String>[uri, ''];
|
|
||||||
}
|
|
||||||
return <String>[uri.substring(0, index), uri.substring(index + 1)];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,41 @@ import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
void f(Stream<String> args) { }
|
void f(Stream<String> args) { }
|
||||||
|
''');
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> test_organizePathImports() async {
|
||||||
|
newFile('/home/test/lib/a.dart', content: '''
|
||||||
|
class A {
|
||||||
|
static void m() {}
|
||||||
|
}
|
||||||
|
''');
|
||||||
|
newFile('/home/test/lib/a/b.dart', content: '''
|
||||||
|
class B {
|
||||||
|
static void m() {}
|
||||||
|
}
|
||||||
|
''');
|
||||||
|
|
||||||
|
await resolveTestCode('''
|
||||||
|
import 'dart:async';
|
||||||
|
import 'a/b.dart';
|
||||||
|
import 'a.dart';
|
||||||
|
|
||||||
|
void f(Stream<String> args) {
|
||||||
|
A.m();
|
||||||
|
B.m();
|
||||||
|
}
|
||||||
|
''');
|
||||||
|
await assertHasFix('''
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'a.dart';
|
||||||
|
import 'a/b.dart';
|
||||||
|
|
||||||
|
void f(Stream<String> args) {
|
||||||
|
A.m();
|
||||||
|
B.m();
|
||||||
|
}
|
||||||
''');
|
''');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue