| Index: pkg/analysis_server/lib/src/services/completion/dart/inherited_contributor.dart
|
| diff --git a/pkg/analysis_server/lib/src/services/completion/inherited_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/inherited_contributor.dart
|
| similarity index 59%
|
| rename from pkg/analysis_server/lib/src/services/completion/inherited_contributor.dart
|
| rename to pkg/analysis_server/lib/src/services/completion/dart/inherited_contributor.dart
|
| index 451da5363ba66f4167301f3bd3002fe7c022c647..eb4807645c0d7364d021936d74ab98c5783d842d 100644
|
| --- a/pkg/analysis_server/lib/src/services/completion/inherited_contributor.dart
|
| +++ b/pkg/analysis_server/lib/src/services/completion/dart/inherited_contributor.dart
|
| @@ -4,6 +4,8 @@
|
|
|
| library services.completion.computer.dart.invocation;
|
|
|
| +import 'dart:async';
|
| +
|
| import 'package:analysis_server/plugin/edit/utilities/change_builder_dart.dart';
|
| import 'package:analysis_server/src/protocol_server.dart'
|
| show CompletionSuggestion, CompletionSuggestionKind, SourceChange;
|
| @@ -17,6 +19,9 @@ import 'package:analyzer/src/generated/element.dart';
|
| import 'package:analyzer/src/generated/engine.dart';
|
| import 'package:analyzer/src/generated/resolver.dart';
|
| import 'package:analyzer/src/generated/source.dart';
|
| +import 'package:analyzer/src/task/dart.dart';
|
| +import 'package:analyzer/task/model.dart';
|
| +import 'package:analysis_server/src/provisional/completion/dart/completion_target.dart';
|
|
|
| /**
|
| * A completion contributor used to suggest replacing partial identifiers inside
|
| @@ -24,23 +29,16 @@ import 'package:analyzer/src/generated/source.dart';
|
| */
|
| class InheritedContributor extends DartCompletionContributor {
|
| @override
|
| - List<CompletionSuggestion> internalComputeSuggestions(
|
| - DartCompletionRequest request) {
|
| - if (!request.isResolved) {
|
| - return null;
|
| - }
|
| - AstNode node = new NodeLocator(request.offset).searchWithin(request.unit);
|
| - if (node == null || !_isMemberLevelIdentifier(node)) {
|
| - return null;
|
| - }
|
| - ClassDeclaration classDeclaration =
|
| - node.getAncestor((AstNode node) => node is ClassDeclaration);
|
| - if (classDeclaration != null) {
|
| - ClassElement element = classDeclaration.element;
|
| - if (element == null) {
|
| - return null;
|
| - }
|
| - return _suggestInheritedMembers(request, node, element);
|
| + Future computeSuggestions(
|
| + DartCompletionRequest request, DartSuggestionCollector collector) {
|
| + if (request.parsedTarget.containingNode is ClassDeclaration) {
|
| + return request.resolvedDeclarationTarget
|
| + .then((CompletionTarget resolvedTarget) {
|
| + _suggestInheritedMembers(
|
| + request,
|
| + (resolvedTarget.containingNode as ClassDeclaration).element,
|
| + collector);
|
| + });
|
| }
|
| return null;
|
| }
|
| @@ -49,14 +47,13 @@ class InheritedContributor extends DartCompletionContributor {
|
| * Return a template for an override of the given [element] in the given
|
| * [source]. If selected, the template will replace the given [identifier].
|
| */
|
| - String _buildRepacementText(
|
| - Source source, SimpleIdentifier identifier, Element element) {
|
| - AnalysisContext context = element.context;
|
| + String _buildRepacementText(DartCompletionRequest request, Element element) {
|
| + AnalysisContext context = request.context;
|
| DartChangeBuilder builder = new DartChangeBuilder(context);
|
| - builder.addFileEdit(source, context.getModificationStamp(source),
|
| + builder.addFileEdit(
|
| + request.source, context.getModificationStamp(request.source),
|
| (DartFileEditBuilder builder) {
|
| - builder.addReplacement(identifier.offset, identifier.length,
|
| - (DartEditBuilder builder) {
|
| + builder.addReplacement(0, 0, (DartEditBuilder builder) {
|
| builder.writeOverrideOfInheritedMember(element);
|
| });
|
| });
|
| @@ -68,14 +65,14 @@ class InheritedContributor extends DartCompletionContributor {
|
| * [source] with an override of the given [element].
|
| */
|
| CompletionSuggestion _buildSuggestion(
|
| - Source source, SimpleIdentifier identifier, Element element) {
|
| - String completion = _buildRepacementText(source, identifier, element);
|
| + DartCompletionRequest request, Element element) {
|
| + String completion = _buildRepacementText(request, element);
|
| CompletionSuggestion suggestion = new CompletionSuggestion(
|
| CompletionSuggestionKind.IDENTIFIER,
|
| DART_RELEVANCE_HIGH,
|
| completion,
|
| - identifier.offset,
|
| 0,
|
| + completion.length,
|
| element.isDeprecated,
|
| false);
|
| suggestion.element = protocol.convertElement(element);
|
| @@ -88,10 +85,10 @@ class InheritedContributor extends DartCompletionContributor {
|
| * start with the given [prefix]. The [map] is used to find all of the members
|
| * that are inherited.
|
| */
|
| - List<String> _computeMemberNames(
|
| - MemberMap map, ClassElement element, String prefix) {
|
| + List<String> _computeMemberNames(MemberMap map, ClassElement element) {
|
| List<String> memberNames = <String>[];
|
| int count = map.size;
|
| + RegExp prefix = new RegExp('[A-Za-z_]');
|
| for (int i = 0; i < count; i++) {
|
| String memberName = map.getKey(i);
|
| if (memberName.startsWith(prefix) && !_hasMember(element, memberName)) {
|
| @@ -113,48 +110,19 @@ class InheritedContributor extends DartCompletionContributor {
|
| }
|
|
|
| /**
|
| - * Return `true` if the given [node] looks like a partial identifier inside a
|
| - * class declaration.
|
| - */
|
| - bool _isMemberLevelIdentifier(AstNode node) {
|
| - if (node is SimpleIdentifier) {
|
| - AstNode parent1 = node.parent;
|
| - if (parent1 is TypeName) {
|
| - AstNode parent2 = parent1.parent;
|
| - if (parent2 is VariableDeclarationList) {
|
| - AstNode parent3 = parent2.parent;
|
| - if (parent3 is FieldDeclaration) {
|
| - NodeList<VariableDeclaration> variables = parent2.variables;
|
| - return variables.length == 1 && variables[0].name.name.isEmpty;
|
| - }
|
| - }
|
| - }
|
| - }
|
| - return false;
|
| - }
|
| -
|
| - /**
|
| * Add any suggestions that are appropriate to the given [request], using the
|
| * given [element] to find inherited members whose name has the given
|
| * [identifier] as a prefix.
|
| */
|
| - List<CompletionSuggestion> _suggestInheritedMembers(
|
| - DartCompletionRequest request,
|
| - SimpleIdentifier identifier,
|
| - ClassElement element) {
|
| - String name = identifier.name;
|
| + void _suggestInheritedMembers(DartCompletionRequest request,
|
| + ClassElement element, DartSuggestionCollector collector) {
|
| InheritanceManager manager = new InheritanceManager(element.library);
|
| MemberMap map = manager.getMapOfMembersInheritedFromInterfaces(element);
|
| - List<String> memberNames = _computeMemberNames(map, element, name);
|
| + List<String> memberNames = _computeMemberNames(map, element);
|
| memberNames.sort();
|
| - List<CompletionSuggestion> suggestions = <CompletionSuggestion>[];
|
| for (String memberName in memberNames) {
|
| - CompletionSuggestion suggestion =
|
| - _buildSuggestion(request.source, identifier, map.get(memberName));
|
| - if (suggestion != null) {
|
| - suggestions.add(suggestion);
|
| - }
|
| + collector.addCompletionSuggestion(
|
| + _buildSuggestion(request, map.get(memberName)));
|
| }
|
| - return suggestions;
|
| }
|
| }
|
|
|