| Index: pkg/analysis_server/test/services/completion/completion_test_util.dart
|
| diff --git a/pkg/analysis_server/test/services/completion/completion_test_util.dart b/pkg/analysis_server/test/services/completion/completion_test_util.dart
|
| index 862934d0963a57432083e33cc97da77108f743d9..67ffd11d8c4e68762d26be306d84c58ebb517304 100644
|
| --- a/pkg/analysis_server/test/services/completion/completion_test_util.dart
|
| +++ b/pkg/analysis_server/test/services/completion/completion_test_util.dart
|
| @@ -234,16 +234,16 @@ abstract class AbstractCompletionTest extends AbstractContextTest {
|
| }
|
|
|
| CompletionSuggestion assertSuggestFunction(String name, String returnType,
|
| - [bool isDeprecated = false, int relevance = DART_RELEVANCE_DEFAULT,
|
| - CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) {
|
| + {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
|
| + bool deprecated: false, int relevance: DART_RELEVANCE_DEFAULT}) {
|
| CompletionSuggestion cs = assertSuggest(name,
|
| - csKind: kind, relevance: relevance, isDeprecated: isDeprecated);
|
| + csKind: kind, relevance: relevance, isDeprecated: deprecated);
|
| expect(cs.returnType, returnType != null ? returnType : 'dynamic');
|
| protocol.Element element = cs.element;
|
| expect(element, isNotNull);
|
| expect(element.kind, equals(protocol.ElementKind.FUNCTION));
|
| expect(element.name, equals(name));
|
| - expect(element.isDeprecated, equals(isDeprecated));
|
| + expect(element.isDeprecated, equals(deprecated));
|
| String param = element.parameters;
|
| expect(param, isNotNull);
|
| expect(param[0], equals('('));
|
| @@ -433,52 +433,7 @@ abstract class AbstractCompletionTest extends AbstractContextTest {
|
| if (!_computeFastCalled) {
|
| expect(computeFast(), isFalse);
|
| }
|
| -
|
| - // Index SDK
|
| - for (Source librarySource in context.librarySources) {
|
| - CompilationUnit unit =
|
| - context.getResolvedCompilationUnit2(librarySource, librarySource);
|
| - if (unit != null) {
|
| - index.indexUnit(context, unit);
|
| - }
|
| - }
|
| -
|
| - var result = context.performAnalysisTask();
|
| - bool resolved = false;
|
| - while (result.hasMoreWork) {
|
| -
|
| - // Update the index
|
| - result.changeNotices.forEach((ChangeNotice notice) {
|
| - CompilationUnit unit = notice.resolvedDartUnit;
|
| - if (unit != null) {
|
| - index.indexUnit(context, unit);
|
| - }
|
| - });
|
| -
|
| - // If the unit has been resolved, then finish the completion
|
| - List<Source> libSourceList = context.getLibrariesContaining(testSource);
|
| - if (libSourceList.length > 0) {
|
| - LibraryElement library = context.getLibraryElement(libSourceList[0]);
|
| - if (library != null) {
|
| - CompilationUnit unit =
|
| - context.getResolvedCompilationUnit(testSource, library);
|
| - if (unit != null) {
|
| - request.unit = unit;
|
| - request.node =
|
| - new NodeLocator.con1(completionOffset).searchWithin(unit);
|
| - resolved = true;
|
| - if (!fullAnalysis) {
|
| - break;
|
| - }
|
| - }
|
| - }
|
| - }
|
| -
|
| - result = context.performAnalysisTask();
|
| - }
|
| - if (!resolved) {
|
| - fail('expected unit to be resolved');
|
| - }
|
| + resolve(fullAnalysis);
|
| return computer.computeFull(request).then(assertFunction);
|
| }
|
|
|
| @@ -531,6 +486,55 @@ abstract class AbstractCompletionTest extends AbstractContextTest {
|
| return cs;
|
| }
|
|
|
| + void resolve(bool fullAnalysis) {
|
| +
|
| + // Index SDK
|
| + for (Source librarySource in context.librarySources) {
|
| + CompilationUnit unit =
|
| + context.getResolvedCompilationUnit2(librarySource, librarySource);
|
| + if (unit != null) {
|
| + index.indexUnit(context, unit);
|
| + }
|
| + }
|
| +
|
| + var result = context.performAnalysisTask();
|
| + bool resolved = false;
|
| + while (result.hasMoreWork) {
|
| +
|
| + // Update the index
|
| + result.changeNotices.forEach((ChangeNotice notice) {
|
| + CompilationUnit unit = notice.resolvedDartUnit;
|
| + if (unit != null) {
|
| + index.indexUnit(context, unit);
|
| + }
|
| + });
|
| +
|
| + // If the unit has been resolved, then finish the completion
|
| + List<Source> libSourceList = context.getLibrariesContaining(testSource);
|
| + if (libSourceList.length > 0) {
|
| + LibraryElement library = context.getLibraryElement(libSourceList[0]);
|
| + if (library != null) {
|
| + CompilationUnit unit =
|
| + context.getResolvedCompilationUnit(testSource, library);
|
| + if (unit != null) {
|
| + request.unit = unit;
|
| + request.node =
|
| + new NodeLocator.con1(completionOffset).searchWithin(unit);
|
| + resolved = true;
|
| + if (!fullAnalysis) {
|
| + break;
|
| + }
|
| + }
|
| + }
|
| + }
|
| +
|
| + result = context.performAnalysisTask();
|
| + }
|
| + if (!resolved) {
|
| + fail('expected unit to be resolved');
|
| + }
|
| + }
|
| +
|
| @override
|
| void setUp() {
|
| super.setUp();
|
| @@ -557,8 +561,8 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
| }
|
|
|
| CompletionSuggestion assertSuggestImportedClass(String name,
|
| - [int relevance = DART_RELEVANCE_DEFAULT,
|
| - CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) {
|
| + {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
|
| + int relevance: DART_RELEVANCE_DEFAULT}) {
|
| if (computer is ImportedComputer) {
|
| return assertSuggestClass(name, relevance: relevance, kind: kind);
|
| } else {
|
| @@ -576,15 +580,10 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
| }
|
|
|
| CompletionSuggestion assertSuggestImportedFunction(
|
| - String name, String returnType, [bool isDeprecated = false,
|
| - int relevance = DART_RELEVANCE_DEFAULT,
|
| - CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) {
|
| - if (computer is ImportedComputer) {
|
| - return assertSuggestFunction(
|
| - name, returnType, isDeprecated, relevance, kind);
|
| - } else {
|
| - return assertNotSuggested(name);
|
| - }
|
| + String name, String returnType,
|
| + {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
|
| + bool deprecated: false, int relevance: DART_RELEVANCE_DEFAULT}) {
|
| + return assertNotSuggested(name);
|
| }
|
|
|
| CompletionSuggestion assertSuggestImportedFunctionTypeAlias(
|
| @@ -682,7 +681,8 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
| }
|
|
|
| CompletionSuggestion assertSuggestLocalClass(String name,
|
| - {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) {
|
| + {CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION,
|
| + int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) {
|
| return assertNotSuggested(name);
|
| }
|
|
|
| @@ -701,8 +701,9 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
| }
|
|
|
| CompletionSuggestion assertSuggestLocalFunction(
|
| - String name, String returnType,
|
| - {bool deprecated: false, int relevance: DART_RELEVANCE_LOCAL_FUNCTION}) {
|
| + String name, String returnType, {bool deprecated: false,
|
| + int relevance: DART_RELEVANCE_LOCAL_FUNCTION,
|
| + CompletionSuggestionKind kind: CompletionSuggestionKind.INVOCATION}) {
|
| return assertNotSuggested(name);
|
| }
|
|
|
| @@ -743,7 +744,7 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
| CompletionSuggestion assertSuggestNonLocalClass(String name,
|
| [int relevance = DART_RELEVANCE_DEFAULT,
|
| CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) {
|
| - return assertSuggestImportedClass(name, relevance, kind);
|
| + return assertSuggestImportedClass(name, relevance: relevance, kind: kind);
|
| }
|
|
|
| Future computeFull(assertFunction(bool result), {bool fullAnalysis: true}) {
|
| @@ -807,6 +808,77 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
| });
|
| }
|
|
|
| + test_ArgumentList_InstanceCreationExpression_functionalArg() {
|
| + // ArgumentList InstanceCreationExpression ExpressionStatement Block
|
| + addSource('/libA.dart', '''
|
| + library A;
|
| + class A { A(f()) { } }
|
| + bool hasLength(int expected) { }
|
| + void baz() { }''');
|
| + addTestSource('''
|
| + import 'dart:async';
|
| + import '/libA.dart';
|
| + class B { }
|
| + String bar() => true;
|
| + void main() {new A(^)}''');
|
| + computeFast();
|
| + return computeFull((bool result) {
|
| + expect(request.replacementOffset, completionOffset);
|
| + expect(request.replacementLength, 0);
|
| + assertNoSuggestions(kind: CompletionSuggestionKind.ARGUMENT_LIST);
|
| + assertSuggestLocalFunction(
|
| + 'bar', 'String', kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestImportedFunction('hasLength', 'bool',
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestImportedFunction('identical', 'bool',
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestLocalClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestImportedClass('A',
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestImportedClass('Object',
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertNotSuggested('main');
|
| + assertNotSuggested('baz');
|
| + assertNotSuggested('print');
|
| + });
|
| + }
|
| +
|
| + test_ArgumentList_InstanceCreationExpression_typedefArg() {
|
| + // ArgumentList InstanceCreationExpression ExpressionStatement Block
|
| + addSource('/libA.dart', '''
|
| + library A;
|
| + typedef Funct();
|
| + class A { A(Funct f) { } }
|
| + bool hasLength(int expected) { }
|
| + void baz() { }''');
|
| + addTestSource('''
|
| + import 'dart:async';
|
| + import '/libA.dart';
|
| + class B { }
|
| + String bar() => true;
|
| + void main() {new A(^)}''');
|
| + computeFast();
|
| + return computeFull((bool result) {
|
| + expect(request.replacementOffset, completionOffset);
|
| + expect(request.replacementLength, 0);
|
| + assertNoSuggestions(kind: CompletionSuggestionKind.ARGUMENT_LIST);
|
| + assertSuggestLocalFunction(
|
| + 'bar', 'String', kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestImportedFunction('hasLength', 'bool',
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestImportedFunction('identical', 'bool',
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestLocalClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestImportedClass('A',
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestImportedClass('Object',
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertNotSuggested('main');
|
| + assertNotSuggested('baz');
|
| + assertNotSuggested('print');
|
| + });
|
| + }
|
| +
|
| test_ArgumentList_local_function() {
|
| // ArgumentList MethodInvocation ExpressionStatement Block
|
| addSource('/libA.dart', '''
|
| @@ -863,6 +935,73 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
| });
|
| }
|
|
|
| + test_ArgumentList_MethodInvocation_functionalArg() {
|
| + // ArgumentList MethodInvocation ExpressionStatement Block
|
| + addSource('/libA.dart', '''
|
| + library A;
|
| + class A { A(f()) { } }
|
| + bool hasLength(int expected) { }
|
| + void baz() { }''');
|
| + addTestSource('''
|
| + import 'dart:async';
|
| + import '/libA.dart';
|
| + class B { }
|
| + String bar(f()) => true;
|
| + void main() {bar(^);}''');
|
| + computeFast();
|
| + return computeFull((bool result) {
|
| + expect(request.replacementOffset, completionOffset);
|
| + expect(request.replacementLength, 0);
|
| + assertNoSuggestions(kind: CompletionSuggestionKind.ARGUMENT_LIST);
|
| + assertSuggestLocalFunction(
|
| + 'bar', 'String', kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestImportedFunction('hasLength', 'bool',
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestImportedFunction('identical', 'bool',
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestLocalClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestImportedClass('A',
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestImportedClass('Object',
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertNotSuggested('main');
|
| + assertNotSuggested('baz');
|
| + assertNotSuggested('print');
|
| + });
|
| + }
|
| +
|
| + test_ArgumentList_MethodInvocation_methodArg() {
|
| + // ArgumentList MethodInvocation ExpressionStatement Block
|
| + addSource('/libA.dart', '''
|
| + library A;
|
| + class A { A(f()) { } }
|
| + bool hasLength(int expected) { }
|
| + void baz() { }''');
|
| + addTestSource('''
|
| + import 'dart:async';
|
| + import '/libA.dart';
|
| + class B { String bar(f()) => true; }
|
| + void main() {new B().bar(^);}''');
|
| + computeFast();
|
| + return computeFull((bool result) {
|
| + expect(request.replacementOffset, completionOffset);
|
| + expect(request.replacementLength, 0);
|
| + assertNoSuggestions(kind: CompletionSuggestionKind.ARGUMENT_LIST);
|
| + assertSuggestImportedFunction(
|
| + 'hasLength', 'bool', kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestImportedFunction('identical', 'bool',
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestLocalClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestImportedClass('A',
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertSuggestImportedClass('Object',
|
| + kind: CompletionSuggestionKind.IDENTIFIER);
|
| + assertNotSuggested('main');
|
| + assertNotSuggested('baz');
|
| + assertNotSuggested('print');
|
| + });
|
| + }
|
| +
|
| test_ArgumentList_namedParam() {
|
| // SimpleIdentifier NamedExpression ArgumentList MethodInvocation
|
| // ExpressionStatement
|
| @@ -1135,7 +1274,7 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
| assertNotSuggested('G');
|
| //assertSuggestImportedClass('H', COMPLETION_RELEVANCE_LOW);
|
| assertSuggestImportedClass('Object');
|
| - assertSuggestImportedFunction('min', 'num', false);
|
| + assertSuggestImportedFunction('min', 'num');
|
| //assertSuggestImportedFunction(
|
| // 'max',
|
| // 'num',
|
| @@ -1205,8 +1344,9 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
| assertNotSuggested('_B');
|
| //assertSuggestImportedClass('C');
|
| // hidden element suggested as low relevance
|
| - assertSuggestImportedClass('D', DART_RELEVANCE_LOW);
|
| - assertSuggestImportedFunction('D1', null, true, DART_RELEVANCE_LOW);
|
| + assertSuggestImportedClass('D', relevance: DART_RELEVANCE_LOW);
|
| + assertSuggestImportedFunction(
|
| + 'D1', null, deprecated: true, relevance: DART_RELEVANCE_LOW);
|
| assertSuggestLocalFunction('D2', 'Z');
|
| //assertSuggestImportedClass('EE');
|
| // hidden element suggested as low relevance
|
| @@ -1762,7 +1902,7 @@ abstract class AbstractSelectorSuggestionTest extends AbstractCompletionTest {
|
| expect(request.replacementOffset, completionOffset);
|
| expect(request.replacementLength, 0);
|
| assertSuggestImportedClass('A');
|
| - assertSuggestImportedFunction('F1', '_B', false);
|
| + assertSuggestImportedFunction('F1', '_B');
|
| assertSuggestLocalClass('C');
|
| assertSuggestLocalMethod('foo', 'C', null);
|
| assertSuggestLocalMethod('bar', 'C', 'void');
|
|
|