Index: pkg/analysis_server/lib/src/services/correction/util.dart |
diff --git a/pkg/analysis_server/lib/src/services/correction/util.dart b/pkg/analysis_server/lib/src/services/correction/util.dart |
index babfeeec4b548dbf35b51616b82feefb0abdb901..c1a0f1fb47250b7e2395d3af944840ecfa3f9f41 100644 |
--- a/pkg/analysis_server/lib/src/services/correction/util.dart |
+++ b/pkg/analysis_server/lib/src/services/correction/util.dart |
@@ -30,7 +30,7 @@ import 'package:path/path.dart'; |
* imported into the given [targetLibrary]. |
*/ |
void addLibraryImports(SourceChange change, LibraryElement targetLibrary, |
- Set<LibraryElement> libraries) { |
+ Set<SourceInfo> libraries) { |
CorrectionUtils libUtils; |
try { |
CompilationUnitElement unitElement = targetLibrary.definingCompilationUnit; |
@@ -54,7 +54,7 @@ void addLibraryImports(SourceChange change, LibraryElement targetLibrary, |
// Prepare all URIs to import. |
List<String> uriList = libraries |
- .map((library) => getLibrarySourceUri(targetLibrary, library.source)) |
+ .map((library) => getLibrarySourceUri(targetLibrary, library)) |
.toList(); |
uriList.sort((a, b) => a.compareTo(b)); |
@@ -366,8 +366,8 @@ Map<String, Element> getImportNamespace(ImportElement imp) { |
/** |
* Computes the best URI to import [what] into [from]. |
*/ |
-String getLibrarySourceUri(LibraryElement from, Source what) { |
- String whatFile = what.fullName; |
+String getLibrarySourceUri(LibraryElement from, SourceInfo what) { |
+ String whatPath = what.path; |
// check if an absolute URI (such as 'dart:' or 'package:') |
Uri whatUri = what.uri; |
String whatUriScheme = whatUri.scheme; |
@@ -376,7 +376,7 @@ String getLibrarySourceUri(LibraryElement from, Source what) { |
} |
// compute a relative URI |
String fromFolder = dirname(from.source.fullName); |
- String relativeFile = relative(whatFile, from: fromFolder); |
+ String relativeFile = relative(whatPath, from: fromFolder); |
return split(relativeFile).join('/'); |
} |
@@ -765,7 +765,7 @@ class CorrectionUtils { |
* if can not be resolved, should be treated as the `dynamic` type. |
*/ |
String getExpressionTypeSource( |
- Expression expression, Set<LibraryElement> librariesToImport) { |
+ Expression expression, Set<SourceInfo> librariesToImport) { |
if (expression == null) { |
return null; |
} |
@@ -1054,7 +1054,7 @@ class CorrectionUtils { |
* @return the source for the parameter with the given type and name. |
*/ |
String getParameterSource( |
- DartType type, String name, Set<LibraryElement> librariesToImport) { |
+ DartType type, String name, Set<SourceInfo> librariesToImport) { |
// no type |
if (type == null || type.isDynamic) { |
return name; |
@@ -1121,7 +1121,7 @@ class CorrectionUtils { |
* Fills [librariesToImport] with [LibraryElement]s whose elements are |
* used by the generated source, but not imported. |
*/ |
- String getTypeSource(DartType type, Set<LibraryElement> librariesToImport, |
+ String getTypeSource(DartType type, Set<SourceInfo> librariesToImport, |
{StringBuffer parametersBuffer}) { |
StringBuffer sb = new StringBuffer(); |
// type parameter |
@@ -1173,7 +1173,9 @@ class CorrectionUtils { |
sb.write("."); |
} |
} else { |
- librariesToImport.add(library); |
+ Source source = library.source; |
+ SourceInfo sourceInfo = new SourceInfo(source.fullName, source.uri); |
+ librariesToImport.add(sourceInfo); |
} |
} |
// append simple name |
@@ -1544,6 +1546,27 @@ class CorrectionUtils_InsertDesc { |
} |
/** |
+ * Information about a [Source], just path and [Uri]. |
+ */ |
+class SourceInfo { |
Brian Wilkerson
2016/12/01 17:52:54
I don't understand the need for this class. Everyw
scheglov
2016/12/01 18:05:21
That's fair.
I replaced SourceInfo with Source.
|
+ final String path; |
+ final Uri uri; |
+ |
+ SourceInfo(this.path, this.uri); |
+ |
+ @override |
+ int get hashCode => uri.hashCode; |
+ |
+ @override |
+ bool operator ==(Object other) { |
+ return other is SourceInfo && other.uri == uri; |
+ } |
+ |
+ @override |
+ String toString() => path; |
+} |
+ |
+/** |
* Utilities to work with [Token]s. |
*/ |
class TokenUtils { |