| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 analysis_server.src.provisional.completion.dart.completion_target; | 5 library analysis_server.src.provisional.completion.dart.completion_target; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 } | 382 } |
| 383 | 383 |
| 384 /** | 384 /** |
| 385 * Determine whether [node] could possibly be the [entity] for a | 385 * Determine whether [node] could possibly be the [entity] for a |
| 386 * [CompletionTarget] associated with the given [offset]. | 386 * [CompletionTarget] associated with the given [offset]. |
| 387 */ | 387 */ |
| 388 static bool _isCandidateNode(AstNode node, int offset) { | 388 static bool _isCandidateNode(AstNode node, int offset) { |
| 389 // If the node's first token is a keyword or identifier, then the node is a | 389 // If the node's first token is a keyword or identifier, then the node is a |
| 390 // candidate entity if its first token is. | 390 // candidate entity if its first token is. |
| 391 Token beginToken = node.beginToken; | 391 Token beginToken = node.beginToken; |
| 392 if (beginToken.type == TokenType.KEYWORD || | 392 if (beginToken.type.isKeyword || beginToken.type == TokenType.IDENTIFIER) { |
| 393 beginToken.type == TokenType.IDENTIFIER) { | |
| 394 return _isCandidateToken(beginToken, offset); | 393 return _isCandidateToken(beginToken, offset); |
| 395 } | 394 } |
| 396 | 395 |
| 397 // Otherwise, the node is a candidate entity only if the offset is before | 396 // Otherwise, the node is a candidate entity only if the offset is before |
| 398 // the beginning of the node. This ensures that completions within a token | 397 // the beginning of the node. This ensures that completions within a token |
| 399 // (e.g. inside a literal string or inside a comment) are evaluated within | 398 // (e.g. inside a literal string or inside a comment) are evaluated within |
| 400 // the context of the token itself. | 399 // the context of the token itself. |
| 401 return offset <= node.offset; | 400 return offset <= node.offset; |
| 402 } | 401 } |
| 403 | 402 |
| 404 /** | 403 /** |
| 405 * Determine whether [token] could possibly be the [entity] for a | 404 * Determine whether [token] could possibly be the [entity] for a |
| 406 * [CompletionTarget] associated with the given [offset]. | 405 * [CompletionTarget] associated with the given [offset]. |
| 407 */ | 406 */ |
| 408 static bool _isCandidateToken(Token token, int offset) { | 407 static bool _isCandidateToken(Token token, int offset) { |
| 409 // A token is considered a candidate entity if the cursor offset is (a) | 408 // A token is considered a candidate entity if the cursor offset is (a) |
| 410 // before the start of the token, (b) within the token, (c) at the end of | 409 // before the start of the token, (b) within the token, (c) at the end of |
| 411 // the token and the token is a keyword or identifier, or (d) at the | 410 // the token and the token is a keyword or identifier, or (d) at the |
| 412 // location of the token and the token is zero length. | 411 // location of the token and the token is zero length. |
| 413 if (offset < token.end) { | 412 if (offset < token.end) { |
| 414 return true; | 413 return true; |
| 415 } else if (offset == token.end) { | 414 } else if (offset == token.end) { |
| 416 return token.type == TokenType.KEYWORD || | 415 return token.type.isKeyword || |
| 417 token.type == TokenType.IDENTIFIER || | 416 token.type == TokenType.IDENTIFIER || |
| 418 token.length == 0; | 417 token.length == 0; |
| 419 } else if (!token.isSynthetic) { | 418 } else if (!token.isSynthetic) { |
| 420 return false; | 419 return false; |
| 421 } | 420 } |
| 422 // If the current token is synthetic, then check the previous token | 421 // If the current token is synthetic, then check the previous token |
| 423 // because it may have been dropped from the parse tree | 422 // because it may have been dropped from the parse tree |
| 424 Token previous = token.previous; | 423 Token previous = token.previous; |
| 425 if (offset < previous.end) { | 424 if (offset < previous.end) { |
| 426 return true; | 425 return true; |
| 427 } else if (offset == previous.end) { | 426 } else if (offset == previous.end) { |
| 428 return token.type == TokenType.KEYWORD || | 427 return token.type.isKeyword || previous.type == TokenType.IDENTIFIER; |
| 429 previous.type == TokenType.IDENTIFIER; | |
| 430 } else { | 428 } else { |
| 431 return false; | 429 return false; |
| 432 } | 430 } |
| 433 } | 431 } |
| 434 | 432 |
| 435 /** | 433 /** |
| 436 * Return `true` if the parameter is a functional parameter. | 434 * Return `true` if the parameter is a functional parameter. |
| 437 */ | 435 */ |
| 438 static bool _isFunctionalParameter(List<ParameterElement> parameters, | 436 static bool _isFunctionalParameter(List<ParameterElement> parameters, |
| 439 int paramIndex, AstNode containingNode) { | 437 int paramIndex, AstNode containingNode) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 450 orElse: () => null); | 448 orElse: () => null); |
| 451 paramType = param?.type; | 449 paramType = param?.type; |
| 452 } | 450 } |
| 453 } else { | 451 } else { |
| 454 paramType = param.type; | 452 paramType = param.type; |
| 455 } | 453 } |
| 456 } | 454 } |
| 457 return paramType is FunctionType || paramType is FunctionTypeAlias; | 455 return paramType is FunctionType || paramType is FunctionTypeAlias; |
| 458 } | 456 } |
| 459 } | 457 } |
| OLD | NEW |