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

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

Issue 830153004: Remove computation with no effect from local completion computer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
11 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; 11 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind;
12 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 12 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
13 import 'package:analysis_server/src/services/completion/local_declaration_visito r.dart'; 13 import 'package:analysis_server/src/services/completion/local_declaration_visito r.dart';
14 import 'package:analysis_server/src/services/completion/optype.dart'; 14 import 'package:analysis_server/src/services/completion/optype.dart';
15 import 'package:analyzer/src/generated/ast.dart'; 15 import 'package:analyzer/src/generated/ast.dart';
16 import 'package:analyzer/src/generated/scanner.dart'; 16 import 'package:analyzer/src/generated/scanner.dart';
17 17
18 /** 18 /**
19 * A computer for calculating `completion.getSuggestions` request results 19 * A computer for calculating `completion.getSuggestions` request results
20 * for the local library in which the completion is requested. 20 * for the local library in which the completion is requested.
21 */ 21 */
22 class LocalComputer extends DartCompletionComputer { 22 class LocalComputer extends DartCompletionComputer {
23 23
24 @override 24 @override
25 bool computeFast(DartCompletionRequest request) { 25 bool computeFast(DartCompletionRequest request) {
26 OpType optype = request.optype; 26 OpType optype = request.optype;
27 if (optype.includeTopLevelSuggestions) { 27 if (optype.includeTopLevelSuggestions) {
28 _LocalVisitor localVisitor = new _LocalVisitor(request, request.offset); 28 _LocalVisitor localVisitor = new _LocalVisitor(
29 localVisitor.typesOnly = optype.includeOnlyTypeNameSuggestions; 29 request,
30 localVisitor.excludeVoidReturn = !optype.includeVoidReturnSuggestions; 30 request.offset,
31 optype.includeOnlyTypeNameSuggestions,
32 !optype.includeVoidReturnSuggestions);
31 33
32 // Collect suggestions from the specific child [AstNode] that contains 34 // Collect suggestions from the specific child [AstNode] that contains
33 // the completion offset and all of its parents recursively. 35 // the completion offset and all of its parents recursively.
34 request.node.accept(localVisitor); 36 request.node.accept(localVisitor);
35 } 37 }
36 38
37 // If the unit is not a part and does not reference any parts 39 // If the unit is not a part and does not reference any parts
38 // then work is complete 40 // then work is complete
39 return !request.unit.directives.any( 41 return !request.unit.directives.any(
40 (Directive directive) => 42 (Directive directive) =>
(...skipping 13 matching lines...) Expand all
54 * that contains the completion offset to the [CompilationUnit]. 56 * that contains the completion offset to the [CompilationUnit].
55 */ 57 */
56 class _LocalVisitor extends LocalDeclarationVisitor { 58 class _LocalVisitor extends LocalDeclarationVisitor {
57 static const DYNAMIC = 'dynamic'; 59 static const DYNAMIC = 'dynamic';
58 60
59 static final TypeName NO_RETURN_TYPE = new TypeName( 61 static final TypeName NO_RETURN_TYPE = new TypeName(
60 new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), 62 new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)),
61 null); 63 null);
62 64
63 final DartCompletionRequest request; 65 final DartCompletionRequest request;
64 bool typesOnly = false; 66 final bool typesOnly;
65 bool excludeVoidReturn; 67 final bool excludeVoidReturn;
66 68
67 _LocalVisitor(this.request, int offset) : super(offset) { 69 _LocalVisitor(this.request, int offset, this.typesOnly,
68 excludeVoidReturn = _computeExcludeVoidReturn(request.node); 70 this.excludeVoidReturn)
69 } 71 : super(offset);
70 72
71 @override 73 @override
72 void declaredClass(ClassDeclaration declaration) { 74 void declaredClass(ClassDeclaration declaration) {
73 bool isDeprecated = _isDeprecated(declaration); 75 bool isDeprecated = _isDeprecated(declaration);
74 CompletionSuggestion suggestion = 76 CompletionSuggestion suggestion =
75 _addSuggestion(declaration.name, null, null, isDeprecated); 77 _addSuggestion(declaration.name, null, null, isDeprecated);
76 if (suggestion != null) { 78 if (suggestion != null) {
77 suggestion.element = _createElement( 79 suggestion.element = _createElement(
78 protocol.ElementKind.CLASS, 80 protocol.ElementKind.CLASS,
79 declaration.name, 81 declaration.name,
(...skipping 19 matching lines...) Expand all
99 isDeprecated); 101 isDeprecated);
100 } 102 }
101 } 103 }
102 104
103 @override 105 @override
104 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { 106 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) {
105 if (typesOnly) { 107 if (typesOnly) {
106 return; 108 return;
107 } 109 }
108 bool isDeprecated = _isDeprecated(fieldDecl) || _isDeprecated(varDecl); 110 bool isDeprecated = _isDeprecated(fieldDecl) || _isDeprecated(varDecl);
109 CompletionSuggestion suggestion = _addSuggestion( 111 CompletionSuggestion suggestion =
110 varDecl.name, 112 _addSuggestion(varDecl.name, null, fieldDecl.parent, isDeprecated);
111 null,
112 fieldDecl.parent,
113 isDeprecated);
114 if (suggestion != null) { 113 if (suggestion != null) {
115 suggestion.element = _createElement( 114 suggestion.element = _createElement(
116 protocol.ElementKind.FIELD, 115 protocol.ElementKind.FIELD,
117 varDecl.name, 116 varDecl.name,
118 null, 117 null,
119 null, 118 null,
120 false, 119 false,
121 isDeprecated); 120 isDeprecated);
122 } 121 }
123 } 122 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 kind = protocol.ElementKind.SETTER; 209 kind = protocol.ElementKind.SETTER;
211 returnType = null; 210 returnType = null;
212 } else { 211 } else {
213 if (excludeVoidReturn && _isVoid(returnType)) { 212 if (excludeVoidReturn && _isVoid(returnType)) {
214 return; 213 return;
215 } 214 }
216 kind = protocol.ElementKind.METHOD; 215 kind = protocol.ElementKind.METHOD;
217 parameters = declaration.parameters.toSource(); 216 parameters = declaration.parameters.toSource();
218 } 217 }
219 bool isDeprecated = _isDeprecated(declaration); 218 bool isDeprecated = _isDeprecated(declaration);
220 CompletionSuggestion suggestion = _addSuggestion( 219 CompletionSuggestion suggestion =
221 declaration.name, 220 _addSuggestion(declaration.name, returnType, declaration.parent, isDepre cated);
222 returnType,
223 declaration.parent,
224 isDeprecated);
225 if (suggestion != null) { 221 if (suggestion != null) {
226 suggestion.element = _createElement( 222 suggestion.element = _createElement(
227 kind, 223 kind,
228 declaration.name, 224 declaration.name,
229 parameters, 225 parameters,
230 returnType, 226 returnType,
231 declaration.isAbstract, 227 declaration.isAbstract,
232 isDeprecated); 228 isDeprecated);
233 } 229 }
234 } 230 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } 292 }
297 } 293 }
298 } 294 }
299 request.suggestions.add(suggestion); 295 request.suggestions.add(suggestion);
300 return suggestion; 296 return suggestion;
301 } 297 }
302 } 298 }
303 return null; 299 return null;
304 } 300 }
305 301
306 bool _computeExcludeVoidReturn(AstNode node) {
307 if (node is Block) {
308 return false;
309 } else if (node is SimpleIdentifier) {
310 return node.parent is ExpressionStatement ? false : true;
311 } else {
312 return true;
313 }
314 }
315
316 302
317 /** 303 /**
318 * Create a new protocol Element for inclusion in a completion suggestion. 304 * Create a new protocol Element for inclusion in a completion suggestion.
319 */ 305 */
320 protocol.Element _createElement(protocol.ElementKind kind, 306 protocol.Element _createElement(protocol.ElementKind kind,
321 SimpleIdentifier id, String parameters, TypeName returnType, bool isAbstra ct, 307 SimpleIdentifier id, String parameters, TypeName returnType, bool isAbstra ct,
322 bool isDeprecated) { 308 bool isDeprecated) {
323 String name = id.name; 309 String name = id.name;
324 int flags = protocol.Element.makeFlags( 310 int flags = protocol.Element.makeFlags(
325 isAbstract: isAbstract, 311 isAbstract: isAbstract,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 if (name == null || name.length <= 0) { 362 if (name == null || name.length <= 0) {
377 return DYNAMIC; 363 return DYNAMIC;
378 } 364 }
379 TypeArgumentList typeArgs = type.typeArguments; 365 TypeArgumentList typeArgs = type.typeArguments;
380 if (typeArgs != null) { 366 if (typeArgs != null) {
381 //TODO (danrubel) include type arguments 367 //TODO (danrubel) include type arguments
382 } 368 }
383 return name; 369 return name;
384 } 370 }
385 } 371 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698