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

Unified Diff: pkg/analyzer_plugin/lib/src/utilities/occurrences/occurrences.dart

Issue 3006703002: Add plugin support for occurrences (and fix typo) (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/analyzer_plugin/lib/src/utilities/occurrences/occurrences.dart
diff --git a/pkg/analyzer_plugin/lib/src/utilities/occurrences/occurrences.dart b/pkg/analyzer_plugin/lib/src/utilities/occurrences/occurrences.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b88aa78955e633dea58eca09c21944dc32db0326
--- /dev/null
+++ b/pkg/analyzer_plugin/lib/src/utilities/occurrences/occurrences.dart
@@ -0,0 +1,60 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:analyzer/dart/analysis/results.dart';
+import 'package:analyzer/file_system/file_system.dart';
+import 'package:analyzer_plugin/protocol/protocol_common.dart'
+ hide AnalysisError;
+import 'package:analyzer_plugin/utilities/occurrences/occurrences.dart';
+
+/**
+ * A concrete implementation of [DartOccurrencesRequest].
+ */
+class DartOccurrencesRequestImpl implements DartOccurrencesRequest {
+ @override
+ final ResourceProvider resourceProvider;
+
+ @override
+ final ResolveResult result;
+
+ /**
+ * Initialize a newly create request with the given data.
+ */
+ DartOccurrencesRequestImpl(this.resourceProvider, this.result);
+
+ @override
+ String get path => result.path;
+}
+
+/**
+ * A concrete implementation of [OccurrencesCollector].
+ */
+class OccurrencesCollectorImpl implements OccurrencesCollector {
+ /**
+ * The locations of the occurrences that have been collected.
+ */
+ Map<Element, List<int>> occurrenceLocations = <Element, List<int>>{};
+
+ /**
+ * Initialize a newly created collector.
+ */
+ OccurrencesCollectorImpl();
+
+ /**
+ * Return the list of occurrences that have been collected.
+ */
+ List<Occurrences> get occurrences {
+ List<Occurrences> occurrences = <Occurrences>[];
+ occurrenceLocations.forEach((Element element, List<int> offsets) {
+ offsets.sort();
+ occurrences.add(new Occurrences(element, offsets, element.name.length));
+ });
+ return occurrences;
+ }
+
+ @override
+ void addOccurrence(Element element, int offset) {
+ occurrenceLocations.putIfAbsent(element, () => <int>[]).add(offset);
+ }
+}
« no previous file with comments | « pkg/analyzer_plugin/lib/plugin/occurrences_mixin.dart ('k') | pkg/analyzer_plugin/lib/utilities/occurrences/occurrences.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698