Skip to content

Commit

Permalink
Fix completion of static members from super classes
Browse files Browse the repository at this point in the history
Fixes #48873

Change-Id: Ife058f8b26e375da0e5f1768be86b7a0d3db15fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242280
Reviewed-by: Samuel Rawlins <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Brian Wilkerson <[email protected]>
  • Loading branch information
asashour authored and Commit Bot committed Apr 23, 2022
1 parent 1f27a7d commit 1bdec73
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,36 +99,42 @@ class LocalReferenceContributor extends DartCompletionContributor {
var opType = request.opType;
if (!isFunctionalArgument) {
for (var accessor in type.accessors) {
if (visibilityTracker._isVisible(accessor.declaration)) {
if (accessor.isGetter) {
if (opType.includeReturnValueSuggestions) {
memberBuilder.addSuggestionForAccessor(
accessor: accessor, inheritanceDistance: inheritanceDistance);
}
} else {
if (opType.includeVoidReturnSuggestions) {
memberBuilder.addSuggestionForAccessor(
accessor: accessor, inheritanceDistance: inheritanceDistance);
if (!accessor.isStatic) {
if (visibilityTracker._isVisible(accessor.declaration)) {
if (accessor.isGetter) {
if (opType.includeReturnValueSuggestions) {
memberBuilder.addSuggestionForAccessor(
accessor: accessor,
inheritanceDistance: inheritanceDistance);
}
} else {
if (opType.includeVoidReturnSuggestions) {
memberBuilder.addSuggestionForAccessor(
accessor: accessor,
inheritanceDistance: inheritanceDistance);
}
}
}
}
}
}
for (var method in type.methods) {
if (visibilityTracker._isVisible(method.declaration)) {
if (!method.returnType.isVoid) {
if (opType.includeReturnValueSuggestions) {
memberBuilder.addSuggestionForMethod(
method: method,
inheritanceDistance: inheritanceDistance,
kind: classMemberSuggestionKind);
}
} else {
if (opType.includeVoidReturnSuggestions) {
memberBuilder.addSuggestionForMethod(
method: method,
inheritanceDistance: inheritanceDistance,
kind: classMemberSuggestionKind);
if (!method.isStatic) {
if (visibilityTracker._isVisible(method.declaration)) {
if (!method.returnType.isVoid) {
if (opType.includeReturnValueSuggestions) {
memberBuilder.addSuggestionForMethod(
method: method,
inheritanceDistance: inheritanceDistance,
kind: classMemberSuggestionKind);
}
} else {
if (opType.includeVoidReturnSuggestions) {
memberBuilder.addSuggestionForMethod(
method: method,
inheritanceDistance: inheritanceDistance,
kind: classMemberSuggestionKind);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3651,6 +3651,50 @@ class B extends A1 with A2 {
assertSuggestMethod('y2', 'A2', 'int');
}

Future<void> test_inherited_static_field() async {
addTestSource('''
class A {
static int f1 = 1;
int f2 = 2;
}
class B extends A {
static int f3 = 3;
int f4 = 4;
void m() {
f^
}
}''');
await computeSuggestions();

assertNotSuggested('f1');
assertSuggestField('f2', 'int');
assertSuggestField('f3', 'int');
assertSuggestField('f4', 'int');
}

Future<void> test_inherited_static_method() async {
addTestSource('''
class A {
static void m1() {};
void m2() {};
}
class B extends A {
static void m3() {};
void m4() {};
void test() {
m^
}
}''');
await computeSuggestions();

assertNotSuggested('m1');
assertSuggestMethod('m2', 'A', 'void');
assertSuggestMethod('m3', 'B', 'void');
assertSuggestMethod('m4', 'B', 'void');
}

Future<void> test_InstanceCreationExpression() async {
addTestSource('''
class A {foo(){var f; {var x;}}}
Expand Down

0 comments on commit 1bdec73

Please sign in to comment.