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

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

Issue 558893002: add code completion declared and return types (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge and remove reference to analysis engine Created 6 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 | 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.dart' hide Element; 7 import 'package:analysis_server/src/protocol.dart' hide Element;
8 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 8 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
9 import 'package:analyzer/src/generated/element.dart'; 9 import 'package:analyzer/src/generated/element.dart';
10 10
(...skipping 16 matching lines...) Expand all
27 }); 27 });
28 } 28 }
29 29
30 @override 30 @override
31 visitElement(Element element) { 31 visitElement(Element element) {
32 // ignored 32 // ignored
33 } 33 }
34 34
35 @override 35 @override
36 visitFieldElement(FieldElement element) { 36 visitFieldElement(FieldElement element) {
37 _addSuggestion(element, CompletionSuggestionKind.FIELD); 37 _addSuggestion(
38 element,
39 CompletionSuggestionKind.FIELD,
40 element.type,
41 element.enclosingElement);
38 } 42 }
39 43
40 @override 44 @override
41 visitMethodElement(MethodElement element) { 45 visitMethodElement(MethodElement element) {
42 _addSuggestion(element, CompletionSuggestionKind.METHOD); 46 _addSuggestion(
47 element,
48 CompletionSuggestionKind.METHOD,
49 element.returnType,
50 element.enclosingElement);
43 } 51 }
44 52
45 @override 53 @override
46 visitPropertyAccessorElement(PropertyAccessorElement element) { 54 visitPropertyAccessorElement(PropertyAccessorElement element) {
47 if (element.isGetter) { 55 if (element.isGetter) {
48 _addSuggestion(element, CompletionSuggestionKind.GETTER); 56 _addSuggestion(
57 element,
58 CompletionSuggestionKind.GETTER,
59 element.returnType,
60 element.enclosingElement);
49 } else if (element.isSetter) { 61 } else if (element.isSetter) {
50 _addSuggestion(element, CompletionSuggestionKind.SETTER); 62 _addSuggestion(
63 element,
64 CompletionSuggestionKind.SETTER,
65 element.returnType,
66 element.enclosingElement);
51 } 67 }
52 } 68 }
53 69
54 void _addSuggestion(Element element, CompletionSuggestionKind kind) { 70 void _addSuggestion(Element element, CompletionSuggestionKind kind,
71 DartType type, ClassElement enclosingElement) {
55 if (element.isSynthetic) { 72 if (element.isSynthetic) {
56 return; 73 return;
57 } 74 }
58 if (element.isPrivate) { 75 if (element.isPrivate) {
59 LibraryElement elementLibrary = 76 LibraryElement elementLibrary =
60 element.getAncestor((parent) => parent is LibraryElement); 77 element.getAncestor((parent) => parent is LibraryElement);
61 LibraryElement unitLibrary = 78 LibraryElement unitLibrary =
62 request.unit.element.getAncestor((parent) => parent is LibraryElement) ; 79 request.unit.element.getAncestor((parent) => parent is LibraryElement) ;
63 if (elementLibrary != unitLibrary) { 80 if (elementLibrary != unitLibrary) {
64 return; 81 return;
65 } 82 }
66 } 83 }
67 String completion = element.displayName; 84 String completion = element.displayName;
68 if (completion == null || 85 if (completion == null ||
69 completion.length <= 0 || 86 completion.length <= 0 ||
70 !_completions.add(completion)) { 87 !_completions.add(completion)) {
71 return; 88 return;
72 } 89 }
73 request.suggestions.add( 90 var suggestion = new CompletionSuggestion(
74 new CompletionSuggestion( 91 kind,
75 kind, 92 CompletionRelevance.DEFAULT,
76 CompletionRelevance.DEFAULT, 93 completion,
77 completion, 94 completion.length,
78 completion.length, 95 0,
79 0, 96 element.isDeprecated,
80 element.isDeprecated, 97 false);
81 false)); 98 if (enclosingElement != null) {
99 suggestion.declaringType = enclosingElement.displayName;
100 }
101 if (type != null) {
102 String typeName = type.displayName;
103 if (typeName != null && typeName.length > 0 && typeName != 'dynamic') {
104 suggestion.returnType = typeName;
105 }
106 }
107 request.suggestions.add(suggestion);
82 } 108 }
83 109
84 /** 110 /**
85 * Add suggestions for the visible members in the given class 111 * Add suggestions for the visible members in the given class
86 */ 112 */
87 static void suggestionsFor(DartCompletionRequest request, Element element) { 113 static void suggestionsFor(DartCompletionRequest request, Element element) {
88 if (element is ClassElement) { 114 if (element is ClassElement) {
89 element.accept(new ClassElementSuggestionBuilder(request)); 115 element.accept(new ClassElementSuggestionBuilder(request));
90 } 116 }
91 } 117 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 /** 173 /**
148 * Add suggestions for the visible members in the given library 174 * Add suggestions for the visible members in the given library
149 */ 175 */
150 static void suggestionsFor(DartCompletionRequest request, 176 static void suggestionsFor(DartCompletionRequest request,
151 LibraryElement library) { 177 LibraryElement library) {
152 if (library != null) { 178 if (library != null) {
153 library.visitChildren(new LibraryElementSuggestionBuilder(request)); 179 library.visitChildren(new LibraryElementSuggestionBuilder(request));
154 } 180 }
155 } 181 }
156 } 182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698