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

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

Issue 1319753002: exclude instance suggestions in static context - fixes #22932 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library services.completion.dart.optype; 5 library services.completion.dart.optype;
6 6
7 import 'package:analysis_server/src/services/completion/completion_target.dart'; 7 import 'package:analysis_server/src/services/completion/completion_target.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/scanner.dart'; 9 import 'package:analyzer/src/generated/scanner.dart';
10 10
11 /** 11 /**
12 * An [AstVisitor] for determining whether top level suggestions or invocation 12 * An [AstVisitor] for determining whether top level suggestions or invocation
13 * suggestions should be made based upon the type of node in which the 13 * suggestions should be made based upon the type of node in which the
14 * suggestions were requested. 14 * suggestions were requested.
15 */ 15 */
16 class OpType { 16 class OpType {
17
18 /** 17 /**
19 * Indicates whether constructor suggestions should be included. 18 * Indicates whether constructor suggestions should be included.
20 */ 19 */
21 bool includeConstructorSuggestions = false; 20 bool includeConstructorSuggestions = false;
22 21
23 /** 22 /**
24 * Indicates whether type names should be suggested. 23 * Indicates whether type names should be suggested.
25 */ 24 */
26 bool includeTypeNameSuggestions = false; 25 bool includeTypeNameSuggestions = false;
27 26
(...skipping 13 matching lines...) Expand all
41 * Indicates whether statement labels should be suggested. 40 * Indicates whether statement labels should be suggested.
42 */ 41 */
43 bool includeStatementLabelSuggestions = false; 42 bool includeStatementLabelSuggestions = false;
44 43
45 /** 44 /**
46 * Indicates whether case labels should be suggested. 45 * Indicates whether case labels should be suggested.
47 */ 46 */
48 bool includeCaseLabelSuggestions = false; 47 bool includeCaseLabelSuggestions = false;
49 48
50 /** 49 /**
50 * Indicates whether the completion location is in the body of a static method .
51 */
52 bool inStaticMethodBody = false;
53
54 /**
51 * Indicates whether the completion target is prefixed. 55 * Indicates whether the completion target is prefixed.
52 */ 56 */
53 bool isPrefixed = false; 57 bool isPrefixed = false;
54 58
55 /** 59 /**
56 * Determine the suggestions that should be made based upon the given 60 * Determine the suggestions that should be made based upon the given
57 * [CompletionTarget] and [offset]. 61 * [CompletionTarget] and [offset].
58 */ 62 */
59 factory OpType.forCompletion(CompletionTarget target, int offset) { 63 factory OpType.forCompletion(CompletionTarget target, int offset) {
60 OpType optype = new OpType._(); 64 OpType optype = new OpType._();
61 target.containingNode 65 target.containingNode
62 .accept(new _OpTypeAstVisitor(optype, target.entity, offset)); 66 .accept(new _OpTypeAstVisitor(optype, target.entity, offset));
67 var mthDecl =
68 target.containingNode.getAncestor((p) => p is MethodDeclaration);
69 optype.inStaticMethodBody =
70 mthDecl is MethodDeclaration && mthDecl.isStatic;
63 return optype; 71 return optype;
64 } 72 }
65 73
66 OpType._(); 74 OpType._();
67 75
68 /** 76 /**
69 * Indicate whether only type names should be suggested 77 * Indicate whether only type names should be suggested
70 */ 78 */
71 bool get includeOnlyTypeNameSuggestions => includeTypeNameSuggestions && 79 bool get includeOnlyTypeNameSuggestions => includeTypeNameSuggestions &&
72 !includeReturnValueSuggestions && 80 !includeReturnValueSuggestions &&
73 !includeVoidReturnSuggestions; 81 !includeVoidReturnSuggestions;
74 } 82 }
75 83
76 class _OpTypeAstVisitor extends GeneralizingAstVisitor { 84 class _OpTypeAstVisitor extends GeneralizingAstVisitor {
77
78 /** 85 /**
79 * The entity (AstNode or Token) which will be replaced or displaced by the 86 * The entity (AstNode or Token) which will be replaced or displaced by the
80 * added text. 87 * added text.
81 */ 88 */
82 final Object entity; 89 final Object entity;
83 90
84 /** 91 /**
85 * The offset within the source at which the completion is requested. 92 * The offset within the source at which the completion is requested.
86 */ 93 */
87 final int offset; 94 final int offset;
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 void visitVariableDeclarationStatement(VariableDeclarationStatement node) {} 641 void visitVariableDeclarationStatement(VariableDeclarationStatement node) {}
635 642
636 @override 643 @override
637 void visitWhileStatement(WhileStatement node) { 644 void visitWhileStatement(WhileStatement node) {
638 if (identical(entity, node.condition)) { 645 if (identical(entity, node.condition)) {
639 optype.includeReturnValueSuggestions = true; 646 optype.includeReturnValueSuggestions = true;
640 optype.includeTypeNameSuggestions = true; 647 optype.includeTypeNameSuggestions = true;
641 } 648 }
642 } 649 }
643 } 650 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698