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

Side by Side Diff: pkg/analysis_server/lib/src/generated/service_computers.dart

Issue 242373005: Translate server interfaces and navigation/outline computers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information.
7
8 library service.computers;
9
10 import 'package:analyzer/src/generated/java_core.dart' show JavaStringBuilder, S tringUtils;
11 import 'package:analyzer/src/generated/source.dart' show Source;
12 import 'package:analyzer/src/generated/scanner.dart' show Token;
13 import 'package:analyzer/src/generated/ast.dart';
14 import 'package:analyzer/src/generated/element.dart' show Element;
15 import 'service_interfaces.dart';
16
17 /**
18 * A concrete implementation of [SourceRegion].
19 */
20 class SourceRegionImpl implements SourceRegion {
21 final int offset;
22
23 final int length;
24
25 SourceRegionImpl(this.offset, this.length);
26
27 @override
28 bool containsInclusive(int x) => offset <= x && x <= offset + length;
29
30 @override
31 String toString() {
32 JavaStringBuilder builder = new JavaStringBuilder();
33 builder.append("[offset=");
34 builder.append(offset);
35 builder.append(", length=");
36 builder.append(length);
37 builder.append("]");
38 return builder.toString();
39 }
40 }
41
42 /**
43 * A concrete implementation of [Outline].
44 */
45 class OutlineImpl implements Outline {
46 final Outline parent;
47
48 final OutlineKind kind;
49
50 final String name;
51
52 final int offset;
53
54 final int length;
55
56 final String arguments;
57
58 final String returnType;
59
60 List<Outline> children = Outline.EMPTY_ARRAY;
61
62 OutlineImpl(this.parent, this.kind, this.name, this.offset, this.length, this. arguments, this.returnType);
63
64 @override
65 String toString() {
66 JavaStringBuilder builder = new JavaStringBuilder();
67 builder.append("[name=");
68 builder.append(name);
69 builder.append(", kind=");
70 builder.append(kind);
71 builder.append(", offset=");
72 builder.append(offset);
73 builder.append(", length=");
74 builder.append(length);
75 builder.append(", arguments=");
76 builder.append(arguments);
77 builder.append(", return=");
78 builder.append(returnType);
79 builder.append(", children=[");
80 builder.append(StringUtils.join(children, ", "));
81 builder.append("]]");
82 return builder.toString();
83 }
84 }
85
86 /**
87 * A computer for [NavigationRegion]s in a Dart [CompilationUnit].
88 */
89 class DartUnitNavigationComputer {
90 final CompilationUnit _unit;
91
92 List<NavigationRegion> _regions = [];
93
94 DartUnitNavigationComputer(this._unit);
95
96 /**
97 * Returns the computed [NavigationRegion]s, not `null`.
98 */
99 List<NavigationRegion> compute() {
100 _unit.accept(new RecursiveAstVisitor_DartUnitNavigationComputer_compute(this ));
101 return new List.from(_regions);
102 }
103
104 /**
105 * If the given [Element] is not `null`, then creates a corresponding
106 * [NavigationRegion].
107 */
108 void _addRegionForNode(AstNode node, Element element) {
109 int offset = node.offset;
110 int length = node.length;
111 _addRegion(offset, length, element);
112 }
113
114 /**
115 * If the given [Element] is not `null`, then creates a corresponding
116 * [NavigationRegion].
117 */
118 void _addRegion(int offset, int length, Element element) {
119 NavigationTarget target = _createTarget(element);
120 if (target == null) {
121 return;
122 }
123 _regions.add(new NavigationRegionImpl(offset, length, <NavigationTarget> [ta rget]));
124 }
125
126 /**
127 * If the given [Element] is not `null`, then creates a corresponding
128 * [NavigationRegion].
129 */
130 void _addRegionForToken(Token token, Element element) {
131 int offset = token.offset;
132 int length = token.length;
133 _addRegion(offset, length, element);
134 }
135
136 /**
137 * Returns the [NavigationTarget] for the given [Element], maybe `null` if
138 * `null` was given.
139 */
140 NavigationTarget _createTarget(Element element) {
141 if (element == null) {
142 return null;
143 }
144 return new NavigationTargetImpl(element.source, _getElementId(element), elem ent.nameOffset, element.displayName.length);
145 }
146
147 String _getElementId(Element element) => element.location.encoding;
148 }
149
150 class RecursiveAstVisitor_DartUnitNavigationComputer_compute extends RecursiveAs tVisitor<Object> {
151 final DartUnitNavigationComputer DartUnitNavigationComputer_this;
152
153 RecursiveAstVisitor_DartUnitNavigationComputer_compute(this.DartUnitNavigation Computer_this) : super();
154
155 @override
156 Object visitAssignmentExpression(AssignmentExpression node) {
157 DartUnitNavigationComputer_this._addRegionForToken(node.operator, node.bestE lement);
158 return super.visitAssignmentExpression(node);
159 }
160
161 @override
162 Object visitBinaryExpression(BinaryExpression node) {
163 DartUnitNavigationComputer_this._addRegionForToken(node.operator, node.bestE lement);
164 return super.visitBinaryExpression(node);
165 }
166
167 @override
168 Object visitIndexExpression(IndexExpression node) {
169 DartUnitNavigationComputer_this._addRegionForToken(node.rightBracket, node.b estElement);
170 return super.visitIndexExpression(node);
171 }
172
173 @override
174 Object visitPostfixExpression(PostfixExpression node) {
175 DartUnitNavigationComputer_this._addRegionForToken(node.operator, node.bestE lement);
176 return super.visitPostfixExpression(node);
177 }
178
179 @override
180 Object visitPrefixExpression(PrefixExpression node) {
181 DartUnitNavigationComputer_this._addRegionForToken(node.operator, node.bestE lement);
182 return super.visitPrefixExpression(node);
183 }
184
185 @override
186 Object visitSimpleIdentifier(SimpleIdentifier node) {
187 DartUnitNavigationComputer_this._addRegionForNode(node, node.bestElement);
188 return super.visitSimpleIdentifier(node);
189 }
190 }
191
192 /**
193 * A concrete implementation of [NavigationRegion].
194 */
195 class NavigationRegionImpl extends SourceRegionImpl implements NavigationRegion {
196 final List<NavigationTarget> targets;
197
198 NavigationRegionImpl(int offset, int length, this.targets) : super(offset, len gth);
199
200 @override
201 String toString() {
202 JavaStringBuilder builder = new JavaStringBuilder();
203 builder.append(super.toString());
204 builder.append(" -> [");
205 builder.append(StringUtils.join(targets, ", "));
206 builder.append("]");
207 return builder.toString();
208 }
209 }
210
211 /**
212 * A concrete implementation of [NavigationTarget].
213 */
214 class NavigationTargetImpl implements NavigationTarget {
215 final Source source;
216
217 final String elementId;
218
219 final int offset;
220
221 final int length;
222
223 NavigationTargetImpl(this.source, this.elementId, this.offset, this.length);
224
225 @override
226 String toString() {
227 JavaStringBuilder builder = new JavaStringBuilder();
228 builder.append("[offset=");
229 builder.append(offset);
230 builder.append(", length=");
231 builder.append(length);
232 builder.append(", source=");
233 builder.append(source);
234 builder.append(", element=");
235 builder.append(elementId);
236 builder.append("]");
237 return builder.toString();
238 }
239 }
240
241 /**
242 * A computer for [Outline]s in a Dart [CompilationUnit].
243 */
244 class DartUnitOutlineComputer {
245 final CompilationUnit _unit;
246
247 DartUnitOutlineComputer(this._unit);
248
249 /**
250 * Returns the computed [Outline]s, not `null`.
251 */
252 Outline compute() {
253 OutlineImpl unitOutline = _newUnitOutline();
254 List<Outline> unitChildren = [];
255 for (CompilationUnitMember unitMember in _unit.declarations) {
256 if (unitMember is ClassDeclaration) {
257 ClassDeclaration classDeclartion = unitMember;
258 OutlineImpl classOutline = _newClassOutline(unitOutline, unitChildren, c lassDeclartion);
259 List<Outline> classChildren = [];
260 for (ClassMember classMember in classDeclartion.members) {
261 if (classMember is ConstructorDeclaration) {
262 ConstructorDeclaration constructorDeclaration = classMember;
263 _newConstructorOutline(classOutline, classChildren, constructorDecla ration);
264 }
265 if (classMember is FieldDeclaration) {
266 FieldDeclaration fieldDeclaration = classMember;
267 VariableDeclarationList fields = fieldDeclaration.fields;
268 if (fields != null) {
269 TypeName fieldType = fields.type;
270 String fieldTypeName = fieldType != null ? fieldType.toSource() : "";
271 for (VariableDeclaration field in fields.variables) {
272 _newField(classOutline, classChildren, fieldTypeName, field);
273 }
274 }
275 }
276 if (classMember is MethodDeclaration) {
277 MethodDeclaration methodDeclaration = classMember;
278 _newMethodOutline(classOutline, classChildren, methodDeclaration);
279 }
280 }
281 classOutline.children = new List.from(classChildren);
282 }
283 if (unitMember is FunctionDeclaration) {
284 FunctionDeclaration functionDeclaration = unitMember;
285 _newFunctionOutline(unitOutline, unitChildren, functionDeclaration);
286 }
287 if (unitMember is ClassTypeAlias) {
288 ClassTypeAlias alias = unitMember;
289 _newClassTypeAlias(unitOutline, unitChildren, alias);
290 }
291 if (unitMember is FunctionTypeAlias) {
292 FunctionTypeAlias alias = unitMember;
293 _newFunctionTypeAliasOutline(unitOutline, unitChildren, alias);
294 }
295 }
296 unitOutline.children = new List.from(unitChildren);
297 return unitOutline;
298 }
299
300 void _addLocalFunctionOutlines(OutlineImpl parenet, FunctionBody body) {
301 List<Outline> localOutlines = [];
302 body.accept(new RecursiveAstVisitor_DartUnitOutlineComputer_addLocalFunction Outlines(this, parenet, localOutlines));
303 parenet.children = new List.from(localOutlines);
304 }
305
306 OutlineImpl _newClassOutline(Outline unitOutline, List<Outline> unitChildren, ClassDeclaration classDeclartion) {
307 SimpleIdentifier nameNode = classDeclartion.name;
308 String name = nameNode.name;
309 OutlineImpl outline = new OutlineImpl(unitOutline, OutlineKind.CLASS, name, nameNode.offset, name.length, null, null);
310 unitChildren.add(outline);
311 return outline;
312 }
313
314 void _newClassTypeAlias(Outline unitOutline, List<Outline> unitChildren, Class TypeAlias alias) {
315 SimpleIdentifier nameNode = alias.name;
316 unitChildren.add(new OutlineImpl(unitOutline, OutlineKind.CLASS_TYPE_ALIAS, nameNode.name, nameNode.offset, nameNode.length, null, null));
317 }
318
319 void _newConstructorOutline(OutlineImpl classOutline, List<Outline> children, ConstructorDeclaration constructorDeclaration) {
320 Identifier returnType = constructorDeclaration.returnType;
321 String name = returnType.name;
322 int offset = returnType.offset;
323 int length = returnType.length;
324 SimpleIdentifier constructorNameNode = constructorDeclaration.name;
325 if (constructorNameNode != null) {
326 name += ".${constructorNameNode.name}";
327 offset = constructorNameNode.offset;
328 length = constructorNameNode.length;
329 }
330 FormalParameterList parameters = constructorDeclaration.parameters;
331 OutlineImpl outline = new OutlineImpl(classOutline, OutlineKind.CONSTRUCTOR, name, offset, length, parameters != null ? parameters.toSource() : "", null);
332 children.add(outline);
333 _addLocalFunctionOutlines(outline, constructorDeclaration.body);
334 }
335
336 void _newField(OutlineImpl classOutline, List<Outline> children, String fieldT ypeName, VariableDeclaration field) {
337 SimpleIdentifier nameNode = field.name;
338 children.add(new OutlineImpl(classOutline, OutlineKind.FIELD, nameNode.name, nameNode.offset, nameNode.length, null, fieldTypeName));
339 }
340
341 void _newFunctionOutline(Outline unitOutline, List<Outline> unitChildren, Func tionDeclaration functionDeclaration) {
342 TypeName returnType = functionDeclaration.returnType;
343 SimpleIdentifier nameNode = functionDeclaration.name;
344 FunctionExpression functionExpression = functionDeclaration.functionExpressi on;
345 FormalParameterList parameters = functionExpression.parameters;
346 OutlineKind kind;
347 if (functionDeclaration.isGetter) {
348 kind = OutlineKind.GETTER;
349 } else if (functionDeclaration.isSetter) {
350 kind = OutlineKind.SETTER;
351 } else {
352 kind = OutlineKind.FUNCTION;
353 }
354 OutlineImpl outline = new OutlineImpl(unitOutline, kind, nameNode.name, name Node.offset, nameNode.length, parameters != null ? parameters.toSource() : "", r eturnType != null ? returnType.toSource() : "");
355 unitChildren.add(outline);
356 _addLocalFunctionOutlines(outline, functionExpression.body);
357 }
358
359 void _newFunctionTypeAliasOutline(Outline unitOutline, List<Outline> unitChild ren, FunctionTypeAlias alias) {
360 TypeName returnType = alias.returnType;
361 SimpleIdentifier nameNode = alias.name;
362 FormalParameterList parameters = alias.parameters;
363 unitChildren.add(new OutlineImpl(unitOutline, OutlineKind.FUNCTION_TYPE_ALIA S, nameNode.name, nameNode.offset, nameNode.length, parameters != null ? paramet ers.toSource() : "", returnType != null ? returnType.toSource() : ""));
364 }
365
366 void _newMethodOutline(OutlineImpl classOutline, List<Outline> children, Metho dDeclaration methodDeclaration) {
367 TypeName returnType = methodDeclaration.returnType;
368 SimpleIdentifier nameNode = methodDeclaration.name;
369 FormalParameterList parameters = methodDeclaration.parameters;
370 OutlineKind kind;
371 if (methodDeclaration.isGetter) {
372 kind = OutlineKind.GETTER;
373 } else if (methodDeclaration.isSetter) {
374 kind = OutlineKind.SETTER;
375 } else {
376 kind = OutlineKind.METHOD;
377 }
378 OutlineImpl outline = new OutlineImpl(classOutline, kind, nameNode.name, nam eNode.offset, nameNode.length, parameters != null ? parameters.toSource() : "", returnType != null ? returnType.toSource() : "");
379 children.add(outline);
380 _addLocalFunctionOutlines(outline, methodDeclaration.body);
381 }
382
383 OutlineImpl _newUnitOutline() => new OutlineImpl(null, OutlineKind.COMPILATION _UNIT, null, 0, 0, null, null);
384 }
385
386 class RecursiveAstVisitor_DartUnitOutlineComputer_addLocalFunctionOutlines exten ds RecursiveAstVisitor<Object> {
387 final DartUnitOutlineComputer DartUnitOutlineComputer_this;
388
389 OutlineImpl parenet;
390
391 List<Outline> localOutlines;
392
393 RecursiveAstVisitor_DartUnitOutlineComputer_addLocalFunctionOutlines(this.Dart UnitOutlineComputer_this, this.parenet, this.localOutlines) : super();
394
395 @override
396 Object visitFunctionDeclaration(FunctionDeclaration node) {
397 DartUnitOutlineComputer_this._newFunctionOutline(parenet, localOutlines, nod e);
398 return null;
399 }
400 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698