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

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

Issue 366463002: Change Maps to HashMaps to save in performance, index and generated directories not touched (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 'dart:collection';
8
7 import 'package:analysis_server/src/computer/element.dart'; 9 import 'package:analysis_server/src/computer/element.dart';
8 import 'package:analysis_server/src/constants.dart'; 10 import 'package:analysis_server/src/constants.dart';
9 import 'package:analyzer/src/generated/ast.dart'; 11 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart' as engine; 12 import 'package:analyzer/src/generated/element.dart' as engine;
11 13
12 14
13 /** 15 /**
14 * A computer for [CompilationUnit] outline. 16 * A computer for [CompilationUnit] outline.
15 */ 17 */
16 class DartUnitOutlineComputer { 18 class DartUnitOutlineComputer {
17 final CompilationUnit _unit; 19 final CompilationUnit _unit;
18 20
19 DartUnitOutlineComputer(this._unit); 21 DartUnitOutlineComputer(this._unit);
20 22
21 /** 23 /**
22 * Returns the computed outline, not `null`. 24 * Returns the computed outline, not `null`.
23 */ 25 */
24 Map<String, Object> compute() { 26 HashMap<String, Object> compute() {
25 Outline unitOutline = _newUnitOutline(); 27 Outline unitOutline = _newUnitOutline();
26 for (CompilationUnitMember unitMember in _unit.declarations) { 28 for (CompilationUnitMember unitMember in _unit.declarations) {
27 if (unitMember is ClassDeclaration) { 29 if (unitMember is ClassDeclaration) {
28 ClassDeclaration classDeclaration = unitMember; 30 ClassDeclaration classDeclaration = unitMember;
29 Outline classOutline = _newClassOutline(unitOutline, classDeclaration); 31 Outline classOutline = _newClassOutline(unitOutline, classDeclaration);
30 for (ClassMember classMember in classDeclaration.members) { 32 for (ClassMember classMember in classDeclaration.members) {
31 if (classMember is ConstructorDeclaration) { 33 if (classMember is ConstructorDeclaration) {
32 ConstructorDeclaration constructorDeclaration = classMember; 34 ConstructorDeclaration constructorDeclaration = classMember;
33 _newConstructorOutline(classOutline, constructorDeclaration); 35 _newConstructorOutline(classOutline, constructorDeclaration);
34 } 36 }
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 */ 303 */
302 final int length; 304 final int length;
303 305
304 /** 306 /**
305 * The offset of the first character of the element. 307 * The offset of the first character of the element.
306 */ 308 */
307 final int offset; 309 final int offset;
308 310
309 Outline(this.element, this.offset, this.length); 311 Outline(this.element, this.offset, this.length);
310 312
311 factory Outline.fromJson(Map<String, Object> map) { 313 factory Outline.fromJson(HashMap<String, Object> map) {
312 Element element = new Element.fromJson(map[ELEMENT]); 314 Element element = new Element.fromJson(map[ELEMENT]);
313 Outline outline = new Outline(element, map[OFFSET], map[LENGTH]); 315 Outline outline = new Outline(element, map[OFFSET], map[LENGTH]);
314 // add children 316 // add children
315 List<Map<String, Object>> childrenMaps = map[CHILDREN]; 317 List<HashMap<String, Object>> childrenMaps = map[CHILDREN];
316 if (childrenMaps != null) { 318 if (childrenMaps != null) {
317 childrenMaps.forEach((childMap) { 319 childrenMaps.forEach((childMap) {
318 outline.children.add(new Outline.fromJson(childMap)); 320 outline.children.add(new Outline.fromJson(childMap));
319 }); 321 });
320 } 322 }
321 // done 323 // done
322 return outline; 324 return outline;
323 } 325 }
324 326
325 Map<String, Object> toJson() { 327 HashMap<String, Object> toJson() {
326 Map<String, Object> json = { 328 HashMap<String, Object> json = {
327 ELEMENT: element.toJson(), 329 ELEMENT: element.toJson(),
328 OFFSET: offset, 330 OFFSET: offset,
329 LENGTH: length 331 LENGTH: length
330 }; 332 };
331 if (children.isNotEmpty) { 333 if (children.isNotEmpty) {
332 json[CHILDREN] = children.map((child) => child.toJson()).toList(); 334 json[CHILDREN] = children.map((child) => child.toJson()).toList();
333 } 335 }
334 return json; 336 return json;
335 } 337 }
336 } 338 }
(...skipping 16 matching lines...) Expand all
353 355
354 356
355 /** 357 /**
356 * A range of characters. 358 * A range of characters.
357 */ 359 */
358 class _SourceRegion { 360 class _SourceRegion {
359 final int length; 361 final int length;
360 final int offset; 362 final int offset;
361 _SourceRegion(this.offset, this.length); 363 _SourceRegion(this.offset, this.length);
362 } 364 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/computer/computer_navigation.dart ('k') | pkg/analysis_server/lib/src/computer/element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698