mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:27:43 +00:00
[analysis_server] Don't show private static members in completion outside of library
Fixes https://github.com/Dart-Code/Dart-Code/issues/4772 Change-Id: I5a033b7464c2325f4f5db309254392e0ec337d07 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329605 Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
parent
08b4f49249
commit
ae78a3d8e5
|
@ -194,6 +194,7 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor<void> {
|
|||
// TODO(scheglov) This looks not ideal - we should suggest getters.
|
||||
for (final field in element.fields) {
|
||||
if (field.isStatic &&
|
||||
field.isAccessibleIn(request.libraryElement) &&
|
||||
typeSystem.isSubtypeOf(field.type, contextType)) {
|
||||
builder.suggestStaticField(field, prefix: prefix);
|
||||
}
|
||||
|
|
|
@ -373,4 +373,51 @@ suggestions
|
|||
kind: methodInvocation
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_expression_private_otherLibrary() async {
|
||||
newFile('$testPackageLibPath/a.dart', '''
|
||||
class A {
|
||||
// ignore: unused_field
|
||||
static const int _s1 = 1;
|
||||
}
|
||||
''');
|
||||
await computeSuggestions('''
|
||||
import 'a.dart';
|
||||
int f() {
|
||||
print(_s^
|
||||
}
|
||||
''');
|
||||
assertNoSuggestion(completion: 'A._s1');
|
||||
}
|
||||
|
||||
Future<void> test_expression_private_sameLibrary_otherFile() async {
|
||||
newFile('$testPackageLibPath/a.dart', '''
|
||||
part of 'test.dart';
|
||||
class A {
|
||||
// ignore: unused_field
|
||||
static const int _s1 = 1;
|
||||
}
|
||||
''');
|
||||
await computeSuggestions('''
|
||||
part 'a.dart';
|
||||
int f() {
|
||||
print(_s^
|
||||
}
|
||||
''');
|
||||
assertSuggestion(completion: 'A._s1');
|
||||
}
|
||||
|
||||
Future<void> test_expression_private_sameLibrary_sameFile() async {
|
||||
await computeSuggestions('''
|
||||
class A {
|
||||
// ignore: unused_field
|
||||
static const int _s1 = 1;
|
||||
}
|
||||
|
||||
int f() {
|
||||
print(_s^
|
||||
}
|
||||
''');
|
||||
assertSuggestion(completion: 'A._s1');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue