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

Side by Side Diff: pkg/analysis_server/lib/src/computer/computer_highlights.dart

Issue 1227143003: Update Analysis Server highlight API and implementation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library computer.highlights; 5 library computer.highlights;
6 6
7 import 'package:analysis_server/src/protocol.dart' hide Element; 7 import 'package:analysis_server/src/protocol.dart' hide Element;
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/element.dart'; 9 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/scanner.dart'; 10 import 'package:analyzer/src/generated/scanner.dart';
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 void _addIdentifierRegion(SimpleIdentifier node) { 56 void _addIdentifierRegion(SimpleIdentifier node) {
57 if (_addIdentifierRegion_keyword(node)) { 57 if (_addIdentifierRegion_keyword(node)) {
58 return; 58 return;
59 } 59 }
60 if (_addIdentifierRegion_class(node)) { 60 if (_addIdentifierRegion_class(node)) {
61 return; 61 return;
62 } 62 }
63 if (_addIdentifierRegion_constructor(node)) { 63 if (_addIdentifierRegion_constructor(node)) {
64 return; 64 return;
65 } 65 }
66 if (_addIdentifierRegion_dynamicType(node)) { 66 if (_addIdentifierRegion_untyped(node)) {
67 return; 67 return;
68 } 68 }
69 if (_addIdentifierRegion_getterSetterDeclaration(node)) { 69 if (_addIdentifierRegion_getterSetterDeclaration(node)) {
70 return; 70 return;
71 } 71 }
72 if (_addIdentifierRegion_field(node)) { 72 if (_addIdentifierRegion_field(node)) {
73 return; 73 return;
74 } 74 }
75 if (_addIdentifierRegion_function(node)) { 75 if (_addIdentifierRegion_function(node)) {
76 return; 76 return;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 128 }
129 129
130 bool _addIdentifierRegion_constructor(SimpleIdentifier node) { 130 bool _addIdentifierRegion_constructor(SimpleIdentifier node) {
131 Element element = node.staticElement; 131 Element element = node.staticElement;
132 if (element is! ConstructorElement) { 132 if (element is! ConstructorElement) {
133 return false; 133 return false;
134 } 134 }
135 return _addRegion_node(node, HighlightRegionType.CONSTRUCTOR); 135 return _addRegion_node(node, HighlightRegionType.CONSTRUCTOR);
136 } 136 }
137 137
138 bool _addIdentifierRegion_dynamicType(SimpleIdentifier node) { 138 bool _addIdentifierRegion_untyped(SimpleIdentifier node) {
139 // should be variable 139 // should be variable
140 Element element = node.staticElement; 140 Element element = node.staticElement;
141 if (element is! VariableElement) { 141 if (element is! VariableElement) {
142 return false; 142 return false;
143 } 143 }
144 // has propagated type 144 // has propagated type
145 if (node.propagatedType != null) { 145 if (node.propagatedType != null) {
146 return false; 146 return false;
147 } 147 }
148 // has dynamic static type 148 // has dynamic static type
149 DartType staticType = node.staticType; 149 DartType staticType = node.staticType;
150 if (staticType == null || !staticType.isDynamic) { 150 if (staticType == null || !staticType.isDynamic) {
151 return false; 151 return false;
152 } 152 }
153 // OK 153 // OK
154 return _addRegion_node(node, HighlightRegionType.DYNAMIC_TYPE); 154 return _addRegion_node(node, HighlightRegionType.UNTYPED_VARIABLE);
155 } 155 }
156 156
157 bool _addIdentifierRegion_field(SimpleIdentifier node) { 157 bool _addIdentifierRegion_field(SimpleIdentifier node) {
158 Element element = node.bestElement; 158 Element element = node.bestElement;
159 if (element is FieldFormalParameterElement) { 159 if (element is FieldFormalParameterElement) {
160 element = (element as FieldFormalParameterElement).field; 160 element = (element as FieldFormalParameterElement).field;
161 } 161 }
162 if (element is PropertyAccessorElement) { 162 if (element is PropertyAccessorElement) {
163 element = (element as PropertyAccessorElement).variable; 163 element = (element as PropertyAccessorElement).variable;
164 } 164 }
165 // prepare type 165 // prepare type
166 HighlightRegionType type; 166 HighlightRegionType type;
167 if (element is FieldElement) { 167 if (element is FieldElement) {
168 Element enclosingElement = element.enclosingElement; 168 Element enclosingElement = element.enclosingElement;
169 if (enclosingElement is ClassElement && enclosingElement.isEnum) { 169 if (enclosingElement is ClassElement && enclosingElement.isEnum) {
170 type = HighlightRegionType.ENUM_CONSTANT; 170 type = HighlightRegionType.ENUM_CONSTANT;
171 } else if (element.isStatic) { 171 } else if (element.isStatic) {
172 type = HighlightRegionType.FIELD_STATIC; 172 type = node.inDeclarationContext()
173 ? HighlightRegionType.STATIC_FIELD_DECLARATION
174 : HighlightRegionType.STATIC_FIELD_REFERENCE;
173 } else { 175 } else {
174 type = HighlightRegionType.FIELD; 176 type = node.inDeclarationContext()
177 ? HighlightRegionType.INSTANCE_FIELD_DECLARATION
178 : HighlightRegionType.INSTANCE_FIELD_REFERENCE;
175 } 179 }
176 } else if (element is TopLevelVariableElement) { 180 } else if (element is TopLevelVariableElement) {
177 type = HighlightRegionType.TOP_LEVEL_VARIABLE; 181 type = node.inDeclarationContext()
182 ? HighlightRegionType.TOP_LEVEL_VARIABLE_DECLARATION
183 : HighlightRegionType.TOP_LEVEL_VARIABLE_REFERENCE;
178 } 184 }
179 // add region 185 // add region
180 if (type != null) { 186 if (type != null) {
181 return _addRegion_node(node, type); 187 return _addRegion_node(node, type);
182 } 188 }
183 return false; 189 return false;
184 } 190 }
185 191
186 bool _addIdentifierRegion_function(SimpleIdentifier node) { 192 bool _addIdentifierRegion_function(SimpleIdentifier node) {
187 Element element = node.staticElement; 193 Element element = node.staticElement;
188 if (element is! FunctionElement) { 194 if (element is! FunctionElement) {
189 return false; 195 return false;
190 } 196 }
191 HighlightRegionType type; 197 HighlightRegionType type;
198 bool isTopLevel = element.enclosingElement is CompilationUnitElement;
192 if (node.inDeclarationContext()) { 199 if (node.inDeclarationContext()) {
193 type = HighlightRegionType.FUNCTION_DECLARATION; 200 type = isTopLevel
201 ? HighlightRegionType.TOP_LEVEL_FUNCTION_DECLARATION
202 : HighlightRegionType.LOCAL_FUNCTION_DECLARATION;
194 } else { 203 } else {
195 type = HighlightRegionType.FUNCTION; 204 type = isTopLevel
205 ? HighlightRegionType.TOP_LEVEL_FUNCTION_REFERENCE
206 : HighlightRegionType.LOCAL_FUNCTION_REFERENCE;
196 } 207 }
197 return _addRegion_node(node, type); 208 return _addRegion_node(node, type);
198 } 209 }
199 210
200 bool _addIdentifierRegion_functionTypeAlias(SimpleIdentifier node) { 211 bool _addIdentifierRegion_functionTypeAlias(SimpleIdentifier node) {
201 Element element = node.staticElement; 212 Element element = node.staticElement;
202 if (element is! FunctionTypeAliasElement) { 213 if (element is! FunctionTypeAliasElement) {
203 return false; 214 return false;
204 } 215 }
205 return _addRegion_node(node, HighlightRegionType.FUNCTION_TYPE_ALIAS); 216 return _addRegion_node(node, HighlightRegionType.FUNCTION_TYPE_ALIAS);
206 } 217 }
207 218
208 bool _addIdentifierRegion_getterSetterDeclaration(SimpleIdentifier node) { 219 bool _addIdentifierRegion_getterSetterDeclaration(SimpleIdentifier node) {
209 // should be declaration 220 // should be declaration
210 AstNode parent = node.parent; 221 AstNode parent = node.parent;
211 if (!(parent is MethodDeclaration || parent is FunctionDeclaration)) { 222 if (!(parent is MethodDeclaration || parent is FunctionDeclaration)) {
212 return false; 223 return false;
213 } 224 }
214 // should be property accessor 225 // should be property accessor
215 Element element = node.staticElement; 226 Element element = node.staticElement;
216 if (element is! PropertyAccessorElement) { 227 if (element is! PropertyAccessorElement) {
217 return false; 228 return false;
218 } 229 }
219 // getter or setter 230 // getter or setter
220 PropertyAccessorElement propertyAccessorElement = 231 PropertyAccessorElement propertyAccessorElement =
221 element as PropertyAccessorElement; 232 element as PropertyAccessorElement;
233 bool isTopLevel = element.enclosingElement is CompilationUnitElement;
234 HighlightRegionType type;
222 if (propertyAccessorElement.isGetter) { 235 if (propertyAccessorElement.isGetter) {
223 return _addRegion_node(node, HighlightRegionType.GETTER_DECLARATION); 236 if (isTopLevel) {
237 type = node.inDeclarationContext()
238 ? HighlightRegionType.TOP_LEVEL_GETTER_DECLARATION
239 : HighlightRegionType.TOP_LEVEL_VARIABLE_REFERENCE;
240 } else if (propertyAccessorElement.isStatic) {
241 type = node.inDeclarationContext()
242 ? HighlightRegionType.STATIC_GETTER_DECLARATION
243 : HighlightRegionType.STATIC_FIELD_REFERENCE;
244 } else {
245 type = node.inDeclarationContext()
246 ? HighlightRegionType.INSTANCE_GETTER_DECLARATION
247 : HighlightRegionType.INSTANCE_FIELD_REFERENCE;
248 }
224 } else { 249 } else {
225 return _addRegion_node(node, HighlightRegionType.SETTER_DECLARATION); 250 if (isTopLevel) {
251 type = node.inDeclarationContext()
252 ? HighlightRegionType.TOP_LEVEL_SETTER_DECLARATION
253 : HighlightRegionType.TOP_LEVEL_VARIABLE_REFERENCE;
254 } else if (propertyAccessorElement.isStatic) {
255 type = node.inDeclarationContext()
256 ? HighlightRegionType.STATIC_SETTER_DECLARATION
257 : HighlightRegionType.STATIC_FIELD_REFERENCE;
258 } else {
259 type = node.inDeclarationContext()
260 ? HighlightRegionType.INSTANCE_SETTER_DECLARATION
261 : HighlightRegionType.INSTANCE_FIELD_REFERENCE;
262 }
226 } 263 }
264 return _addRegion_node(node, type);
227 } 265 }
228 266
229 bool _addIdentifierRegion_importPrefix(SimpleIdentifier node) { 267 bool _addIdentifierRegion_importPrefix(SimpleIdentifier node) {
230 Element element = node.staticElement; 268 Element element = node.staticElement;
231 if (element is! PrefixElement) { 269 if (element is! PrefixElement) {
232 return false; 270 return false;
233 } 271 }
234 return _addRegion_node(node, HighlightRegionType.IMPORT_PREFIX); 272 return _addRegion_node(node, HighlightRegionType.IMPORT_PREFIX);
235 } 273 }
236 274
(...skipping 12 matching lines...) Expand all
249 } 287 }
250 return _addRegion_node(node, HighlightRegionType.LABEL); 288 return _addRegion_node(node, HighlightRegionType.LABEL);
251 } 289 }
252 290
253 bool _addIdentifierRegion_localVariable(SimpleIdentifier node) { 291 bool _addIdentifierRegion_localVariable(SimpleIdentifier node) {
254 Element element = node.staticElement; 292 Element element = node.staticElement;
255 if (element is! LocalVariableElement) { 293 if (element is! LocalVariableElement) {
256 return false; 294 return false;
257 } 295 }
258 // OK 296 // OK
259 HighlightRegionType type; 297 HighlightRegionType type = node.inDeclarationContext()
260 if (node.inDeclarationContext()) { 298 ? HighlightRegionType.LOCAL_VARIABLE_DECLARATION
261 type = HighlightRegionType.LOCAL_VARIABLE_DECLARATION; 299 : HighlightRegionType.LOCAL_VARIABLE_REFERENCE;
262 } else {
263 type = HighlightRegionType.LOCAL_VARIABLE;
264 }
265 return _addRegion_node(node, type); 300 return _addRegion_node(node, type);
266 } 301 }
267 302
268 bool _addIdentifierRegion_method(SimpleIdentifier node) { 303 bool _addIdentifierRegion_method(SimpleIdentifier node) {
269 Element element = node.bestElement; 304 Element element = node.bestElement;
270 if (element is! MethodElement) { 305 if (element is! MethodElement) {
271 return false; 306 return false;
272 } 307 }
273 MethodElement methodElement = element as MethodElement; 308 MethodElement methodElement = element as MethodElement;
274 bool isStatic = methodElement.isStatic; 309 bool isStatic = methodElement.isStatic;
275 // OK 310 // OK
276 HighlightRegionType type; 311 HighlightRegionType type;
277 if (node.inDeclarationContext()) { 312 if (node.inDeclarationContext()) {
278 if (isStatic) { 313 if (isStatic) {
279 type = HighlightRegionType.METHOD_DECLARATION_STATIC; 314 type = HighlightRegionType.STATIC_METHOD_DECLARATION;
280 } else { 315 } else {
281 type = HighlightRegionType.METHOD_DECLARATION; 316 type = HighlightRegionType.INSTANCE_METHOD_DECLARATION;
282 } 317 }
283 } else { 318 } else {
284 if (isStatic) { 319 if (isStatic) {
285 type = HighlightRegionType.METHOD_STATIC; 320 type = HighlightRegionType.STATIC_METHOD_REFERENCE;
286 } else { 321 } else {
287 type = HighlightRegionType.METHOD; 322 type = HighlightRegionType.INSTANCE_METHOD_REFERENCE;
288 } 323 }
289 } 324 }
290 return _addRegion_node(node, type); 325 return _addRegion_node(node, type);
291 } 326 }
292 327
293 bool _addIdentifierRegion_parameter(SimpleIdentifier node) { 328 bool _addIdentifierRegion_parameter(SimpleIdentifier node) {
294 Element element = node.staticElement; 329 Element element = node.staticElement;
295 if (element is! ParameterElement) { 330 if (element is! ParameterElement) {
296 return false; 331 return false;
297 } 332 }
298 return _addRegion_node(node, HighlightRegionType.PARAMETER); 333 HighlightRegionType type = node.inDeclarationContext()
334 ? HighlightRegionType.PARAMETER_DECLARATION
335 : HighlightRegionType.PARAMETER_REFERENCE;
336 return _addRegion_node(node, type);
299 } 337 }
300 338
301 bool _addIdentifierRegion_typeParameter(SimpleIdentifier node) { 339 bool _addIdentifierRegion_typeParameter(SimpleIdentifier node) {
302 Element element = node.staticElement; 340 Element element = node.staticElement;
303 if (element is! TypeParameterElement) { 341 if (element is! TypeParameterElement) {
304 return false; 342 return false;
305 } 343 }
306 return _addRegion_node(node, HighlightRegionType.TYPE_PARAMETER); 344 return _addRegion_node(node, HighlightRegionType.TYPE_PARAMETER);
307 } 345 }
308 346
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 void _addRegions_functionBody(FunctionBody node) { 753 void _addRegions_functionBody(FunctionBody node) {
716 Token keyword = node.keyword; 754 Token keyword = node.keyword;
717 if (keyword != null) { 755 if (keyword != null) {
718 Token star = node.star; 756 Token star = node.star;
719 int offset = keyword.offset; 757 int offset = keyword.offset;
720 int end = star != null ? star.end : keyword.end; 758 int end = star != null ? star.end : keyword.end;
721 computer._addRegion(offset, end - offset, HighlightRegionType.BUILT_IN); 759 computer._addRegion(offset, end - offset, HighlightRegionType.BUILT_IN);
722 } 760 }
723 } 761 }
724 } 762 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698