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

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

Issue 562333002: Issue 17024. Quick Fix to find imported library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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
Index: pkg/analysis_server/lib/src/services/correction/fix_internal.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
index e8e3350b2a77c2aa5241262e3186491610ed5c7a..9fed0c4c76535f7bd4ff725486a588f658860044 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -130,6 +130,9 @@ class FixProcessor {
CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT) {
_addFix_createConstructorSuperExplicit();
}
+ if (errorCode == CompileTimeErrorCode.URI_DOES_NOT_EXIST) {
+ _addFix_replaceImportUri();
+ }
if (errorCode == HintCode.DIVISION_OPTIMIZATION) {
_addFix_useEffectiveIntegerDivision();
}
@@ -970,6 +973,33 @@ class FixProcessor {
_addFix(FixKind.REMOVE_UNUSED_IMPORT, []);
}
+ void _addFix_replaceImportUri() {
+ if (node is SimpleStringLiteral) {
+ SimpleStringLiteral stringLiteral = node;
+ String uri = stringLiteral.value;
+ String uriName = substringAfterLast(uri, '/');
+ AnalysisContext context = unitLibraryElement.context;
+ for (Source libSource in context.librarySources) {
+ String libFile = libSource.fullName;
+ if (substringAfterLast(libFile, '/') == uriName) {
+ String fixedUri;
+ // may be "package:" URI
+ String libPackageUri = _findPackageUri(context, libFile);
+ if (libPackageUri != null) {
+ fixedUri = libPackageUri;
+ } else {
+ String relativeFile = relative(libFile, from: unitLibraryFolder);
+ fixedUri = split(relativeFile).join('/');
+ }
+ // add fix
+ SourceRange range = rf.rangeNode(node);
+ _addReplaceEdit(range, "'$fixedUri'");
+ _addFix(FixKind.REPLACE_IMPORT_URI, [fixedUri]);
+ }
+ }
+ }
+ }
+
void _addFix_replaceWithConstInstanceCreation() {
if (coveredNode is InstanceCreationExpression) {
var instanceCreation = coveredNode as InstanceCreationExpression;
@@ -1819,7 +1849,6 @@ class FixProcessor {
* Returns the "package" URI, may be `null`.
*/
static String _findPackageUri(AnalysisContext context, String path) {
-// Source fileSource = new FileBasedSource.con1(path);
Source fileSource = new NonExistingSource(path, UriKind.FILE_URI);
Uri uri = context.sourceFactory.restoreUri(fileSource);
if (uri == null) {
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix.dart ('k') | pkg/analysis_server/lib/src/services/correction/strings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698