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

Side by Side Diff: runtime/observatory/lib/src/elements/class_tree.dart

Issue 1807263004: Improve class-tree, class-view, and instance-view. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: code review Created 4 years, 9 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
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 class_tree_element; 5 library class_tree_element;
6 6
7 import 'observatory_element.dart'; 7 import 'observatory_element.dart';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'package:logging/logging.dart'; 9 import 'package:logging/logging.dart';
10 import 'package:observatory/app.dart'; 10 import 'package:observatory/app.dart';
11 import 'package:observatory/service.dart'; 11 import 'package:observatory/service.dart';
12 import 'package:polymer/polymer.dart'; 12 import 'package:polymer/polymer.dart';
13 13
14 class ClassTreeRow extends TableTreeRow { 14 class ClassTreeRow extends TableTreeRow {
15 @reflectable final Isolate isolate; 15 @reflectable final Isolate isolate;
16 @reflectable final Class cls; 16 @reflectable final Class cls;
17 ClassTreeRow(this.isolate, this.cls, TableTree tree, ClassTreeRow parent) 17 ClassTreeRow(this.isolate, this.cls, TableTree tree, ClassTreeRow parent)
18 : super(tree, parent) { 18 : super(tree, parent) {
19 assert(isolate != null); 19 assert(isolate != null);
20 assert(cls != null); 20 assert(cls != null);
21 } 21 }
22 22
23 void onShow() { 23 void _addChildren(List<Class> subclasses) {
24 super.onShow(); 24 for (var subclass in subclasses) {
25 if (children.length == 0) { 25 if (subclass.isPatch) {
26 for (var subclass in cls.subclasses) { 26 continue;
27 if (subclass.isPatch) { 27 }
28 continue; 28 if (subclass.mixin != null) {
29 } 29 _addChildren(subclass.subclasses);
30 } else {
30 var row = new ClassTreeRow(isolate, subclass, tree, this); 31 var row = new ClassTreeRow(isolate, subclass, tree, this);
31 children.add(row); 32 children.add(row);
32 } 33 }
33 } 34 }
35 }
36
37 void _addMixins(Class cls) async {
38 var classCell = flexColumns[0];
39 if (cls.superclass == null) {
40 return;
41 }
42 bool first = true;
43 while (cls.superclass != null && cls.superclass.mixin != null) {
44 cls = cls.superclass;
45 await cls.mixin.load();
46 var span = new SpanElement();
47 span.style.alignSelf = 'center';
48 span.style.whiteSpace = 'pre';
49 if (first) {
50 span.text = ' with ';
51 } else {
52 span.text = ', ';
53 }
54 classCell.children.add(span);
55 var mixinRef = new Element.tag('class-ref');
56 mixinRef.ref = cls.mixin.typeClass;
57 mixinRef.style.alignSelf = 'center';
58 classCell.children.add(mixinRef);
59 first = false;
60 }
61 }
62
63 void _addClass(Class cls) async {
34 var classCell = flexColumns[0]; 64 var classCell = flexColumns[0];
35 classCell.style.justifyContent = 'flex-start'; 65 classCell.style.justifyContent = 'flex-start';
36 var classRef = new Element.tag('class-ref'); 66 var classRef = new Element.tag('class-ref');
37 classRef.ref = cls; 67 classRef.ref = cls;
38 classRef.style.alignSelf = 'center'; 68 classRef.style.alignSelf = 'center';
39 classCell.children.add(classRef); 69 classCell.children.add(classRef);
70 if (cls.superclass != null && cls.superclass.mixin != null) {
71 await _addMixins(cls);
72 }
73 if (cls.subclasses.isNotEmpty) {
74 var span = new SpanElement();
75 span.style.paddingLeft = '.5em';
76 span.style.alignSelf = 'center';
77 int subclassCount = _indirectSubclassCount(cls) - 1;
78 if (subclassCount > 1) {
79 span.text = '($subclassCount subclasses)';
80 } else {
81 span.text = '($subclassCount subclass)';
82 }
83 classCell.children.add(span);
84 }
85 }
86
87 void onShow() {
88 super.onShow();
89 if (children.length == 0) {
90 _addChildren(cls.subclasses);
91 }
92 _addClass(cls);
93 }
94
95 static int _indirectSubclassCount(var cls) {
96 int count = 0;
97 if (cls.mixin == null) {
98 // Don't count synthetic mixin classes in subclass count.
99 count++;
100 }
101 for (var subclass in cls.subclasses) {
102 count += _indirectSubclassCount(subclass);
103 }
104 return count;
40 } 105 }
41 106
42 bool hasChildren() { 107 bool hasChildren() {
43 return cls.subclasses.length > 0; 108 return cls.subclasses.isNotEmpty;
44 } 109 }
45 } 110 }
46 111
47 112
48 @CustomTag('class-tree') 113 @CustomTag('class-tree')
49 class ClassTreeElement extends ObservatoryElement { 114 class ClassTreeElement extends ObservatoryElement {
50 @observable Isolate isolate; 115 @observable Isolate isolate;
51 116
52 TableTree tree; 117 TableTree tree;
53 118
(...skipping 24 matching lines...) Expand all
78 } catch (e, stackTrace) { 143 } catch (e, stackTrace) {
79 Logger.root.warning('_update', e, stackTrace); 144 Logger.root.warning('_update', e, stackTrace);
80 } 145 }
81 // Check if we only have one node at the root and expand it. 146 // Check if we only have one node at the root and expand it.
82 if (tree.rows.length == 1) { 147 if (tree.rows.length == 1) {
83 tree.toggle(tree.rows[0]); 148 tree.toggle(tree.rows[0]);
84 } 149 }
85 notifyPropertyChange(#tree, null, tree); 150 notifyPropertyChange(#tree, null, tree);
86 } 151 }
87 } 152 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/app/view_model.dart ('k') | runtime/observatory/lib/src/elements/class_view.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698