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

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

Issue 643153003: add imported inherited member suggestions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 2 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 | Annotate | Revision Log
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.suggestion.builder; 5 library services.completion.suggestion.builder;
6 6
7 import 'package:analysis_server/src/protocol_server.dart' as protocol; 7 import 'package:analysis_server/src/protocol_server.dart' as protocol;
8 import 'package:analysis_server/src/protocol_server.dart' hide Element, 8 import 'package:analysis_server/src/protocol_server.dart' hide Element,
9 ElementKind; 9 ElementKind;
10 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 10 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
11 import 'package:analyzer/src/generated/ast.dart';
11 import 'package:analyzer/src/generated/element.dart'; 12 import 'package:analyzer/src/generated/element.dart';
12 13
13 /** 14 /**
15 * Call the given function with each non-null non-empty inherited type name
16 * that is defined in the given class.
17 */
18 visitInheritedTypeNames(ClassDeclaration node, void inherited(String name)) {
19
20 void visit(TypeName type) {
21 if (type != null) {
22 Identifier id = type.name;
23 if (id != null) {
24 String name = id.name;
25 if (name != null && name.length > 0) {
26 inherited(name);
27 }
28 }
29 }
30 }
31
32 ExtendsClause extendsClause = node.extendsClause;
33 if (extendsClause != null) {
34 visit(extendsClause.superclass);
35 }
36 ImplementsClause implementsClause = node.implementsClause;
37 if (implementsClause != null) {
38 NodeList<TypeName> interfaces = implementsClause.interfaces;
39 if (interfaces != null) {
40 interfaces.forEach((TypeName type) {
41 visit(type);
42 });
43 }
44 }
45 WithClause withClause = node.withClause;
46 if (withClause != null) {
47 NodeList<TypeName> mixinTypes = withClause.mixinTypes;
48 if (mixinTypes != null) {
49 mixinTypes.forEach((TypeName type) {
50 visit(type);
51 });
52 }
53 }
54 }
55
56 /**
57 * Call the given functions with each non-null non-empty inherited class
58 * declaration, if the class is defined locally, or type name if it is not
59 * defined locally.
60 */
61 void visitInheritedTypes(ClassDeclaration node, void
62 local(ClassDeclaration classNode), void imported(String typeName)) {
63 CompilationUnit unit = node.getAncestor((p) => p is CompilationUnit);
64 List<ClassDeclaration> todo = new List<ClassDeclaration>();
65 todo.add(node);
66 Set<String> visited = new Set<String>();
67 while (todo.length > 0) {
68 node = todo.removeLast();
69 visitInheritedTypeNames(node, (String name) {
70 if (visited.add(name)) {
71 var classNode = unit.declarations.firstWhere((member) {
72 if (member is ClassDeclaration) {
73 SimpleIdentifier id = member.name;
74 if (id != null && id.name == name) {
75 return true;
76 }
77 }
78 return false;
79 }, orElse: () => null);
80 if (classNode is ClassDeclaration) {
81 local(classNode);
82 todo.add(classNode);
83 } else {
84 imported(name);
85 }
86 }
87 });
88 }
89 }
90
91 /**
14 * This class visits elements in a class and provides suggestions based upon 92 * This class visits elements in a class and provides suggestions based upon
15 * the visible members in that class. Clients should call 93 * the visible members in that class. Clients should call
16 * [ClassElementSuggestionBuilder.suggestionsFor]. 94 * [ClassElementSuggestionBuilder.suggestionsFor].
17 */ 95 */
18 class ClassElementSuggestionBuilder extends _AbstractSuggestionBuilder { 96 class ClassElementSuggestionBuilder extends _AbstractSuggestionBuilder {
19 97
20 ClassElementSuggestionBuilder(DartCompletionRequest request) : super(request); 98 ClassElementSuggestionBuilder(DartCompletionRequest request) : super(request);
21 99
22 @override 100 @override
23 visitClassElement(ClassElement element) { 101 visitClassElement(ClassElement element) {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 308 }
231 if (type != null) { 309 if (type != null) {
232 String typeName = type.displayName; 310 String typeName = type.displayName;
233 if (typeName != null && typeName.length > 0 && typeName != 'dynamic') { 311 if (typeName != null && typeName.length > 0 && typeName != 'dynamic') {
234 suggestion.returnType = typeName; 312 suggestion.returnType = typeName;
235 } 313 }
236 } 314 }
237 request.suggestions.add(suggestion); 315 request.suggestions.add(suggestion);
238 } 316 }
239 } 317 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698