Chromium Code Reviews| OLD | NEW |
|---|---|
| 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.contributor.dart.local; | 5 library services.completion.contributor.dart.local; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart' as protocol | 9 import 'package:analysis_server/src/protocol.dart' as protocol |
| 10 show Element, ElementKind; | 10 show Element, ElementKind; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 found = true; | 86 found = true; |
| 87 _addSuggestion(declaration, member); | 87 _addSuggestion(declaration, member); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 if (!found) { | 90 if (!found) { |
| 91 _addSuggestion(declaration, null); | 91 _addSuggestion(declaration, null); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 @override | 95 @override |
| 96 void declaredClassTypeAlias(ClassTypeAlias declaration) { | 96 void declaredClassTypeAlias(ClassTypeAlias declaration) {} |
| 97 // TODO: implement declaredClassTypeAlias | |
| 98 } | |
| 99 | 97 |
| 100 @override | 98 @override |
| 101 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { | 99 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) {} |
| 102 // TODO: implement declaredField | |
| 103 } | |
| 104 | 100 |
| 105 @override | 101 @override |
| 106 void declaredFunction(FunctionDeclaration declaration) { | 102 void declaredFunction(FunctionDeclaration declaration) {} |
| 107 // TODO: implement declaredFunction | |
| 108 } | |
| 109 | 103 |
| 110 @override | 104 @override |
| 111 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) { | 105 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) {} |
| 112 // TODO: implement declaredFunctionTypeAlias | |
| 113 } | |
| 114 | 106 |
| 115 @override | 107 @override |
| 116 void declaredLabel(Label label, bool isCaseLabel) { | 108 void declaredLabel(Label label, bool isCaseLabel) {} |
| 117 // TODO: implement declaredLabel | |
| 118 } | |
| 119 | 109 |
| 120 @override | 110 @override |
| 121 void declaredLocalVar(SimpleIdentifier name, TypeName type) { | 111 void declaredLocalVar(SimpleIdentifier name, TypeName type) {} |
| 122 // TODO: implement declaredLocalVar | |
| 123 } | |
| 124 | 112 |
| 125 @override | 113 @override |
| 126 void declaredMethod(MethodDeclaration declaration) { | 114 void declaredMethod(MethodDeclaration declaration) {} |
| 127 // TODO: implement declaredMethod | |
| 128 } | |
| 129 | 115 |
| 130 @override | 116 @override |
| 131 void declaredParam(SimpleIdentifier name, TypeName type) { | 117 void declaredParam(SimpleIdentifier name, TypeName type) {} |
| 132 // TODO: implement declaredParam | |
| 133 } | |
| 134 | 118 |
| 135 @override | 119 @override |
| 136 void declaredTopLevelVar( | 120 void declaredTopLevelVar( |
| 137 VariableDeclarationList varList, VariableDeclaration varDecl) { | 121 VariableDeclarationList varList, VariableDeclaration varDecl) {} |
| 138 // TODO: implement declaredTopLevelVar | |
| 139 } | |
| 140 | 122 |
| 141 /** | 123 /** |
| 142 * For the given class and constructor, | 124 * For the given class and constructor, |
| 143 * add a suggestion of the form B(...) or B.name(...). | 125 * add a suggestion of the form B(...) or B.name(...). |
| 144 * If the given constructor is `null` | 126 * If the given constructor is `null` |
| 145 * then add a default constructor suggestion. | 127 * then add a default constructor suggestion. |
| 146 */ | 128 */ |
| 147 CompletionSuggestion _addSuggestion( | 129 CompletionSuggestion _addSuggestion( |
| 148 ClassDeclaration classDecl, ConstructorDeclaration constructorDecl) { | 130 ClassDeclaration classDecl, ConstructorDeclaration constructorDecl) { |
| 149 SimpleIdentifier elemId; | 131 SimpleIdentifier elemId; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 suggestion.element = createElement( | 380 suggestion.element = createElement( |
| 399 protocol.ElementKind.CLASS_TYPE_ALIAS, declaration.name, | 381 protocol.ElementKind.CLASS_TYPE_ALIAS, declaration.name, |
| 400 returnType: NO_RETURN_TYPE, | 382 returnType: NO_RETURN_TYPE, |
| 401 isAbstract: true, | 383 isAbstract: true, |
| 402 isDeprecated: deprecated); | 384 isDeprecated: deprecated); |
| 403 } | 385 } |
| 404 } | 386 } |
| 405 } | 387 } |
| 406 | 388 |
| 407 @override | 389 @override |
| 390 void declaredEnum(EnumDeclaration declaration) { | |
|
Paul Berry
2015/05/29 17:55:57
This method looks almost identical to the two meth
danrubel
2015/06/01 04:26:56
Good point. Will do in a subsequent CL so as not t
danrubel
2015/06/04 17:55:52
https://codereview.chromium.org/1163973004/
| |
| 391 SimpleIdentifier enumId = declaration.name; | |
| 392 if (enumId != null) { | |
| 393 bool deprecated = isDeprecated(declaration); | |
| 394 if (optype.includeTypeNameSuggestions) { | |
| 395 CompletionSuggestion suggestion = _addSuggestion( | |
| 396 enumId, NO_RETURN_TYPE, deprecated, DART_RELEVANCE_DEFAULT); | |
| 397 if (suggestion != null) { | |
| 398 suggestion.element = createElement( | |
| 399 protocol.ElementKind.ENUM, enumId, | |
| 400 returnType: NO_RETURN_TYPE, isDeprecated: deprecated); | |
| 401 } | |
| 402 } | |
| 403 } | |
| 404 } | |
| 405 | |
| 406 @override | |
| 408 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { | 407 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { |
| 409 if (optype.includeReturnValueSuggestions) { | 408 if (optype.includeReturnValueSuggestions) { |
| 410 CompletionSuggestion suggestion = | 409 CompletionSuggestion suggestion = |
| 411 createFieldSuggestion(fieldDecl, varDecl); | 410 createFieldSuggestion(fieldDecl, varDecl); |
| 412 if (suggestion != null) { | 411 if (suggestion != null) { |
| 413 request.addSuggestion(suggestion); | 412 request.addSuggestion(suggestion); |
| 414 } | 413 } |
| 415 } | 414 } |
| 416 } | 415 } |
| 417 | 416 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 } | 589 } |
| 591 return typeId.name; | 590 return typeId.name; |
| 592 }).toList(); | 591 }).toList(); |
| 593 suggestion.requiredParameterCount = paramList.where( | 592 suggestion.requiredParameterCount = paramList.where( |
| 594 (FormalParameter param) => param is! DefaultFormalParameter).length; | 593 (FormalParameter param) => param is! DefaultFormalParameter).length; |
| 595 suggestion.hasNamedParameters = paramList | 594 suggestion.hasNamedParameters = paramList |
| 596 .any((FormalParameter param) => param.kind == ParameterKind.NAMED); | 595 .any((FormalParameter param) => param.kind == ParameterKind.NAMED); |
| 597 } | 596 } |
| 598 | 597 |
| 599 CompletionSuggestion _addSuggestion(SimpleIdentifier id, TypeName returnType, | 598 CompletionSuggestion _addSuggestion(SimpleIdentifier id, TypeName returnType, |
| 600 bool isDeprecated, int defaultRelevance, {ClassDeclaration classDecl}) { | 599 bool isDeprecated, int defaultRelevance, |
| 600 {ClassDeclaration classDecl, SimpleIdentifier enumName}) { | |
| 601 CompletionSuggestion suggestion = createSuggestion( | 601 CompletionSuggestion suggestion = createSuggestion( |
| 602 id, isDeprecated, defaultRelevance, returnType, classDecl: classDecl); | 602 id, isDeprecated, defaultRelevance, returnType, |
| 603 classDecl: classDecl, enumName: enumName); | |
| 603 if (suggestion != null) { | 604 if (suggestion != null) { |
| 604 request.addSuggestion(suggestion); | 605 request.addSuggestion(suggestion); |
| 605 } | 606 } |
| 606 return suggestion; | 607 return suggestion; |
| 607 } | 608 } |
| 608 | 609 |
| 609 bool _isVoid(TypeName returnType) { | 610 bool _isVoid(TypeName returnType) { |
| 610 if (returnType != null) { | 611 if (returnType != null) { |
| 611 Identifier id = returnType.name; | 612 Identifier id = returnType.name; |
| 612 if (id != null && id.name == 'void') { | 613 if (id != null && id.name == 'void') { |
| 613 return true; | 614 return true; |
| 614 } | 615 } |
| 615 } | 616 } |
| 616 return false; | 617 return false; |
| 617 } | 618 } |
| 618 } | 619 } |
| OLD | NEW |