Skip to content

Commit eeecd53

Browse files
scheglovCommit Queue
authored andcommitted
De-duplicate refactoringContext in RefactoringProducer.
Change-Id: Ia1dcbaf301d37d977b22742bf8198c64f7d34159 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311159 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 69c62b1 commit eeecd53

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

pkg/analysis_server/lib/src/services/refactoring/framework/refactoring_producer.dart

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dar
1717
/// An object that can compute a refactoring in a Dart file.
1818
abstract class RefactoringProducer {
1919
/// The context in which the refactoring was requested.
20-
final RefactoringContext _context;
20+
final RefactoringContext refactoringContext;
2121

22-
/// Initialize a newly created refactoring producer to create a refactoring in
23-
/// the given [_context].
24-
RefactoringProducer(this._context);
22+
/// Initialize a newly created refactoring producer.
23+
RefactoringProducer(this.refactoringContext);
2524

2625
/// The most deeply nested node whose range completely includes the range of
2726
/// characters described by [selectionOffset] and [selectionLength].
28-
AstNode? get coveringNode => _context.coveringNode;
27+
AstNode? get coveringNode => refactoringContext.coveringNode;
2928

3029
/// Return whether this refactor is considered experimental and will only
3130
/// be included if the user has opted-in.
@@ -39,47 +38,50 @@ abstract class RefactoringProducer {
3938

4039
/// Return the result of resolving the library in which the refactoring was
4140
/// invoked.
42-
ResolvedLibraryResult get libraryResult => _context.resolvedLibraryResult;
41+
ResolvedLibraryResult get libraryResult {
42+
return refactoringContext.resolvedLibraryResult;
43+
}
4344

4445
/// Return a list of the parameters to send to the client.
4546
List<CommandParameter> get parameters;
4647

47-
RefactoringContext get refactoringContext => _context;
48-
4948
/// Return the search engine used to search outside the resolved library.
50-
SearchEngine get searchEngine => _context.searchEngine;
49+
SearchEngine get searchEngine => refactoringContext.searchEngine;
5150

5251
/// Return the selection, or `null` if the selection is not valid.
53-
Selection? get selection => _context.selection;
52+
Selection? get selection => refactoringContext.selection;
5453

5554
/// Return the offset of the first character after the selection range.
56-
int get selectionEnd => _context.selectionEnd;
55+
int get selectionEnd => refactoringContext.selectionEnd;
5756

5857
/// Return the number of selected characters.
59-
int get selectionLength => _context.selectionLength;
58+
int get selectionLength => refactoringContext.selectionLength;
6059

6160
/// Return the offset of the beginning of the selection range.
62-
int get selectionOffset => _context.selectionOffset;
61+
int get selectionOffset => refactoringContext.selectionOffset;
6362

6463
/// Return the helper used to efficiently access resolved units.
65-
AnalysisSessionHelper get sessionHelper => _context.sessionHelper;
64+
AnalysisSessionHelper get sessionHelper => refactoringContext.sessionHelper;
6665

6766
/// Return `true` if the client has support for creating files. Subclasses
6867
/// that require the ability to create new files must not create a refactoring
6968
/// if this getter returns `false`.
70-
bool get supportsFileCreation =>
71-
_context.server.clientCapabilities?.documentChanges == true &&
72-
_context.server.clientCapabilities?.createResourceOperations == true;
69+
bool get supportsFileCreation {
70+
final capabilities = refactoringContext.server.clientCapabilities;
71+
return capabilities != null &&
72+
capabilities.documentChanges == true &&
73+
capabilities.createResourceOperations == true;
74+
}
7375

7476
/// Return the title of this refactoring.
7577
String get title;
7678

7779
/// Return the result of resolving the file in which the refactoring was
7880
/// invoked.
79-
ResolvedUnitResult get unitResult => _context.resolvedUnitResult;
81+
ResolvedUnitResult get unitResult => refactoringContext.resolvedUnitResult;
8082

8183
/// Return the correction utilities for this refactoring.
82-
CorrectionUtils get utils => _context.utils;
84+
CorrectionUtils get utils => refactoringContext.utils;
8385

8486
/// Given the [commandArguments] associated with the command, use the
8587
/// [builder] to generate the edits necessary to apply this refactoring.
@@ -89,15 +91,17 @@ abstract class RefactoringProducer {
8991
bool isAvailable();
9092

9193
/// Return `true` if the selection is inside the given [token].
92-
bool selectionIsInToken(Token? token) => _context.selectionIsInToken(token);
94+
bool selectionIsInToken(Token? token) {
95+
return refactoringContext.selectionIsInToken(token);
96+
}
9397

9498
/// Return `true` if the client has support for command parameters of the
9599
/// provided `kind`. Subclasses that produce command parameters of this kind
96100
/// that don't have a default value must not create a refactoring if this
97101
/// returns `false`.
98-
bool supportsCommandParameter(String kind) =>
99-
_context
100-
.server.clientCapabilities?.codeActionCommandParameterSupportedKinds
101-
.contains(kind) ??
102-
false;
102+
bool supportsCommandParameter(String kind) {
103+
final capabilities = refactoringContext.server.clientCapabilities;
104+
return capabilities != null &&
105+
capabilities.codeActionCommandParameterSupportedKinds.contains(kind);
106+
}
103107
}

0 commit comments

Comments
 (0)