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

Side by Side Diff: pkg/analysis_server/lib/src/computer/computer_outline.dart

Issue 340183003: 'Element' and 'Outline' implementations for the new server API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/computer/element.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 computer.outline; 5 library computer.outline;
6 6
7 import 'package:analysis_server/src/computer/element.dart';
7 import 'package:analysis_server/src/constants.dart'; 8 import 'package:analysis_server/src/constants.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart' as ane;
Brian Wilkerson 2014/06/18 20:37:09 What does "ane" stand for? Given that I can't tell
scheglov 2014/06/18 20:43:27 Done.
9 11
10 12
11 /** 13 /**
12 * A computer for [CompilationUnit] outline. 14 * A computer for [CompilationUnit] outline.
13 */ 15 */
14 class DartUnitOutlineComputer { 16 class DartUnitOutlineComputer {
15 final CompilationUnit _unit; 17 final CompilationUnit _unit;
16 18
17 DartUnitOutlineComputer(this._unit); 19 DartUnitOutlineComputer(this._unit);
18 20
19 /** 21 /**
20 * Returns the computed outline, not `null`. 22 * Returns the computed outline, not `null`.
21 */ 23 */
22 Map<String, Object> compute() { 24 Map<String, Object> compute() {
23 _Outline unitOutline = _newUnitOutline(); 25 Outline unitOutline = _newUnitOutline();
24 for (CompilationUnitMember unitMember in _unit.declarations) { 26 for (CompilationUnitMember unitMember in _unit.declarations) {
25 if (unitMember is ClassDeclaration) { 27 if (unitMember is ClassDeclaration) {
26 ClassDeclaration classDeclaration = unitMember; 28 ClassDeclaration classDeclaration = unitMember;
27 _Outline classOutline = _newClassOutline(unitOutline, classDeclaration); 29 Outline classOutline = _newClassOutline(unitOutline, classDeclaration);
28 for (ClassMember classMember in classDeclaration.members) { 30 for (ClassMember classMember in classDeclaration.members) {
29 if (classMember is ConstructorDeclaration) { 31 if (classMember is ConstructorDeclaration) {
30 ConstructorDeclaration constructorDeclaration = classMember; 32 ConstructorDeclaration constructorDeclaration = classMember;
31 _newConstructorOutline(classOutline, constructorDeclaration); 33 _newConstructorOutline(classOutline, constructorDeclaration);
32 } 34 }
33 if (classMember is FieldDeclaration) { 35 if (classMember is FieldDeclaration) {
34 FieldDeclaration fieldDeclaration = classMember; 36 FieldDeclaration fieldDeclaration = classMember;
35 VariableDeclarationList fields = fieldDeclaration.fields; 37 VariableDeclarationList fields = fieldDeclaration.fields;
36 if (fields != null) { 38 if (fields != null) {
37 TypeName fieldType = fields.type; 39 TypeName fieldType = fields.type;
38 String fieldTypeName = fieldType != null ? fieldType.toSource() : ""; 40 String fieldTypeName = fieldType != null ? fieldType.toSource() :
41 '';
Brian Wilkerson 2014/06/18 20:37:09 Unfortunate line break...
scheglov 2014/06/18 20:43:27 Yes. At some point we need to improve the formatte
39 for (VariableDeclaration field in fields.variables) { 42 for (VariableDeclaration field in fields.variables) {
40 _newVariableOutline(classOutline, fieldTypeName, _OutlineKind.FI ELD, field, fieldDeclaration.isStatic); 43 _newVariableOutline(classOutline, fieldTypeName,
44 ElementKind.FIELD, field, fieldDeclaration.isStatic);
41 } 45 }
42 } 46 }
43 } 47 }
44 if (classMember is MethodDeclaration) { 48 if (classMember is MethodDeclaration) {
45 MethodDeclaration methodDeclaration = classMember; 49 MethodDeclaration methodDeclaration = classMember;
46 _newMethodOutline(classOutline, methodDeclaration); 50 _newMethodOutline(classOutline, methodDeclaration);
47 } 51 }
48 } 52 }
49 } 53 }
50 if (unitMember is TopLevelVariableDeclaration) { 54 if (unitMember is TopLevelVariableDeclaration) {
51 TopLevelVariableDeclaration fieldDeclaration = unitMember; 55 TopLevelVariableDeclaration fieldDeclaration = unitMember;
52 VariableDeclarationList fields = fieldDeclaration.variables; 56 VariableDeclarationList fields = fieldDeclaration.variables;
53 if (fields != null) { 57 if (fields != null) {
54 TypeName fieldType = fields.type; 58 TypeName fieldType = fields.type;
55 String fieldTypeName = fieldType != null ? fieldType.toSource() : ""; 59 String fieldTypeName = fieldType != null ? fieldType.toSource() : '';
56 for (VariableDeclaration field in fields.variables) { 60 for (VariableDeclaration field in fields.variables) {
57 _newVariableOutline(unitOutline, fieldTypeName, _OutlineKind.TOP_LEV EL_VARIABLE, field, false); 61 _newVariableOutline(unitOutline, fieldTypeName,
62 ElementKind.TOP_LEVEL_VARIABLE, field, false);
58 } 63 }
59 } 64 }
60 } 65 }
61 if (unitMember is FunctionDeclaration) { 66 if (unitMember is FunctionDeclaration) {
62 FunctionDeclaration functionDeclaration = unitMember; 67 FunctionDeclaration functionDeclaration = unitMember;
63 _newFunctionOutline(unitOutline, functionDeclaration); 68 _newFunctionOutline(unitOutline, functionDeclaration, true);
64 } 69 }
65 if (unitMember is ClassTypeAlias) { 70 if (unitMember is ClassTypeAlias) {
66 ClassTypeAlias alias = unitMember; 71 ClassTypeAlias alias = unitMember;
67 _newClassTypeAlias(unitOutline, alias); 72 _newClassTypeAlias(unitOutline, alias);
68 } 73 }
69 if (unitMember is FunctionTypeAlias) { 74 if (unitMember is FunctionTypeAlias) {
70 FunctionTypeAlias alias = unitMember; 75 FunctionTypeAlias alias = unitMember;
71 _newFunctionTypeAliasOutline(unitOutline, alias); 76 _newFunctionTypeAliasOutline(unitOutline, alias);
72 } 77 }
73 } 78 }
74 return unitOutline.toJson(); 79 return unitOutline.toJson();
75 } 80 }
76 81
77 void _addLocalFunctionOutlines(_Outline parent, FunctionBody body) { 82 void _addLocalFunctionOutlines(Outline parent, FunctionBody body) {
78 body.accept(new _LocalFunctionOutlinesVisitor(this, parent)); 83 body.accept(new _LocalFunctionOutlinesVisitor(this, parent));
79 } 84 }
80 85
81 /** 86 /**
82 * Returns the [AstNode]'s source region. 87 * Returns the [AstNode]'s source region.
83 */ 88 */
84 _SourceRegion _getSourceRegion(AstNode node) { 89 _SourceRegion _getSourceRegion(AstNode node) {
85 int endOffset = node.end; 90 int endOffset = node.end;
86 // prepare position of the node among its siblings 91 // prepare position of the node among its siblings
87 int firstOffset; 92 int firstOffset;
(...skipping 30 matching lines...) Expand all
118 // first child: [endOfParent, endOfNode] 123 // first child: [endOfParent, endOfNode]
119 int index = siblings.indexOf(node); 124 int index = siblings.indexOf(node);
120 if (index == 0) { 125 if (index == 0) {
121 return new _SourceRegion(firstOffset, endOffset - firstOffset); 126 return new _SourceRegion(firstOffset, endOffset - firstOffset);
122 } 127 }
123 // not first child: [endOfPreviousSibling, endOfNode] 128 // not first child: [endOfPreviousSibling, endOfNode]
124 int prevSiblingEnd = siblings[index - 1].end; 129 int prevSiblingEnd = siblings[index - 1].end;
125 return new _SourceRegion(prevSiblingEnd, endOffset - prevSiblingEnd); 130 return new _SourceRegion(prevSiblingEnd, endOffset - prevSiblingEnd);
126 } 131 }
127 132
128 _Outline _newClassOutline(_Outline parent, ClassDeclaration classDeclaration) { 133 Outline _newClassOutline(Outline parent, ClassDeclaration classDeclaration) {
129 SimpleIdentifier nameNode = classDeclaration.name; 134 SimpleIdentifier nameNode = classDeclaration.name;
130 String name = nameNode.name; 135 String name = nameNode.name;
131 _SourceRegion sourceRegion = _getSourceRegion(classDeclaration); 136 _SourceRegion sourceRegion = _getSourceRegion(classDeclaration);
132 _Outline outline = new _Outline( 137 Element element = new Element(ElementKind.CLASS, name, nameNode.offset,
133 _OutlineKind.CLASS, name, 138 nameNode.length, Identifier.isPrivateName(name), _isDeprecated(
134 nameNode.offset, nameNode.length, 139 classDeclaration), isAbstract: classDeclaration.isAbstract);
135 sourceRegion.offset, sourceRegion.length, 140 Outline outline = new Outline(element, sourceRegion.offset,
136 classDeclaration.isAbstract, false, 141 sourceRegion.length);
137 null, null);
138 parent.children.add(outline); 142 parent.children.add(outline);
139 return outline; 143 return outline;
140 } 144 }
141 145
142 void _newClassTypeAlias(_Outline parent, ClassTypeAlias alias) { 146 void _newClassTypeAlias(Outline parent, ClassTypeAlias alias) {
143 SimpleIdentifier nameNode = alias.name; 147 SimpleIdentifier nameNode = alias.name;
144 String name = nameNode.name; 148 String name = nameNode.name;
145 _SourceRegion sourceRegion = _getSourceRegion(alias); 149 _SourceRegion sourceRegion = _getSourceRegion(alias);
146 _Outline outline = new _Outline( 150 Element element = new Element(ElementKind.CLASS_TYPE_ALIAS, name,
147 _OutlineKind.CLASS_TYPE_ALIAS, name, 151 nameNode.offset, nameNode.length, Identifier.isPrivateName(name), _isDep recated(
148 nameNode.offset, nameNode.length, 152 alias), isAbstract: alias.isAbstract);
149 sourceRegion.offset, sourceRegion.length, 153 Outline outline = new Outline(element, sourceRegion.offset,
150 alias.isAbstract, false, 154 sourceRegion.length);
151 null, null); 155 parent.children.add(outline);
152 parent.children.add(outline); 156 }
153 } 157
154 158 void _newConstructorOutline(Outline parent,
155 void _newConstructorOutline(_Outline parent, ConstructorDeclaration constructo r) { 159 ConstructorDeclaration constructor) {
156 Identifier returnType = constructor.returnType; 160 Identifier returnType = constructor.returnType;
157 String name = returnType.name; 161 String name = returnType.name;
158 int offset = returnType.offset; 162 int offset = returnType.offset;
159 int length = returnType.length; 163 int length = returnType.length;
160 SimpleIdentifier constructorNameNode = constructor.name; 164 SimpleIdentifier constructorNameNode = constructor.name;
165 bool isPrivate = false;
161 if (constructorNameNode != null) { 166 if (constructorNameNode != null) {
162 String constructorName = constructorNameNode.name; 167 String constructorName = constructorNameNode.name;
163 name += ".${constructorName}"; 168 isPrivate = Identifier.isPrivateName(constructorName);
169 name += '.${constructorName}';
164 offset = constructorNameNode.offset; 170 offset = constructorNameNode.offset;
165 length = constructorNameNode.length; 171 length = constructorNameNode.length;
166 } 172 }
167 _SourceRegion sourceRegion = _getSourceRegion(constructor); 173 _SourceRegion sourceRegion = _getSourceRegion(constructor);
168 FormalParameterList parameters = constructor.parameters; 174 FormalParameterList parameters = constructor.parameters;
169 String parametersStr = parameters != null ? parameters.toSource() : ""; 175 String parametersStr = parameters != null ? parameters.toSource() : '';
170 _Outline outline = new _Outline( 176 Element element = new Element(ElementKind.CONSTRUCTOR, name, offset, length,
171 _OutlineKind.CONSTRUCTOR, name, 177 isPrivate, _isDeprecated(constructor), parameters: parametersStr);
172 offset, length, 178 Outline outline = new Outline(element, sourceRegion.offset,
173 sourceRegion.offset, sourceRegion.length, 179 sourceRegion.length);
174 false, false,
175 parametersStr, null);
176 parent.children.add(outline); 180 parent.children.add(outline);
177 _addLocalFunctionOutlines(outline, constructor.body); 181 _addLocalFunctionOutlines(outline, constructor.body);
178 } 182 }
179 183
180 void _newFunctionOutline(_Outline parent, FunctionDeclaration function) { 184 void _newFunctionOutline(Outline parent, FunctionDeclaration function,
185 bool isStatic) {
181 TypeName returnType = function.returnType; 186 TypeName returnType = function.returnType;
182 SimpleIdentifier nameNode = function.name; 187 SimpleIdentifier nameNode = function.name;
183 String name = nameNode.name; 188 String name = nameNode.name;
184 FunctionExpression functionExpression = function.functionExpression; 189 FunctionExpression functionExpression = function.functionExpression;
185 FormalParameterList parameters = functionExpression.parameters; 190 FormalParameterList parameters = functionExpression.parameters;
186 _OutlineKind kind; 191 ElementKind kind;
187 if (function.isGetter) { 192 if (function.isGetter) {
188 kind = _OutlineKind.GETTER; 193 kind = ElementKind.GETTER;
189 } else if (function.isSetter) { 194 } else if (function.isSetter) {
190 kind = _OutlineKind.SETTER; 195 kind = ElementKind.SETTER;
191 } else { 196 } else {
192 kind = _OutlineKind.FUNCTION; 197 kind = ElementKind.FUNCTION;
193 } 198 }
194 _SourceRegion sourceRegion = _getSourceRegion(function); 199 _SourceRegion sourceRegion = _getSourceRegion(function);
195 String parametersStr = parameters != null ? parameters.toSource() : ""; 200 String parametersStr = parameters != null ? parameters.toSource() : '';
196 String returnTypeStr = returnType != null ? returnType.toSource() : ""; 201 String returnTypeStr = returnType != null ? returnType.toSource() : '';
197 _Outline outline = new _Outline( 202 Element element = new Element(kind, name, nameNode.offset, nameNode.length,
198 kind, name, 203 Identifier.isPrivateName(name), _isDeprecated(function), parameters:
199 nameNode.offset, nameNode.length, 204 parametersStr, returnType: returnTypeStr, isStatic: isStatic);
200 sourceRegion.offset, sourceRegion.length, 205 Outline outline = new Outline(element, sourceRegion.offset,
201 false, false, 206 sourceRegion.length);
202 parametersStr, returnTypeStr);
203 parent.children.add(outline); 207 parent.children.add(outline);
204 _addLocalFunctionOutlines(outline, functionExpression.body); 208 _addLocalFunctionOutlines(outline, functionExpression.body);
205 } 209 }
206 210
207 void _newFunctionTypeAliasOutline(_Outline parent, FunctionTypeAlias alias) { 211 void _newFunctionTypeAliasOutline(Outline parent, FunctionTypeAlias alias) {
208 TypeName returnType = alias.returnType; 212 TypeName returnType = alias.returnType;
209 SimpleIdentifier nameNode = alias.name; 213 SimpleIdentifier nameNode = alias.name;
210 String name = nameNode.name; 214 String name = nameNode.name;
211 _SourceRegion sourceRegion = _getSourceRegion(alias); 215 _SourceRegion sourceRegion = _getSourceRegion(alias);
212 FormalParameterList parameters = alias.parameters; 216 FormalParameterList parameters = alias.parameters;
213 String parametersStr = parameters != null ? parameters.toSource() : ""; 217 String parametersStr = parameters != null ? parameters.toSource() : '';
214 String returnTypeStr = returnType != null ? returnType.toSource() : ""; 218 String returnTypeStr = returnType != null ? returnType.toSource() : '';
215 _Outline outline = new _Outline( 219 Element element = new Element(ElementKind.FUNCTION_TYPE_ALIAS, name,
216 _OutlineKind.FUNCTION_TYPE_ALIAS, name, 220 nameNode.offset, nameNode.length, Identifier.isPrivateName(name), _isDep recated(
217 nameNode.offset, nameNode.length, 221 alias), parameters: parametersStr, returnType: returnTypeStr);
218 sourceRegion.offset, sourceRegion.length, 222 Outline outline = new Outline(element, sourceRegion.offset,
219 false, false, 223 sourceRegion.length);
220 parametersStr, returnTypeStr); 224 parent.children.add(outline);
221 parent.children.add(outline); 225 }
222 } 226
223 227 void _newMethodOutline(Outline parent, MethodDeclaration method) {
224 void _newMethodOutline(_Outline parent, MethodDeclaration method) {
225 TypeName returnType = method.returnType; 228 TypeName returnType = method.returnType;
226 SimpleIdentifier nameNode = method.name; 229 SimpleIdentifier nameNode = method.name;
227 String name = nameNode.name; 230 String name = nameNode.name;
228 FormalParameterList parameters = method.parameters; 231 FormalParameterList parameters = method.parameters;
229 _OutlineKind kind; 232 ElementKind kind;
230 if (method.isGetter) { 233 if (method.isGetter) {
231 kind = _OutlineKind.GETTER; 234 kind = ElementKind.GETTER;
232 } else if (method.isSetter) { 235 } else if (method.isSetter) {
233 kind = _OutlineKind.SETTER; 236 kind = ElementKind.SETTER;
234 } else { 237 } else {
235 kind = _OutlineKind.METHOD; 238 kind = ElementKind.METHOD;
236 } 239 }
237 _SourceRegion sourceRegion = _getSourceRegion(method); 240 _SourceRegion sourceRegion = _getSourceRegion(method);
238 String parametersStr = parameters != null ? parameters.toSource() : ""; 241 String parametersStr = parameters != null ? parameters.toSource() : '';
239 String returnTypeStr = returnType != null ? returnType.toSource() : ""; 242 String returnTypeStr = returnType != null ? returnType.toSource() : '';
240 _Outline outline = new _Outline( 243 Element element = new Element(kind, name, nameNode.offset, nameNode.length,
241 kind, name, 244 Identifier.isPrivateName(name), _isDeprecated(method), parameters:
242 nameNode.offset, nameNode.length, 245 parametersStr, returnType: returnTypeStr, isAbstract: method.isAbstract,
243 sourceRegion.offset, sourceRegion.length, 246 isStatic: method.isStatic);
244 method.isAbstract, method.isStatic, 247 Outline outline = new Outline(element, sourceRegion.offset,
245 parametersStr, returnTypeStr); 248 sourceRegion.length);
246 parent.children.add(outline); 249 parent.children.add(outline);
247 _addLocalFunctionOutlines(outline, method.body); 250 _addLocalFunctionOutlines(outline, method.body);
248 } 251 }
249 252
250 _Outline _newUnitOutline() { 253 Outline _newUnitOutline() {
251 return new _Outline( 254 Element element = new Element(ElementKind.COMPILATION_UNIT, '<unit>',
252 _OutlineKind.COMPILATION_UNIT, "<unit>", 255 _unit.offset, _unit.length, false, false);
253 _unit.offset, _unit.length, 256 return new Outline(element, _unit.offset, _unit.length);
254 _unit.offset, _unit.length, 257 }
255 false, false, 258
256 null, null); 259 void _newVariableOutline(Outline parent, String typeName, ElementKind kind,
257 } 260 VariableDeclaration variable, bool isStatic) {
258
259 void _newVariableOutline(_Outline parent, String typeName, _OutlineKind kind, VariableDeclaration variable, bool isStatic) {
260 SimpleIdentifier nameNode = variable.name; 261 SimpleIdentifier nameNode = variable.name;
261 String name = nameNode.name; 262 String name = nameNode.name;
262 _SourceRegion sourceRegion = _getSourceRegion(variable); 263 _SourceRegion sourceRegion = _getSourceRegion(variable);
263 _Outline outline = new _Outline( 264 Element element = new Element(kind, name, nameNode.offset, nameNode.length,
264 kind, name, 265 Identifier.isPrivateName(name), _isDeprecated(variable), returnType: typ eName,
265 nameNode.offset, nameNode.length, 266 isStatic: isStatic, isConst: variable.isConst, isFinal: variable.isFinal );
266 sourceRegion.offset, sourceRegion.length, 267 Outline outline = new Outline(element, sourceRegion.offset,
267 false, isStatic, 268 sourceRegion.length);
268 null, typeName); 269 parent.children.add(outline);
269 parent.children.add(outline); 270 }
271
272 /**
273 * Returns `true` if the given [element] is not `null` and deprecated.
274 */
275 static bool _isDeprecated(Declaration declaration) {
276 ane.Element element = declaration.element;
277 return element != null && element.isDeprecated;
270 } 278 }
271 } 279 }
272 280
273 281
282 /**
283 * An element outline.
284 */
285 class Outline {
286 static const List<Outline> EMPTY_ARRAY = const <Outline>[];
287
288 /**
289 * The children of the node.
290 * The field will be omitted in JSON if the node has no children.
291 */
292 final List<Outline> children = <Outline>[];
293
294 /**
295 * A description of the element represented by this node.
296 */
297 final Element element;
298
299 /**
300 * The length of the element.
301 */
302 final int length;
303
304 /**
305 * The offset of the first character of the element.
306 */
307 final int offset;
308
309 Outline(this.element, this.offset, this.length);
310
311 factory Outline.fromJson(Map<String, Object> map) {
312 Element element = new Element.fromJson(map[ELEMENT]);
313 Outline outline = new Outline(element, map[OFFSET], map[LENGTH]);
314 // add children
315 List<Map<String, Object>> childrenMaps = map[CHILDREN];
316 if (childrenMaps != null) {
317 childrenMaps.forEach((childMap) {
318 outline.children.add(new Outline.fromJson(childMap));
319 });
320 }
321 // done
322 return outline;
323 }
324
325 Map<String, Object> toJson() {
326 Map<String, Object> json = {
327 ELEMENT: element.toJson(),
328 OFFSET: offset,
329 LENGTH: length
330 };
331 if (children.isNotEmpty) {
332 json[CHILDREN] = children.map((child) => child.toJson()).toList();
333 }
334 return json;
335 }
336 }
337
338
274 /** 339 /**
275 * A visitor for building local function outlines. 340 * A visitor for building local function outlines.
276 */ 341 */
277 class _LocalFunctionOutlinesVisitor extends RecursiveAstVisitor { 342 class _LocalFunctionOutlinesVisitor extends RecursiveAstVisitor {
278 final DartUnitOutlineComputer outlineComputer; 343 final DartUnitOutlineComputer outlineComputer;
279 final _Outline parent; 344 final Outline parent;
280 345
281 _LocalFunctionOutlinesVisitor(this.outlineComputer, this.parent); 346 _LocalFunctionOutlinesVisitor(this.outlineComputer, this.parent);
282 347
283 @override 348 @override
284 visitFunctionDeclaration(FunctionDeclaration node) { 349 visitFunctionDeclaration(FunctionDeclaration node) {
285 outlineComputer._newFunctionOutline(parent, node); 350 outlineComputer._newFunctionOutline(parent, node, false);
286 } 351 }
287 } 352 }
288 353
289 354
290
291 /** 355 /**
292 * A range of characters. 356 * A range of characters.
293 */ 357 */
294 class _SourceRegion { 358 class _SourceRegion {
359 final int length;
295 final int offset; 360 final int offset;
296 final int length;
297 _SourceRegion(this.offset, this.length); 361 _SourceRegion(this.offset, this.length);
298 } 362 }
299
300
301 /**
302 * Element outline kinds.
303 */
304 class _OutlineKind {
305 static const _OutlineKind CLASS = const _OutlineKind('CLASS');
306 static const _OutlineKind CLASS_TYPE_ALIAS = const _OutlineKind('CLASS_TYPE_AL IAS');
307 static const _OutlineKind COMPILATION_UNIT = const _OutlineKind('COMPILATION_U NIT');
308 static const _OutlineKind CONSTRUCTOR = const _OutlineKind('CONSTRUCTOR');
309 static const _OutlineKind GETTER = const _OutlineKind('GETTER');
310 static const _OutlineKind FIELD = const _OutlineKind('FIELD');
311 static const _OutlineKind FUNCTION = const _OutlineKind('FUNCTION');
312 static const _OutlineKind FUNCTION_TYPE_ALIAS = const _OutlineKind('FUNCTION_T YPE_ALIAS');
313 static const _OutlineKind LIBRARY = const _OutlineKind('LIBRARY');
314 static const _OutlineKind METHOD = const _OutlineKind('METHOD');
315 static const _OutlineKind SETTER = const _OutlineKind('SETTER');
316 static const _OutlineKind TOP_LEVEL_VARIABLE = const _OutlineKind('TOP_LEVEL_V ARIABLE');
317 static const _OutlineKind UNKNOWN = const _OutlineKind('UNKNOWN');
318 static const _OutlineKind UNIT_TEST_CASE = const _OutlineKind('UNIT_TEST_CASE' );
319 static const _OutlineKind UNIT_TEST_GROUP = const _OutlineKind('UNIT_TEST_GROU P');
320
321 final String name;
322
323 const _OutlineKind(this.name);
324 }
325
326
327 /**
328 * An element outline.
329 */
330 class _Outline {
331 static const List<_Outline> EMPTY_ARRAY = const <_Outline>[];
332
333 final _OutlineKind kind;
334 final String name;
335 final int nameOffset;
336 final int nameLength;
337 final int elementOffset;
338 final int elementLength;
339 final bool isAbstract;
340 final bool isStatic;
341 final String parameters;
342 final String returnType;
343 final List<_Outline> children = <_Outline>[];
344
345 _Outline(this.kind, this.name,
346 this.nameOffset, this.nameLength,
347 this.elementOffset, this.elementLength,
348 this.isAbstract, this.isStatic,
349 this.parameters, this.returnType);
350
351 Map<String, Object> toJson() {
352 Map<String, Object> json = {
353 KIND: kind.name,
354 NAME: name,
355 NAME_OFFSET: nameOffset,
356 NAME_LENGTH: nameLength,
357 ELEMENT_OFFSET: elementOffset,
358 ELEMENT_LENGTH: elementLength,
359 IS_ABSTRACT: isAbstract,
360 IS_STATIC: isStatic
361 };
362 if (parameters != null) {
363 json[PARAMETERS] = parameters;
364 }
365 if (returnType != null) {
366 json[RETURN_TYPE] = returnType;
367 }
368 if (children.isNotEmpty) {
369 json[CHILDREN] = children.map((child) => child.toJson()).toList();
370 }
371 return json;
372 }
373 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/computer/element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698