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

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

Issue 2998703002: Handle creation of class members in files other than the file containing the error (issue 30327) (Closed)
Patch Set: Created 3 years, 4 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 3accd66aef277792cc2b45ff0a7fb41c4c3def71..e25e759af336bc0d06d96fb26618bb6ba8fe76ff 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -1167,7 +1167,7 @@ class FixProcessor {
ClassDeclaration targetClassNode = targetTypeNode;
// prepare location
ClassMemberLocation targetLocation =
- utils.prepareNewFieldLocation(targetClassNode);
+ _getUtilsFor(targetClassNode).prepareNewFieldLocation(targetClassNode);
// build field source
Source targetSource = targetClassElement.source;
String targetFile = targetSource.fullName;
@@ -1324,7 +1324,7 @@ class FixProcessor {
ClassDeclaration targetClassNode = targetTypeNode;
// prepare location
ClassMemberLocation targetLocation =
- utils.prepareNewGetterLocation(targetClassNode);
+ _getUtilsFor(targetClassNode).prepareNewGetterLocation(targetClassNode);
// build method source
Source targetSource = targetClassElement.source;
String targetFile = targetSource.fullName;
@@ -2866,6 +2866,26 @@ class FixProcessor {
}
/**
+ * Return the correction utilities that should be used when creating an edit
+ * in the compilation unit containing the given [node].
+ */
+ CorrectionUtils _getUtilsFor(AstNode node) {
+ CompilationUnit targetUnit =
+ node.getAncestor((node) => node is CompilationUnit);
+ CompilationUnitElement targetUnitElement = targetUnit?.element;
+ CorrectionUtils realUtils = utils;
+ if (targetUnitElement != utils.unit.element) {
+ realUtils = new CorrectionUtils(targetUnit);
+ ClassDeclaration targetClass =
+ node.getAncestor((node) => node is ClassDeclaration);
+ if (targetClass != null) {
+ realUtils.targetClassElement = targetClass.element;
+ }
+ }
+ return realUtils;
+ }
+
+ /**
* Returns an expected [DartType] of [expression], may be `null` if cannot be
* inferred.
*/

Powered by Google App Engine
This is Rietveld 408576698