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

Unified Diff: pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart

Issue 2972463003: Use DartEditBuilder to write types and remove dead code (Closed)
Patch Set: Created 3 years, 6 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/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
diff --git a/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart b/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
index b98fe4ab26cbae7a90fa74a206ae7ae9c7017a71..2579f32f95032e7996fe7d821d2c0913a7de7db3 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
@@ -486,7 +486,7 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder {
String typeSource = _getTypeSource(
type, finder.enclosingClass, finder.enclosingExecutable,
methodBeingCopied: methodBeingCopied);
- if (typeSource != 'dynamic') {
+ if (typeSource.isNotEmpty && typeSource != 'dynamic') {
if (groupName != null) {
addLinkedEdit(groupName, (LinkedEditBuilder builder) {
write(typeSource);
@@ -957,6 +957,17 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder {
parameterParent == enclosingClass ||
parameterParent == methodBeingCopied;
}
+ Element element = type.element;
+ if (element == null) {
+ return true;
+ }
+ LibraryElement definingLibrary = element.library;
+ LibraryElement importingLibrary = dartFileEditBuilder.unit.element.library;
+ if (definingLibrary != null && definingLibrary != importingLibrary) {
+ if (element.isPrivate) {
+ return false;
+ }
+ }
return true;
}
}
@@ -1015,8 +1026,19 @@ class DartFileEditBuilderImpl extends FileEditBuilderImpl
@override
void finalize() {
- _addLibraryImports(
- changeBuilder.sourceChange, unit.element.library, librariesToImport);
+ CompilationUnitElement unitElement = unit.element;
+ LibraryElement libraryElement = unitElement.library;
+ CompilationUnitElement definingUnitElement =
+ libraryElement.definingCompilationUnit;
+ if (definingUnitElement == unitElement) {
+ _addLibraryImports(libraryElement, librariesToImport);
+ } else {
+ (changeBuilder as DartChangeBuilder).addFileEdit(
+ definingUnitElement.source.fullName, (DartFileEditBuilder builder) {
+ (builder as DartFileEditBuilderImpl)
+ ._addLibraryImports(libraryElement, librariesToImport);
+ });
+ }
}
@override
@@ -1051,11 +1073,10 @@ class DartFileEditBuilderImpl extends FileEditBuilderImpl
}
/**
- * Adds edits to the given [change] that ensure that all the [libraries] are
- * imported into the given [targetLibrary].
+ * Adds edits ensure that all the [libraries] are imported into the given
+ * [targetLibrary].
*/
- void _addLibraryImports(SourceChange change, LibraryElement targetLibrary,
- Set<Source> libraries) {
+ void _addLibraryImports(LibraryElement targetLibrary, Set<Source> libraries) {
// Prepare information about existing imports.
LibraryDirective libraryDirective;
List<ImportDirective> importDirectives = <ImportDirective>[];

Powered by Google App Engine
This is Rietveld 408576698