blob: 6e7253d1ee615fca989b15e6818512bd3d69a12b [file] [log] [blame]
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/src/protocol_server.dart';
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
import 'package:analysis_server/src/services/completion/dart/completion_manager.dart';
import 'package:analysis_server/src/services/completion/dart/local_reference_contributor.dart';
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'completion_contributor_util.dart';
void main() {
defineReflectiveSuite(() {
defineReflectiveTests(LocalReferenceContributorTest);
});
}
@reflectiveTest
class LocalReferenceContributorTest extends DartCompletionContributorTest {
@override
bool get isNullExpectedReturnTypeConsideredDynamic => false;
@override
DartCompletionContributor createContributor(
DartCompletionRequest request,
SuggestionBuilder builder,
) {
return LocalReferenceContributor(request, builder);
}
Future<void> test_ArgDefaults_function() async {
addTestSource('''
bool hasLength(int a, bool b) => false;
void f() {h^}''');
await computeSuggestions();
assertSuggestFunction('hasLength', 'bool',
defaultArgListString: 'a, b',
defaultArgumentListTextRanges: [0, 1, 3, 1]);
}
Future<void> test_ArgDefaults_function_none() async {
addTestSource('''
bool hasLength() => false;
void f() {h^}''');
await computeSuggestions();
assertSuggestFunction('hasLength', 'bool',
defaultArgListString: null, defaultArgumentListTextRanges: null);
}
Future<void> test_ArgDefaults_function_with_optional_positional() async {
writeTestPackageConfig(meta: true);
addTestSource('''
import 'package:meta/meta.dart';
bool foo(int bar, [bool boo, int baz]) => false;
void f() {h^}''');
await computeSuggestions();
assertSuggestFunction('foo', 'bool',
defaultArgListString: 'bar', defaultArgumentListTextRanges: [0, 3]);
}
Future<void> test_ArgDefaults_function_with_required_named() async {
writeTestPackageConfig(meta: true);
addTestSource('''
import 'package:meta/meta.dart';
bool foo(int bar, {bool boo, @required int baz}) => false;
void f() {h^}''');
await computeSuggestions();
assertSuggestFunction('foo', 'bool',
defaultArgListString: 'bar, baz: baz',
defaultArgumentListTextRanges: [0, 3, 10, 3]);
}
Future<void> test_ArgDefaults_inherited_method_with_required_named() async {
writeTestPackageConfig(meta: true);
resolveSource('/home/test/lib/b.dart', '''
import 'package:meta/meta.dart';
lib libB;
class A {
bool foo(int bar, {bool boo, @required int baz}) => false;
}''');
addTestSource('''
import "b.dart";
class B extends A {
b() => f^
}
''');
await computeSuggestions();
assertSuggestMethod('foo', 'A', 'bool',
defaultArgListString: 'bar, baz: baz');
}
Future<void> test_ArgDefaults_method_with_required_named() async {
writeTestPackageConfig(meta: true);
addTestSource('''
import 'package:meta/meta.dart';
class A {
bool foo(int bar, {bool boo, @required int baz}) => false;
baz() {
f^
}
}''');
await computeSuggestions();
assertSuggestMethod('foo', 'A', 'bool',
defaultArgListString: 'bar, baz: baz',
defaultArgumentListTextRanges: [0, 3, 10, 3]);
}
Future<void> test_ArgumentList() async {
// ArgumentList MethodInvocation ExpressionStatement Block
addSource('/home/test/lib/a.dart', '''
library A;
bool hasLength(int expected) { }
void baz() { }''');
addTestSource('''
import 'a.dart';;
class B { }
String bar() => true;
void f() {expect(^)}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestFunction('bar', 'String');
assertNotSuggested('hasLength');
assertNotSuggested('identical');
assertSuggestClass('B');
assertNotSuggested('Object');
assertNotSuggested('f');
assertNotSuggested('baz');
assertNotSuggested('print');
}
Future<void> test_ArgumentList_imported_function() async {
// ArgumentList MethodInvocation ExpressionStatement Block
addSource('/home/test/lib/a.dart', '''
library A;
bool hasLength(int expected) { }
expect(arg) { }
void baz() { }''');
addTestSource('''
import 'a.dart';
class B { }
String bar() => true;
void f() {expect(^)}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestFunction('bar', 'String');
assertNotSuggested('hasLength');
assertNotSuggested('identical');
assertSuggestClass('B');
assertNotSuggested('Object');
assertNotSuggested('f');
assertNotSuggested('baz');
assertNotSuggested('print');
}
Future<void>
test_ArgumentList_InstanceCreationExpression_functionalArg() async {
// ArgumentList InstanceCreationExpression ExpressionStatement Block
addSource('/home/test/lib/a.dart', '''
library A;
class A { A(f()) { } }
bool hasLength(int expected) { }
void baz() { }''');
addTestSource('''
import 'dart:async';
import 'a.dart';;
class B { }
String bar() => true;
void f() {new A(^)}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestFunction('bar', 'String',
kind: CompletionSuggestionKind.IDENTIFIER);
assertNotSuggested('hasLength');
assertNotSuggested('identical');
assertSuggestClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
assertNotSuggested('A');
assertNotSuggested('Object');
assertNotSuggested('f');
assertNotSuggested('baz');
assertNotSuggested('print');
}
Future<void> test_ArgumentList_InstanceCreationExpression_typedefArg() async {
// ArgumentList InstanceCreationExpression ExpressionStatement Block
addSource('/home/test/lib/a.dart', '''
library A;
typedef Funct();
class A { A(Funct f) { } }
bool hasLength(int expected) { }
void baz() { }''');
addTestSource('''
import 'dart:async';
import 'a.dart';;
class B { }
String bar() => true;
void f() {new A(^)}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestFunction('bar', 'String',
kind: CompletionSuggestionKind.IDENTIFIER);
assertNotSuggested('hasLength');
assertNotSuggested('identical');
assertSuggestClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
assertNotSuggested('A');
assertNotSuggested('Object');
assertNotSuggested('f');
assertNotSuggested('baz');
assertNotSuggested('print');
}
Future<void> test_ArgumentList_local_function() async {
// ArgumentList MethodInvocation ExpressionStatement Block
addSource('/home/test/lib/a.dart', '''
library A;
bool hasLength(int expected) { }
void baz() { }''');
addTestSource('''
import 'a.dart';
expect(arg) { }
class B { }
String bar() => true;
void f() {expect(^)}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestFunction('bar', 'String');
assertNotSuggested('hasLength');
assertNotSuggested('identical');
assertSuggestClass('B');
assertNotSuggested('Object');
assertNotSuggested('main');
assertNotSuggested('baz');
assertNotSuggested('print');
}
Future<void> test_ArgumentList_local_method() async {
// ArgumentList MethodInvocation ExpressionStatement Block
addSource('/home/test/lib/a.dart', '''
library A;
bool hasLength(int expected) { }
void baz() { }''');
addTestSource('''
import 'a.dart';
class B {
expect(arg) { }
void foo() {expect(^)}}
String bar() => true;''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestFunction('bar', 'String');
assertNotSuggested('hasLength');
assertNotSuggested('identical');
assertSuggestClass('B');
assertNotSuggested('Object');
assertNotSuggested('f');
assertNotSuggested('baz');
assertNotSuggested('print');
}
Future<void> test_ArgumentList_MethodInvocation_functionalArg() async {
// ArgumentList MethodInvocation ExpressionStatement Block
addSource('/home/test/lib/a.dart', '''
library A;
class A { A(f()) { } }
bool hasLength(int expected) { }
void baz() { }''');
addTestSource('''
import 'dart:async';
import 'a.dart';;
class B { }
String bar(f()) => true;
void f() {boo(){} bar(^);}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestFunction('bar', 'String',
kind: CompletionSuggestionKind.IDENTIFIER);
assertSuggestFunction('boo', 'Null',
kind: CompletionSuggestionKind.IDENTIFIER);
assertNotSuggested('hasLength');
assertNotSuggested('identical');
assertSuggestClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
assertNotSuggested('A');
assertNotSuggested('Object');
assertNotSuggested('f');
assertNotSuggested('baz');
assertNotSuggested('print');
}
Future<void> test_ArgumentList_MethodInvocation_functionalArg2() async {
// ArgumentList MethodInvocation ExpressionStatement Block
addSource('/home/test/lib/a.dart', '''
library A;
class A { A(f()) { } }
bool hasLength(int expected) { }
void baz() { }''');
addTestSource('''
import 'dart:async';
import 'a.dart';;
class B { }
String bar({inc()}) => true;
void f() {boo(){} bar(inc: ^);}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestFunction(
'bar',
'String',
kind: CompletionSuggestionKind.IDENTIFIER,
);
assertSuggestFunction(
'boo',
'Null',
kind: CompletionSuggestionKind.IDENTIFIER,
);
assertNotSuggested('hasLength');
assertNotSuggested('identical');
assertSuggestClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
assertNotSuggested('A');
assertNotSuggested('Object');
assertNotSuggested('baz');
assertNotSuggested('print');
}
Future<void> test_ArgumentList_MethodInvocation_methodArg() async {
// ArgumentList MethodInvocation ExpressionStatement Block
addSource('/home/test/lib/a.dart', '''
library A;
class A { A(f()) { } }
bool hasLength(int expected) { }
void baz() { }''');
addTestSource('''
import 'dart:async';
import 'a.dart';;
class B { String bar(f()) => true; }
void f() {new B().bar(^);}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertNotSuggested('hasLength');
assertNotSuggested('identical');
assertSuggestClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
assertNotSuggested('A');
assertNotSuggested('Object');
assertNotSuggested('f');
assertNotSuggested('baz');
assertNotSuggested('print');
}
Future<void> test_ArgumentList_namedFieldParam_tear_off() async {
addSource('/home/test/lib/a.dart', '''
typedef void VoidCallback();
class Button {
final VoidCallback onPressed;
Button({this.onPressed});
}
''');
addTestSource('''
import 'a.dart';;
class PageState {
void _incrementCounter() { }
build() =>
new Button(
onPressed: ^
);
}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggest('_incrementCounter',
csKind: CompletionSuggestionKind.IDENTIFIER);
}
Future<void> test_ArgumentList_namedParam() async {
// SimpleIdentifier NamedExpression ArgumentList MethodInvocation
// ExpressionStatement
addSource('/home/test/lib/a.dart', '''
library A;
bool hasLength(int expected) { }''');
addTestSource('''
import 'a.dart';
String bar() => true;
void f() {expect(foo: ^)}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestFunction('bar', 'String');
assertNotSuggested('hasLength');
assertNotSuggested('f');
}
Future<void> test_ArgumentList_namedParam_filter() async {
// SimpleIdentifier NamedExpression ArgumentList
// InstanceCreationExpression
addTestSource('''
class A {}
class B extends A {}
class C implements A {}
class D {}
class E {
A a;
E({A someA});
}
A a = new A();
B b = new B();
C c = new C();
D d = new D();
E e = new E(someA: ^);
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestTopLevelVar('a', 'A');
assertSuggestTopLevelVar('b', 'B');
assertSuggestTopLevelVar('c', 'C');
assertSuggestTopLevelVar('d', 'D');
assertSuggestTopLevelVar('e', 'E');
}
Future<void> test_ArgumentList_namedParam_tear_off() async {
addSource('/home/test/lib/a.dart', '''
typedef void VoidCallback();
class Button {
Button({VoidCallback onPressed});
}
''');
addTestSource('''
import 'a.dart';;
class PageState {
void _incrementCounter() { }
build() =>
new Button(
onPressed: ^
);
}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggest('_incrementCounter',
csKind: CompletionSuggestionKind.IDENTIFIER);
}
Future<void> test_ArgumentList_namedParam_tear_off_1() async {
addSource('/home/test/lib/a.dart', '''
typedef void VoidCallback();
class Button {
Button({VoidCallback onPressed, int x});
}
''');
addTestSource('''
import 'a.dart';;
class PageState {
void _incrementCounter() { }
build() =>
new Button(
onPressed: ^
);
}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggest('_incrementCounter',
csKind: CompletionSuggestionKind.IDENTIFIER);
}
Future<void> test_ArgumentList_namedParam_tear_off_2() async {
addSource('/home/test/lib/a.dart', '''
typedef void VoidCallback();
class Button {
Button({ int x, VoidCallback onPressed);
}
''');
addTestSource('''
import 'a.dart';;
class PageState {
void _incrementCounter() { }
build() =>
new Button(
onPressed: ^
);
}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggest('_incrementCounter',
csKind: CompletionSuggestionKind.IDENTIFIER);
}
Future<void> test_AsExpression_type() async {
// SimpleIdentifier TypeName AsExpression
addTestSource('''
class A {var b; X _c; foo() {var a; (a as ^).foo();}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertNotSuggested('b');
assertNotSuggested('_c');
assertNotSuggested('Object');
assertSuggestClass('A');
assertNotSuggested('==');
}
@failingTest
Future<void> test_AsExpression_type_filter_extends() async {
// This test fails because we are not filtering out the class `A` when
// suggesting types. We ought to do so because there's no reason to cast a
// value to the type it already has.
// SimpleIdentifier TypeName AsExpression
addTestSource('''
class A {} class B extends A {} class C extends A {} class D {}
f(A a){ (a as ^) }''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('B');
assertSuggestClass('C');
assertNotSuggested('A');
assertNotSuggested('D');
assertNotSuggested('Object');
}
@failingTest
Future<void> test_AsExpression_type_filter_implements() async {
// This test fails because we are not filtering out the class `A` when
// suggesting types. We ought to do so because there's no reason to cast a
// value to the type it already has.
// SimpleIdentifier TypeName AsExpression
addTestSource('''
class A {} class B implements A {} class C implements A {} class D {}
f(A a){ (a as ^) }''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('B');
assertSuggestClass('C');
assertNotSuggested('A');
assertNotSuggested('D');
assertNotSuggested('Object');
}
Future<void> test_AsExpression_type_filter_undefined_type() async {
// SimpleIdentifier TypeName AsExpression
addTestSource('''
class A {}
f(U u){ (u as ^) }''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('A');
}
Future<void> test_AssignmentExpression_name() async {
// SimpleIdentifier VariableDeclaration VariableDeclarationList
// VariableDeclarationStatement Block
addTestSource('class A {} void f() {int a; int ^b = 1;}');
await computeSuggestions();
assertNoSuggestions();
}
Future<void> test_AssignmentExpression_RHS() async {
// SimpleIdentifier VariableDeclaration VariableDeclarationList
// VariableDeclarationStatement Block
addTestSource('class A {} f() {int a; int b = ^}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestLocalVariable('a', 'int');
assertSuggestFunction('f', null);
assertSuggestClass('A');
assertNotSuggested('Object');
}
Future<void> test_AssignmentExpression_type() async {
// SimpleIdentifier TypeName VariableDeclarationList
// VariableDeclarationStatement Block
addTestSource('''
class A {} void f() {
int a;
^ b = 1;
}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('A');
assertNotSuggested('int');
// TODO (danrubel) When entering 1st of 2 identifiers on assignment LHS
// the user may be either (1) entering a type for the assignment
// or (2) starting a new statement.
// Consider suggesting only types
// if only spaces separates the 1st and 2nd identifiers.
//assertNotSuggested('a');
//assertNotSuggested('f');
//assertNotSuggested('identical');
}
Future<void> test_AssignmentExpression_type_newline() async {
// SimpleIdentifier TypeName VariableDeclarationList
// VariableDeclarationStatement Block
addTestSource('''
class A {} void f() {
int a;
^
b = 1;
}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('A');
assertNotSuggested('int');
// Allow non-types preceding an identifier on LHS of assignment
// if newline follows first identifier
// because user is probably starting a new statement
assertSuggestLocalVariable('a', 'int');
assertSuggestFunction('f', null);
assertNotSuggested('identical');
}
Future<void> test_AssignmentExpression_type_partial() async {
// SimpleIdentifier TypeName VariableDeclarationList
// VariableDeclarationStatement Block
addTestSource('''
class A {} void f() {
int a;
int^ b = 1;
}''');
await computeSuggestions();
expect(replacementOffset, completionOffset - 3);
expect(replacementLength, 3);
assertSuggestClass('A');
assertNotSuggested('int');
// TODO (danrubel) When entering 1st of 2 identifiers on assignment LHS
// the user may be either (1) entering a type for the assignment
// or (2) starting a new statement.
// Consider suggesting only types
// if only spaces separates the 1st and 2nd identifiers.
//assertNotSuggested('a');
//assertNotSuggested('f');
//assertNotSuggested('identical');
}
Future<void> test_AssignmentExpression_type_partial_newline() async {
// SimpleIdentifier TypeName VariableDeclarationList
// VariableDeclarationStatement Block
addTestSource('''
class A {} void f() {
int a;
i^
b = 1;
}''');
await computeSuggestions();
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertSuggestClass('A');
assertNotSuggested('int');
// Allow non-types preceding an identifier on LHS of assignment
// if newline follows first identifier
// because user is probably starting a new statement
assertSuggestLocalVariable('a', 'int');
assertSuggestFunction('f', null);
assertNotSuggested('identical');
}
Future<void> test_AwaitExpression() async {
// SimpleIdentifier AwaitExpression ExpressionStatement
addTestSource('''
class A {int x; int y() => 0;}
f() async {A a; await ^}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestLocalVariable('a', 'A');
assertSuggestFunction('f', null);
assertSuggestClass('A');
assertNotSuggested('Object');
}
Future<void> test_AwaitExpression2() async {
// SimpleIdentifier AwaitExpression ExpressionStatement
addTestSource('''
class A {
int x;
Future y() async {return 0;}
foo() async {await ^ await y();}
}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestMethod('y', 'A', 'Future<dynamic>');
assertSuggestClass('A');
assertNotSuggested('Object');
}
Future<void> test_AwaitExpression_inherited() async {
// SimpleIdentifier AwaitExpression ExpressionStatement
resolveSource('/home/test/lib/b.dart', '''
lib libB;
class A {
Future y() async {return 0;}
}''');
addTestSource('''
import "b.dart";
class B extends A {
Future a() async {return 0;}
foo() async {await ^}
}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggest('a', elemKind: ElementKind.METHOD);
assertSuggest('foo', elemKind: ElementKind.METHOD);
assertSuggest('B', elemKind: ElementKind.CLASS);
assertNotSuggested('A');
assertNotSuggested('Object');
assertSuggestMethod('y', 'A', 'Future<dynamic>');
}
Future<void> test_BinaryExpression_LHS() async {
// SimpleIdentifier BinaryExpression VariableDeclaration
// VariableDeclarationList VariableDeclarationStatement
addTestSource('void f() {int a = 1, b = ^ + 2;}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
// We should not have the type boost, but we do.
// The reason is that coveringNode is VariableDeclaration, and the
// entity is BinaryExpression, so the expected type is int.
// It would be more correct to use BinaryExpression as coveringNode.
assertSuggestLocalVariable('a', 'int');
assertNotSuggested('Object');
assertNotSuggested('b');
}
Future<void> test_BinaryExpression_RHS() async {
// SimpleIdentifier BinaryExpression VariableDeclaration
// VariableDeclarationList VariableDeclarationStatement
addTestSource('void f() {int a = 1, b = 2 + ^;}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestLocalVariable('a', 'int');
assertNotSuggested('Object');
assertNotSuggested('b');
assertNotSuggested('==');
}
Future<void> test_Block() async {
// Block BlockFunctionBody MethodDeclaration
addSource('/home/test/lib/ab.dart', '''
export "dart:math" hide max;
class A {int x;}
@deprecated D1() {int x;}
class _B {boo() { partBoo() {}} }''');
addSource('/home/test/lib/cd.dart', '''
String T1;
var _T2;
class C { }
class D { }''');
addSource('/home/test/lib/eef.dart', '''
class EE { }
class F { }''');
addSource('/home/test/lib/g.dart', 'class G { }');
addSource('/home/test/lib/h.dart', '''
class H { }
int T3;
var _T4;'''); // not imported
addTestSource('''
import "ab.dart";
import "cd.dart" hide D;
import "eef.dart" show EE;
import "g.dart" as g;
int T5;
var _T6;
String get T7 => 'hello';
set T8(int value) { partT8() {} }
Z D2() {int x;}
class X {
int get clog => 8;
set blog(value) { }
a() {
var f;
localF(int arg1) { }
{var x;}
^ var r;
}
void b() { }}
class Z { }''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('X', elemFile: testFile);
assertSuggestClass('Z');
assertSuggestMethod('a', 'X', null);
assertSuggestMethod('b', 'X', 'void');
assertSuggestFunction('localF', 'Null');
assertSuggestLocalVariable('f', null);
// Don't suggest locals out of scope
assertNotSuggested('r');
assertNotSuggested('x');
assertNotSuggested('partT8');
assertNotSuggested('A');
assertNotSuggested('_B');
assertNotSuggested('C');
assertNotSuggested('partBoo');
// hidden element suggested as low relevance
// but imported results are partially filtered
//assertNotSuggested('D');
//assertNotSuggested(
// 'D1', null, true, COMPLETION_RELEVANCE_LOW);
assertSuggestFunction('D2', 'Z');
assertNotSuggested('EE');
// hidden element suggested as low relevance
//assertNotSuggested('F');
// Suggested by LibraryPrefixContributor
assertNotSuggested('g');
assertNotSuggested('G');
//assertNotSuggested('H');
assertNotSuggested('Object');
assertNotSuggested('min');
assertNotSuggested('_T2');
//assertNotSuggested('T3');
assertNotSuggested('_T4');
assertSuggestTopLevelVar('T5', 'int');
assertSuggestTopLevelVar('_T6', null);
assertNotSuggested('==');
assertSuggestGetter('T7', 'String');
assertSuggestSetter('T8');
assertSuggestGetter('clog', 'int');
assertSuggestSetter('blog');
// TODO (danrubel) suggest HtmlElement as low relevance
assertNotSuggested('HtmlElement');
assertNotSuggested('Uri');
assertNotSuggested('parseIPv6Address');
assertNotSuggested('parseHex');
}
Future<void> test_Block_final() async {
// Block BlockFunctionBody MethodDeclaration
addSource('/home/test/lib/ab.dart', '''
export "dart:math" hide max;
class A {int x;}
@deprecated D1() {int x;}
class _B {boo() { partBoo() {}} }''');
addSource('/home/test/lib/cd.dart', '''
String T1;
var _T2;
class C { }
class D { }''');
addSource('/home/test/lib/eef.dart', '''
class EE { }
class F { }''');
addSource('/home/test/lib/g.dart', 'class G { }');
addSource('/home/test/lib/h.dart', '''
class H { }
int T3;
var _T4;'''); // not imported
addTestSource('''
import "ab.dart";
import "cd.dart" hide D;
import "eef.dart" show EE;
import "g.dart" as g;
int T5;
var _T6;
String get T7 => 'hello';
set T8(int value) { partT8() {} }
Z D2() {int x;}
class X {
int get clog => 8;
set blog(value) { }
a() {
var f;
localF(int arg1) { }
{var x;}
final ^
}
void b() { }}
class Z { }''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('X');
assertSuggestClass('Z');
assertNotSuggested('a');
assertNotSuggested('b');
assertNotSuggested('localF');
assertNotSuggested('f');
// Don't suggest locals out of scope
assertNotSuggested('r');
assertNotSuggested('x');
assertNotSuggested('partT8');
assertNotSuggested('A');
assertNotSuggested('_B');
assertNotSuggested('C');
assertNotSuggested('partBoo');
// hidden element suggested as low relevance
// but imported results are partially filtered
//assertNotSuggested('D');
//assertNotSuggested(
// 'D1', null, true, COMPLETION_RELEVANCE_LOW);
assertNotSuggested('D2');
assertNotSuggested('EE');
// hidden element suggested as low relevance
//assertNotSuggested('F');
// Suggested by LibraryPrefixContributor
assertNotSuggested('g');
assertNotSuggested('G');
//assertNotSuggested('H');
assertNotSuggested('Object');
assertNotSuggested('min');
//assertNotSuggested(
// 'max',
// 'num',
// false,
// COMPLETION_RELEVANCE_LOW);
assertNotSuggested('T1');
assertNotSuggested('_T2');
//assertNotSuggested('T3');
assertNotSuggested('_T4');
assertNotSuggested('T5');
assertNotSuggested('_T6');
assertNotSuggested('==');
assertNotSuggested('T7');
assertNotSuggested('T8');
assertNotSuggested('clog');
assertNotSuggested('blog');
// TODO (danrubel) suggest HtmlElement as low relevance
assertNotSuggested('HtmlElement');
assertNotSuggested('Uri');
assertNotSuggested('parseIPv6Address');
assertNotSuggested('parseHex');
}
Future<void> test_Block_final2() async {
addTestSource('void f() {final S^ v;}');
await computeSuggestions();
assertNotSuggested('String');
}
Future<void> test_Block_final3() async {
addTestSource('void f() {final ^ v;}');
await computeSuggestions();
assertNotSuggested('String');
}
Future<void> test_Block_final_final() async {
// Block BlockFunctionBody MethodDeclaration
addSource('/home/test/lib/ab.dart', '''
export "dart:math" hide max;
class A {int x;}
@deprecated D1() {int x;}
class _B {boo() { partBoo() {}} }''');
addSource('/home/test/lib/cd.dart', '''
String T1;
var _T2;
class C { }
class D { }''');
addSource('/home/test/lib/eef.dart', '''
class EE { }
class F { }''');
addSource('/home/test/lib/g.dart', 'class G { }');
addSource('/home/test/lib/h.dart', '''
class H { }
int T3;
var _T4;'''); // not imported
addTestSource('''
import "ab.dart";
import "cd.dart" hide D;
import "eef.dart" show EE;
import "g.dart" as g;
int T5;
var _T6;
String get T7 => 'hello';
set T8(int value) { partT8() {} }
Z D2() {int x;}
class X {
int get clog => 8;
set blog(value) { }
a() {
final ^
final var f;
localF(int arg1) { }
{var x;}
}
void b() { }}
class Z { }''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('X');
assertSuggestClass('Z');
assertNotSuggested('a');
assertNotSuggested('b');
assertNotSuggested('localF');
assertNotSuggested('f');
// Don't suggest locals out of scope
assertNotSuggested('r');
assertNotSuggested('x');
assertNotSuggested('partT8');
assertNotSuggested('A');
assertNotSuggested('_B');
assertNotSuggested('C');
assertNotSuggested('partBoo');
// hidden element suggested as low relevance
// but imported results are partially filtered
//assertNotSuggested('D');
//assertNotSuggested(
// 'D1', null, true, COMPLETION_RELEVANCE_LOW);
assertNotSuggested('D2');
assertNotSuggested('EE');
// hidden element suggested as low relevance
//assertNotSuggested('F');
// Suggested by LibraryPrefixContributor
assertNotSuggested('g');
assertNotSuggested('G');
//assertNotSuggested('H');
assertNotSuggested('Object');
assertNotSuggested('min');
//assertNotSuggested(
// 'max',
// 'num',
// false,
// COMPLETION_RELEVANCE_LOW);
assertNotSuggested('T1');
assertNotSuggested('_T2');
//assertNotSuggested('T3');
assertNotSuggested('_T4');
assertNotSuggested('T5');
assertNotSuggested('_T6');
assertNotSuggested('==');
assertNotSuggested('T7');
assertNotSuggested('T8');
assertNotSuggested('clog');
assertNotSuggested('blog');
// TODO (danrubel) suggest HtmlElement as low relevance
assertNotSuggested('HtmlElement');
assertNotSuggested('Uri');
assertNotSuggested('parseIPv6Address');
assertNotSuggested('parseHex');
}
Future<void> test_Block_final_var() async {
// Block BlockFunctionBody MethodDeclaration
addSource('/home/test/lib/ab.dart', '''
export "dart:math" hide max;
class A {int x;}
@deprecated D1() {int x;}
class _B {boo() { partBoo() {}} }''');
addSource('/home/test/lib/cd.dart', '''
String T1;
var _T2;
class C { }
class D { }''');
addSource('/home/test/lib/eef.dart', '''
class EE { }
class F { }''');
addSource('/home/test/lib/g.dart', 'class G { }');
addSource('/home/test/lib/h.dart', '''
class H { }
int T3;
var _T4;'''); // not imported
addTestSource('''
import "ab.dart";
import "cd.dart" hide D;
import "eef.dart" show EE;
import "g.dart" as g;
int T5;
var _T6;
String get T7 => 'hello';
set T8(int value) { partT8() {} }
Z D2() {int x;}
class X {
int get clog => 8;
set blog(value) { }
a() {
final ^
var f;
localF(int arg1) { }
{var x;}
}
void b() { }}
class Z { }''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('X');
assertSuggestClass('Z');
assertNotSuggested('a');
assertNotSuggested('b');
assertNotSuggested('localF');
assertNotSuggested('f');
// Don't suggest locals out of scope
assertNotSuggested('r');
assertNotSuggested('x');
assertNotSuggested('partT8');
assertNotSuggested('A');
assertNotSuggested('_B');
assertNotSuggested('C');
assertNotSuggested('partBoo');
// hidden element suggested as low relevance
// but imported results are partially filtered
//assertNotSuggested('D');
//assertNotSuggested(
// 'D1', null, true, COMPLETION_RELEVANCE_LOW);
assertNotSuggested('D2');
assertNotSuggested('EE');
// hidden element suggested as low relevance
//assertNotSuggested('F');
// Suggested by LibraryPrefixContributor
assertNotSuggested('g');
assertNotSuggested('G');
//assertNotSuggested('H');
assertNotSuggested('Object');
assertNotSuggested('min');
//assertNotSuggested(
// 'max',
// 'num',
// false,
// COMPLETION_RELEVANCE_LOW);
assertNotSuggested('T1');
assertNotSuggested('_T2');
//assertNotSuggested('T3');
assertNotSuggested('_T4');
assertNotSuggested('T5');
assertNotSuggested('_T6');
assertNotSuggested('==');
assertNotSuggested('T7');
assertNotSuggested('T8');
assertNotSuggested('clog');
assertNotSuggested('blog');
// TODO (danrubel) suggest HtmlElement as low relevance
assertNotSuggested('HtmlElement');
assertNotSuggested('Uri');
assertNotSuggested('parseIPv6Address');
assertNotSuggested('parseHex');
}
Future<void> test_Block_identifier_partial() async {
addSource('/home/test/lib/ab.dart', '''
export "dart:math" hide max;
class A {int x;}
@deprecated D1() {int x;}
class _B { }''');
addSource('/home/test/lib/cd.dart', '''
String T1;
var _T2;
class C { }
class D { }''');
addSource('/home/test/lib/eef.dart', '''
class EE { }
class F { }''');
addSource('/home/test/lib/g.dart', 'class G { }');
addSource('/home/test/lib/h.dart', '''
class H { }
class D3 { }
int T3;
var _T4;'''); // not imported
addTestSource('''
import "ab.dart";
import "cd.dart" hide D;
import "eef.dart" show EE;
import "g.dart" as g;
int T5;
var _T6;
Z D2() {int x;}
class X {a() {var f; {var x;} D^ var r;} void b() { }}
class Z { }''');
await computeSuggestions();
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertSuggestClass('X');
assertSuggestClass('Z');
assertSuggestMethod('a', 'X', null);
assertSuggestMethod('b', 'X', 'void');
assertSuggestLocalVariable('f', null);
// Don't suggest locals out of scope
assertNotSuggested('r');
assertNotSuggested('x');
// imported elements are portially filtered
//assertNotSuggested('A');
assertNotSuggested('_B');
//assertNotSuggested('C');
// hidden element suggested as low relevance
assertNotSuggested('D');
assertNotSuggested('D1');
assertSuggestFunction('D2', 'Z');
// unimported elements suggested with low relevance
assertNotSuggested('D3');
//assertNotSuggested('EE');
// hidden element suggested as low relevance
//assertNotSuggested('F');
//assertSuggestLibraryPrefix('g');
assertNotSuggested('G');
//assertNotSuggested('H');
//assertNotSuggested('Object');
//assertNotSuggested('min');
//assertNotSuggested(
// 'max',
// 'num',
// false,
// COMPLETION_RELEVANCE_LOW);
//assertSuggestTopLevelVarGetterSetter('T1', 'String');
assertNotSuggested('_T2');
//assertNotSuggested('T3');
assertNotSuggested('_T4');
//assertSuggestTopLevelVar('T5', 'int', relevance: DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE);
//assertSuggestTopLevelVar('_T6', null);
assertNotSuggested('==');
// TODO (danrubel) suggest HtmlElement as low relevance
assertNotSuggested('HtmlElement');
}
Future<void> test_Block_inherited_imported() async {
// Block BlockFunctionBody MethodDeclaration ClassDeclaration
resolveSource('/home/test/lib/b.dart', '''
lib B;
class F { var f1; f2() { } get f3 => 0; set f4(fx) { } var _pf; }
class E extends F { var e1; e2() { } }
class I { int i1; i2() { } }
class M { var m1; int m2() { } }''');
addTestSource('''
import "b.dart";
class A extends E implements I with M {a() {^}}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggest('e1', elemKind: ElementKind.FIELD);
assertSuggest('f1', elemKind: ElementKind.FIELD);
assertSuggest('i1', elemKind: ElementKind.FIELD);
assertSuggest('m1', elemKind: ElementKind.FIELD);
assertSuggest('f3', elemKind: ElementKind.GETTER);
assertSuggest('f4', elemKind: ElementKind.SETTER);
assertSuggest('e2', elemKind: ElementKind.METHOD);
assertSuggest('f2', elemKind: ElementKind.METHOD);
assertSuggest('i2', elemKind: ElementKind.METHOD);
assertSuggest('m2', elemKind: ElementKind.METHOD);
assertSuggest('toString', elemKind: ElementKind.METHOD);
}
Future<void> test_Block_inherited_imported_from_constructor() async {
// Block BlockFunctionBody ConstructorDeclaration ClassDeclaration
resolveSource('/home/test/lib/b.dart', '''
lib B;
class F { var f1; f2() { } get f3 => 0; set f4(fx) { } var _pf; }
class E extends F { var e1; e2() { } }
class I { int i1; i2() { } }
class M { var m1; int m2() { } }''');
addTestSource('''
import "b.dart";
class A extends E implements I with M {const A() {^}}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestField('e1', null);
assertSuggestField('f1', null);
assertSuggestField('i1', 'int');
assertSuggestField('m1', null);
assertSuggestGetter('f3', null);
assertSuggestSetter('f4');
assertSuggestMethod('e2', 'E', null);
assertSuggestMethod('f2', 'F', null);
assertSuggestMethod('i2', 'I', null);
assertSuggestMethod('m2', 'M', 'int');
assertNotSuggested('==');
}
Future<void> test_Block_inherited_imported_from_method() async {
// Block BlockFunctionBody MethodDeclaration ClassDeclaration
resolveSource('/home/test/lib/b.dart', '''
lib B;
class F { var f1; f2() { } get f3 => 0; set f4(fx) { } var _pf; }
class E extends F { var e1; e2() { } }
class I { int i1; i2() { } }
class M { var m1; int m2() { } }''');
addTestSource('''
import "b.dart";
class A extends E implements I with M {a() {^}}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestField('e1', null);
assertSuggestField('f1', null);
assertSuggestField('i1', 'int');
assertSuggestField('m1', null);
assertSuggestGetter('f3', null);
assertSuggestSetter('f4');
assertSuggestMethod('e2', 'E', null);
assertSuggestMethod('f2', 'F', null);
assertSuggestMethod('i2', 'I', null);
assertSuggestMethod('m2', 'M', 'int');
assertNotSuggested('==');
}
Future<void> test_Block_inherited_local() async {
// Block BlockFunctionBody MethodDeclaration ClassDeclaration
addTestSource('''
class F { var f1; f2() { } get f3 => 0; set f4(fx) { } }
class E extends F { var e1; e2() { } }
class I { int i1; i2() { } }
class M { var m1; int m2() { } }
class A extends E implements I with M {a() {^}}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggest('e1', elemKind: ElementKind.FIELD);
assertSuggest('f1', elemKind: ElementKind.FIELD);
assertSuggest('i1', elemKind: ElementKind.FIELD);
assertSuggest('m1', elemKind: ElementKind.FIELD);
assertSuggest('f3', elemKind: ElementKind.GETTER);
assertSuggest('f4', elemKind: ElementKind.SETTER);
assertSuggest('e2', elemKind: ElementKind.METHOD);
assertSuggest('f2', elemKind: ElementKind.METHOD);
assertSuggest('i2', elemKind: ElementKind.METHOD);
assertSuggest('m2', elemKind: ElementKind.METHOD);
assertSuggest('toString', elemKind: ElementKind.METHOD);
}
Future<void> test_Block_inherited_local_from_constructor() async {
// Block BlockFunctionBody ConstructorDeclaration ClassDeclaration
addTestSource('''
class F { var f1; f2() { } get f3 => 0; set f4(fx) { } }
class E extends F { var e1; e2() { } }
class I { int i1; i2() { } }
class M { var m1; int m2() { } }
class A extends E implements I with M {const A() {^}}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestField('e1', null);
assertSuggestField('f1', null);
assertSuggestField('i1', 'int');
assertSuggestField('m1', null);
assertSuggestGetter('f3', null);
assertSuggestSetter('f4');
assertSuggestMethod('e2', 'E', null);
assertSuggestMethod('f2', 'F', null);
assertSuggestMethod('i2', 'I', null);
assertSuggestMethod('m2', 'M', 'int');
}
Future<void> test_Block_inherited_local_from_method() async {
// Block BlockFunctionBody MethodDeclaration ClassDeclaration
addTestSource('''
class F { var f1; f2() { } get f3 => 0; set f4(fx) { } }
class E extends F { var e1; e2() { } }
class I { int i1; i2() { } }
class M { var m1; int m2() { } }
class A extends E implements I with M {a() {^}}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestField('e1', null);
assertSuggestField('f1', null);
assertSuggestField('i1', 'int');
assertSuggestField('m1', null);
assertSuggestGetter('f3', null);
assertSuggestSetter('f4');
assertSuggestMethod('e2', 'E', null);
assertSuggestMethod('f2', 'F', null);
assertSuggestMethod('i2', 'I', null);
assertSuggestMethod('m2', 'M', 'int');
}
Future<void> test_Block_local_function() async {
addSource('/home/test/lib/ab.dart', '''
export "dart:math" hide max;
class A {int x;}
@deprecated D1() {int x;}
class _B {boo() { partBoo() {}} }''');
addSource('/home/test/lib/cd.dart', '''
String T1;
var _T2;
class C { }
class D { }''');
addSource('/home/test/lib/eef.dart', '''
class EE { }
class F { }''');
addSource('/home/test/lib/g.dart', 'class G { }');
addSource('/home/test/lib/h.dart', '''
class H { }
int T3;
var _T4;'''); // not imported
addTestSource('''
import "ab.dart";
import "cd.dart" hide D;
import "eef.dart" show EE;
import "g.dart" as g;
int T5;
var _T6;
String get T7 => 'hello';
set T8(int value) { partT8() {} }
Z D2() {int x;}
class X {
int get clog => 8;
set blog(value) { }
a() {
var f;
localF(int arg1) { }
{var x;}
p^ var r;
}
void b() { }}
class Z { }''');
await computeSuggestions();
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertNotSuggested('partT8');
assertNotSuggested('partBoo');
assertNotSuggested('parseIPv6Address');
assertNotSuggested('parseHex');
}
Future<void> test_Block_setterWithoutParameters() async {
addTestSource('''
set foo() {}
void f() {
^
}
''');
await computeSuggestions();
assertSuggestSetter('foo');
}
Future<void> test_Block_unimported() async {
newFile('$testPackageLibPath/a.dart', content: 'class A {}');
addTestSource('void f() { ^ }');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
// Not imported, so not suggested
assertNotSuggested('A');
assertNotSuggested('Future');
}
Future<void> test_CascadeExpression_selector1() async {
// PropertyAccess CascadeExpression ExpressionStatement Block
addSource('/home/test/lib/b.dart', '''
class B { }''');
addTestSource('''
import "b.dart";
class A {var b; X _c;}
class X{}
// looks like a cascade to the parser
// but the user is trying to get completions for a non-cascade
void f() {A a; a.^.z}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertNotSuggested('b');
assertNotSuggested('_c');
assertNotSuggested('Object');
assertNotSuggested('A');
assertNotSuggested('B');
assertNotSuggested('X');
assertNotSuggested('z');
assertNotSuggested('==');
}
Future<void> test_CascadeExpression_selector2() async {
// SimpleIdentifier PropertyAccess CascadeExpression ExpressionStatement
addSource('/home/test/lib/b.dart', '''
class B { }''');
addTestSource('''
import "b.dart";
class A {var b; X _c;}
class X{}
void f() {A a; a..^z}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 1);
assertNotSuggested('b');
assertNotSuggested('_c');
assertNotSuggested('Object');
assertNotSuggested('A');
assertNotSuggested('B');
assertNotSuggested('X');
assertNotSuggested('z');
assertNotSuggested('==');
}
Future<void> test_CascadeExpression_selector2_withTrailingReturn() async {
// PropertyAccess CascadeExpression ExpressionStatement Block
addSource('/home/test/lib/b.dart', '''
class B { }''');
addTestSource('''
import "b.dart";
class A {var b; X _c;}
class X{}
void f() {A a; a..^ return}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertNotSuggested('b');
assertNotSuggested('_c');
assertNotSuggested('Object');
assertNotSuggested('A');
assertNotSuggested('B');
assertNotSuggested('X');
assertNotSuggested('z');
assertNotSuggested('==');
}
Future<void> test_CascadeExpression_target() async {
// SimpleIdentifier CascadeExpression ExpressionStatement
addTestSource('''
class A {var b; X _c;}
class X{}
void f() {A a; a^..b}''');
await computeSuggestions();
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertNotSuggested('b');
assertNotSuggested('_c');
assertSuggestLocalVariable('a', 'A');
assertSuggestClass('A');
assertSuggestClass('X');
// top level results are partially filtered
//assertNotSuggested('Object');
assertNotSuggested('==');
}
Future<void> test_CatchClause_onType() async {
// TypeName CatchClause TryStatement
addTestSource('class A {a() {try{var x;} on ^ {}}}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('A');
assertNotSuggested('Object');
assertNotSuggested('a');
assertNotSuggested('x');
}
Future<void> test_CatchClause_onType_noBrackets() async {
// TypeName CatchClause TryStatement
addTestSource('class A {a() {try{var x;} on ^}}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('A', elemOffset: 6);
assertNotSuggested('Object');
assertNotSuggested('x');
}
Future<void> test_CatchClause_typed() async {
// Block CatchClause TryStatement
addTestSource('''
class A {
a() {
try {
var x;
} on E catch (e) {
^
}
}
}
class E {}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestParameter('e', 'E');
assertSuggestMethod('a', 'A', null);
assertNotSuggested('Object');
assertNotSuggested('x');
}
Future<void> test_CatchClause_untyped() async {
// Block CatchClause TryStatement
addTestSource('class A {a() {try{var x;} catch (e, s) {^}}}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestParameter('e', 'Object');
assertSuggestParameter('s', 'StackTrace');
assertSuggestMethod('a', 'A', null);
assertNotSuggested('Object');
assertNotSuggested('x');
}
Future<void> test_ClassDeclaration_body() async {
// ClassDeclaration CompilationUnit
addSource('/home/test/lib/b.dart', '''
class B { }''');
addTestSource('''
import "b.dart" as x;
@deprecated class A {^}
class _B {}
A T;''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
var suggestionA = assertSuggestClass('A', isDeprecated: true).element;
if (suggestionA != null) {
expect(suggestionA.isDeprecated, isTrue);
expect(suggestionA.isPrivate, isFalse);
}
var suggestionB = assertSuggestClass('_B').element;
if (suggestionB != null) {
expect(suggestionB.isDeprecated, isFalse);
expect(suggestionB.isPrivate, isTrue);
}
assertNotSuggested('Object');
assertNotSuggested('T');
// Suggested by LibraryPrefixContributor
assertNotSuggested('x');
}
Future<void> test_ClassDeclaration_body_final() async {
// ClassDeclaration CompilationUnit
addSource('/home/test/lib/b.dart', '''
class B { }''');
addTestSource('''
import "b.dart" as x;
class A {final ^}
class _B {}
A T;''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('A');
assertSuggestClass('_B');
assertNotSuggested('Object');
assertNotSuggested('T');
// Suggested by LibraryPrefixContributor
assertNotSuggested('x');
}
Future<void> test_ClassDeclaration_body_final_field() async {
// ClassDeclaration CompilationUnit
addSource('/home/test/lib/b.dart', '''
class B { }''');
addTestSource('''
import "b.dart" as x;
class A {final ^ A(){}}
class _B {}
A T;''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('A');
assertSuggestClass('_B');
assertNotSuggested('String');
assertNotSuggested('T');
// Suggested by LibraryPrefixContributor
assertNotSuggested('x');
}
Future<void> test_ClassDeclaration_body_final_field2() async {
// ClassDeclaration CompilationUnit
addSource('/home/test/lib/b.dart', '''
class B { }''');
addTestSource('''
import "b.dart" as Soo;
class A {final S^ A();}
class _B {}
A Sew;''');
await computeSuggestions();
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertSuggestClass('A');
assertSuggestClass('_B');
assertNotSuggested('String');
assertNotSuggested('Sew');
// Suggested by LibraryPrefixContributor
assertNotSuggested('Soo');
}
Future<void> test_ClassDeclaration_body_final_final() async {
// ClassDeclaration CompilationUnit
addSource('/home/test/lib/b.dart', '''
class B { }''');
addTestSource('''
import "b.dart" as x;
class A {final ^ final foo;}
class _B {}
A T;''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('A');
assertSuggestClass('_B');
assertNotSuggested('Object');
assertNotSuggested('T');
// Suggested by LibraryPrefixContributor
assertNotSuggested('x');
}
Future<void> test_ClassDeclaration_body_final_var() async {
// ClassDeclaration CompilationUnit
addSource('/home/test/lib/b.dart', '''
class B { }''');
addTestSource('''
import "b.dart" as x;
class A {final ^ var foo;}
class _B {}
A T;''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestClass('A');
assertSuggestClass('_B');
assertNotSuggested('Object');
assertNotSuggested('T');
// Suggested by LibraryPrefixContributor
assertNotSuggested('x');
}
Future<void> test_classReference_in_comment() async {
addTestSource(r'''
class Abc { }
class Abcd { }
// A^
class Foo { }
''');
await computeSuggestions();
assertNotSuggested('Abc');
assertNotSuggested('Abcd');
}
Future<void> test_classReference_in_comment_eof() async {
addTestSource(r'''
class Abc { }
class Abcd { }
// A^
''');
await computeSuggestions();
assertNotSuggested('Abc');
assertNotSuggested('Abcd');
}
Future<void> test_Combinator_hide() async {
// SimpleIdentifier HideCombinator ImportDirective
addSource('/home/test/lib/ab.dart', '''
library libAB;
part 'partAB.dart';
class A { }
class B { }''');
addSource('/partAB.dart', '''
part of libAB;
var T1;
PB F1() => new PB();
class PB { }''');
addSource('/home/test/lib/cd.dart', '''
class C { }
class D { }''');
addTestSource('''
import "ab.dart" hide ^;
import "cd.dart";
class X {}''');
await computeSuggestions();
assertNoSuggestions();
}
Future<void> test_Combinator_show() async {
// SimpleIdentifier HideCombinator ImportDirective
addSource('/home/test/lib/ab.dart', '''
library libAB;
part 'partAB.dart';
class A { }
class B { }''');
addSource('/partAB.dart', '''
part of libAB;
var T1;
PB F1() => new PB();
typedef PB2 F2(int blat);
class Clz = Object with Object;
class PB { }''');
addSource('/home/test/lib/cd.dart', '''
class C { }
class D { }''');
addTestSource('''
import "ab.dart" show ^;
import "cd.dart";
class X {}''');
await computeSuggestions();
assertNoSuggestions();
}
Future<void> test_ConditionalExpression_elseExpression() async {
// SimpleIdentifier ConditionalExpression ReturnStatement
addSource('/home/test/lib/a.dart', '''
int T1;
F1() { }
class A {int x;}''');
addTestSource('''
import "a.dart";
int T2;
F2() { }
class B {int x;}
class C {foo(){var f; {var x;} return a ? T1 : T^}}''');
await computeSuggestions();
// top level results are partially filtered based on first char
assertSuggestTopLevelVar('T2', 'int');
// TODO (danrubel) getter is being suggested instead of top level var
//assertNotSuggested('T1');
}
Future<void> test_ConditionalExpression_elseExpression_empty() async {
// SimpleIdentifier ConditionalExpression ReturnStatement
addSource('/home/test/lib/a.dart', '''
int T1;
F1() { }
class A {int x;}''');
addTestSource('''
import "a.dart";
int T2;
F2() { }
class B {int x;}
class C {foo(){var f; {var x;} return a ? T1 : ^}}''');
await computeSuggestions();
assertNotSuggested('x');
assertSuggestLocalVariable('f', null);
assertSuggestMethod('foo', 'C', null);
assertSuggestClass('C');
assertSuggestFunction('F2', null);
assertSuggestTopLevelVar('T2', 'int');
assertNotSuggested('A');
assertNotSuggested('F1');
// TODO (danrubel) getter is being suggested instead of top level var
//assertNotSuggested('T1');
}
Future<void> test_ConditionalExpression_partial_thenExpression() async {
// SimpleIdentifier ConditionalExpression ReturnStatement
addSource('/home/test/lib/a.dart', '''
int T1;
F1() { }
class A {int x;}''');
addTestSource('''
import "a.dart";
int T2;
F2() { }
class B {int x;}
class C {foo(){var f; {var x;} return a ? T^}}''');
await computeSuggestions();
// top level results are partially filtered based on first char
assertSuggestTopLevelVar('T2', 'int');
// TODO (danrubel) getter is being suggested instead of top level var
//assertNotSuggested('T1');
}
Future<void> test_ConditionalExpression_partial_thenExpression_empty() async {
// SimpleIdentifier ConditionalExpression ReturnStatement
addSource('/home/test/lib/a.dart', '''
int T1;
F1() { }
class A {int x;}''');
addTestSource('''
import "a.dart";
int T2;
F2() { }
class B {int x;}
class C {foo(){var f; {var x;} return a ? ^}}''');
await computeSuggestions();
assertNotSuggested('x');
assertSuggestLocalVariable('f', null);
assertSuggestMethod('foo', 'C', null);
assertSuggestClass('C');
assertSuggestFunction('F2', null);
assertSuggestTopLevelVar('T2', 'int');
assertNotSuggested('A');
assertNotSuggested('F1');
// TODO (danrubel) getter is being suggested instead of top level var
//assertNotSuggested('T1');
}
Future<void> test_ConditionalExpression_thenExpression() async {
// SimpleIdentifier ConditionalExpression ReturnStatement
addSource('/home/test/lib/a.dart', '''
int T1;
F1() { }
class A {int x;}''');
addTestSource('''
import "a.dart";
int T2;
F2() { }
class B {int x;}
class C {foo(){var f; {var x;} return a ? T^ : c}}''');
await computeSuggestions();
// top level results are partially filtered based on first char
assertSuggestTopLevelVar('T2', 'int');
// TODO (danrubel) getter is being suggested instead of top level var
//assertNotSuggested('T1');
}
Future<void> test_constructor_parameters_mixed_required_and_named() async {
addTestSource('class A {A(x, {int y}) {^}}');
await computeSuggestions();
assertSuggestParameter('x', null);
assertSuggestParameter('y', 'int');
}
Future<void>
test_constructor_parameters_mixed_required_and_positional() async {
addTestSource('class A {A(x, [int y]) {^}}');
await computeSuggestions();
assertSuggestParameter('x', null);
assertSuggestParameter('y', 'int');
}
Future<void> test_constructor_parameters_named() async {
addTestSource('class A {A({x, int y}) {^}}');
await computeSuggestions();
assertSuggestParameter('x', null);
assertSuggestParameter('y', 'int');
}
Future<void> test_constructor_parameters_positional() async {
addTestSource('class A {A([x, int y]) {^}}');
await computeSuggestions();
assertSuggestParameter('x', null);
assertSuggestParameter('y', 'int');
}
Future<void> test_constructor_parameters_required() async {
addTestSource('class A {A(x, int y) {^}}');
await computeSuggestions();
assertSuggestParameter('x', null);
assertSuggestParameter('y', 'int');
}
Future<void> test_ConstructorFieldInitializer_name() async {
addTestSource('''
class A {
final int foo;
A() : ^
}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestField('foo', 'int');
}
Future<void> test_ConstructorFieldInitializer_value() async {
addTestSource('''
var foo = 0;
class A {
final int bar;
A() : bar = ^
}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestTopLevelVar('foo', 'int');
}
Future<void> test_ConstructorName_importedClass() async {
// SimpleIdentifier PrefixedIdentifier TypeName ConstructorName
// InstanceCreationExpression
addSource('/home/test/lib/b.dart', '''
lib B;
int T1;
F1() { }
class X {X.c(); X._d(); z() {}}''');
addTestSource('''
import "b.dart";
var m;
void f() {new X.^}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
// Suggested by NamedConstructorContributor
assertNotSuggested('c');
assertNotSuggested('F1');
assertNotSuggested('T1');
assertNotSuggested('_d');
assertNotSuggested('z');
assertNotSuggested('m');
}
Future<void> test_ConstructorName_importedFactory() async {
// SimpleIdentifier PrefixedIdentifier TypeName ConstructorName
// InstanceCreationExpression
addSource('/home/test/lib/b.dart', '''
lib B;
int T1;
F1() { }
class X {factory X.c(); factory X._d(); z() {}}''');
addTestSource('''
import "b.dart";
var m;
void f() {new X.^}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
// Suggested by NamedConstructorContributor
assertNotSuggested('c');
assertNotSuggested('F1');
assertNotSuggested('T1');
assertNotSuggested('_d');
assertNotSuggested('z');
assertNotSuggested('m');
}
Future<void> test_ConstructorName_importedFactory2() async {
// SimpleIdentifier PrefixedIdentifier TypeName ConstructorName
// InstanceCreationExpression
addTestSource('''
void f() {new String.fr^omCharCodes([]);}''');
await computeSuggestions();
expect(replacementOffset, completionOffset - 2);
expect(replacementLength, 13);
// Suggested by NamedConstructorContributor
assertNotSuggested('fromCharCodes');
assertNotSuggested('isEmpty');
assertNotSuggested('isNotEmpty');
assertNotSuggested('length');
assertNotSuggested('Object');
assertNotSuggested('String');
}
Future<void> test_ConstructorName_localClass() async {
// SimpleIdentifier PrefixedIdentifier TypeName ConstructorName
// InstanceCreationExpression
addTestSource('''
int T1;
F1() { }
class X {X.c(); X._d(); z() {}}
void f() {new X.^}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
// Suggested by NamedConstructorContributor
assertNotSuggested('c');
assertNotSuggested('_d');
assertNotSuggested('F1');
assertNotSuggested('T1');
assertNotSuggested('z');
assertNotSuggested('m');
}
Future<void> test_ConstructorName_localFactory() async {
// SimpleIdentifier PrefixedIdentifier TypeName ConstructorName
// InstanceCreationExpression
addTestSource('''
int T1;
F1() { }
class X {factory X.c(); factory X._d(); z() {}}
void f() {new X.^}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
// Suggested by NamedConstructorContributor
assertNotSuggested('c');
assertNotSuggested('_d');
assertNotSuggested('F1');
assertNotSuggested('T1');
assertNotSuggested('z');
assertNotSuggested('m');
}
Future<void> test_DefaultFormalParameter_named_expression() async {
// DefaultFormalParameter FormalParameterList MethodDeclaration
addTestSource('''
foo() { }
void bar() { }
class A {a(blat: ^) { }}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestFunction('foo', null);
assertSuggestMethod('a', 'A', null);
assertSuggestClass('A');
assertNotSuggested('String');
assertNotSuggested('identical');
}
Future<void> test_doc_classMember() async {
var docLines = r'''
/// My documentation.
/// Short description.
///
/// Longer description.
''';
void assertDoc(CompletionSuggestion suggestion) {
expect(suggestion.docSummary, 'My documentation.\nShort description.');
expect(suggestion.docComplete,
'My documentation.\nShort description.\n\nLonger description.');
}
addTestSource('''
class C {
$docLines
int myField;
$docLines
myMethod() {}
$docLines
int get myGetter => 0;
void f() {^}
}''');
await computeSuggestions();
{
var suggestion = assertSuggestField('myField', 'int');
assertDoc(suggestion);
}
{
var suggestion = assertSuggestMethod('myMethod', 'C', null);
assertDoc(suggestion);
}
{
var suggestion = assertSuggestGetter('myGetter', 'int');
assertDoc(suggestion);
}
}
Future<void> test_doc_macro() async {
dartdocInfo.addTemplateNamesAndValues([
'template_name'
], [
'''
Macro contents on
multiple lines.
'''
]);
addTestSource('''
/// {@macro template_name}
///
/// With an additional line.
int x = 0;
void f() {^}
''');
await computeSuggestions();
var suggestion = assertSuggestTopLevelVar('x', 'int');
expect(suggestion.docSummary, 'Macro contents on\nmultiple lines.');
expect(suggestion.docComplete,
'Macro contents on\nmultiple lines.\n\n\nWith an additional line.');
}
Future<void> test_doc_topLevel() async {
var docLines = r'''
/// My documentation.
/// Short description.
///
/// Longer description.
''';
void assertDoc(CompletionSuggestion suggestion) {
expect(suggestion.docSummary, 'My documentation.\nShort description.');
expect(suggestion.docComplete,
'My documentation.\nShort description.\n\nLonger description.');
}
addTestSource('''
$docLines
class MyClass {}
$docLines
class MyMixinApplication = Object with MyClass;
$docLines
enum MyEnum {A, B, C}
$docLines
void myFunction() {}
$docLines
int myVariable;
void f() {^}
''');
await computeSuggestions();
{
var suggestion = assertSuggestClass('MyClass');
assertDoc(suggestion);
}
{
var suggestion = assertSuggestClass('MyMixinApplication');
assertDoc(suggestion);
}
{
var suggestion = assertSuggestEnum('MyEnum');
assertDoc(suggestion);
}
{
var suggestion = assertSuggestFunction('myFunction', 'void');
assertDoc(suggestion);
}
{
var suggestion = assertSuggestTopLevelVar('myVariable', 'int');
assertDoc(suggestion);
}
}
Future<void> test_enum() async {
addTestSource('enum E { one, two } void f() {^}');
await computeSuggestions();
assertSuggestEnum('E');
assertSuggestEnumConst('E.one');
assertSuggestEnumConst('E.two');
assertNotSuggested('one');
assertNotSuggested('two');
}
Future<void> test_enum_deprecated() async {
addTestSource('@deprecated enum E { one, two } void f() {^}');
await computeSuggestions();
assertSuggestEnum('E', isDeprecated: true);
assertSuggestEnumConst('E.one', isDeprecated: true);
assertSuggestEnumConst('E.two', isDeprecated: true);
assertNotSuggested('one');
assertNotSuggested('two');
}
Future<void> test_enum_filter() async {
addTestSource('''
enum E { one, two }
enum F { three, four }
void foo({E e}) {}
void f() {
foo(e: ^);
}
''');
await computeSuggestions();
assertSuggestEnum('E');
assertSuggestEnumConst('E.one');
assertSuggestEnumConst('E.two');
assertSuggestEnum('F');
assertSuggestEnumConst('F.three');
assertSuggestEnumConst('F.four');
}
Future<void> test_enum_filter_assignment() async {
addTestSource('''
enum E { one, two }
enum F { three, four }
void f() {
E e;
e = ^;
}
''');
await computeSuggestions();
assertSuggestEnum('E');
assertSuggestEnumConst('E.one');
assertSuggestEnumConst('E.two');
assertSuggestEnum('F');
assertSuggestEnumConst('F.three');
assertSuggestEnumConst('F.four');
}
Future<void> test_enum_filter_binaryEquals() async {
addTestSource('''
enum E { one, two }
enum F { three, four }
void f(E e) {
e == ^;
}
''');
await computeSuggestions();
assertSuggestEnum('E');
assertSuggestEnumConst('E.one');
assertSuggestEnumConst('E.two');
assertSuggestEnum('F');
assertSuggestEnumConst('F.three');
assertSuggestEnumConst('F.four');
}
Future<void> test_enum_filter_switchCase() async {
addTestSource('''
enum E { one, two }
enum F { three, four }
void f(E e) {
switch (e) {
case ^
}
}
''');
await computeSuggestions();
assertSuggestEnum('E');
assertSuggestEnumConst('E.one');
assertSuggestEnumConst('E.two');
assertSuggestEnum('F');
assertSuggestEnumConst('F.three');
assertSuggestEnumConst('F.four');
}
Future<void> test_enum_filter_variableDeclaration() async {
addTestSource('''
enum E { one, two }
enum F { three, four }
void f() {
E e = ^;
}
''');
await computeSuggestions();
assertSuggestEnum('E');
assertSuggestEnumConst('E.one');
assertSuggestEnumConst('E.two');
assertSuggestEnum('F');
assertSuggestEnumConst('F.three');
assertSuggestEnumConst('F.four');
}
Future<void> test_enum_shadowed() async {
addTestSource('''
enum E { one, two }
void f() {
int E = 0;
^
}
''');
await computeSuggestions();
assertSuggest('E', elemKind: ElementKind.LOCAL_VARIABLE);
// Enum and all its constants are shadowed by the local variable.
assertNotSuggested('E', elemKind: ElementKind.ENUM);
assertNotSuggested('E.one', elemKind: ElementKind.ENUM_CONSTANT);
assertNotSuggested('E.two', elemKind: ElementKind.ENUM_CONSTANT);
}
Future<void> test_expression_localVariable() async {
addTestSource('''
void f() {
var v = 0;
^
}
''');
await computeSuggestions();
assertSuggestLocalVariable('v', 'int');
}
Future<void> test_expression_parameter() async {
addTestSource('''
void f(int a) {
^
}
''');
await computeSuggestions();
assertSuggestParameter('a', 'int');
}
Future<void> test_expression_typeParameter_classDeclaration() async {
addTestSource('''
class A<T> {
void m() {
^
}
}
class B<U> {}
''');
await computeSuggestions();
assertSuggestTypeParameter('T');
assertNotSuggested('U');
}
Future<void> test_expression_typeParameter_classTypeAlias() async {
addTestSource('''
class A<U> {}
class B<T> = A<^>;
''');
await computeSuggestions();
assertSuggestTypeParameter('T');
assertNotSuggested('U');
}
Future<void> test_expression_typeParameter_functionDeclaration() async {
addTestSource('''
void f<T>() {
^
}
void g<U>() {}
''');
await computeSuggestions();
assertSuggestTypeParameter('T');
assertNotSuggested('U');
}
Future<void> test_expression_typeParameter_functionDeclaration_local() async {
addTestSource('''
void f() {
void g2<U>() {}
void g<T>() {
^
}
}
''');
await computeSuggestions();
assertSuggestTypeParameter('T');
assertNotSuggested('U');
}
Future<void> test_expression_typeParameter_functionTypeAlias() async {
addTestSource('''
typedef void F<T>(^);
''');
await computeSuggestions();
assertSuggestTypeParameter('T');
}
Future<void> test_expression_typeParameter_genericTypeAlias() async {
addTestSource('''
typedef F<T> = void Function<U>(^);
''');
await computeSuggestions();
assertSuggestTypeParameter('T');
assertSuggestTypeParameter('U');
}
Future<void> test_expression_typeParameter_methodDeclaration() async {
addTestSource('''
class A {
void m<T>() {
^
}
void m2<U>() {}
}
''');
await computeSuggestions();
assertSuggestTypeParameter('T');
assertNotSuggested('U');
}
Future<void> test_expression_typeParameter_mixinDeclaration() async {
addTestSource('''
mixin M<T> {
void m() {
^
}
}
class B<U> {}
''');
await computeSuggestions();
assertSuggestTypeParameter('T');
assertNotSuggested('U');
}
Future<void> test_ExpressionStatement_identifier() async {
// SimpleIdentifier ExpressionStatement Block
addSource('/home/test/lib/a.dart', '''
_B F1() { }
class A {int x;}
class _B { }''');
addTestSource('''
import "a.dart";
typedef int F2(int blat);
class Clz = Object with Object;
class C {foo(){^} void bar() {}}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertNotSuggested('A');
assertNotSuggested('F1');
assertSuggestClass('C');
assertSuggestMethod('foo', 'C', null);
assertSuggestMethod('bar', 'C', 'void');
assertSuggestTypeAlias('F2',
aliasedType: 'int Function(int)', returnType: 'int');
assertSuggestClass('Clz');
assertSuggestClass('C');
assertNotSuggested('x');
assertNotSuggested('_B');
}
Future<void> test_ExpressionStatement_name() async {
// ExpressionStatement Block BlockFunctionBody MethodDeclaration
addSource('/home/test/lib/a.dart', '''
B T1;
class B{}''');
addTestSource('''
import "a.dart";
class C {a() {C ^}}''');
await computeSuggestions();
assertNoSuggestions();
}
Future<void> test_ExtendsClause() async {
addTestSource('''
class A {}
mixin M {}
class B extends ^
''');
await computeSuggestions();
assertSuggestClass('A');
assertNotSuggested('M');
}
Future<void> test_ExtensionDeclaration_extendedType() async {
addTestSource('''
class A {}
extension E on ^
''');
await computeSuggestions();
assertSuggestClass('A');
assertNotSuggested('E');
}
Future<void> test_ExtensionDeclaration_extendedType2() async {
addTestSource('''
class A {}
extension E on ^ {}
''');
await computeSuggestions();
assertSuggestClass('A');
assertNotSuggested('E');
}
Future<void> test_extensionDeclaration_inMethod() async {
// ExtensionDeclaration CompilationUnit
addTestSource('''
extension E on int {}
class C {
void m() {
^
}
}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggest('E');
}
Future<void> test_ExtensionDeclaration_member() async {
addTestSource('''
class A {}
extension E on A { ^ }
''');
await computeSuggestions();
assertSuggestClass('A');
}
Future<void> test_extensionDeclaration_notInBody() async {
// ExtensionDeclaration CompilationUnit
addSource('/home/test/lib/b.dart', '''
class B { }''');
addTestSource('''
import "b.dart" as x;
extension E on int {^}
class _B {}
A T;''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
var suggestionB = assertSuggestClass('_B').element;
if (suggestionB != null) {
expect(suggestionB.isDeprecated, isFalse);
expect(suggestionB.isPrivate, isTrue);
}
assertNotSuggested('Object');
assertNotSuggested('T');
assertNotSuggested('E');
// Suggested by LibraryPrefixContributor
assertNotSuggested('x');
}
Future<void> test_ExtensionDeclaration_shadowed() async {
// ExtensionDeclaration CompilationUnit
addTestSource('''
extension E on int {
void m() {
int E = 1;
^
}
}
''');
await computeSuggestions();
assertNotSuggested('E', elemKind: ElementKind.EXTENSION);
assertSuggest('E', elemKind: ElementKind.LOCAL_VARIABLE);
}
Future<void> test_ExtensionDeclaration_unnamed() async {
// ExtensionDeclaration CompilationUnit
addTestSource('''
extension on String {
void something() => this.^
}
''');
await computeSuggestions();
assertNoSuggestions();
}
Future<void> test_FieldDeclaration_name_typed() async {
// SimpleIdentifier VariableDeclaration VariableDeclarationList
// FieldDeclaration
addSource('/home/test/lib/a.dart', 'class A { }');
addTestSource('''
import "a.dart";
class C {A ^}''');
await computeSuggestions();
assertNoSuggestions();
}
Future<void> test_FieldDeclaration_name_var() async {
// SimpleIdentifier VariableDeclaration VariableDeclarationList
// FieldDeclaration
addSource('/home/test/lib/a.dart', 'class A { }');
addTestSource('''
import "a.dart";
class C {var ^}''');
await computeSuggestions();
assertNoSuggestions();
}
Future<void> test_FieldDeclaration_shadowed() async {
// SimpleIdentifier VariableDeclaration VariableDeclarationList
// FieldDeclaration
addTestSource('''
class A {
int foo;
void bar() {
int foo; ^
}
}
''');
await computeSuggestions();
assertNotSuggested('foo', elemKind: ElementKind.FIELD);
assertSuggest('foo', elemKind: ElementKind.LOCAL_VARIABLE);
}
Future<void> test_FieldFormalParameter_in_non_constructor() async {
// SimpleIdentifier FieldFormalParameter FormalParameterList
addTestSource('class A {B(this.^foo) {}}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 3);
assertNoSuggestions();
}
Future<void> test_flutter_setState_hasPrefix() async {
var spaces_4 = ' ' * 4;
var spaces_6 = ' ' * 6;
await _check_flutter_setState(
' setSt',
'''
setState(() {
$spaces_6
$spaces_4});''',
20);
}
Future<void> test_flutter_setState_longPrefix() async {
var spaces_6 = ' ' * 6;
var spaces_8 = ' ' * 8;
await _check_flutter_setState(
' setSt',
'''
setState(() {
$spaces_8
$spaces_6});''',
22);
}
Future<void> test_flutter_setState_noPrefix() async {
var spaces_4 = ' ' * 4;
var spaces_6 = ' ' * 6;
await _check_flutter_setState(
' ',
'''
setState(() {
$spaces_6
$spaces_4});''',
20);
}
Future<void> test_forEachPartsWithIdentifier_class() async {
addTestSource('''
class C {}
void f() {
for(C in [0, 1, 2]) {
^
}
}
''');
await computeSuggestions();
// Using `C` in for-each is invalid, but we should not crash.
}
Future<void> test_forEachPartsWithIdentifier_localLevelVariable() async {
addTestSource('''
void f() {
int v;
for(v in [0, 1, 2]) {
^
}
}
''');
await computeSuggestions();
// We don't actually use anything from the `for`, and `v` is suggested
// just because it is a visible top-level declaration.
assertSuggestLocalVariable('v', 'int');
}
Future<void> test_forEachPartsWithIdentifier_topLevelVariable() async {
addTestSource('''
int v;
void f() {
for(v in [0, 1, 2]) {
^
}
}
''');
await computeSuggestions();
// We don't actually use anything from the `for`, and `v` is suggested
// just because it is a visible top-level declaration.
assertSuggestTopLevelVar('v', 'int');
}
Future<void> test_ForEachStatement() async {
// SimpleIdentifier ForEachStatement
addTestSource('void f() {List<int> values; for (int index in ^)}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestLocalVariable('values', 'List<int>');
assertNotSuggested('index');
}
Future<void> test_ForEachStatement2() async {
// SimpleIdentifier ForEachStatement
addTestSource('void f() {List<int> values; for (int index in i^)}');
await computeSuggestions();
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertSuggestLocalVariable('values', 'List<int>');
assertNotSuggested('index');
}
Future<void> test_ForEachStatement3() async {
// SimpleIdentifier ParenthesizedExpression ForEachStatement
addTestSource('void f() {List<int> values; for (int index in (i^))}');
await computeSuggestions();
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertSuggestLocalVariable('values', 'List<int>');
assertNotSuggested('index');
}
Future<void> test_ForEachStatement_body_typed() async {
// Block ForEachStatement
addTestSource('void f(args) {for (int foo in bar) {^}}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestParameter('args', null);
assertSuggestLocalVariable('foo', 'int');
assertNotSuggested('Object');
}
Future<void> test_ForEachStatement_body_untyped() async {
// Block ForEachStatement
addTestSource('void f(args) {for (var foo in bar) {^}}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestParameter('args', null);
assertSuggestLocalVariable('foo', null);
assertNotSuggested('Object');
}
Future<void> test_ForEachStatement_iterable() async {
// SimpleIdentifier ForEachStatement Block
addTestSource('void f(args) {for (int foo in ^) {}}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestParameter('args', null);
assertNotSuggested('Object');
}
Future<void> test_ForEachStatement_loopVariable() async {
// SimpleIdentifier ForEachStatement Block
addTestSource('void f(args) {for (^ in args) {}}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertNotSuggested('args');
assertNotSuggested('String');
}
Future<void> test_ForEachStatement_loopVariable_type() async {
// SimpleIdentifier ForEachStatement Block
addTestSource('void f(args) {for (^ foo in args) {}}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertNotSuggested('args');
assertNotSuggested('foo');
assertNotSuggested('String');
}
Future<void> test_ForEachStatement_loopVariable_type2() async {
// DeclaredIdentifier ForEachStatement Block
addTestSource('void f(args) {for (S^ foo in args) {}}');
await computeSuggestions();
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertNotSuggested('args');
assertNotSuggested('foo');
assertNotSuggested('String');
}
@failingTest
Future<void> test_ForEachStatement_statement_typed() async {
// Statement ForEachStatement
addTestSource('void f(args) {for (int foo in bar) ^}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestParameter('args', null);
assertSuggestLocalVariable('foo', 'int');
assertNotSuggested('Object');
}
@failingTest
Future<void> test_ForEachStatement_statement_untyped() async {
// Statement ForEachStatement
addTestSource('void f(args) {for (var foo in bar) ^}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestParameter('args', null);
assertSuggestLocalVariable('foo', null);
assertNotSuggested('Object');
}
Future<void> test_forElement_body() async {
addTestSource('var x = [for (int i; i < 10; ++i) ^];');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestLocalVariable('i', 'int');
assertNotSuggested('Object');
}
Future<void> test_forElement_condition() async {
addTestSource('var x = [for (int index = 0; i^)];');
await computeSuggestions();
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertSuggestLocalVariable('index', 'int');
}
Future<void> test_forElement_initializer() async {
addTestSource('var x = [for (^)];');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertNotSuggested('Object');
assertNotSuggested('int');
}
Future<void> test_forElement_updaters() async {
addTestSource('var x = [for (int index = 0; index < 10; i^)];');
await computeSuggestions();
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertSuggestLocalVariable('index', 'int');
}
Future<void> test_forElement_updaters_prefix_expression() async {
addTestSource('''
var x = [for (int index = 0; index < 10; ++i^)];
''');
await computeSuggestions();
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertSuggestLocalVariable('index', 'int');
}
Future<void> test_FormalParameterList() async {
// FormalParameterList MethodDeclaration
addTestSource('''
foo() { }
void bar() { }
class A {a(^) { }}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertNotSuggested('foo');
assertNotSuggested('a');
assertSuggestClass('A');
assertNotSuggested('String');
assertNotSuggested('identical');
assertNotSuggested('bar');
}
Future<void> test_ForStatement_body() async {
// Block ForStatement
addTestSource('void f(args) {for (int i; i < 10; ++i) {^}}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestLocalVariable('i', 'int');
assertNotSuggested('Object');
}
Future<void> test_ForStatement_condition() async {
// SimpleIdentifier ForStatement
addTestSource('void f() {for (int index = 0; i^)}');
await computeSuggestions();
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertSuggestLocalVariable('index', 'int');
}
Future<void> test_ForStatement_initializer() async {
// SimpleIdentifier ForStatement
addTestSource('void f() {List a; for (^)}');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertNotSuggested('a');
assertNotSuggested('Object');
assertNotSuggested('int');
}
Future<void> test_ForStatement_updaters() async {
// SimpleIdentifier ForStatement
addTestSource('void f() {for (int index = 0; index < 10; i^)}');
await computeSuggestions();
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertSuggestLocalVariable('index', 'int');
}
Future<void> test_ForStatement_updaters_prefix_expression() async {
// SimpleIdentifier PrefixExpression ForStatement
addTestSource('''
void bar() { }
f() {for (int index = 0; index < 10; ++i^)}''');
await computeSuggestions();
expect(replacementOffset, completionOffset - 1);
expect(replacementLength, 1);
assertSuggestLocalVariable('index', 'int');
assertSuggestFunction('f', null);
assertNotSuggested('bar');
}
Future<void> test_function_parameters_mixed_required_and_named() async {
addTestSource('''
void m(x, {int y}) {}
class B extends A {
void f() {^}
}
''');
await computeSuggestions();
var suggestion = assertSuggestFunction('m', 'void');
var parameterNames = suggestion.parameterNames!;
var parameterTypes = suggestion.parameterTypes!;
expect(parameterNames, hasLength(2));
expect(parameterNames[0], 'x');
expect(parameterTypes[0], 'dynamic');
expect(parameterNames[1], 'y');
expect(parameterTypes[1], 'int');
expect(suggestion.requiredParameterCount, 1);
expect(suggestion.hasNamedParameters, true);
}
Future<void> test_function_parameters_mixed_required_and_positional() async {
addTestSource('''
void m(x, [int y]) {}
class B extends A {
void f() {^}
}
''');
await computeSuggestions();
var suggestion = assertSuggestFunction('m', 'void');
var parameterNames = suggestion.parameterNames!;
var parameterTypes = suggestion.parameterTypes!;
expect(parameterNames, hasLength(2));
expect(parameterNames[0], 'x');
expect(parameterTypes[0], 'dynamic');
expect(parameterNames[1], 'y');
expect(parameterTypes[1], 'int');
expect(suggestion.requiredParameterCount, 1);
expect(suggestion.hasNamedParameters, false);
}
Future<void> test_function_parameters_named() async {
addTestSource('''
void m({x, int y}) {}
class B extends A {
void f() {^}
}
''');
await computeSuggestions();
var suggestion = assertSuggestFunction('m', 'void');
var parameterNames = suggestion.parameterNames!;
var parameterTypes = suggestion.parameterTypes!;
expect(parameterNames, hasLength(2));
expect(parameterNames[0], 'x');
expect(parameterTypes[0], 'dynamic');
expect(parameterNames[1], 'y');
expect(parameterTypes[1], 'int');
expect(suggestion.requiredParameterCount, 0);
expect(suggestion.hasNamedParameters, true);
}
Future<void> test_function_parameters_none() async {
addTestSource('''
void m() {}
class B extends A {
void f() {^}
}
''');
await computeSuggestions();
var suggestion = assertSuggestFunction('m', 'void');
expect(suggestion.parameterNames, isEmpty);
expect(suggestion.parameterTypes, isEmpty);
expect(suggestion.requiredParameterCount, 0);
expect(suggestion.hasNamedParameters, false);
}
Future<void> test_function_parameters_positional() async {
addTestSource('''
void m([x, int y]) {}
class B extends A {
void f() {^}
}
''');
await computeSuggestions();
var suggestion = assertSuggestFunction('m', 'void');
var parameterNames = suggestion.parameterNames!;
var parameterTypes = suggestion.parameterTypes!;
expect(parameterNames, hasLength(2));
expect(parameterNames[0], 'x');
expect(parameterTypes[0], 'dynamic');
expect(parameterNames[1], 'y');
expect(parameterTypes[1], 'int');
expect(suggestion.requiredParameterCount, 0);
expect(suggestion.hasNamedParameters, false);
}
Future<void> test_function_parameters_required() async {
addTestSource('''
void m(x, int y) {}
class B extends A {
void f() {^}
}
''');
await computeSuggestions();
var suggestion = assertSuggestFunction('m', 'void');
var parameterNames = suggestion.parameterNames!;
var parameterTypes = suggestion.parameterTypes!;
expect(parameterNames, hasLength(2));
expect(parameterNames[0], 'x');
expect(parameterTypes[0], 'dynamic');
expect(parameterNames[1], 'y');
expect(parameterTypes[1], 'int');
expect(suggestion.requiredParameterCount, 2);
expect(suggestion.hasNamedParameters, false);
}
Future<void> test_functionDeclaration_parameter() async {
addTestSource('''
void f<T>(^) {}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestTypeParameter('T');
}
Future<void> test_FunctionDeclaration_returnType_afterComment() async {
// ClassDeclaration CompilationUnit
addSource('/home/test/lib/a.dart', '''
int T1;
F1() { }
typedef D1();
class C1 {C1(this.x) { } int x;}''');
addTestSource('''
import "a.dart";
int T2;
F2() { }
typedef D2();
class C2 { }
/* */ ^ zoo(z) { } String name;''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertNotSuggested('Object');
assertNotSuggested('T1');
assertNotSuggested('F1');
assertNotSuggested('D1');
assertNotSuggested('C1');
assertNotSuggested('T2');
assertNotSuggested('F2');
assertSuggestTypeAlias('D2',
aliasedType: 'dynamic Function()', returnType: 'dynamic');
assertSuggestClass('C2');
assertNotSuggested('name');
}
Future<void> test_FunctionDeclaration_returnType_afterComment2() async {
// FunctionDeclaration ClassDeclaration CompilationUnit
addSource('/home/test/lib/a.dart', '''
int T1;
F1() { }
typedef D1();
class C1 {C1(this.x) { } int x;}''');
addTestSource('''
import "a.dart";
int T2;
F2() { }
typedef D2();
class C2 { }
/** */ ^ zoo(z) { } String name;''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertNotSuggested('Object');
assertNotSuggested('T1');
assertNotSuggested('F1');
assertNotSuggested('D1');
assertNotSuggested('C1');
assertNotSuggested('T2');
assertNotSuggested('F2');
assertSuggestTypeAlias('D2',
aliasedType: 'dynamic Function()', returnType: 'dynamic');
assertSuggestClass('C2');
assertNotSuggested('name');
}
Future<void> test_FunctionDeclaration_returnType_afterComment3() async {
// FunctionDeclaration ClassDeclaration CompilationUnit
addSource('/home/test/lib/a.dart', '''
int T1;
F1() { }
typedef D1();
class C1 {C1(this.x) { } int x;}''');
addTestSource('''
import "a.dart";
int T2;
F2() { }
typedef D2();
/// some dartdoc
class C2 { }
^ zoo(z) { } String name;''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertNotSuggested('Object');
assertNotSuggested('T1');
assertNotSuggested('F1');
assertNotSuggested('D1');
assertNotSuggested('C1');
assertNotSuggested('T2');
assertNotSuggested('F2');
assertSuggestTypeAlias('D2',
aliasedType: 'dynamic Function()', returnType: 'dynamic');
assertSuggestClass('C2');
assertNotSuggested('name');
}
Future<void> test_FunctionDeclaration_shadowed() async {
// Block BlockFunctionBody FunctionDeclaration
addTestSource('''
void bar() {
int bar = 1;
^
}
''');
await computeSuggestions();
assertNotSuggested('bar', elemKind: ElementKind.FUNCTION);
assertSuggest('bar', elemKind: ElementKind.LOCAL_VARIABLE);
}
Future<void> test_functionDeclaration_typeParameterBounds() async {
addTestSource('''
void f<T extends C<^>>() {}
class C<E> {}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestTypeParameter('T');
}
Future<void> test_FunctionExpression_body_function() async {
// Block BlockFunctionBody FunctionExpression
addTestSource('''
void bar() { }
String foo(List args) {
x.then((R b) {^});
}
class R {}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
var f = assertSuggestFunction('foo', 'String', isDeprecated: false).element;
if (f != null) {
expect(f.isPrivate, isFalse);
}
assertSuggestFunction('bar', 'void');
assertSuggestParameter('args', 'List<dynamic>');
assertSuggestParameter('b', 'R');
assertNotSuggested('Object');
}
@failingTest
Future<void> test_functionExpression_expressionBody() async {
// This test fails because the OpType at the completion location doesn't
// allow for functions that return `void`. But because the expected return
// type is `dynamic` we probably want to allow it.
addTestSource('''
void f() {
g(() => ^);
}
void g(dynamic Function() h) {}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestFunction('f', 'void');
assertSuggestFunction('g', 'void');
}
Future<void> test_functionExpression_parameterList() async {
addTestSource('''
var c = <T>(^) {};
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestTypeParameter('T');
}
Future<void> test_genericFunctionType_parameterList() async {
addTestSource('''
void f(int Function<T>(^) g) {}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestTypeParameter('T');
}
Future<void> test_IfStatement() async {
// SimpleIdentifier IfStatement
addTestSource('''
class A {
var b;
X _c;
foo() {
A a; if (true) ^
}
}
class X {}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestField('b', null);
assertSuggestField('_c', 'X');
assertNotSuggested('Object');
assertSuggestClass('A');
assertNotSuggested('==');
}
Future<void> test_IfStatement_condition() async {
// SimpleIdentifier IfStatement Block BlockFunctionBody
addTestSource('''
class A {int x; int y() => 0;}
f(){var a; if (^)}''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestLocalVariable('a', null);
assertSuggestFunction('f', null);
assertSuggestClass('A');
assertNotSuggested('Object');
}
Future<void> test_IfStatement_empty() async {
// SimpleIdentifier IfStatement
addTestSource('''
class A {
var b;
X _c;
foo() {
A a;
if (^) something
}
}
class X {}
''');
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
assertSuggestField('b', null);
assertSuggestField('_c', 'X');
assertNotSuggested('Object');
assertSuggestClass('A');
assertNotSuggested('==');
}
Future<void> test_IfStatement_empty_private() async {
// SimpleIdentifier IfStatement
addTestSource('''
class A {
var b;
X _c;
foo() {
A a;