Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: pkg/analysis_server/lib/src/services/completion/dart/static_member_contributor.dart

Issue 1516883002: do not suggest completions for cascade on library prefix - fixes #25215 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/services/completion/dart/static_member_contributor.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/static_member_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/static_member_contributor.dart
index cb94c1de9f2333d8408e9dab8e8ad5bcda799265..301e5d8560b36e9bf7be2fa8e56eacf406339bc6 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/static_member_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/static_member_contributor.dart
@@ -7,7 +7,6 @@ library services.completion.contributor.dart.static_member;
import 'dart:async';
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
-import 'package:analysis_server/src/provisional/completion/dart/completion_target.dart';
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart';
import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/element.dart';
@@ -23,61 +22,33 @@ class StaticMemberContributor extends DartCompletionContributor {
@override
Future<List<CompletionSuggestion>> computeSuggestions(
DartCompletionRequest request) async {
- // Determine if the target looks like a prefixed identifier,
- // a method invocation, or a property access
- SimpleIdentifier targetId = _getTargetId(request.target);
- if (targetId == null) {
+ // Determine if the target looks like a static method invocation,
+ // or a static property access
+ if (request.dotTarget is! Identifier || request.target.isCascade) {
return EMPTY_LIST;
}
// Resolve the expression and the containing library
- await request.resolveExpression(targetId);
- LibraryElement containingLibrary = await request.libraryElement;
- // Gracefully degrade if the library could not be determined
- // e.g. detached part file or source change
- if (containingLibrary == null) {
- return EMPTY_LIST;
- }
+ await request.resolveExpression(request.dotTarget);
// Recompute the target since resolution may have changed it
- targetId = _getTargetId(request.target);
- if (targetId == null) {
- return EMPTY_LIST;
- }
-
- // Build the suggestions
- Element elem = targetId.bestElement;
- if (elem is ClassElement) {
- _SuggestionBuilder builder = new _SuggestionBuilder(containingLibrary);
- elem.accept(builder);
- return builder.suggestions;
- }
- return EMPTY_LIST;
- }
-
- /**
- * Return the identifier to the left of the 'dot' or `null` if none.
- */
- SimpleIdentifier _getTargetId(CompletionTarget target) {
- AstNode node = target.containingNode;
- if (node is MethodInvocation) {
- if (identical(node.methodName, target.entity)) {
- Expression target = node.realTarget;
- if (target is SimpleIdentifier) {
- return target;
+ Expression targetId = request.dotTarget;
+ if (targetId is Identifier && !request.target.isCascade) {
+ Element elem = targetId.bestElement;
+ if (elem is ClassElement) {
+ LibraryElement containingLibrary = await request.libraryElement;
+ // Gracefully degrade if the library could not be determined
+ // e.g. detached part file or source change
+ if (containingLibrary == null) {
+ return EMPTY_LIST;
}
- } else {
- return null;
- }
- }
- if (node is PrefixedIdentifier) {
- if (identical(node.identifier, target.entity)) {
- return node.prefix;
- } else {
- return null;
+
+ _SuggestionBuilder builder = new _SuggestionBuilder(containingLibrary);
+ elem.accept(builder);
+ return builder.suggestions;
}
}
- return null;
+ return EMPTY_LIST;
}
}

Powered by Google App Engine
This is Rietveld 408576698