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

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

Issue 389413002: Use HasToJson when set Reponse/Notification parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 computer.outline; 5 library computer.outline;
6 6
7 import 'package:analysis_server/src/collections.dart';
7 import 'package:analysis_server/src/computer/element.dart'; 8 import 'package:analysis_server/src/computer/element.dart';
8 import 'package:analysis_server/src/constants.dart'; 9 import 'package:analysis_server/src/constants.dart';
9 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart' as engine; 11 import 'package:analyzer/src/generated/element.dart' as engine;
11 import 'package:analyzer/src/generated/engine.dart'; 12 import 'package:analyzer/src/generated/engine.dart';
12 import 'package:analyzer/src/generated/source.dart'; 13 import 'package:analyzer/src/generated/source.dart';
13 14
14 15
15 /** 16 /**
16 * A computer for [CompilationUnit] outline. 17 * A computer for [CompilationUnit] outline.
17 */ 18 */
18 class DartUnitOutlineComputer { 19 class DartUnitOutlineComputer {
19 final CompilationUnit _unit; 20 final CompilationUnit _unit;
20 String file; 21 String file;
21 LineInfo lineInfo; 22 LineInfo lineInfo;
22 23
23 DartUnitOutlineComputer(AnalysisContext context, Source source, this._unit) { 24 DartUnitOutlineComputer(AnalysisContext context, Source source, this._unit) {
24 file = source.fullName; 25 file = source.fullName;
25 lineInfo = context.getLineInfo(source); 26 lineInfo = context.getLineInfo(source);
26 } 27 }
27 28
28 /** 29 /**
29 * Returns the computed outline, not `null`. 30 * Returns the computed outline, not `null`.
30 */ 31 */
31 Map<String, Object> compute() { 32 Outline compute() {
32 Outline unitOutline = _newUnitOutline(); 33 Outline unitOutline = _newUnitOutline();
33 for (CompilationUnitMember unitMember in _unit.declarations) { 34 for (CompilationUnitMember unitMember in _unit.declarations) {
34 if (unitMember is ClassDeclaration) { 35 if (unitMember is ClassDeclaration) {
35 ClassDeclaration classDeclaration = unitMember; 36 ClassDeclaration classDeclaration = unitMember;
36 Outline classOutline = _newClassOutline(unitOutline, classDeclaration); 37 Outline classOutline = _newClassOutline(unitOutline, classDeclaration);
37 for (ClassMember classMember in classDeclaration.members) { 38 for (ClassMember classMember in classDeclaration.members) {
38 if (classMember is ConstructorDeclaration) { 39 if (classMember is ConstructorDeclaration) {
39 ConstructorDeclaration constructorDeclaration = classMember; 40 ConstructorDeclaration constructorDeclaration = classMember;
40 _newConstructorOutline(classOutline, constructorDeclaration); 41 _newConstructorOutline(classOutline, constructorDeclaration);
41 } 42 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 77 }
77 if (unitMember is ClassTypeAlias) { 78 if (unitMember is ClassTypeAlias) {
78 ClassTypeAlias alias = unitMember; 79 ClassTypeAlias alias = unitMember;
79 _newClassTypeAlias(unitOutline, alias); 80 _newClassTypeAlias(unitOutline, alias);
80 } 81 }
81 if (unitMember is FunctionTypeAlias) { 82 if (unitMember is FunctionTypeAlias) {
82 FunctionTypeAlias alias = unitMember; 83 FunctionTypeAlias alias = unitMember;
83 _newFunctionTypeAliasOutline(unitOutline, alias); 84 _newFunctionTypeAliasOutline(unitOutline, alias);
84 } 85 }
85 } 86 }
86 return unitOutline.toJson(); 87 return unitOutline;
87 } 88 }
88 89
89 void _addLocalFunctionOutlines(Outline parent, FunctionBody body) { 90 void _addLocalFunctionOutlines(Outline parent, FunctionBody body) {
90 body.accept(new _LocalFunctionOutlinesVisitor(this, parent)); 91 body.accept(new _LocalFunctionOutlinesVisitor(this, parent));
91 } 92 }
92 93
93 Location _getLocationNode(AstNode node) { 94 Location _getLocationNode(AstNode node) {
94 int offset = node.offset; 95 int offset = node.offset;
95 int length = node.length; 96 int length = node.length;
96 return _getLocationOffsetLength(offset, length); 97 return _getLocationOffsetLength(offset, length);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 static bool _isDeprecated(Declaration declaration) { 297 static bool _isDeprecated(Declaration declaration) {
297 engine.Element element = declaration.element; 298 engine.Element element = declaration.element;
298 return element != null && element.isDeprecated; 299 return element != null && element.isDeprecated;
299 } 300 }
300 } 301 }
301 302
302 303
303 /** 304 /**
304 * An element outline. 305 * An element outline.
305 */ 306 */
306 class Outline { 307 class Outline implements HasToJson {
307 static const List<Outline> EMPTY_ARRAY = const <Outline>[]; 308 static const List<Outline> EMPTY_ARRAY = const <Outline>[];
308 309
309 /** 310 /**
310 * The children of the node. 311 * The children of the node.
311 * The field will be omitted in JSON if the node has no children. 312 * The field will be omitted in JSON if the node has no children.
312 */ 313 */
313 final List<Outline> children = <Outline>[]; 314 final List<Outline> children = <Outline>[];
314 315
315 /** 316 /**
316 * A description of the element represented by this node. 317 * A description of the element represented by this node.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 375
375 376
376 /** 377 /**
377 * A range of characters. 378 * A range of characters.
378 */ 379 */
379 class _SourceRegion { 380 class _SourceRegion {
380 final int length; 381 final int length;
381 final int offset; 382 final int offset;
382 _SourceRegion(this.offset, this.length); 383 _SourceRegion(this.offset, this.length);
383 } 384 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698