Skip to content

Commit

Permalink
contribute local completions for mixin members
Browse files Browse the repository at this point in the history
Fixes: dart-lang/sdk#39795

Change-Id: I1a186dd63e59463706d18dd484653c0bee70ba90
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132165
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
  • Loading branch information
pq authored and commit-bot@chromium.org committed Jan 16, 2020
1 parent d19b2b0 commit c7745a1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4050,6 +4050,32 @@ A T;''');
assertNotSuggested('x');
}

test_mixinDeclaration_method_access() async {
addTestSource(r'''
class A { }
mixin X on A {
int _x() => 0;
int get x => ^
}
''');
await computeSuggestions();
assertSuggestMethod('_x', 'X', 'int');
}

test_mixinDeclaration_property_access() async {
addTestSource(r'''
class A { }
mixin X on A {
int _x;
int get x => ^
}
''');
await computeSuggestions();
assertSuggestField('_x', 'int');
}

test_new_instance() async {
addTestSource('import "dart:math"; class A {x() {new Random().^}}');
await computeSuggestions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ abstract class LocalDeclarationVisitor extends GeneralizingAstVisitor {

@override
void visitClassDeclaration(ClassDeclaration node) {
_visitClassDeclarationMembers(node);
_visitClassOrMixinMembers(node);
visitNode(node);
}

Expand Down Expand Up @@ -146,13 +146,13 @@ abstract class LocalDeclarationVisitor extends GeneralizingAstVisitor {
}

@override
visitConstructorDeclaration(ConstructorDeclaration node) {
void visitConstructorDeclaration(ConstructorDeclaration node) {
_visitParamList(node.parameters);
visitNode(node);
}

@override
visitForStatement(ForStatement node) {
void visitForStatement(ForStatement node) {
var forLoopParts = node.forLoopParts;
if (forLoopParts is ForEachPartsWithDeclaration) {
DeclaredIdentifier loopVariable = forLoopParts.loopVariable;
Expand Down Expand Up @@ -199,6 +199,12 @@ abstract class LocalDeclarationVisitor extends GeneralizingAstVisitor {
visitNode(node);
}

@override
void visitMixinDeclaration(MixinDeclaration node) {
_visitClassOrMixinMembers(node);
visitNode(node);
}

@override
void visitNode(AstNode node) {
// Support the case of searching partial ASTs by aborting on nodes with no
Expand Down Expand Up @@ -227,7 +233,7 @@ abstract class LocalDeclarationVisitor extends GeneralizingAstVisitor {
visitNode(node);
}

void _visitClassDeclarationMembers(ClassDeclaration node) {
void _visitClassOrMixinMembers(ClassOrMixinDeclaration node) {
for (ClassMember member in node.members) {
if (member is FieldDeclaration) {
member.fields.variables.forEach((VariableDeclaration varDecl) {
Expand Down Expand Up @@ -263,7 +269,7 @@ abstract class LocalDeclarationVisitor extends GeneralizingAstVisitor {
}
}

_visitStatements(NodeList<Statement> statements) {
void _visitStatements(NodeList<Statement> statements) {
for (Statement stmt in statements) {
if (stmt.offset < offset) {
if (stmt is VariableDeclarationStatement) {
Expand Down

0 comments on commit c7745a1

Please sign in to comment.