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

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/local_computer.dart

Issue 690793004: make deprecated elements have low suggestion relevance (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 1 month 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 | Annotate | Revision Log
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 services.completion.computer.dart.local; 5 library services.completion.computer.dart.local;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element,
10 ElementKind; 10 ElementKind;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 node.declarations.forEach((Declaration declaration) { 126 node.declarations.forEach((Declaration declaration) {
127 if (declaration is ClassDeclaration) { 127 if (declaration is ClassDeclaration) {
128 _addClassSuggestion(declaration); 128 _addClassSuggestion(declaration);
129 } else if (declaration is EnumDeclaration) { 129 } else if (declaration is EnumDeclaration) {
130 // _addSuggestion(d.name, CompletionSuggestionKind.ENUM); 130 // _addSuggestion(d.name, CompletionSuggestionKind.ENUM);
131 } else if (declaration is FunctionDeclaration) { 131 } else if (declaration is FunctionDeclaration) {
132 _addFunctionSuggestion(declaration); 132 _addFunctionSuggestion(declaration);
133 } else if (declaration is TopLevelVariableDeclaration) { 133 } else if (declaration is TopLevelVariableDeclaration) {
134 _addTopLevelVarSuggestions(declaration.variables); 134 _addTopLevelVarSuggestions(declaration.variables);
135 } else if (declaration is ClassTypeAlias) { 135 } else if (declaration is ClassTypeAlias) {
136 CompletionSuggestion suggestion = _addSuggestion( 136 bool isDeprecated = _isDeprecated(declaration);
137 declaration.name, 137 CompletionSuggestion suggestion =
138 null, 138 _addSuggestion(declaration.name, null, null, isDeprecated);
139 null);
140 if (suggestion != null) { 139 if (suggestion != null) {
141 suggestion.element = _createElement( 140 suggestion.element = _createElement(
142 protocol.ElementKind.CLASS_TYPE_ALIAS, 141 protocol.ElementKind.CLASS_TYPE_ALIAS,
143 declaration.name, 142 declaration.name,
144 null, 143 null,
145 NO_RETURN_TYPE, 144 NO_RETURN_TYPE,
146 true, 145 true,
147 _isDeprecated(declaration.metadata)); 146 isDeprecated);
148 } 147 }
149 } else if (declaration is FunctionTypeAlias) { 148 } else if (declaration is FunctionTypeAlias) {
150 CompletionSuggestion suggestion = _addSuggestion( 149 bool isDeprecated = _isDeprecated(declaration);
151 declaration.name, 150 CompletionSuggestion suggestion =
152 declaration.returnType, 151 _addSuggestion(declaration.name, declaration.returnType, null, isDep recated);
153 null);
154 if (suggestion != null) { 152 if (suggestion != null) {
153 // TODO (danrubel) determine parameters and return type
155 suggestion.element = _createElement( 154 suggestion.element = _createElement(
156 protocol.ElementKind.FUNCTION_TYPE_ALIAS, 155 protocol.ElementKind.FUNCTION_TYPE_ALIAS,
157 declaration.name, 156 declaration.name,
158 null, 157 null,
159 // TODO (danrubel) determine parameters 158 NO_RETURN_TYPE,
160 NO_RETURN_TYPE, // TODO (danrubel) determine return type 159 true,
161 true, _isDeprecated(declaration.metadata)); 160 isDeprecated);
162 } 161 }
163 } 162 }
164 }); 163 });
165 } 164 }
166 165
167 @override 166 @override
168 visitExpressionStatement(ExpressionStatement node) { 167 visitExpressionStatement(ExpressionStatement node) {
169 Expression expression = node.expression; 168 Expression expression = node.expression;
170 if (expression is SimpleIdentifier) { 169 if (expression is SimpleIdentifier) {
171 if (expression.end < request.offset) { 170 if (expression.end < request.offset) {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 node.members.forEach((ClassMember classMbr) { 298 node.members.forEach((ClassMember classMbr) {
300 if (classMbr is FieldDeclaration) { 299 if (classMbr is FieldDeclaration) {
301 _addFieldSuggestions(node, classMbr); 300 _addFieldSuggestions(node, classMbr);
302 } else if (classMbr is MethodDeclaration) { 301 } else if (classMbr is MethodDeclaration) {
303 _addMethodSuggestion(node, classMbr); 302 _addMethodSuggestion(node, classMbr);
304 } 303 }
305 }); 304 });
306 } 305 }
307 306
308 void _addClassSuggestion(ClassDeclaration declaration) { 307 void _addClassSuggestion(ClassDeclaration declaration) {
308 bool isDeprecated = _isDeprecated(declaration);
309 CompletionSuggestion suggestion = 309 CompletionSuggestion suggestion =
310 _addSuggestion(declaration.name, null, null); 310 _addSuggestion(declaration.name, null, null, isDeprecated);
311 if (suggestion != null) { 311 if (suggestion != null) {
312 suggestion.element = _createElement( 312 suggestion.element = _createElement(
313 protocol.ElementKind.CLASS, 313 protocol.ElementKind.CLASS,
314 declaration.name, 314 declaration.name,
315 null, 315 null,
316 NO_RETURN_TYPE, 316 NO_RETURN_TYPE,
317 declaration.isAbstract, 317 declaration.isAbstract,
318 _isDeprecated(declaration.metadata)); 318 isDeprecated);
319 } 319 }
320 } 320 }
321 321
322 void _addFieldSuggestions(ClassDeclaration node, FieldDeclaration fieldDecl) { 322 void _addFieldSuggestions(ClassDeclaration node, FieldDeclaration fieldDecl) {
323 if (typesOnly) { 323 if (typesOnly) {
324 return; 324 return;
325 } 325 }
326 bool isDeprecated = _isDeprecated(fieldDecl.metadata); 326 bool isDeprecated = _isDeprecated(fieldDecl);
327 fieldDecl.fields.variables.forEach((VariableDeclaration varDecl) { 327 fieldDecl.fields.variables.forEach((VariableDeclaration varDecl) {
328 bool isSingleFieldDeprecated = isDeprecated || _isDeprecated(varDecl);
328 CompletionSuggestion suggestion = _addSuggestion( 329 CompletionSuggestion suggestion = _addSuggestion(
329 varDecl.name, 330 varDecl.name,
330 fieldDecl.fields.type, 331 fieldDecl.fields.type,
331 node); 332 node,
333 isSingleFieldDeprecated);
332 if (suggestion != null) { 334 if (suggestion != null) {
333 suggestion.element = _createElement( 335 suggestion.element = _createElement(
334 protocol.ElementKind.GETTER, 336 protocol.ElementKind.GETTER,
335 varDecl.name, 337 varDecl.name,
336 '()', 338 '()',
337 fieldDecl.fields.type, 339 fieldDecl.fields.type,
338 false, 340 false,
339 isDeprecated || _isDeprecated(varDecl.metadata)); 341 isSingleFieldDeprecated);
340 } 342 }
341 }); 343 });
342 } 344 }
343 345
344 void _addFunctionSuggestion(FunctionDeclaration declaration) { 346 void _addFunctionSuggestion(FunctionDeclaration declaration) {
345 if (typesOnly) { 347 if (typesOnly) {
346 return; 348 return;
347 } 349 }
348 if (excludeVoidReturn && _isVoid(declaration.returnType)) { 350 if (excludeVoidReturn && _isVoid(declaration.returnType)) {
349 return; 351 return;
350 } 352 }
351 CompletionSuggestion suggestion = _addSuggestion( 353 bool isDeprecated = _isDeprecated(declaration);
352 declaration.name, 354 CompletionSuggestion suggestion =
353 declaration.returnType, 355 _addSuggestion(declaration.name, declaration.returnType, null, isDepreca ted);
354 null);
355 if (suggestion != null) { 356 if (suggestion != null) {
356 suggestion.element = _createElement( 357 suggestion.element = _createElement(
357 protocol.ElementKind.FUNCTION, 358 protocol.ElementKind.FUNCTION,
358 declaration.name, 359 declaration.name,
359 declaration.functionExpression.parameters.toSource(), 360 declaration.functionExpression.parameters.toSource(),
360 declaration.returnType, 361 declaration.returnType,
361 false, 362 false,
362 _isDeprecated(declaration.metadata)); 363 isDeprecated);
363 } 364 }
364 } 365 }
365 366
366 void _addLocalVarSuggestion(SimpleIdentifier id, TypeName returnType) { 367 void _addLocalVarSuggestion(SimpleIdentifier id, TypeName returnType) {
367 if (typesOnly) { 368 if (typesOnly) {
368 return; 369 return;
369 } 370 }
370 CompletionSuggestion suggestion = 371 CompletionSuggestion suggestion =
371 _addSuggestion(id, returnType, null); 372 _addSuggestion(id, returnType, null, false);
372 if (suggestion != null) { 373 if (suggestion != null) {
373 suggestion.element = _createElement( 374 suggestion.element = _createElement(
374 protocol.ElementKind.LOCAL_VARIABLE, 375 protocol.ElementKind.LOCAL_VARIABLE,
375 id, 376 id,
376 null, 377 null,
377 returnType, 378 returnType,
378 false, 379 false,
379 false); 380 false);
380 } 381 }
381 } 382 }
(...skipping 13 matching lines...) Expand all
395 } 396 }
396 kind = protocol.ElementKind.SETTER; 397 kind = protocol.ElementKind.SETTER;
397 parameters = '(${classMbr.returnType.toSource()} value)'; 398 parameters = '(${classMbr.returnType.toSource()} value)';
398 } else { 399 } else {
399 if (excludeVoidReturn && _isVoid(classMbr.returnType)) { 400 if (excludeVoidReturn && _isVoid(classMbr.returnType)) {
400 return; 401 return;
401 } 402 }
402 kind = protocol.ElementKind.METHOD; 403 kind = protocol.ElementKind.METHOD;
403 parameters = classMbr.parameters.toSource(); 404 parameters = classMbr.parameters.toSource();
404 } 405 }
405 CompletionSuggestion suggestion = _addSuggestion( 406 bool isDeprecated = _isDeprecated(classMbr);
406 classMbr.name, 407 CompletionSuggestion suggestion =
407 classMbr.returnType, 408 _addSuggestion(classMbr.name, classMbr.returnType, node, isDeprecated);
408 node);
409 if (suggestion != null) { 409 if (suggestion != null) {
410 suggestion.element = _createElement( 410 suggestion.element = _createElement(
411 kind, 411 kind,
412 classMbr.name, 412 classMbr.name,
413 parameters, 413 parameters,
414 classMbr.returnType, 414 classMbr.returnType,
415 classMbr.isAbstract, 415 classMbr.isAbstract,
416 _isDeprecated(classMbr.metadata)); 416 isDeprecated);
417 } 417 }
418 } 418 }
419 419
420 void _addParamListSuggestions(FormalParameterList paramList) { 420 void _addParamListSuggestions(FormalParameterList paramList) {
421 if (typesOnly) { 421 if (typesOnly) {
422 return; 422 return;
423 } 423 }
424 if (paramList != null) { 424 if (paramList != null) {
425 paramList.parameters.forEach((FormalParameter param) { 425 paramList.parameters.forEach((FormalParameter param) {
426 NormalFormalParameter normalParam; 426 NormalFormalParameter normalParam;
(...skipping 13 matching lines...) Expand all
440 _addParamSuggestion(param.identifier, type); 440 _addParamSuggestion(param.identifier, type);
441 }); 441 });
442 } 442 }
443 } 443 }
444 444
445 void _addParamSuggestion(SimpleIdentifier identifier, TypeName type) { 445 void _addParamSuggestion(SimpleIdentifier identifier, TypeName type) {
446 if (typesOnly) { 446 if (typesOnly) {
447 return; 447 return;
448 } 448 }
449 CompletionSuggestion suggestion = 449 CompletionSuggestion suggestion =
450 _addSuggestion(identifier, type, null); 450 _addSuggestion(identifier, type, null, false);
451 if (suggestion != null) { 451 if (suggestion != null) {
452 suggestion.element = _createElement( 452 suggestion.element = _createElement(
453 protocol.ElementKind.PARAMETER, 453 protocol.ElementKind.PARAMETER,
454 identifier, 454 identifier,
455 null, 455 null,
456 type, 456 type,
457 false, 457 false,
458 false); 458 false);
459 } 459 }
460 } 460 }
461 461
462 CompletionSuggestion _addSuggestion(SimpleIdentifier id, 462 CompletionSuggestion _addSuggestion(SimpleIdentifier id, TypeName typeName,
463 TypeName typeName, ClassDeclaration classDecl) { 463 ClassDeclaration classDecl, bool isDeprecated) {
464 if (id != null) { 464 if (id != null) {
465 String completion = id.name; 465 String completion = id.name;
466 if (completion != null && completion.length > 0 && completion != '_') { 466 if (completion != null && completion.length > 0 && completion != '_') {
467 CompletionSuggestion suggestion = new CompletionSuggestion( 467 CompletionSuggestion suggestion = new CompletionSuggestion(
468 CompletionSuggestionKind.INVOCATION, 468 CompletionSuggestionKind.INVOCATION,
469 CompletionRelevance.DEFAULT, 469 isDeprecated ? CompletionRelevance.LOW : CompletionRelevance.DEFAULT ,
470 completion, 470 completion,
471 completion.length, 471 completion.length,
472 0, 472 0,
473 false, 473 false,
474 false); 474 false);
475 if (classDecl != null) { 475 if (classDecl != null) {
476 SimpleIdentifier identifier = classDecl.name; 476 SimpleIdentifier identifier = classDecl.name;
477 if (identifier != null) { 477 if (identifier != null) {
478 String name = identifier.name; 478 String name = identifier.name;
479 if (name != null && name.length > 0) { 479 if (name != null && name.length > 0) {
(...skipping 15 matching lines...) Expand all
495 } 495 }
496 } 496 }
497 return null; 497 return null;
498 } 498 }
499 499
500 void _addTopLevelVarSuggestions(VariableDeclarationList varList) { 500 void _addTopLevelVarSuggestions(VariableDeclarationList varList) {
501 if (typesOnly) { 501 if (typesOnly) {
502 return; 502 return;
503 } 503 }
504 if (varList != null) { 504 if (varList != null) {
505 bool isDeprecated = _isDeprecated(varList.metadata); 505 bool isDeprecated = _isDeprecated(varList);
506 varList.variables.forEach((VariableDeclaration varDecl) { 506 varList.variables.forEach((VariableDeclaration varDecl) {
507 CompletionSuggestion suggestion = _addSuggestion( 507 bool isSingleVarDeprecated = isDeprecated || _isDeprecated(varDecl);
508 varDecl.name, 508 CompletionSuggestion suggestion =
509 varList.type, 509 _addSuggestion(varDecl.name, varList.type, null, isSingleVarDeprecat ed);
510 null);
511 if (suggestion != null) { 510 if (suggestion != null) {
512 suggestion.element = _createElement( 511 suggestion.element = _createElement(
513 protocol.ElementKind.TOP_LEVEL_VARIABLE, 512 protocol.ElementKind.TOP_LEVEL_VARIABLE,
514 varDecl.name, 513 varDecl.name,
515 null, 514 null,
516 varList.type, 515 varList.type,
517 false, 516 false,
518 isDeprecated || _isDeprecated(varDecl.metadata)); 517 isSingleVarDeprecated);
519 } 518 }
520 }); 519 });
521 } 520 }
522 } 521 }
523 522
524 bool _computeExcludeVoidReturn(AstNode node) { 523 bool _computeExcludeVoidReturn(AstNode node) {
525 if (node is Block) { 524 if (node is Block) {
526 return false; 525 return false;
527 } else if (node is SimpleIdentifier) { 526 } else if (node is SimpleIdentifier) {
528 return node.parent is ExpressionStatement ? false : true; 527 return node.parent is ExpressionStatement ? false : true;
(...skipping 14 matching lines...) Expand all
543 isDeprecated: isDeprecated, 542 isDeprecated: isDeprecated,
544 isPrivate: Identifier.isPrivateName(name)); 543 isPrivate: Identifier.isPrivateName(name));
545 return new protocol.Element( 544 return new protocol.Element(
546 kind, 545 kind,
547 name, 546 name,
548 flags, 547 flags,
549 parameters: parameters, 548 parameters: parameters,
550 returnType: _nameForType(returnType)); 549 returnType: _nameForType(returnType));
551 } 550 }
552 551
552
553 /** 553 /**
554 * Return `true` if the @deprecated annotation is present 554 * Return `true` if the @deprecated annotation is present
555 */ 555 */
556 bool _isDeprecated(NodeList<Annotation> metadata) => 556 bool _isDeprecated(AnnotatedNode node) {
557 metadata != null && 557 if (node != null) {
558 metadata.any( 558 NodeList<Annotation> metadata = node.metadata;
559 (Annotation a) => a.name is SimpleIdentifier && a.name.name == 'de precated'); 559 if (metadata != null) {
560 return metadata.any((Annotation a) {
561 return a.name is SimpleIdentifier && a.name.name == 'deprecated';
562 });
563 }
564 }
565 return false;
566 }
560 567
561 bool _isVoid(TypeName returnType) { 568 bool _isVoid(TypeName returnType) {
562 if (returnType != null) { 569 if (returnType != null) {
563 Identifier id = returnType.name; 570 Identifier id = returnType.name;
564 if (id != null && id.name == 'void') { 571 if (id != null && id.name == 'void') {
565 return true; 572 return true;
566 } 573 }
567 } 574 }
568 return false; 575 return false;
569 } 576 }
(...skipping 16 matching lines...) Expand all
586 if (name == null || name.length <= 0) { 593 if (name == null || name.length <= 0) {
587 return DYNAMIC; 594 return DYNAMIC;
588 } 595 }
589 TypeArgumentList typeArgs = type.typeArguments; 596 TypeArgumentList typeArgs = type.typeArguments;
590 if (typeArgs != null) { 597 if (typeArgs != null) {
591 //TODO (danrubel) include type arguments 598 //TODO (danrubel) include type arguments
592 } 599 }
593 return name; 600 return name;
594 } 601 }
595 } 602 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698