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

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

Issue 961583002: Issue 20827. Extract library importing helper and use it fox Quick Fixes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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/lib/src/services/correction/fix_internal.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/assist_internal.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
index 376e4140cb4b7b9f5a07e82f20be4ac399386065..85a5194299f8320adf6fe819447b54cef88076a8 100644
--- a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart
@@ -54,8 +54,8 @@ class AssistProcessor {
SourceChange change = new SourceChange('<message>');
- AssistProcessor(this.source, this.file, this.unit,
- this.selectionOffset, this.selectionLength) {
+ AssistProcessor(this.source, this.file, this.unit, this.selectionOffset,
+ this.selectionLength) {
unitElement = unit.element;
context = unitElement.context;
unitLibraryElement = unitElement.library;
@@ -173,46 +173,6 @@ class AssistProcessor {
doSourceChange_addElementEdit(change, unitElement, edit);
}
- void _addLibraryImports(Set<LibraryElement> libraries) {
- LibraryElement libElement = unitLibraryElement;
- CompilationUnitElement libUnitElement = libElement.definingCompilationUnit;
- CompilationUnit libUnit = libUnitElement.node;
- // prepare new import location
- int offset = 0;
- String prefix;
- String suffix;
- {
- // if no directives
- prefix = '';
- suffix = eol;
- CorrectionUtils libraryUtils = new CorrectionUtils(libUnit);
- // after last directive in library
- for (Directive directive in libUnit.directives) {
- if (directive is LibraryDirective || directive is ImportDirective) {
- offset = directive.end;
- prefix = eol;
- suffix = '';
- }
- }
- // if still at the beginning of the file, skip shebang and line comments
- if (offset == 0) {
- CorrectionUtils_InsertDesc desc = libraryUtils.getInsertDescTop();
- offset = desc.offset;
- prefix = desc.prefix;
- suffix = desc.suffix + eol;
- }
- }
- // insert imports
- for (LibraryElement library in libraries) {
- String importPath = getLibrarySourceUri(libElement, library.source);
- String importCode = "${prefix}import '$importPath';$suffix";
- doSourceChange_addElementEdit(
- change,
- unitLibraryElement,
- new SourceEdit(offset, 0, importCode));
- }
- }
-
void _addProposal_addTypeAnnotation_DeclaredIdentifier() {
DeclaredIdentifier declaredIdentifier =
node.getAncestor((n) => n is DeclaredIdentifier);
@@ -241,7 +201,7 @@ class AssistProcessor {
_configureTargetLocation(node);
Set<LibraryElement> librariesToImport = new Set<LibraryElement>();
typeSource = utils.getTypeSource(type, librariesToImport);
- _addLibraryImports(librariesToImport);
+ addLibraryImports(change, unitLibraryElement, librariesToImport);
} else {
_coverageMarker();
return;
@@ -296,7 +256,7 @@ class AssistProcessor {
_configureTargetLocation(node);
Set<LibraryElement> librariesToImport = new Set<LibraryElement>();
typeSource = utils.getTypeSource(type, librariesToImport);
- _addLibraryImports(librariesToImport);
+ addLibraryImports(change, unitLibraryElement, librariesToImport);
} else {
_coverageMarker();
return;
@@ -343,7 +303,7 @@ class AssistProcessor {
_configureTargetLocation(node);
Set<LibraryElement> librariesToImport = new Set<LibraryElement>();
typeSource = utils.getTypeSource(type, librariesToImport);
- _addLibraryImports(librariesToImport);
+ addLibraryImports(change, unitLibraryElement, librariesToImport);
}
// add edit
_addInsertEdit(name.offset, '$typeSource ');
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/correction/fix_internal.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698