mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:56:57 +00:00
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:
parent
ad11e5d615
commit
456890cd2c
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue