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

Unified Diff: pkg/analysis_server/lib/src/services/refactoring/refactoring_internal.dart

Issue 1764553002: Make SearchMatch usable for the new index - remove the element field. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
Index: pkg/analysis_server/lib/src/services/refactoring/refactoring_internal.dart
diff --git a/pkg/analysis_server/lib/src/services/refactoring/refactoring_internal.dart b/pkg/analysis_server/lib/src/services/refactoring/refactoring_internal.dart
index f435ff97588a0b19af161562e1ed9cbe99b35bd3..17fdb68f205fa9fa5dbf24122fdff258b167259b 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/refactoring_internal.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/refactoring_internal.dart
@@ -12,9 +12,17 @@ import 'package:analysis_server/src/services/correction/status.dart';
import 'package:analysis_server/src/services/refactoring/refactoring.dart';
import 'package:analysis_server/src/services/search/search_engine.dart';
import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
import 'package:analyzer/src/generated/source.dart';
/**
+ * Return a new [SourceReference] instance for the given [match].
+ */
+SourceReference getSourceReference(SearchMatch match) {
+ return new SourceReference(match);
+}
+
+/**
* When a [Source] (a file) is used in more than one context, [SearchEngine]
* will return separate [SearchMatch]s for each context. But in rename
* refactorings we want to update each [Source] only once.
@@ -22,11 +30,7 @@ import 'package:analyzer/src/generated/source.dart';
List<SourceReference> getSourceReferences(List<SearchMatch> matches) {
var uniqueReferences = new HashMap<SourceReference, SourceReference>();
for (SearchMatch match in matches) {
- Element element = match.element;
- String file = element.source.fullName;
- SourceRange range = match.sourceRange;
- SourceReference newReference = new SourceReference(
- file, range, element, match.isResolved, match.isQualified);
+ SourceReference newReference = getSourceReference(match);
SourceReference oldReference = uniqueReferences[newReference];
if (oldReference == null) {
uniqueReferences[newReference] = newReference;
@@ -56,16 +60,22 @@ abstract class RefactoringImpl implements Refactoring {
/**
* The [SourceRange] in some [Source].
+ *
+ * TODO(scheglov) inline this class as SearchMatch
*/
class SourceReference {
- final String file;
- final SourceRange range;
- final Element element;
- final bool isResolved;
- final bool isQualified;
+ final SearchMatch _match;
+
+ SourceReference(this._match);
+
+ AnalysisContext get context => _match.context;
- SourceReference(
- this.file, this.range, this.element, this.isResolved, this.isQualified);
+ Element get element => _match.element;
+
+ /**
+ * The full path of the file containing the match.
+ */
+ String get file => _match.file;
@override
int get hashCode {
@@ -74,6 +84,12 @@ class SourceReference {
return hash;
}
+ bool get isResolved => _match.isResolved;
+
+ SourceRange get range => _match.sourceRange;
+
+ Source get unitSource => _match.unitSource;
+
@override
bool operator ==(Object other) {
if (identical(other, this)) {
@@ -90,7 +106,7 @@ class SourceReference {
*/
void addEdit(SourceChange change, String newText, {String id}) {
SourceEdit edit = createEdit(newText, id: id);
- doSourceChange_addElementEdit(change, element, edit);
+ doSourceChange_addSourceEdit(change, context, unitSource, edit);
}
/**

Powered by Google App Engine
This is Rietveld 408576698