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.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 |
10 ElementKind; | 10 show Element, 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 import 'package:analyzer/src/generated/utilities_dart.dart'; | 17 import 'package:analyzer/src/generated/utilities_dart.dart'; |
18 | 18 |
19 /** | 19 /** |
20 * A computer for calculating `completion.getSuggestions` request results | 20 * A computer for calculating `completion.getSuggestions` request results |
21 * for the local library in which the completion is requested. | 21 * for the local library in which the completion is requested. |
22 */ | 22 */ |
23 class LocalComputer extends DartCompletionComputer { | 23 class LocalComputer extends DartCompletionComputer { |
24 | |
25 @override | 24 @override |
26 bool computeFast(DartCompletionRequest request) { | 25 bool computeFast(DartCompletionRequest request) { |
27 OpType optype = request.optype; | 26 OpType optype = request.optype; |
28 if (optype.includeTopLevelSuggestions) { | 27 if (optype.includeTopLevelSuggestions) { |
29 _LocalVisitor localVisitor = new _LocalVisitor( | 28 _LocalVisitor localVisitor = new _LocalVisitor(request, request.offset, |
30 request, | |
31 request.offset, | |
32 optype.includeOnlyTypeNameSuggestions, | 29 optype.includeOnlyTypeNameSuggestions, |
33 !optype.includeVoidReturnSuggestions); | 30 !optype.includeVoidReturnSuggestions); |
34 | 31 |
35 // Collect suggestions from the specific child [AstNode] that contains | 32 // Collect suggestions from the specific child [AstNode] that contains |
36 // the completion offset and all of its parents recursively. | 33 // the completion offset and all of its parents recursively. |
37 localVisitor.visit(request.node); | 34 localVisitor.visit(request.node); |
38 } | 35 } |
39 if (optype.includeStatementLabelSuggestions || | 36 if (optype.includeStatementLabelSuggestions || |
40 optype.includeCaseLabelSuggestions) { | 37 optype.includeCaseLabelSuggestions) { |
41 _LabelVisitor labelVisitor = new _LabelVisitor( | 38 _LabelVisitor labelVisitor = new _LabelVisitor(request, |
42 request, | |
43 optype.includeStatementLabelSuggestions, | 39 optype.includeStatementLabelSuggestions, |
44 optype.includeCaseLabelSuggestions); | 40 optype.includeCaseLabelSuggestions); |
45 labelVisitor.visit(request.node); | 41 labelVisitor.visit(request.node); |
46 } | 42 } |
47 | 43 |
48 // If the unit is not a part and does not reference any parts | 44 // If the unit is not a part and does not reference any parts |
49 // then work is complete | 45 // then work is complete |
50 return !request.unit.directives.any( | 46 return !request.unit.directives.any((Directive directive) => |
51 (Directive directive) => | 47 directive is PartOfDirective || directive is PartDirective); |
52 directive is PartOfDirective || directive is PartDirective); | |
53 } | 48 } |
54 | 49 |
55 @override | 50 @override |
56 Future<bool> computeFull(DartCompletionRequest request) { | 51 Future<bool> computeFull(DartCompletionRequest request) { |
57 // TODO: implement computeFull | 52 // TODO: implement computeFull |
58 // include results from part files that are included in the library | 53 // include results from part files that are included in the library |
59 return new Future.value(false); | 54 return new Future.value(false); |
60 } | 55 } |
61 } | 56 } |
62 | 57 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 void declaredMethod(MethodDeclaration declaration) { | 121 void declaredMethod(MethodDeclaration declaration) { |
127 // ignored | 122 // ignored |
128 } | 123 } |
129 | 124 |
130 @override | 125 @override |
131 void declaredParam(SimpleIdentifier name, TypeName type) { | 126 void declaredParam(SimpleIdentifier name, TypeName type) { |
132 // ignored | 127 // ignored |
133 } | 128 } |
134 | 129 |
135 @override | 130 @override |
136 void declaredTopLevelVar(VariableDeclarationList varList, | 131 void declaredTopLevelVar( |
137 VariableDeclaration varDecl) { | 132 VariableDeclarationList varList, VariableDeclaration varDecl) { |
138 // ignored | 133 // ignored |
139 } | 134 } |
140 | 135 |
141 @override | 136 @override |
142 void visitFunctionExpression(FunctionExpression node) { | 137 void visitFunctionExpression(FunctionExpression node) { |
143 // Labels are only accessible within the local function, so stop visiting | 138 // Labels are only accessible within the local function, so stop visiting |
144 // once we reach a function boundary. | 139 // once we reach a function boundary. |
145 finished(); | 140 finished(); |
146 } | 141 } |
147 | 142 |
148 @override | 143 @override |
149 void visitMethodDeclaration(MethodDeclaration node) { | 144 void visitMethodDeclaration(MethodDeclaration node) { |
150 // Labels are only accessible within the local function, so stop visiting | 145 // Labels are only accessible within the local function, so stop visiting |
151 // once we reach a function boundary. | 146 // once we reach a function boundary. |
152 finished(); | 147 finished(); |
153 } | 148 } |
154 | 149 |
155 CompletionSuggestion _addSuggestion(SimpleIdentifier id) { | 150 CompletionSuggestion _addSuggestion(SimpleIdentifier id) { |
156 if (id != null) { | 151 if (id != null) { |
157 String completion = id.name; | 152 String completion = id.name; |
158 if (completion != null && completion.length > 0 && completion != '_') { | 153 if (completion != null && completion.length > 0 && completion != '_') { |
159 CompletionSuggestion suggestion = new CompletionSuggestion( | 154 CompletionSuggestion suggestion = new CompletionSuggestion( |
160 CompletionSuggestionKind.IDENTIFIER, | 155 CompletionSuggestionKind.IDENTIFIER, DART_RELEVANCE_DEFAULT, |
161 DART_RELEVANCE_DEFAULT, | 156 completion, completion.length, 0, false, false); |
162 completion, | |
163 completion.length, | |
164 0, | |
165 false, | |
166 false); | |
167 request.suggestions.add(suggestion); | 157 request.suggestions.add(suggestion); |
168 return suggestion; | 158 return suggestion; |
169 } | 159 } |
170 } | 160 } |
171 return null; | 161 return null; |
172 } | 162 } |
173 | 163 |
174 /** | 164 /** |
175 * Create a new protocol Element for inclusion in a completion suggestion. | 165 * Create a new protocol Element for inclusion in a completion suggestion. |
176 */ | 166 */ |
177 protocol.Element _createElement(protocol.ElementKind kind, | 167 protocol.Element _createElement( |
178 SimpleIdentifier id) { | 168 protocol.ElementKind kind, SimpleIdentifier id) { |
179 String name = id.name; | 169 String name = id.name; |
180 int flags = | 170 int flags = |
181 protocol.Element.makeFlags(isPrivate: Identifier.isPrivateName(name)); | 171 protocol.Element.makeFlags(isPrivate: Identifier.isPrivateName(name)); |
182 return new protocol.Element(kind, name, flags); | 172 return new protocol.Element(kind, name, flags); |
183 } | 173 } |
184 } | 174 } |
185 | 175 |
186 /** | 176 /** |
187 * A visitor for collecting suggestions from the most specific child [AstNode] | 177 * A visitor for collecting suggestions from the most specific child [AstNode] |
188 * that contains the completion offset to the [CompilationUnit]. | 178 * that contains the completion offset to the [CompilationUnit]. |
189 */ | 179 */ |
190 class _LocalVisitor extends LocalDeclarationVisitor { | 180 class _LocalVisitor extends LocalDeclarationVisitor { |
191 static const DYNAMIC = 'dynamic'; | 181 static const DYNAMIC = 'dynamic'; |
192 | 182 |
193 static final TypeName NO_RETURN_TYPE = new TypeName( | 183 static final TypeName NO_RETURN_TYPE = new TypeName( |
194 new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), | 184 new SimpleIdentifier(new StringToken(TokenType.IDENTIFIER, '', 0)), null); |
195 null); | |
196 | 185 |
197 final DartCompletionRequest request; | 186 final DartCompletionRequest request; |
198 final bool typesOnly; | 187 final bool typesOnly; |
199 final bool excludeVoidReturn; | 188 final bool excludeVoidReturn; |
200 | 189 |
201 _LocalVisitor(this.request, int offset, this.typesOnly, | 190 _LocalVisitor( |
202 this.excludeVoidReturn) | 191 this.request, int offset, this.typesOnly, this.excludeVoidReturn) |
203 : super(offset); | 192 : super(offset); |
204 | 193 |
205 @override | 194 @override |
206 void declaredClass(ClassDeclaration declaration) { | 195 void declaredClass(ClassDeclaration declaration) { |
207 bool isDeprecated = _isDeprecated(declaration); | 196 bool isDeprecated = _isDeprecated(declaration); |
208 CompletionSuggestion suggestion = _addSuggestion( | 197 CompletionSuggestion suggestion = _addSuggestion( |
209 declaration.name, | 198 declaration.name, NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT); |
210 NO_RETURN_TYPE, | |
211 isDeprecated, | |
212 DART_RELEVANCE_DEFAULT); | |
213 if (suggestion != null) { | 199 if (suggestion != null) { |
214 suggestion.element = _createElement( | 200 suggestion.element = _createElement( |
215 protocol.ElementKind.CLASS, | 201 protocol.ElementKind.CLASS, declaration.name, |
216 declaration.name, | |
217 returnType: NO_RETURN_TYPE, | 202 returnType: NO_RETURN_TYPE, |
218 isAbstract: declaration.isAbstract, | 203 isAbstract: declaration.isAbstract, |
219 isDeprecated: isDeprecated); | 204 isDeprecated: isDeprecated); |
220 } | 205 } |
221 } | 206 } |
222 | 207 |
223 @override | 208 @override |
224 void declaredClassTypeAlias(ClassTypeAlias declaration) { | 209 void declaredClassTypeAlias(ClassTypeAlias declaration) { |
225 bool isDeprecated = _isDeprecated(declaration); | 210 bool isDeprecated = _isDeprecated(declaration); |
226 CompletionSuggestion suggestion = _addSuggestion( | 211 CompletionSuggestion suggestion = _addSuggestion( |
227 declaration.name, | 212 declaration.name, NO_RETURN_TYPE, isDeprecated, DART_RELEVANCE_DEFAULT); |
228 NO_RETURN_TYPE, | |
229 isDeprecated, | |
230 DART_RELEVANCE_DEFAULT); | |
231 if (suggestion != null) { | 213 if (suggestion != null) { |
232 suggestion.element = _createElement( | 214 suggestion.element = _createElement( |
233 protocol.ElementKind.CLASS_TYPE_ALIAS, | 215 protocol.ElementKind.CLASS_TYPE_ALIAS, declaration.name, |
234 declaration.name, | |
235 returnType: NO_RETURN_TYPE, | 216 returnType: NO_RETURN_TYPE, |
236 isAbstract: true, | 217 isAbstract: true, |
237 isDeprecated: isDeprecated); | 218 isDeprecated: isDeprecated); |
238 } | 219 } |
239 } | 220 } |
240 | 221 |
241 @override | 222 @override |
242 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { | 223 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) { |
243 if (typesOnly) { | 224 if (typesOnly) { |
244 return; | 225 return; |
245 } | 226 } |
246 bool isDeprecated = _isDeprecated(fieldDecl) || _isDeprecated(varDecl); | 227 bool isDeprecated = _isDeprecated(fieldDecl) || _isDeprecated(varDecl); |
247 TypeName type = fieldDecl.fields.type; | 228 TypeName type = fieldDecl.fields.type; |
248 CompletionSuggestion suggestion = _addSuggestion( | 229 CompletionSuggestion suggestion = _addSuggestion( |
249 varDecl.name, | 230 varDecl.name, type, isDeprecated, DART_RELEVANCE_LOCAL_FIELD, |
250 type, | |
251 isDeprecated, | |
252 DART_RELEVANCE_LOCAL_FIELD, | |
253 classDecl: fieldDecl.parent); | 231 classDecl: fieldDecl.parent); |
254 if (suggestion != null) { | 232 if (suggestion != null) { |
255 suggestion.element = _createElement( | 233 suggestion.element = _createElement( |
256 protocol.ElementKind.FIELD, | 234 protocol.ElementKind.FIELD, varDecl.name, |
257 varDecl.name, | 235 returnType: type, isDeprecated: isDeprecated); |
258 returnType: type, | |
259 isDeprecated: isDeprecated); | |
260 } | 236 } |
261 } | 237 } |
262 | 238 |
263 @override | 239 @override |
264 void declaredFunction(FunctionDeclaration declaration) { | 240 void declaredFunction(FunctionDeclaration declaration) { |
265 if (typesOnly) { | 241 if (typesOnly) { |
266 return; | 242 return; |
267 } | 243 } |
268 TypeName returnType = declaration.returnType; | 244 TypeName returnType = declaration.returnType; |
269 bool isDeprecated = _isDeprecated(declaration); | 245 bool isDeprecated = _isDeprecated(declaration); |
(...skipping 10 matching lines...) Expand all Loading... |
280 returnType = NO_RETURN_TYPE; | 256 returnType = NO_RETURN_TYPE; |
281 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; | 257 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; |
282 } else { | 258 } else { |
283 if (excludeVoidReturn && _isVoid(returnType)) { | 259 if (excludeVoidReturn && _isVoid(returnType)) { |
284 return; | 260 return; |
285 } | 261 } |
286 kind = protocol.ElementKind.FUNCTION; | 262 kind = protocol.ElementKind.FUNCTION; |
287 defaultRelevance = DART_RELEVANCE_LOCAL_FUNCTION; | 263 defaultRelevance = DART_RELEVANCE_LOCAL_FUNCTION; |
288 } | 264 } |
289 CompletionSuggestion suggestion = _addSuggestion( | 265 CompletionSuggestion suggestion = _addSuggestion( |
290 declaration.name, | 266 declaration.name, returnType, isDeprecated, defaultRelevance); |
291 returnType, | |
292 isDeprecated, | |
293 defaultRelevance); | |
294 if (suggestion != null) { | 267 if (suggestion != null) { |
295 FormalParameterList param = declaration.functionExpression.parameters; | 268 FormalParameterList param = declaration.functionExpression.parameters; |
296 suggestion.element = _createElement( | 269 suggestion.element = _createElement(kind, declaration.name, |
297 kind, | |
298 declaration.name, | |
299 parameters: param != null ? param.toSource() : null, | 270 parameters: param != null ? param.toSource() : null, |
300 returnType: returnType, | 271 returnType: returnType, |
301 isDeprecated: isDeprecated); | 272 isDeprecated: isDeprecated); |
302 if (kind == protocol.ElementKind.FUNCTION) { | 273 if (kind == protocol.ElementKind.FUNCTION) { |
303 _addParameterInfo( | 274 _addParameterInfo( |
304 suggestion, | 275 suggestion, declaration.functionExpression.parameters); |
305 declaration.functionExpression.parameters); | |
306 } | 276 } |
307 } | 277 } |
308 } | 278 } |
309 | 279 |
310 @override | 280 @override |
311 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) { | 281 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) { |
312 bool isDeprecated = _isDeprecated(declaration); | 282 bool isDeprecated = _isDeprecated(declaration); |
313 TypeName returnType = declaration.returnType; | 283 TypeName returnType = declaration.returnType; |
314 CompletionSuggestion suggestion = _addSuggestion( | 284 CompletionSuggestion suggestion = _addSuggestion( |
315 declaration.name, | 285 declaration.name, returnType, isDeprecated, DART_RELEVANCE_DEFAULT); |
316 returnType, | |
317 isDeprecated, | |
318 DART_RELEVANCE_DEFAULT); | |
319 if (suggestion != null) { | 286 if (suggestion != null) { |
320 // TODO (danrubel) determine parameters and return type | 287 // TODO (danrubel) determine parameters and return type |
321 suggestion.element = _createElement( | 288 suggestion.element = _createElement( |
322 protocol.ElementKind.FUNCTION_TYPE_ALIAS, | 289 protocol.ElementKind.FUNCTION_TYPE_ALIAS, declaration.name, |
323 declaration.name, | 290 returnType: returnType, isAbstract: true, isDeprecated: isDeprecated); |
324 returnType: returnType, | |
325 isAbstract: true, | |
326 isDeprecated: isDeprecated); | |
327 } | 291 } |
328 } | 292 } |
329 | 293 |
330 @override | 294 @override |
331 void declaredLabel(Label label, bool isCaseLabel) { | 295 void declaredLabel(Label label, bool isCaseLabel) { |
332 // ignored | 296 // ignored |
333 } | 297 } |
334 | 298 |
335 @override | 299 @override |
336 void declaredLocalVar(SimpleIdentifier name, TypeName type) { | 300 void declaredLocalVar(SimpleIdentifier name, TypeName type) { |
337 if (typesOnly) { | 301 if (typesOnly) { |
338 return; | 302 return; |
339 } | 303 } |
340 CompletionSuggestion suggestion = | 304 CompletionSuggestion suggestion = |
341 _addSuggestion(name, type, false, DART_RELEVANCE_LOCAL_VARIABLE); | 305 _addSuggestion(name, type, false, DART_RELEVANCE_LOCAL_VARIABLE); |
342 if (suggestion != null) { | 306 if (suggestion != null) { |
343 suggestion.element = | 307 suggestion.element = _createElement( |
344 _createElement(protocol.ElementKind.LOCAL_VARIABLE, name, returnType:
type); | 308 protocol.ElementKind.LOCAL_VARIABLE, name, returnType: type); |
345 } | 309 } |
346 } | 310 } |
347 | 311 |
348 @override | 312 @override |
349 void declaredMethod(MethodDeclaration declaration) { | 313 void declaredMethod(MethodDeclaration declaration) { |
350 if (typesOnly) { | 314 if (typesOnly) { |
351 return; | 315 return; |
352 } | 316 } |
353 protocol.ElementKind kind; | 317 protocol.ElementKind kind; |
354 String parameters; | 318 String parameters; |
(...skipping 13 matching lines...) Expand all Loading... |
368 } else { | 332 } else { |
369 if (excludeVoidReturn && _isVoid(returnType)) { | 333 if (excludeVoidReturn && _isVoid(returnType)) { |
370 return; | 334 return; |
371 } | 335 } |
372 kind = protocol.ElementKind.METHOD; | 336 kind = protocol.ElementKind.METHOD; |
373 parameters = declaration.parameters.toSource(); | 337 parameters = declaration.parameters.toSource(); |
374 defaultRelevance = DART_RELEVANCE_LOCAL_METHOD; | 338 defaultRelevance = DART_RELEVANCE_LOCAL_METHOD; |
375 } | 339 } |
376 bool isDeprecated = _isDeprecated(declaration); | 340 bool isDeprecated = _isDeprecated(declaration); |
377 CompletionSuggestion suggestion = _addSuggestion( | 341 CompletionSuggestion suggestion = _addSuggestion( |
378 declaration.name, | 342 declaration.name, returnType, isDeprecated, defaultRelevance, |
379 returnType, | |
380 isDeprecated, | |
381 defaultRelevance, | |
382 classDecl: declaration.parent); | 343 classDecl: declaration.parent); |
383 if (suggestion != null) { | 344 if (suggestion != null) { |
384 suggestion.element = _createElement( | 345 suggestion.element = _createElement(kind, declaration.name, |
385 kind, | |
386 declaration.name, | |
387 parameters: parameters, | 346 parameters: parameters, |
388 returnType: returnType, | 347 returnType: returnType, |
389 isAbstract: declaration.isAbstract, | 348 isAbstract: declaration.isAbstract, |
390 isDeprecated: isDeprecated); | 349 isDeprecated: isDeprecated); |
391 if (kind == protocol.ElementKind.METHOD) { | 350 if (kind == protocol.ElementKind.METHOD) { |
392 _addParameterInfo(suggestion, declaration.parameters); | 351 _addParameterInfo(suggestion, declaration.parameters); |
393 } | 352 } |
394 } | 353 } |
395 } | 354 } |
396 | 355 |
397 @override | 356 @override |
398 void declaredParam(SimpleIdentifier name, TypeName type) { | 357 void declaredParam(SimpleIdentifier name, TypeName type) { |
399 if (typesOnly) { | 358 if (typesOnly) { |
400 return; | 359 return; |
401 } | 360 } |
402 CompletionSuggestion suggestion = | 361 CompletionSuggestion suggestion = |
403 _addSuggestion(name, type, false, DART_RELEVANCE_PARAMETER); | 362 _addSuggestion(name, type, false, DART_RELEVANCE_PARAMETER); |
404 if (suggestion != null) { | 363 if (suggestion != null) { |
405 suggestion.element = | 364 suggestion.element = _createElement(protocol.ElementKind.PARAMETER, name, |
406 _createElement(protocol.ElementKind.PARAMETER, name, returnType: type)
; | 365 returnType: type); |
407 } | 366 } |
408 } | 367 } |
409 | 368 |
410 @override | 369 @override |
411 void declaredTopLevelVar(VariableDeclarationList varList, | 370 void declaredTopLevelVar( |
412 VariableDeclaration varDecl) { | 371 VariableDeclarationList varList, VariableDeclaration varDecl) { |
413 if (typesOnly) { | 372 if (typesOnly) { |
414 return; | 373 return; |
415 } | 374 } |
416 bool isDeprecated = _isDeprecated(varList) || _isDeprecated(varDecl); | 375 bool isDeprecated = _isDeprecated(varList) || _isDeprecated(varDecl); |
417 CompletionSuggestion suggestion = _addSuggestion( | 376 CompletionSuggestion suggestion = _addSuggestion(varDecl.name, varList.type, |
418 varDecl.name, | 377 isDeprecated, DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE); |
419 varList.type, | |
420 isDeprecated, | |
421 DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE); | |
422 if (suggestion != null) { | 378 if (suggestion != null) { |
423 suggestion.element = _createElement( | 379 suggestion.element = _createElement( |
424 protocol.ElementKind.TOP_LEVEL_VARIABLE, | 380 protocol.ElementKind.TOP_LEVEL_VARIABLE, varDecl.name, |
425 varDecl.name, | 381 returnType: varList.type, isDeprecated: isDeprecated); |
426 returnType: varList.type, | |
427 isDeprecated: isDeprecated); | |
428 } | 382 } |
429 } | 383 } |
430 | 384 |
431 void _addParameterInfo(CompletionSuggestion suggestion, | 385 void _addParameterInfo( |
432 FormalParameterList parameters) { | 386 CompletionSuggestion suggestion, FormalParameterList parameters) { |
433 var paramList = parameters.parameters; | 387 var paramList = parameters.parameters; |
434 suggestion.parameterNames = | 388 suggestion.parameterNames = paramList |
435 paramList.map((FormalParameter param) => param.identifier.name).toList()
; | 389 .map((FormalParameter param) => param.identifier.name) |
| 390 .toList(); |
436 suggestion.parameterTypes = paramList.map((FormalParameter param) { | 391 suggestion.parameterTypes = paramList.map((FormalParameter param) { |
437 TypeName type = null; | 392 TypeName type = null; |
438 if (param is DefaultFormalParameter) { | 393 if (param is DefaultFormalParameter) { |
439 NormalFormalParameter child = param.parameter; | 394 NormalFormalParameter child = param.parameter; |
440 if (child is SimpleFormalParameter) { | 395 if (child is SimpleFormalParameter) { |
441 type = child.type; | 396 type = child.type; |
442 } else if (child is FieldFormalParameter) { | 397 } else if (child is FieldFormalParameter) { |
443 type = child.type; | 398 type = child.type; |
444 } | 399 } |
445 } | 400 } |
446 if (param is SimpleFormalParameter) { | 401 if (param is SimpleFormalParameter) { |
447 type = param.type; | 402 type = param.type; |
448 } else if (param is FieldFormalParameter) { | 403 } else if (param is FieldFormalParameter) { |
449 type = param.type; | 404 type = param.type; |
450 } | 405 } |
451 if (type == null) { | 406 if (type == null) { |
452 return 'dynamic'; | 407 return 'dynamic'; |
453 } | 408 } |
454 Identifier typeId = type.name; | 409 Identifier typeId = type.name; |
455 if (typeId == null) { | 410 if (typeId == null) { |
456 return 'dynamic'; | 411 return 'dynamic'; |
457 } | 412 } |
458 return typeId.name; | 413 return typeId.name; |
459 }).toList(); | 414 }).toList(); |
460 suggestion.requiredParameterCount = paramList.where( | 415 suggestion.requiredParameterCount = paramList.where( |
461 (FormalParameter param) => param is! DefaultFormalParameter).length; | 416 (FormalParameter param) => param is! DefaultFormalParameter).length; |
462 suggestion.hasNamedParameters = | 417 suggestion.hasNamedParameters = paramList |
463 paramList.any((FormalParameter param) => param.kind == ParameterKind.NAM
ED); | 418 .any((FormalParameter param) => param.kind == ParameterKind.NAMED); |
464 } | 419 } |
465 | 420 |
466 CompletionSuggestion _addSuggestion(SimpleIdentifier id, TypeName returnType, | 421 CompletionSuggestion _addSuggestion(SimpleIdentifier id, TypeName returnType, |
467 bool isDeprecated, int defaultRelevance, {ClassDeclaration classDecl}) { | 422 bool isDeprecated, int defaultRelevance, {ClassDeclaration classDecl}) { |
468 if (id != null) { | 423 if (id != null) { |
469 String completion = id.name; | 424 String completion = id.name; |
470 if (completion != null && completion.length > 0 && completion != '_') { | 425 if (completion != null && completion.length > 0 && completion != '_') { |
471 CompletionSuggestion suggestion = new CompletionSuggestion( | 426 CompletionSuggestion suggestion = new CompletionSuggestion( |
472 CompletionSuggestionKind.INVOCATION, | 427 CompletionSuggestionKind.INVOCATION, |
473 isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance, | 428 isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance, completion, |
474 completion, | 429 completion.length, 0, isDeprecated, false, |
475 completion.length, | |
476 0, | |
477 isDeprecated, | |
478 false, | |
479 returnType: _nameForType(returnType)); | 430 returnType: _nameForType(returnType)); |
480 if (classDecl != null) { | 431 if (classDecl != null) { |
481 SimpleIdentifier identifier = classDecl.name; | 432 SimpleIdentifier identifier = classDecl.name; |
482 if (identifier != null) { | 433 if (identifier != null) { |
483 String name = identifier.name; | 434 String name = identifier.name; |
484 if (name != null && name.length > 0) { | 435 if (name != null && name.length > 0) { |
485 suggestion.declaringType = name; | 436 suggestion.declaringType = name; |
486 } | 437 } |
487 } | 438 } |
488 } | 439 } |
489 request.suggestions.add(suggestion); | 440 request.suggestions.add(suggestion); |
490 return suggestion; | 441 return suggestion; |
491 } | 442 } |
492 } | 443 } |
493 return null; | 444 return null; |
494 } | 445 } |
495 | 446 |
496 | |
497 /** | 447 /** |
498 * Create a new protocol Element for inclusion in a completion suggestion. | 448 * Create a new protocol Element for inclusion in a completion suggestion. |
499 */ | 449 */ |
500 protocol.Element _createElement(protocol.ElementKind kind, | 450 protocol.Element _createElement( |
501 SimpleIdentifier id, {String parameters, TypeName returnType, bool isAbstr
act: | 451 protocol.ElementKind kind, SimpleIdentifier id, {String parameters, |
502 false, bool isDeprecated: false}) { | 452 TypeName returnType, bool isAbstract: false, bool isDeprecated: false}) { |
503 String name = id.name; | 453 String name = id.name; |
504 int flags = protocol.Element.makeFlags( | 454 int flags = protocol.Element.makeFlags( |
505 isAbstract: isAbstract, | 455 isAbstract: isAbstract, |
506 isDeprecated: isDeprecated, | 456 isDeprecated: isDeprecated, |
507 isPrivate: Identifier.isPrivateName(name)); | 457 isPrivate: Identifier.isPrivateName(name)); |
508 return new protocol.Element( | 458 return new protocol.Element(kind, name, flags, |
509 kind, | 459 parameters: parameters, returnType: _nameForType(returnType)); |
510 name, | |
511 flags, | |
512 parameters: parameters, | |
513 returnType: _nameForType(returnType)); | |
514 } | 460 } |
515 | 461 |
516 /** | 462 /** |
517 * Return `true` if the @deprecated annotation is present | 463 * Return `true` if the @deprecated annotation is present |
518 */ | 464 */ |
519 bool _isDeprecated(AnnotatedNode node) { | 465 bool _isDeprecated(AnnotatedNode node) { |
520 if (node != null) { | 466 if (node != null) { |
521 NodeList<Annotation> metadata = node.metadata; | 467 NodeList<Annotation> metadata = node.metadata; |
522 if (metadata != null) { | 468 if (metadata != null) { |
523 return metadata.any((Annotation a) { | 469 return metadata.any((Annotation a) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 if (name == null || name.length <= 0) { | 502 if (name == null || name.length <= 0) { |
557 return DYNAMIC; | 503 return DYNAMIC; |
558 } | 504 } |
559 TypeArgumentList typeArgs = type.typeArguments; | 505 TypeArgumentList typeArgs = type.typeArguments; |
560 if (typeArgs != null) { | 506 if (typeArgs != null) { |
561 //TODO (danrubel) include type arguments | 507 //TODO (danrubel) include type arguments |
562 } | 508 } |
563 return name; | 509 return name; |
564 } | 510 } |
565 } | 511 } |
OLD | NEW |