OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014, the Dart project authors. | 2 * Copyright (c) 2014, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 | 14 |
15 package com.google.dart.tools.core.internal.analysis.model; | 15 package com.google.dart.tools.core.internal.analysis.model; |
16 | 16 |
17 import com.google.common.collect.ImmutableMap; | 17 import com.google.common.collect.ImmutableMap; |
| 18 import com.google.common.collect.ImmutableSet; |
18 import com.google.common.collect.Maps; | 19 import com.google.common.collect.Maps; |
19 import com.google.common.collect.Sets; | 20 import com.google.common.collect.Sets; |
20 import com.google.dart.engine.source.Source; | 21 import com.google.dart.engine.source.Source; |
21 import com.google.dart.server.AnalysisServer; | 22 import com.google.dart.server.AnalysisServer; |
22 import com.google.dart.server.ListSourceSet; | 23 import com.google.dart.server.ListSourceSet; |
23 import com.google.dart.server.NavigationRegion; | 24 import com.google.dart.server.NavigationRegion; |
24 import com.google.dart.server.NotificationKind; | 25 import com.google.dart.server.NotificationKind; |
| 26 import com.google.dart.server.Outline; |
25 import com.google.dart.tools.core.analysis.model.AnalysisServerData; | 27 import com.google.dart.tools.core.analysis.model.AnalysisServerData; |
| 28 import com.google.dart.tools.core.analysis.model.AnalysisServerOutlineListener; |
26 | 29 |
27 import java.util.Map; | 30 import java.util.Map; |
28 import java.util.Set; | 31 import java.util.Set; |
29 | 32 |
30 /** | 33 /** |
31 * Instances of {@code AnalysisServerData} manage and provide access to analysis
results reported by | 34 * Instances of {@code AnalysisServerData} manage and provide access to analysis
results reported by |
32 * {@link AnalysisServer}. | 35 * {@link AnalysisServer}. |
33 * | 36 * |
34 * @coverage dart.tools.core.model | 37 * @coverage dart.tools.core.model |
35 */ | 38 */ |
36 public class AnalysisServerDataImpl implements AnalysisServerData { | 39 public class AnalysisServerDataImpl implements AnalysisServerData { |
37 private final Map<String, Map<Source, NavigationRegion[]>> navigationData = Ma
ps.newHashMap(); | 40 private final Map<String, Map<Source, NavigationRegion[]>> navigationData = Ma
ps.newHashMap(); |
38 private final Map<String, Set<Source>> navigationSubscriptions = Maps.newHashM
ap(); | 41 private final Map<String, Set<Source>> navigationSubscriptions = Maps.newHashM
ap(); |
| 42 private final Map<String, Map<Source, Set<AnalysisServerOutlineListener>>> out
lineSubscriptions = Maps.newHashMap(); |
39 | 43 |
40 private AnalysisServer server; | 44 private AnalysisServer server; |
41 | 45 |
42 @Override | 46 @Override |
43 public NavigationRegion[] getNavigation(String contextId, Source source) { | 47 public NavigationRegion[] getNavigation(String contextId, Source source) { |
44 Map<Source, NavigationRegion[]> contextRegions = navigationData.get(contextI
d); | 48 Map<Source, NavigationRegion[]> contextRegions = navigationData.get(contextI
d); |
45 if (contextRegions == null) { | 49 if (contextRegions == null) { |
46 return NavigationRegion.EMPTY_ARRAY; | 50 return NavigationRegion.EMPTY_ARRAY; |
47 } | 51 } |
48 NavigationRegion[] sourceRegions = contextRegions.get(source); | 52 NavigationRegion[] sourceRegions = contextRegions.get(source); |
49 if (sourceRegions == null) { | 53 if (sourceRegions == null) { |
50 return NavigationRegion.EMPTY_ARRAY; | 54 return NavigationRegion.EMPTY_ARRAY; |
51 } | 55 } |
52 return sourceRegions; | 56 return sourceRegions; |
53 } | 57 } |
54 | 58 |
55 public void internalComputedNavigation(String contextId, Source source, Naviga
tionRegion[] targets) { | |
56 Map<Source, NavigationRegion[]> contextRegions = navigationData.get(contextI
d); | |
57 if (contextRegions == null) { | |
58 contextRegions = Maps.newHashMap(); | |
59 navigationData.put(contextId, contextRegions); | |
60 } | |
61 contextRegions.put(source, targets); | |
62 } | |
63 | |
64 /** | 59 /** |
65 * Deletes all the data associated with the given context. | 60 * Deletes all the data associated with the given context. |
66 */ | 61 */ |
67 public void internalDeleteContext(String contextId) { | 62 public void internalDeleteContext(String contextId) { |
68 navigationData.remove(contextId); | 63 navigationData.remove(contextId); |
69 navigationSubscriptions.remove(contextId); | 64 navigationSubscriptions.remove(contextId); |
70 } | 65 } |
71 | 66 |
72 /** | 67 /** |
73 * Sets the {@link AnalysisServer} to talk to. | 68 * Sets the {@link AnalysisServer} to talk to. |
(...skipping 10 matching lines...) Expand all Loading... |
84 navigationSubscriptions.put(contextId, sources); | 79 navigationSubscriptions.put(contextId, sources); |
85 } | 80 } |
86 if (sources.add(source)) { | 81 if (sources.add(source)) { |
87 server.subscribe( | 82 server.subscribe( |
88 contextId, | 83 contextId, |
89 ImmutableMap.of(NotificationKind.NAVIGATION, ListSourceSet.create(sour
ces))); | 84 ImmutableMap.of(NotificationKind.NAVIGATION, ListSourceSet.create(sour
ces))); |
90 } | 85 } |
91 } | 86 } |
92 | 87 |
93 @Override | 88 @Override |
| 89 public void subscribeOutline(String contextId, Source source, |
| 90 AnalysisServerOutlineListener listener) { |
| 91 Map<Source, Set<AnalysisServerOutlineListener>> sourceSubscriptions = outlin
eSubscriptions.get(contextId); |
| 92 if (sourceSubscriptions == null) { |
| 93 sourceSubscriptions = Maps.newHashMap(); |
| 94 outlineSubscriptions.put(contextId, sourceSubscriptions); |
| 95 } |
| 96 Set<AnalysisServerOutlineListener> subscriptions = sourceSubscriptions.get(s
ource); |
| 97 if (subscriptions == null) { |
| 98 subscriptions = Sets.newHashSet(); |
| 99 sourceSubscriptions.put(source, subscriptions); |
| 100 } |
| 101 if (subscriptions.add(listener)) { |
| 102 Set<Source> sourceSet = sourceSubscriptions.keySet(); |
| 103 server.subscribe( |
| 104 contextId, |
| 105 ImmutableMap.of(NotificationKind.OUTLINE, ListSourceSet.create(sourceS
et))); |
| 106 } |
| 107 } |
| 108 |
| 109 @Override |
94 public void unsubscribeNavigation(String contextId, Source source) { | 110 public void unsubscribeNavigation(String contextId, Source source) { |
95 Set<Source> sources = navigationSubscriptions.get(contextId); | 111 Set<Source> sources = navigationSubscriptions.get(contextId); |
96 if (sources == null) { | 112 if (sources == null) { |
97 return; | 113 return; |
98 } | 114 } |
99 if (sources.remove(source)) { | 115 if (sources.remove(source)) { |
100 server.subscribe( | 116 server.subscribe( |
101 contextId, | 117 contextId, |
102 ImmutableMap.of(NotificationKind.NAVIGATION, ListSourceSet.create(sour
ces))); | 118 ImmutableMap.of(NotificationKind.NAVIGATION, ListSourceSet.create(sour
ces))); |
103 } | 119 } |
104 } | 120 } |
| 121 |
| 122 @Override |
| 123 public void unsubscribeOutline(String contextId, Source source, |
| 124 AnalysisServerOutlineListener listener) { |
| 125 Map<Source, Set<AnalysisServerOutlineListener>> sourceSubscriptions = outlin
eSubscriptions.get(contextId); |
| 126 if (sourceSubscriptions == null) { |
| 127 return; |
| 128 } |
| 129 Set<AnalysisServerOutlineListener> subscriptions = sourceSubscriptions.get(s
ource); |
| 130 if (subscriptions == null) { |
| 131 return; |
| 132 } |
| 133 if (subscriptions.remove(listener)) { |
| 134 if (subscriptions.isEmpty()) { |
| 135 sourceSubscriptions.remove(source); |
| 136 Set<Source> sourceSet = sourceSubscriptions.keySet(); |
| 137 server.subscribe( |
| 138 contextId, |
| 139 ImmutableMap.of(NotificationKind.OUTLINE, ListSourceSet.create(sourc
eSet))); |
| 140 } |
| 141 } |
| 142 } |
| 143 |
| 144 void internalComputedNavigation(String contextId, Source source, NavigationReg
ion[] targets) { |
| 145 Map<Source, NavigationRegion[]> contextRegions = navigationData.get(contextI
d); |
| 146 if (contextRegions == null) { |
| 147 contextRegions = Maps.newHashMap(); |
| 148 navigationData.put(contextId, contextRegions); |
| 149 } |
| 150 contextRegions.put(source, targets); |
| 151 } |
| 152 |
| 153 void internalComputedOutline(String contextId, Source source, Outline outline)
{ |
| 154 Map<Source, Set<AnalysisServerOutlineListener>> sourceSubscriptions = outlin
eSubscriptions.get(contextId); |
| 155 if (sourceSubscriptions == null) { |
| 156 return; |
| 157 } |
| 158 Set<AnalysisServerOutlineListener> subscriptions = sourceSubscriptions.get(s
ource); |
| 159 if (subscriptions == null) { |
| 160 return; |
| 161 } |
| 162 subscriptions = ImmutableSet.copyOf(subscriptions); |
| 163 for (AnalysisServerOutlineListener listener : subscriptions) { |
| 164 listener.computedOutline(contextId, source, outline); |
| 165 } |
| 166 } |
105 } | 167 } |
OLD | NEW |