| 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 show Element, |
| 10 ElementKind; | 10 ElementKind; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 finished = true; | 153 finished = true; |
| 154 return true; | 154 return true; |
| 155 } | 155 } |
| 156 | 156 |
| 157 CompletionSuggestion _addSuggestion(SimpleIdentifier id) { | 157 CompletionSuggestion _addSuggestion(SimpleIdentifier id) { |
| 158 if (id != null) { | 158 if (id != null) { |
| 159 String completion = id.name; | 159 String completion = id.name; |
| 160 if (completion != null && completion.length > 0 && completion != '_') { | 160 if (completion != null && completion.length > 0 && completion != '_') { |
| 161 CompletionSuggestion suggestion = new CompletionSuggestion( | 161 CompletionSuggestion suggestion = new CompletionSuggestion( |
| 162 CompletionSuggestionKind.IDENTIFIER, | 162 CompletionSuggestionKind.IDENTIFIER, |
| 163 COMPLETION_RELEVANCE_DEFAULT, | 163 DART_RELEVANCE_DEFAULT, |
| 164 completion, | 164 completion, |
| 165 completion.length, | 165 completion.length, |
| 166 0, | 166 0, |
| 167 false, | 167 false, |
| 168 false); | 168 false); |
| 169 request.suggestions.add(suggestion); | 169 request.suggestions.add(suggestion); |
| 170 return suggestion; | 170 return suggestion; |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 return null; | 173 return null; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 204 this.excludeVoidReturn) | 204 this.excludeVoidReturn) |
| 205 : super(offset); | 205 : super(offset); |
| 206 | 206 |
| 207 @override | 207 @override |
| 208 void declaredClass(ClassDeclaration declaration) { | 208 void declaredClass(ClassDeclaration declaration) { |
| 209 bool isDeprecated = _isDeprecated(declaration); | 209 bool isDeprecated = _isDeprecated(declaration); |
| 210 CompletionSuggestion suggestion = _addSuggestion( | 210 CompletionSuggestion suggestion = _addSuggestion( |
| 211 declaration.name, | 211 declaration.name, |
| 212 NO_RETURN_TYPE, | 212 NO_RETURN_TYPE, |
| 213 isDeprecated, | 213 isDeprecated, |
| 214 COMPLETION_RELEVANCE_DEFAULT); | 214 DART_RELEVANCE_DEFAULT); |
| 215 if (suggestion != null) { | 215 if (suggestion != null) { |
| 216 suggestion.element = _createElement( | 216 suggestion.element = _createElement( |
| 217 protocol.ElementKind.CLASS, | 217 protocol.ElementKind.CLASS, |
| 218 declaration.name, | 218 declaration.name, |
| 219 returnType: NO_RETURN_TYPE, | 219 returnType: NO_RETURN_TYPE, |
| 220 isAbstract: declaration.isAbstract, | 220 isAbstract: declaration.isAbstract, |
| 221 isDeprecated: isDeprecated); | 221 isDeprecated: isDeprecated); |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 | 224 |
| 225 @override | 225 @override |
| 226 void declaredClassTypeAlias(ClassTypeAlias declaration) { | 226 void declaredClassTypeAlias(ClassTypeAlias declaration) { |
| 227 bool isDeprecated = _isDeprecated(declaration); | 227 bool isDeprecated = _isDeprecated(declaration); |
| 228 CompletionSuggestion suggestion = _addSuggestion( | 228 CompletionSuggestion suggestion = _addSuggestion( |
| 229 declaration.name, | 229 declaration.name, |
| 230 NO_RETURN_TYPE, | 230 NO_RETURN_TYPE, |
| 231 isDeprecated, | 231 isDeprecated, |
| 232 COMPLETION_RELEVANCE_DEFAULT); | 232 DART_RELEVANCE_DEFAULT); |
| 233 if (suggestion != null) { | 233 if (suggestion != null) { |
| 234 suggestion.element = _createElement( | 234 suggestion.element = _createElement( |
| 235 protocol.ElementKind.CLASS_TYPE_ALIAS, | 235 protocol.ElementKind.CLASS_TYPE_ALIAS, |
| 236 declaration.name, | 236 declaration.name, |
| 237 returnType: NO_RETURN_TYPE, | 237 returnType: NO_RETURN_TYPE, |
| 238 isAbstract: true, | 238 isAbstract: true, |
| 239 isDeprecated: isDeprecated); | 239 isDeprecated: isDeprecated); |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 | 242 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 263 } | 263 } |
| 264 | 264 |
| 265 @override | 265 @override |
| 266 void declaredFunction(FunctionDeclaration declaration) { | 266 void declaredFunction(FunctionDeclaration declaration) { |
| 267 if (typesOnly) { | 267 if (typesOnly) { |
| 268 return; | 268 return; |
| 269 } | 269 } |
| 270 TypeName returnType = declaration.returnType; | 270 TypeName returnType = declaration.returnType; |
| 271 bool isDeprecated = _isDeprecated(declaration); | 271 bool isDeprecated = _isDeprecated(declaration); |
| 272 protocol.ElementKind kind; | 272 protocol.ElementKind kind; |
| 273 int defaultRelevance = COMPLETION_RELEVANCE_DEFAULT; | 273 int defaultRelevance = DART_RELEVANCE_DEFAULT; |
| 274 if (declaration.isGetter) { | 274 if (declaration.isGetter) { |
| 275 kind = protocol.ElementKind.GETTER; | 275 kind = protocol.ElementKind.GETTER; |
| 276 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; | 276 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; |
| 277 } else if (declaration.isSetter) { | 277 } else if (declaration.isSetter) { |
| 278 if (excludeVoidReturn) { | 278 if (excludeVoidReturn) { |
| 279 return; | 279 return; |
| 280 } | 280 } |
| 281 kind = protocol.ElementKind.SETTER; | 281 kind = protocol.ElementKind.SETTER; |
| 282 returnType = NO_RETURN_TYPE; | 282 returnType = NO_RETURN_TYPE; |
| 283 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; | 283 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 310 } | 310 } |
| 311 | 311 |
| 312 @override | 312 @override |
| 313 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) { | 313 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) { |
| 314 bool isDeprecated = _isDeprecated(declaration); | 314 bool isDeprecated = _isDeprecated(declaration); |
| 315 TypeName returnType = declaration.returnType; | 315 TypeName returnType = declaration.returnType; |
| 316 CompletionSuggestion suggestion = _addSuggestion( | 316 CompletionSuggestion suggestion = _addSuggestion( |
| 317 declaration.name, | 317 declaration.name, |
| 318 returnType, | 318 returnType, |
| 319 isDeprecated, | 319 isDeprecated, |
| 320 COMPLETION_RELEVANCE_DEFAULT); | 320 DART_RELEVANCE_DEFAULT); |
| 321 if (suggestion != null) { | 321 if (suggestion != null) { |
| 322 // TODO (danrubel) determine parameters and return type | 322 // TODO (danrubel) determine parameters and return type |
| 323 suggestion.element = _createElement( | 323 suggestion.element = _createElement( |
| 324 protocol.ElementKind.FUNCTION_TYPE_ALIAS, | 324 protocol.ElementKind.FUNCTION_TYPE_ALIAS, |
| 325 declaration.name, | 325 declaration.name, |
| 326 returnType: returnType, | 326 returnType: returnType, |
| 327 isAbstract: true, | 327 isAbstract: true, |
| 328 isDeprecated: isDeprecated); | 328 isDeprecated: isDeprecated); |
| 329 } | 329 } |
| 330 } | 330 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 348 } | 348 } |
| 349 | 349 |
| 350 @override | 350 @override |
| 351 void declaredMethod(MethodDeclaration declaration) { | 351 void declaredMethod(MethodDeclaration declaration) { |
| 352 if (typesOnly) { | 352 if (typesOnly) { |
| 353 return; | 353 return; |
| 354 } | 354 } |
| 355 protocol.ElementKind kind; | 355 protocol.ElementKind kind; |
| 356 String parameters; | 356 String parameters; |
| 357 TypeName returnType = declaration.returnType; | 357 TypeName returnType = declaration.returnType; |
| 358 int defaultRelevance = COMPLETION_RELEVANCE_DEFAULT; | 358 int defaultRelevance = DART_RELEVANCE_DEFAULT; |
| 359 if (declaration.isGetter) { | 359 if (declaration.isGetter) { |
| 360 kind = protocol.ElementKind.GETTER; | 360 kind = protocol.ElementKind.GETTER; |
| 361 parameters = null; | 361 parameters = null; |
| 362 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; | 362 defaultRelevance = DART_RELEVANCE_LOCAL_ACCESSOR; |
| 363 } else if (declaration.isSetter) { | 363 } else if (declaration.isSetter) { |
| 364 if (excludeVoidReturn) { | 364 if (excludeVoidReturn) { |
| 365 return; | 365 return; |
| 366 } | 366 } |
| 367 kind = protocol.ElementKind.SETTER; | 367 kind = protocol.ElementKind.SETTER; |
| 368 returnType = NO_RETURN_TYPE; | 368 returnType = NO_RETURN_TYPE; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 paramList.any((FormalParameter param) => param.kind == ParameterKind.NAM
ED); | 465 paramList.any((FormalParameter param) => param.kind == ParameterKind.NAM
ED); |
| 466 } | 466 } |
| 467 | 467 |
| 468 CompletionSuggestion _addSuggestion(SimpleIdentifier id, TypeName returnType, | 468 CompletionSuggestion _addSuggestion(SimpleIdentifier id, TypeName returnType, |
| 469 bool isDeprecated, int defaultRelevance, {ClassDeclaration classDecl}) { | 469 bool isDeprecated, int defaultRelevance, {ClassDeclaration classDecl}) { |
| 470 if (id != null) { | 470 if (id != null) { |
| 471 String completion = id.name; | 471 String completion = id.name; |
| 472 if (completion != null && completion.length > 0 && completion != '_') { | 472 if (completion != null && completion.length > 0 && completion != '_') { |
| 473 CompletionSuggestion suggestion = new CompletionSuggestion( | 473 CompletionSuggestion suggestion = new CompletionSuggestion( |
| 474 CompletionSuggestionKind.INVOCATION, | 474 CompletionSuggestionKind.INVOCATION, |
| 475 isDeprecated ? COMPLETION_RELEVANCE_LOW : defaultRelevance, | 475 isDeprecated ? DART_RELEVANCE_LOW : defaultRelevance, |
| 476 completion, | 476 completion, |
| 477 completion.length, | 477 completion.length, |
| 478 0, | 478 0, |
| 479 isDeprecated, | 479 isDeprecated, |
| 480 false, | 480 false, |
| 481 returnType: _nameForType(returnType)); | 481 returnType: _nameForType(returnType)); |
| 482 if (classDecl != null) { | 482 if (classDecl != null) { |
| 483 SimpleIdentifier identifier = classDecl.name; | 483 SimpleIdentifier identifier = classDecl.name; |
| 484 if (identifier != null) { | 484 if (identifier != null) { |
| 485 String name = identifier.name; | 485 String name = identifier.name; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 if (name == null || name.length <= 0) { | 558 if (name == null || name.length <= 0) { |
| 559 return DYNAMIC; | 559 return DYNAMIC; |
| 560 } | 560 } |
| 561 TypeArgumentList typeArgs = type.typeArguments; | 561 TypeArgumentList typeArgs = type.typeArguments; |
| 562 if (typeArgs != null) { | 562 if (typeArgs != null) { |
| 563 //TODO (danrubel) include type arguments | 563 //TODO (danrubel) include type arguments |
| 564 } | 564 } |
| 565 return name; | 565 return name; |
| 566 } | 566 } |
| 567 } | 567 } |
| OLD | NEW |