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

Side by Side Diff: pkg/analysis_services/lib/completion/completion_suggestion.dart

Issue 424543004: incremental progress aligning code completion api to spec (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address comments Created 6 years, 4 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; 5 library services.completion.suggestion;
6 6
7 import 'package:analysis_services/constants.dart';
7 import 'package:analysis_services/json.dart'; 8 import 'package:analysis_services/json.dart';
8 import 'package:analysis_services/constants.dart';
9 import 'package:analyzer/src/generated/element.dart'; 9 import 'package:analyzer/src/generated/element.dart';
10 10
11 /** 11 /**
12 * An enumeration of the relevance of a completion suggestion.
13 */
14 class CompletionRelevance {
15 static const CompletionRelevance LOW = const CompletionRelevance('LOW');
16 static const CompletionRelevance DEFAULT =
17 const CompletionRelevance('DEFAULT');
18 static const CompletionRelevance HIGH = const CompletionRelevance('HIGH');
19
20 final String name;
21
22 const CompletionRelevance(this.name);
23
24 static CompletionRelevance value(String name) {
25 if (LOW.name == name) return LOW;
26 if (DEFAULT.name == name) return DEFAULT;
27 if (HIGH.name == name) return HIGH;
28 throw new ArgumentError('Unknown CompletionRelevance: $name');
29 }
30 }
31
32 /**
12 * A single completion suggestion. 33 * A single completion suggestion.
13 */ 34 */
14 class CompletionSuggestion implements HasToJson { 35 class CompletionSuggestion implements HasToJson {
15 36
16 /** 37 /**
17 * The kind of element being suggested. 38 * The kind of element being suggested.
18 */ 39 */
19 final CompletionSuggestionKind kind; 40 final CompletionSuggestionKind kind;
20 41
21 /** 42 /**
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 IS_POTENTIAL: isPotential 114 IS_POTENTIAL: isPotential
94 }; 115 };
95 } 116 }
96 } 117 }
97 118
98 /** 119 /**
99 * An enumeration of the kinds of elements that can be included 120 * An enumeration of the kinds of elements that can be included
100 * in a completion suggestion. 121 * in a completion suggestion.
101 */ 122 */
102 class CompletionSuggestionKind { 123 class CompletionSuggestionKind {
124 static const CompletionSuggestionKind ARGUMENT_LIST =
125 const CompletionSuggestionKind('ARGUMENT_LIST');
103 static const CompletionSuggestionKind CLASS = 126 static const CompletionSuggestionKind CLASS =
104 const CompletionSuggestionKind('CLASS'); 127 const CompletionSuggestionKind('CLASS');
105 static const CompletionSuggestionKind CLASS_ALIAS = 128 static const CompletionSuggestionKind CLASS_ALIAS =
106 const CompletionSuggestionKind('CLASS_ALIAS'); 129 const CompletionSuggestionKind('CLASS_ALIAS');
107 static const CompletionSuggestionKind CONSTRUCTOR = 130 static const CompletionSuggestionKind CONSTRUCTOR =
108 const CompletionSuggestionKind('CONSTRUCTOR'); 131 const CompletionSuggestionKind('CONSTRUCTOR');
109 static const CompletionSuggestionKind FIELD = 132 static const CompletionSuggestionKind FIELD =
110 const CompletionSuggestionKind('FIELD'); 133 const CompletionSuggestionKind('FIELD');
111 static const CompletionSuggestionKind FUNCTION = 134 static const CompletionSuggestionKind FUNCTION =
112 const CompletionSuggestionKind('FUNCTION'); 135 const CompletionSuggestionKind('FUNCTION');
113 static const CompletionSuggestionKind FUNCTION_ALIAS =
114 const CompletionSuggestionKind('FUNCTION_ALIAS');
115 static const CompletionSuggestionKind FUNCTION_TYPE_ALIAS = 136 static const CompletionSuggestionKind FUNCTION_TYPE_ALIAS =
116 const CompletionSuggestionKind('FUNCTION_TYPE_ALIAS'); 137 const CompletionSuggestionKind('FUNCTION_TYPE_ALIAS');
117 static const CompletionSuggestionKind GETTER = 138 static const CompletionSuggestionKind GETTER =
118 const CompletionSuggestionKind('GETTER'); 139 const CompletionSuggestionKind('GETTER');
119 static const CompletionSuggestionKind IMPORT = 140 static const CompletionSuggestionKind IMPORT =
120 const CompletionSuggestionKind('IMPORT'); 141 const CompletionSuggestionKind('IMPORT');
121 static const CompletionSuggestionKind LIBRARY_PREFIX = 142 static const CompletionSuggestionKind LIBRARY_PREFIX =
122 const CompletionSuggestionKind('LIBRARY_PREFIX'); 143 const CompletionSuggestionKind('LIBRARY_PREFIX');
123 static const CompletionSuggestionKind METHOD = 144 static const CompletionSuggestionKind METHOD =
124 const CompletionSuggestionKind('METHOD'); 145 const CompletionSuggestionKind('METHOD');
125 static const CompletionSuggestionKind METHOD_NAME = 146 static const CompletionSuggestionKind METHOD_NAME =
126 const CompletionSuggestionKind('METHOD_NAME'); 147 const CompletionSuggestionKind('METHOD_NAME');
148 static const CompletionSuggestionKind NAMED_ARGUMENT =
149 const CompletionSuggestionKind('NAMED_ARGUMENT');
150 static const CompletionSuggestionKind OPTIONAL_ARGUMENT =
151 const CompletionSuggestionKind('OPTIONAL_ARGUMENT');
127 static const CompletionSuggestionKind PARAMETER = 152 static const CompletionSuggestionKind PARAMETER =
128 const CompletionSuggestionKind('PARAMETER'); 153 const CompletionSuggestionKind('PARAMETER');
129 static const CompletionSuggestionKind SETTER = 154 static const CompletionSuggestionKind SETTER =
130 const CompletionSuggestionKind('SETTER'); 155 const CompletionSuggestionKind('SETTER');
156 static const CompletionSuggestionKind TOP_LEVEL_VARIABLE =
157 const CompletionSuggestionKind('TOP_LEVEL_VARIABLE');
158 static const CompletionSuggestionKind TYPE_PARAMETER =
159 const CompletionSuggestionKind('TYPE_PARAMETER');
160 // TODO (danrubel) consider renaming VARIABLE --> LOCAL_VARIABLE
161 // to match ElementKind.LOCAL_VARIABLE
131 static const CompletionSuggestionKind VARIABLE = 162 static const CompletionSuggestionKind VARIABLE =
132 const CompletionSuggestionKind('VARIABLE'); 163 const CompletionSuggestionKind('VARIABLE');
133 static const CompletionSuggestionKind TYPE_PARAMETER =
134 const CompletionSuggestionKind('TYPE_PARAMETER');
135 static const CompletionSuggestionKind ARGUMENT_LIST =
136 const CompletionSuggestionKind('ARGUMENT_LIST');
137 static const CompletionSuggestionKind OPTIONAL_ARGUMENT =
138 const CompletionSuggestionKind('OPTIONAL_ARGUMENT');
139 static const CompletionSuggestionKind NAMED_ARGUMENT =
140 const CompletionSuggestionKind('NAMED_ARGUMENT');
141 static const CompletionSuggestionKind TOP_LEVEL_VARIABLE =
142 const CompletionSuggestionKind('TOP_LEVEL_VARIABLE');
143 164
144 final String name; 165 final String name;
145 166
146 const CompletionSuggestionKind(this.name); 167 const CompletionSuggestionKind(this.name);
147 168
148 @override 169 @override
149 String toString() => name; 170 String toString() => name;
150 171
151 static CompletionSuggestionKind valueOf(String name) {
152 if (CLASS.name == name) return CLASS;
153 if (CLASS_ALIAS.name == name) return CLASS_ALIAS;
154 if (CONSTRUCTOR.name == name) return CONSTRUCTOR;
155 if (FIELD.name == name) return FIELD;
156 if (FUNCTION.name == name) return FUNCTION;
157 if (FUNCTION_ALIAS.name == name) return FUNCTION_ALIAS;
158 if (FUNCTION_TYPE_ALIAS.name == name) return FUNCTION_TYPE_ALIAS;
159 if (GETTER.name == name) return GETTER;
160 if (IMPORT.name == name) return IMPORT;
161 if (LIBRARY_PREFIX.name == name) return LIBRARY_PREFIX;
162 if (METHOD.name == name) return METHOD;
163 if (METHOD_NAME.name == name) return METHOD_NAME;
164 if (PARAMETER.name == name) return PARAMETER;
165 if (SETTER.name == name) return SETTER;
166 if (VARIABLE.name == name) return VARIABLE;
167 if (TYPE_PARAMETER.name == name) return TYPE_PARAMETER;
168 if (ARGUMENT_LIST.name == name) return ARGUMENT_LIST;
169 if (OPTIONAL_ARGUMENT.name == name) return OPTIONAL_ARGUMENT;
170 if (NAMED_ARGUMENT.name == name) return NAMED_ARGUMENT;
171 if (TOP_LEVEL_VARIABLE.name == name) return TOP_LEVEL_VARIABLE;
172 throw new ArgumentError('Unknown CompletionSuggestionKind: $name');
173 }
174
175 static CompletionSuggestionKind fromElementKind(ElementKind kind) { 172 static CompletionSuggestionKind fromElementKind(ElementKind kind) {
176 // ElementKind.ANGULAR_FORMATTER, 173 // ElementKind.ANGULAR_FORMATTER,
177 // ElementKind.ANGULAR_COMPONENT, 174 // ElementKind.ANGULAR_COMPONENT,
178 // ElementKind.ANGULAR_CONTROLLER, 175 // ElementKind.ANGULAR_CONTROLLER,
179 // ElementKind.ANGULAR_DIRECTIVE, 176 // ElementKind.ANGULAR_DIRECTIVE,
180 // ElementKind.ANGULAR_PROPERTY, 177 // ElementKind.ANGULAR_PROPERTY,
181 // ElementKind.ANGULAR_SCOPE_PROPERTY, 178 // ElementKind.ANGULAR_SCOPE_PROPERTY,
182 // ElementKind.ANGULAR_SELECTOR, 179 // ElementKind.ANGULAR_SELECTOR,
183 // ElementKind.ANGULAR_VIEW, 180 // ElementKind.ANGULAR_VIEW,
184 if (kind == ElementKind.CLASS) return CLASS; 181 if (kind == ElementKind.CLASS) return CLASS;
185 // ElementKind.COMPILATION_UNIT, 182 // ElementKind.COMPILATION_UNIT,
186 if (kind == ElementKind.CONSTRUCTOR) return CONSTRUCTOR; 183 if (kind == ElementKind.CONSTRUCTOR) return CONSTRUCTOR;
187 // ElementKind.DYNAMIC, 184 // ElementKind.DYNAMIC,
188 // ElementKind.EMBEDDED_HTML_SCRIPT, 185 // ElementKind.EMBEDDED_HTML_SCRIPT,
189 // ElementKind.ERROR, 186 // ElementKind.ERROR,
190 // ElementKind.EXPORT, 187 // ElementKind.EXPORT,
191 // ElementKind.EXTERNAL_HTML_SCRIPT, 188 // ElementKind.EXTERNAL_HTML_SCRIPT,
192 if (kind == ElementKind.FIELD) return FIELD; 189 if (kind == ElementKind.FIELD) return FIELD;
193 if (kind == ElementKind.FUNCTION) return FUNCTION; 190 if (kind == ElementKind.FUNCTION) return FUNCTION;
191 if (kind == ElementKind.FUNCTION_TYPE_ALIAS) return FUNCTION_TYPE_ALIAS;
194 if (kind == ElementKind.GETTER) return GETTER; 192 if (kind == ElementKind.GETTER) return GETTER;
195 // ElementKind.HTML, 193 // ElementKind.HTML,
196 if (kind == ElementKind.IMPORT) return IMPORT; 194 if (kind == ElementKind.IMPORT) return IMPORT;
197 // ElementKind.LABEL, 195 // ElementKind.LABEL,
198 // ElementKind.LIBRARY, 196 // ElementKind.LIBRARY,
199 // ElementKind.LOCAL_VARIABLE, 197 if (kind == ElementKind.LOCAL_VARIABLE) return VARIABLE;
200 if (kind == ElementKind.METHOD) return METHOD; 198 if (kind == ElementKind.METHOD) return METHOD;
201 // ElementKind.NAME, 199 // ElementKind.NAME,
202 if (kind == ElementKind.PARAMETER) return PARAMETER; 200 if (kind == ElementKind.PARAMETER) return PARAMETER;
203 // ElementKind.POLYMER_ATTRIBUTE, 201 // ElementKind.POLYMER_ATTRIBUTE,
204 // ElementKind.POLYMER_TAG_DART, 202 // ElementKind.POLYMER_TAG_DART,
205 // ElementKind.POLYMER_TAG_HTML, 203 // ElementKind.POLYMER_TAG_HTML,
206 // ElementKind.PREFIX, 204 // ElementKind.PREFIX,
207 if (kind == ElementKind.SETTER) return SETTER; 205 if (kind == ElementKind.SETTER) return SETTER;
208 if (kind == ElementKind.TOP_LEVEL_VARIABLE) return TOP_LEVEL_VARIABLE; 206 if (kind == ElementKind.TOP_LEVEL_VARIABLE) return TOP_LEVEL_VARIABLE;
209 if (kind == ElementKind.FUNCTION_TYPE_ALIAS) return FUNCTION_TYPE_ALIAS;
210 // ElementKind.TYPE_PARAMETER, 207 // ElementKind.TYPE_PARAMETER,
211 // ElementKind.UNIVERSE 208 // ElementKind.UNIVERSE
212 throw new ArgumentError('Unknown CompletionSuggestionKind for: $kind'); 209 throw new ArgumentError('Unknown CompletionSuggestionKind for: $kind');
213 } 210 }
214 }
215 211
216 /** 212 static CompletionSuggestionKind valueOf(String name) {
217 * An enumeration of the relevance of a completion suggestion. 213 if (ARGUMENT_LIST.name == name) return ARGUMENT_LIST;
218 */ 214 if (CLASS.name == name) return CLASS;
219 class CompletionRelevance { 215 if (CLASS_ALIAS.name == name) return CLASS_ALIAS;
220 static const CompletionRelevance LOW = const CompletionRelevance('LOW'); 216 if (CONSTRUCTOR.name == name) return CONSTRUCTOR;
221 static const CompletionRelevance DEFAULT = 217 if (FIELD.name == name) return FIELD;
222 const CompletionRelevance('DEFAULT'); 218 if (FUNCTION.name == name) return FUNCTION;
223 static const CompletionRelevance HIGH = const CompletionRelevance('HIGH'); 219 if (FUNCTION_TYPE_ALIAS.name == name) return FUNCTION_TYPE_ALIAS;
224 220 if (GETTER.name == name) return GETTER;
225 final String name; 221 if (IMPORT.name == name) return IMPORT;
226 222 if (LIBRARY_PREFIX.name == name) return LIBRARY_PREFIX;
227 const CompletionRelevance(this.name); 223 if (METHOD.name == name) return METHOD;
228 224 if (METHOD_NAME.name == name) return METHOD_NAME;
229 static CompletionRelevance value(String name) { 225 if (NAMED_ARGUMENT.name == name) return NAMED_ARGUMENT;
230 if (LOW.name == name) return LOW; 226 if (OPTIONAL_ARGUMENT.name == name) return OPTIONAL_ARGUMENT;
231 if (DEFAULT.name == name) return DEFAULT; 227 if (PARAMETER.name == name) return PARAMETER;
232 if (HIGH.name == name) return HIGH; 228 if (SETTER.name == name) return SETTER;
233 throw new ArgumentError('Unknown CompletionRelevance: $name'); 229 if (TOP_LEVEL_VARIABLE.name == name) return TOP_LEVEL_VARIABLE;
230 if (TYPE_PARAMETER.name == name) return TYPE_PARAMETER;
231 if (VARIABLE.name == name) return VARIABLE;
232 throw new ArgumentError('Unknown CompletionSuggestionKind: $name');
234 } 233 }
235 } 234 }
OLDNEW
« no previous file with comments | « pkg/analysis_services/lib/completion/completion_computer.dart ('k') | pkg/analysis_services/lib/constants.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698