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

Unified Diff: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/analysis/model/AnalysisServerDataImpl.java

Issue 304273007: Use 'analysis.setSubscriptions' HIGHLIGHTS in Editor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use addAnalysisSubscription/removeAnalysisSubscription Created 6 years, 7 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: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/analysis/model/AnalysisServerDataImpl.java
diff --git a/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/analysis/model/AnalysisServerDataImpl.java b/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/analysis/model/AnalysisServerDataImpl.java
index 93b12e6744c4afbd78eb80bf00e3d90e432d0494..21c3f69b6ef719b8ba7870fbac8a204f09656dd0 100644
--- a/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/analysis/model/AnalysisServerDataImpl.java
+++ b/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/analysis/model/AnalysisServerDataImpl.java
@@ -14,7 +14,6 @@
package com.google.dart.tools.core.internal.analysis.model;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -47,6 +46,7 @@ public class AnalysisServerDataImpl implements AnalysisServerData {
private final Map<String, Set<AnalysisServerOutlineListener>> outlineSubscriptions = Maps.newHashMap();
private final Map<String, AnalysisError[]> errorData = Maps.newHashMap();
private final Map<String, NavigationRegion[]> navigationData = Maps.newHashMap();
+ private final Map<AnalysisService, List<String>> analysisSubscriptions = Maps.newHashMap();
// TODO(scheglov) restore or remove for the new API
// private final Map<String, Set<ErrorCode>> fixableErrorCodesData = Maps.newHashMap();
@@ -96,10 +96,7 @@ public class AnalysisServerDataImpl implements AnalysisServerData {
highlightsSubscriptions.put(file, subscriptions);
}
if (subscriptions.add(listener)) {
- Set<String> fileSet = highlightsSubscriptions.keySet();
- List<String> fileList = Lists.newArrayList(fileSet);
- // TODO(scheglov) new API requires full set of services and files
- server.setAnalysisSubscriptions(ImmutableMap.of(AnalysisService.HIGHLIGHT, fileList));
+ addAnalysisSubscription(AnalysisService.HIGHLIGHTS, file);
}
}
@@ -141,17 +138,13 @@ public class AnalysisServerDataImpl implements AnalysisServerData {
@Override
public void unsubscribeHighlights(String file, AnalysisServerHighlightsListener listener) {
- // TODO(scheglov) restore or remove for the new API
Set<AnalysisServerHighlightsListener> subscriptions = highlightsSubscriptions.get(file);
if (subscriptions == null) {
return;
}
if (subscriptions.remove(listener)) {
if (subscriptions.isEmpty()) {
- Set<String> fileSet = highlightsSubscriptions.keySet();
- List<String> fileList = Lists.newArrayList(fileSet);
- // TODO(scheglov) new API requires full set of services and files
- server.setAnalysisSubscriptions(ImmutableMap.of(AnalysisService.HIGHLIGHT, fileList));
+ removeAnalysisSubscription(AnalysisService.HIGHLIGHTS, file);
}
}
}
@@ -229,4 +222,35 @@ public class AnalysisServerDataImpl implements AnalysisServerData {
// TODO(scheglov) restore or remove for the new API
// fixableErrorCodesData.put(contextId, Sets.newHashSet(errorCodes));
}
+
+ /**
+ * Adds the given file to the subscription list for the given {@link AnalysisService}.
+ */
+ private void addAnalysisSubscription(AnalysisService service, String file) {
+ List<String> files = analysisSubscriptions.get(service);
+ if (files == null) {
+ files = Lists.newArrayList();
+ analysisSubscriptions.put(service, files);
+ }
+ if (!files.contains(file)) {
+ files.add(file);
+ server.setAnalysisSubscriptions(analysisSubscriptions);
+ }
+ }
+
+ /**
+ * Removes the given file from the subscription list for the given {@link AnalysisService}.
+ */
+ private void removeAnalysisSubscription(AnalysisService service, String file) {
+ List<String> files = analysisSubscriptions.get(service);
+ if (files == null) {
+ return;
+ }
+ if (files.remove(file)) {
+ if (files.isEmpty()) {
+ analysisSubscriptions.remove(service);
+ }
+ server.setAnalysisSubscriptions(analysisSubscriptions);
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698