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

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

Issue 1236433003: Revert "Update Analysis Server highlight API and implementation." (Closed) Base URL: https://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_dynamicLocal(node)) { 66 if (_addIdentifierRegion_dynamicType(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_dynamicLocal(SimpleIdentifier node) { 138 bool _addIdentifierRegion_dynamicType(SimpleIdentifier node) {
139 // no propagated type 139 // should be variable
140 Element element = node.staticElement;
141 if (element is! VariableElement) {
142 return false;
143 }
144 // has propagated type
140 if (node.propagatedType != null) { 145 if (node.propagatedType != null) {
141 return false; 146 return false;
142 } 147 }
143 // has dynamic static type 148 // has dynamic static type
144 DartType staticType = node.staticType; 149 DartType staticType = node.staticType;
145 if (staticType == null || !staticType.isDynamic) { 150 if (staticType == null || !staticType.isDynamic) {
146 return false; 151 return false;
147 } 152 }
148 // OK 153 // OK
149 Element element = node.staticElement; 154 return _addRegion_node(node, HighlightRegionType.DYNAMIC_TYPE);
150 if (element is LocalVariableElement) {
151 HighlightRegionType type = node.inDeclarationContext()
152 ? HighlightRegionType.DYNAMIC_LOCAL_VARIABLE_DECLARATION
153 : HighlightRegionType.DYNAMIC_LOCAL_VARIABLE_REFERENCE;
154 return _addRegion_node(node, type);
155 }
156 if (element is ParameterElement) {
157 HighlightRegionType type = node.inDeclarationContext()
158 ? HighlightRegionType.DYNAMIC_PARAMETER_DECLARATION
159 : HighlightRegionType.DYNAMIC_PARAMETER_REFERENCE;
160 return _addRegion_node(node, type);
161 }
162 return false;
163 } 155 }
164 156
165 bool _addIdentifierRegion_field(SimpleIdentifier node) { 157 bool _addIdentifierRegion_field(SimpleIdentifier node) {
166 Element element = node.bestElement; 158 Element element = node.bestElement;
167 if (element is FieldFormalParameterElement) { 159 if (element is FieldFormalParameterElement) {
168 element = (element as FieldFormalParameterElement).field; 160 element = (element as FieldFormalParameterElement).field;
169 } 161 }
162 if (element is PropertyAccessorElement) {
163 element = (element as PropertyAccessorElement).variable;
164 }
170 // prepare type 165 // prepare type
171 HighlightRegionType type; 166 HighlightRegionType type;
172 if (element is FieldElement) { 167 if (element is FieldElement) {
173 Element enclosingElement = element.enclosingElement; 168 Element enclosingElement = element.enclosingElement;
174 if (enclosingElement is ClassElement && enclosingElement.isEnum) { 169 if (enclosingElement is ClassElement && enclosingElement.isEnum) {
175 type = HighlightRegionType.ENUM_CONSTANT; 170 type = HighlightRegionType.ENUM_CONSTANT;
176 } else if (element.isStatic) { 171 } else if (element.isStatic) {
177 type = HighlightRegionType.STATIC_FIELD_DECLARATION; 172 type = HighlightRegionType.FIELD_STATIC;
178 } else { 173 } else {
179 type = node.inDeclarationContext() 174 type = HighlightRegionType.FIELD;
180 ? HighlightRegionType.INSTANCE_FIELD_DECLARATION
181 : HighlightRegionType.INSTANCE_FIELD_REFERENCE;
182 } 175 }
183 } else if (element is TopLevelVariableElement) { 176 } else if (element is TopLevelVariableElement) {
184 type = HighlightRegionType.TOP_LEVEL_VARIABLE_DECLARATION; 177 type = HighlightRegionType.TOP_LEVEL_VARIABLE;
185 }
186 if (element is PropertyAccessorElement) {
187 PropertyAccessorElement accessor = element;
188 Element enclosingElement = element.enclosingElement;
189 if (accessor.variable is TopLevelVariableElement) {
190 type = accessor.isGetter
191 ? HighlightRegionType.TOP_LEVEL_GETTER_REFERENCE
192 : HighlightRegionType.TOP_LEVEL_SETTER_REFERENCE;
193 } else if (enclosingElement is ClassElement && enclosingElement.isEnum) {
194 type = HighlightRegionType.ENUM_CONSTANT;
195 } else if (accessor.isStatic) {
196 type = accessor.isGetter
197 ? HighlightRegionType.STATIC_GETTER_REFERENCE
198 : HighlightRegionType.STATIC_SETTER_REFERENCE;
199 } else {
200 type = accessor.isGetter
201 ? HighlightRegionType.INSTANCE_GETTER_REFERENCE
202 : HighlightRegionType.INSTANCE_SETTER_REFERENCE;
203 }
204 } 178 }
205 // add region 179 // add region
206 if (type != null) { 180 if (type != null) {
207 return _addRegion_node(node, type); 181 return _addRegion_node(node, type);
208 } 182 }
209 return false; 183 return false;
210 } 184 }
211 185
212 bool _addIdentifierRegion_function(SimpleIdentifier node) { 186 bool _addIdentifierRegion_function(SimpleIdentifier node) {
213 Element element = node.staticElement; 187 Element element = node.staticElement;
214 if (element is! FunctionElement) { 188 if (element is! FunctionElement) {
215 return false; 189 return false;
216 } 190 }
217 HighlightRegionType type; 191 HighlightRegionType type;
218 bool isTopLevel = element.enclosingElement is CompilationUnitElement;
219 if (node.inDeclarationContext()) { 192 if (node.inDeclarationContext()) {
220 type = isTopLevel 193 type = HighlightRegionType.FUNCTION_DECLARATION;
221 ? HighlightRegionType.TOP_LEVEL_FUNCTION_DECLARATION
222 : HighlightRegionType.LOCAL_FUNCTION_DECLARATION;
223 } else { 194 } else {
224 type = isTopLevel 195 type = HighlightRegionType.FUNCTION;
225 ? HighlightRegionType.TOP_LEVEL_FUNCTION_REFERENCE
226 : HighlightRegionType.LOCAL_FUNCTION_REFERENCE;
227 } 196 }
228 return _addRegion_node(node, type); 197 return _addRegion_node(node, type);
229 } 198 }
230 199
231 bool _addIdentifierRegion_functionTypeAlias(SimpleIdentifier node) { 200 bool _addIdentifierRegion_functionTypeAlias(SimpleIdentifier node) {
232 Element element = node.staticElement; 201 Element element = node.staticElement;
233 if (element is! FunctionTypeAliasElement) { 202 if (element is! FunctionTypeAliasElement) {
234 return false; 203 return false;
235 } 204 }
236 return _addRegion_node(node, HighlightRegionType.FUNCTION_TYPE_ALIAS); 205 return _addRegion_node(node, HighlightRegionType.FUNCTION_TYPE_ALIAS);
237 } 206 }
238 207
239 bool _addIdentifierRegion_getterSetterDeclaration(SimpleIdentifier node) { 208 bool _addIdentifierRegion_getterSetterDeclaration(SimpleIdentifier node) {
240 // should be declaration 209 // should be declaration
241 AstNode parent = node.parent; 210 AstNode parent = node.parent;
242 if (!(parent is MethodDeclaration || parent is FunctionDeclaration)) { 211 if (!(parent is MethodDeclaration || parent is FunctionDeclaration)) {
243 return false; 212 return false;
244 } 213 }
245 // should be property accessor 214 // should be property accessor
246 Element element = node.staticElement; 215 Element element = node.staticElement;
247 if (element is! PropertyAccessorElement) { 216 if (element is! PropertyAccessorElement) {
248 return false; 217 return false;
249 } 218 }
250 // getter or setter 219 // getter or setter
251 PropertyAccessorElement propertyAccessorElement = 220 PropertyAccessorElement propertyAccessorElement =
252 element as PropertyAccessorElement; 221 element as PropertyAccessorElement;
253 bool isTopLevel = element.enclosingElement is CompilationUnitElement;
254 HighlightRegionType type;
255 if (propertyAccessorElement.isGetter) { 222 if (propertyAccessorElement.isGetter) {
256 if (isTopLevel) { 223 return _addRegion_node(node, HighlightRegionType.GETTER_DECLARATION);
257 type = HighlightRegionType.TOP_LEVEL_GETTER_DECLARATION;
258 } else if (propertyAccessorElement.isStatic) {
259 type = HighlightRegionType.STATIC_GETTER_DECLARATION;
260 } else {
261 type = HighlightRegionType.INSTANCE_GETTER_DECLARATION;
262 }
263 } else { 224 } else {
264 if (isTopLevel) { 225 return _addRegion_node(node, HighlightRegionType.SETTER_DECLARATION);
265 type = HighlightRegionType.TOP_LEVEL_SETTER_DECLARATION;
266 } else if (propertyAccessorElement.isStatic) {
267 type = HighlightRegionType.STATIC_SETTER_DECLARATION;
268 } else {
269 type = HighlightRegionType.INSTANCE_SETTER_DECLARATION;
270 }
271 } 226 }
272 return _addRegion_node(node, type);
273 } 227 }
274 228
275 bool _addIdentifierRegion_importPrefix(SimpleIdentifier node) { 229 bool _addIdentifierRegion_importPrefix(SimpleIdentifier node) {
276 Element element = node.staticElement; 230 Element element = node.staticElement;
277 if (element is! PrefixElement) { 231 if (element is! PrefixElement) {
278 return false; 232 return false;
279 } 233 }
280 return _addRegion_node(node, HighlightRegionType.IMPORT_PREFIX); 234 return _addRegion_node(node, HighlightRegionType.IMPORT_PREFIX);
281 } 235 }
282 236
(...skipping 12 matching lines...) Expand all
295 } 249 }
296 return _addRegion_node(node, HighlightRegionType.LABEL); 250 return _addRegion_node(node, HighlightRegionType.LABEL);
297 } 251 }
298 252
299 bool _addIdentifierRegion_localVariable(SimpleIdentifier node) { 253 bool _addIdentifierRegion_localVariable(SimpleIdentifier node) {
300 Element element = node.staticElement; 254 Element element = node.staticElement;
301 if (element is! LocalVariableElement) { 255 if (element is! LocalVariableElement) {
302 return false; 256 return false;
303 } 257 }
304 // OK 258 // OK
305 HighlightRegionType type = node.inDeclarationContext() 259 HighlightRegionType type;
306 ? HighlightRegionType.LOCAL_VARIABLE_DECLARATION 260 if (node.inDeclarationContext()) {
307 : HighlightRegionType.LOCAL_VARIABLE_REFERENCE; 261 type = HighlightRegionType.LOCAL_VARIABLE_DECLARATION;
262 } else {
263 type = HighlightRegionType.LOCAL_VARIABLE;
264 }
308 return _addRegion_node(node, type); 265 return _addRegion_node(node, type);
309 } 266 }
310 267
311 bool _addIdentifierRegion_method(SimpleIdentifier node) { 268 bool _addIdentifierRegion_method(SimpleIdentifier node) {
312 Element element = node.bestElement; 269 Element element = node.bestElement;
313 if (element is! MethodElement) { 270 if (element is! MethodElement) {
314 return false; 271 return false;
315 } 272 }
316 MethodElement methodElement = element as MethodElement; 273 MethodElement methodElement = element as MethodElement;
317 bool isStatic = methodElement.isStatic; 274 bool isStatic = methodElement.isStatic;
318 // OK 275 // OK
319 HighlightRegionType type; 276 HighlightRegionType type;
320 if (node.inDeclarationContext()) { 277 if (node.inDeclarationContext()) {
321 if (isStatic) { 278 if (isStatic) {
322 type = HighlightRegionType.STATIC_METHOD_DECLARATION; 279 type = HighlightRegionType.METHOD_DECLARATION_STATIC;
323 } else { 280 } else {
324 type = HighlightRegionType.INSTANCE_METHOD_DECLARATION; 281 type = HighlightRegionType.METHOD_DECLARATION;
325 } 282 }
326 } else { 283 } else {
327 if (isStatic) { 284 if (isStatic) {
328 type = HighlightRegionType.STATIC_METHOD_REFERENCE; 285 type = HighlightRegionType.METHOD_STATIC;
329 } else { 286 } else {
330 type = HighlightRegionType.INSTANCE_METHOD_REFERENCE; 287 type = HighlightRegionType.METHOD;
331 } 288 }
332 } 289 }
333 return _addRegion_node(node, type); 290 return _addRegion_node(node, type);
334 } 291 }
335 292
336 bool _addIdentifierRegion_parameter(SimpleIdentifier node) { 293 bool _addIdentifierRegion_parameter(SimpleIdentifier node) {
337 Element element = node.staticElement; 294 Element element = node.staticElement;
338 if (element is! ParameterElement) { 295 if (element is! ParameterElement) {
339 return false; 296 return false;
340 } 297 }
341 HighlightRegionType type = node.inDeclarationContext() 298 return _addRegion_node(node, HighlightRegionType.PARAMETER);
342 ? HighlightRegionType.PARAMETER_DECLARATION
343 : HighlightRegionType.PARAMETER_REFERENCE;
344 return _addRegion_node(node, type);
345 } 299 }
346 300
347 bool _addIdentifierRegion_typeParameter(SimpleIdentifier node) { 301 bool _addIdentifierRegion_typeParameter(SimpleIdentifier node) {
348 Element element = node.staticElement; 302 Element element = node.staticElement;
349 if (element is! TypeParameterElement) { 303 if (element is! TypeParameterElement) {
350 return false; 304 return false;
351 } 305 }
352 return _addRegion_node(node, HighlightRegionType.TYPE_PARAMETER); 306 return _addRegion_node(node, HighlightRegionType.TYPE_PARAMETER);
353 } 307 }
354 308
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 void _addRegions_functionBody(FunctionBody node) { 715 void _addRegions_functionBody(FunctionBody node) {
762 Token keyword = node.keyword; 716 Token keyword = node.keyword;
763 if (keyword != null) { 717 if (keyword != null) {
764 Token star = node.star; 718 Token star = node.star;
765 int offset = keyword.offset; 719 int offset = keyword.offset;
766 int end = star != null ? star.end : keyword.end; 720 int end = star != null ? star.end : keyword.end;
767 computer._addRegion(offset, end - offset, HighlightRegionType.BUILT_IN); 721 computer._addRegion(offset, end - offset, HighlightRegionType.BUILT_IN);
768 } 722 }
769 } 723 }
770 } 724 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | pkg/analysis_server/lib/src/generated_protocol.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698