| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/analysis/results.dart'; |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 8 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/source/package_map_resolver.dart'; | 9 import 'package:analyzer/source/package_map_resolver.dart'; |
| 9 import 'package:analyzer/src/dart/analysis/driver.dart'; | |
| 10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| 11 import 'package:analyzer_plugin/protocol/protocol_common.dart'; | 11 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| 12 import 'package:analyzer_plugin/src/utilities/completion/completion_core.dart'; | 12 import 'package:analyzer_plugin/src/utilities/completion/completion_core.dart'; |
| 13 import 'package:analyzer_plugin/src/utilities/completion/completion_target.dart'
; | 13 import 'package:analyzer_plugin/src/utilities/completion/completion_target.dart'
; |
| 14 import 'package:analyzer_plugin/utilities/completion/completion_core.dart'; | 14 import 'package:analyzer_plugin/utilities/completion/completion_core.dart'; |
| 15 import 'package:analyzer_plugin/utilities/completion/relevance.dart'; | 15 import 'package:analyzer_plugin/utilities/completion/relevance.dart'; |
| 16 import 'package:test/test.dart'; | 16 import 'package:test/test.dart'; |
| 17 | 17 |
| 18 import '../../support/abstract_context.dart'; | 18 import '../../support/abstract_context.dart'; |
| 19 import 'flutter_util.dart'; | 19 import 'flutter_util.dart'; |
| 20 | 20 |
| 21 int suggestionComparator(CompletionSuggestion s1, CompletionSuggestion s2) { | 21 int suggestionComparator(CompletionSuggestion s1, CompletionSuggestion s2) { |
| 22 String c1 = s1.completion.toLowerCase(); | 22 String c1 = s1.completion.toLowerCase(); |
| 23 String c2 = s2.completion.toLowerCase(); | 23 String c2 = s2.completion.toLowerCase(); |
| 24 return c1.compareTo(c2); | 24 return c1.compareTo(c2); |
| 25 } | 25 } |
| 26 | 26 |
| 27 abstract class DartCompletionContributorTest extends AbstractContextTest { | 27 abstract class DartCompletionContributorTest extends AbstractContextTest { |
| 28 static const String _UNCHECKED = '__UNCHECKED__'; | 28 static const String _UNCHECKED = '__UNCHECKED__'; |
| 29 String testFile; | 29 String testFile; |
| 30 Source testSource; | 30 Source testSource; |
| 31 int completionOffset; | 31 int completionOffset; |
| 32 int replacementOffset; | 32 int replacementOffset; |
| 33 int replacementLength; | 33 int replacementLength; |
| 34 CompletionContributor contributor; | 34 CompletionContributor contributor; |
| 35 CompletionRequest request; | 35 DartCompletionRequest request; |
| 36 List<CompletionSuggestion> suggestions; | 36 List<CompletionSuggestion> suggestions; |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * If `true` and `null` is specified as the suggestion's expected returnType | 39 * If `true` and `null` is specified as the suggestion's expected returnType |
| 40 * then the actual suggestion is expected to have a `dynamic` returnType. | 40 * then the actual suggestion is expected to have a `dynamic` returnType. |
| 41 * Newer tests return `false` so that they can distinguish between | 41 * Newer tests return `false` so that they can distinguish between |
| 42 * `dynamic` and `null`. | 42 * `dynamic` and `null`. |
| 43 * Eventually all tests should be converted and this getter removed. | 43 * Eventually all tests should be converted and this getter removed. |
| 44 */ | 44 */ |
| 45 bool get isNullExpectedReturnTypeConsideredDynamic => true; | 45 bool get isNullExpectedReturnTypeConsideredDynamic => true; |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 | 448 |
| 449 /** | 449 /** |
| 450 * Return a [Future] that completes with the containing library information | 450 * Return a [Future] that completes with the containing library information |
| 451 * after it is accessible via [context.getLibrariesContaining]. | 451 * after it is accessible via [context.getLibrariesContaining]. |
| 452 */ | 452 */ |
| 453 Future<Null> computeLibrariesContaining() { | 453 Future<Null> computeLibrariesContaining() { |
| 454 return driver.getResult(testFile).then((result) => null); | 454 return driver.getResult(testFile).then((result) => null); |
| 455 } | 455 } |
| 456 | 456 |
| 457 Future computeSuggestions() async { | 457 Future computeSuggestions() async { |
| 458 AnalysisResult analysisResult = await driver.getResult(testFile); | 458 ResolveResult result = await driver.getResult(testFile); |
| 459 testSource = analysisResult.unit.element.source; | 459 testSource = result.unit.element.source; |
| 460 request = | 460 request = new DartCompletionRequestImpl(provider, completionOffset, result); |
| 461 new CompletionRequestImpl(provider, analysisResult, completionOffset); | |
| 462 | 461 |
| 463 CompletionTarget target = | 462 CompletionTarget target = |
| 464 new CompletionTarget.forOffset(request.result.unit, request.offset); | 463 new CompletionTarget.forOffset(request.result.unit, request.offset); |
| 465 var range = target.computeReplacementRange(request.offset); | 464 var range = target.computeReplacementRange(request.offset); |
| 466 replacementOffset = range.offset; | 465 replacementOffset = range.offset; |
| 467 replacementLength = range.length; | 466 replacementLength = range.length; |
| 468 | 467 |
| 469 // Request completions | 468 // Request completions |
| 470 CompletionCollectorImpl collector = new CompletionCollectorImpl(); | 469 CompletionCollectorImpl collector = new CompletionCollectorImpl(); |
| 471 await contributor.computeSuggestions(request, collector); | 470 await contributor.computeSuggestions(request, collector); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 addSource(path, content); | 559 addSource(path, content); |
| 561 } | 560 } |
| 562 | 561 |
| 563 @override | 562 @override |
| 564 void setUp() { | 563 void setUp() { |
| 565 super.setUp(); | 564 super.setUp(); |
| 566 testFile = provider.convertPath('/completionTest.dart'); | 565 testFile = provider.convertPath('/completionTest.dart'); |
| 567 contributor = createContributor(); | 566 contributor = createContributor(); |
| 568 } | 567 } |
| 569 } | 568 } |
| OLD | NEW |