Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 analysis_server.src.status.ast_writer; | 5 library analysis_server.src.status.ast_writer; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/java_engine.dart'; | |
| 10 | 11 |
| 11 /** | 12 /** |
| 12 * A visitor that will produce an HTML representation of an AST structure. | 13 * A visitor that will produce an HTML representation of an AST structure. |
| 13 */ | 14 */ |
| 14 class AstWriter extends UnifyingAstVisitor { | 15 class AstWriter extends UnifyingAstVisitor { |
| 15 /** | 16 /** |
| 16 * The buffer on which the HTML is to be written. | 17 * The buffer on which the HTML is to be written. |
| 17 */ | 18 */ |
| 18 final StringBuffer buffer; | 19 final StringBuffer buffer; |
| 19 | 20 |
| 20 /** | 21 /** |
| 21 * The current level of indentation. | 22 * The current level of indentation. |
| 22 */ | 23 */ |
| 23 int indentLevel = 0; | 24 int indentLevel = 0; |
| 24 | 25 |
| 25 /** | 26 /** |
| 27 * A list containing the exceptions that were caught while attempting to write | |
| 28 * out an AST structure. | |
| 29 */ | |
| 30 List<CaughtException> exceptions = <CaughtException>[]; | |
| 31 | |
| 32 /** | |
| 26 * Initialize a newly created element writer to write the HTML representation | 33 * Initialize a newly created element writer to write the HTML representation |
| 27 * of visited nodes on the given [buffer]. | 34 * of visited nodes on the given [buffer]. |
| 28 */ | 35 */ |
| 29 AstWriter(this.buffer); | 36 AstWriter(this.buffer); |
| 30 | 37 |
| 31 @override | 38 @override |
| 32 void visitNode(AstNode node) { | 39 void visitNode(AstNode node) { |
| 33 _writeNode(node); | 40 _writeNode(node); |
| 34 indentLevel++; | 41 indentLevel++; |
| 35 try { | 42 try { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 _writeProperty('static type', node.staticType); | 174 _writeProperty('static type', node.staticType); |
| 168 _writeProperty('propagated type', node.propagatedType); | 175 _writeProperty('propagated type', node.propagatedType); |
| 169 } | 176 } |
| 170 } | 177 } |
| 171 | 178 |
| 172 /** | 179 /** |
| 173 * Write the [value] of the property with the given [name]. | 180 * Write the [value] of the property with the given [name]. |
| 174 */ | 181 */ |
| 175 void _writeProperty(String name, Object value) { | 182 void _writeProperty(String name, Object value) { |
| 176 if (value != null) { | 183 if (value != null) { |
| 184 String valueString = null; | |
| 185 try { | |
| 186 valueString = value.toString(); | |
| 187 } catch (exception, stackTrace) { | |
| 188 exceptions.add(new CaughtException(exception, stackTrace)); | |
| 189 } | |
| 177 _indent(2); | 190 _indent(2); |
| 178 buffer.write('$name = '); | 191 buffer.write('$name = '); |
| 179 buffer.write(HTML_ESCAPE.convert(value.toString())); | 192 if (valueString == null) { |
| 193 buffer.write('<span style="color: #FF0000">'); | |
| 194 buffer.write(HTML_ESCAPE.convert(value.runtimeType.toString())); | |
|
Paul Berry
2015/02/02 23:08:59
Nit: this will print "Null" in red whenever an err
Brian Wilkerson
2015/02/02 23:25:03
Why? The value of 'value' is known to be non-null,
Paul Berry
2015/02/02 23:32:27
Sorry, I misread the code. lgtm as is.
| |
| 195 buffer.write('</span>'); | |
| 196 } else { | |
| 197 buffer.write(HTML_ESCAPE.convert(valueString)); | |
| 198 } | |
| 180 buffer.write('<br>'); | 199 buffer.write('<br>'); |
| 181 } | 200 } |
| 182 } | 201 } |
| 183 } | 202 } |
| OLD | NEW |