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

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

Issue 1871073003: Fix for issue 22357: use type information on the RHS of is expressions to improve quality of comple… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Comments from DanR- only resolve if the request containing node is an Expression Created 4 years, 8 months 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/optype.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/optype.dart b/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
index 42f45c5d7f371c6dacc7d00b090b2c5871d0d12b..274609926f9f239edc898acd9946c09bf3805bfb 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
@@ -10,6 +10,7 @@ import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/ast/token.dart';
import 'package:analyzer/src/generated/utilities_dart.dart';
@@ -30,6 +31,13 @@ class OpType {
bool includeTypeNameSuggestions = false;
/**
+ * If [includeTypeNameSuggestions] is set to true, then this function may be
+ * set to the non-default function to filter out potential suggestions based
+ * on their static [DartType].
+ */
+ Function typeNameSuggestionsFilter = (DartType _) => true;
+
+ /**
* Indicates whether setters along with methods and functions that
* have a [void] return type should be suggested.
*/
@@ -494,10 +502,11 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
void visitIsExpression(IsExpression node) {
if (identical(entity, node.type)) {
optype.includeTypeNameSuggestions = true;
- // TODO (danrubel) Possible future improvement:
- // on the RHS of an "is" or "as" expression, don't suggest types that are
- // guaranteed to pass or guaranteed to fail the cast.
- // See dartbug.com/18860
+ optype.typeNameSuggestionsFilter = (DartType dartType) {
+ DartType bestType = node.expression.bestType;
+ return bestType.isDynamic ||
+ (dartType.isSubtypeOf(bestType) && dartType != bestType);
+ };
}
}

Powered by Google App Engine
This is Rietveld 408576698