Enable completion in AssertInitializer.

R=brianwilkerson@google.com, danrubel@google.com

Bug: https://github.com/flutter/flutter-intellij/issues/1101
Change-Id: Id17a701cac0e98afc373cf89089916cf5f983cff
Reviewed-on: https://dart-review.googlesource.com/40472
Reviewed-by: Dan Rubel <danrubel@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Konstantin Shcheglov 2018-02-12 01:01:31 +00:00
parent ad11e5d615
commit 456890cd2c
4 changed files with 51 additions and 20 deletions

View file

@ -14,8 +14,8 @@ import 'package:analyzer_plugin/protocol/protocol_common.dart';
import 'package:analyzer_plugin/src/utilities/completion/optype.dart';
const ASYNC_STAR = 'async*';
const DEFERRED_AS = 'deferred as';
const DEFAULT_COLON = 'default:';
const DEFERRED_AS = 'deferred as';
const EXPORT_STATEMENT = "export '';";
const IMPORT_STATEMENT = "import '';";
const PART_STATEMENT = "part '';";
@ -220,8 +220,14 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
@override
visitConstructorDeclaration(ConstructorDeclaration node) {
if (node.initializers.isNotEmpty && node.initializers.last == entity) {
_addSuggestion(Keyword.SUPER);
if (node.initializers.isNotEmpty) {
if (entity is ConstructorInitializer) {
_addSuggestion(Keyword.ASSERT);
}
if (node.initializers.last == entity) {
_addSuggestion(Keyword.SUPER);
_addSuggestion(Keyword.THIS);
}
}
}
@ -346,23 +352,6 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
}
}
@override
visitParenthesizedExpression(ParenthesizedExpression node) {
Expression expression = node.expression;
if (expression is Identifier || expression is PropertyAccess) {
if (entity == node.rightParenthesis) {
var next = expression.endToken.next;
if (next == entity || next == droppedToken) {
// Fasta parses `if (x i^)` as `if (x ^) where the `i` is in the token
// stream but not part of the ParenthesizedExpression.
_addSuggestion(Keyword.IS, DART_RELEVANCE_HIGH);
return;
}
}
}
_addExpressionKeywords(node);
}
@override
visitIfStatement(IfStatement node) {
if (_isPreviousTokenSynthetic(entity, TokenType.CLOSE_PAREN)) {
@ -455,6 +444,23 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
// ignored
}
@override
visitParenthesizedExpression(ParenthesizedExpression node) {
Expression expression = node.expression;
if (expression is Identifier || expression is PropertyAccess) {
if (entity == node.rightParenthesis) {
var next = expression.endToken.next;
if (next == entity || next == droppedToken) {
// Fasta parses `if (x i^)` as `if (x ^) where the `i` is in the token
// stream but not part of the ParenthesizedExpression.
_addSuggestion(Keyword.IS, DART_RELEVANCE_HIGH);
return;
}
}
}
_addExpressionKeywords(node);
}
@override
visitPrefixedIdentifier(PrefixedIdentifier node) {
if (entity != node.identifier) {

View file

@ -837,6 +837,18 @@ class C {
assertSuggestKeywords([]);
}
test_constructor_initializers_first() async {
addTestSource('class A { int f; A() : ^, f = 1; }');
await computeSuggestions();
assertSuggestKeywords([Keyword.ASSERT]);
}
test_constructor_initializers_last() async {
addTestSource('class A { A() : ^; }');
await computeSuggestions();
assertSuggestKeywords([Keyword.ASSERT, Keyword.SUPER, Keyword.THIS]);
}
test_constructor_param() async {
addTestSource('class A { A(^) {});}');
await computeSuggestions();

View file

@ -279,6 +279,14 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
}
}
@override
void visitAssertInitializer(AssertInitializer node) {
if (identical(entity, node.condition)) {
optype.includeReturnValueSuggestions = true;
optype.includeTypeNameSuggestions = true;
}
}
@override
void visitAssertStatement(AssertStatement node) {
if (identical(entity, node.condition)) {

View file

@ -223,6 +223,11 @@ class OpTypeTest extends AbstractContextTest {
await assertOpType(returnValue: true, typeNames: true);
}
test_AssertInitializer() async {
addTestSource('class C { C() : assert(^); }');
await assertOpType(returnValue: true, typeNames: true);
}
test_AssignmentExpression_name() async {
// SimpleIdentifier VariableDeclaration VariableDeclarationList
// VariableDeclarationStatement Block