Chromium Code Reviews| Index: pkg/analysis_server/lib/src/status/ast_writer.dart |
| diff --git a/pkg/analysis_server/lib/src/status/ast_writer.dart b/pkg/analysis_server/lib/src/status/ast_writer.dart |
| index 99229a099af66ece2211c71cbc34368674ffb43e..ea364516075f66aed8d77d5e72a7387649382b49 100644 |
| --- a/pkg/analysis_server/lib/src/status/ast_writer.dart |
| +++ b/pkg/analysis_server/lib/src/status/ast_writer.dart |
| @@ -4,43 +4,26 @@ |
| library analysis_server.src.status.ast_writer; |
| -import 'dart:convert'; |
| - |
| -import 'package:analysis_server/src/get_handler.dart'; |
| +import 'package:analysis_server/src/status/tree_writer.dart'; |
| import 'package:analyzer/src/generated/ast.dart'; |
| -import 'package:analyzer/src/generated/element.dart'; |
| -import 'package:analyzer/src/generated/java_engine.dart'; |
| -import 'package:analyzer/src/generated/source.dart'; |
| +import 'dart:collection'; |
| /** |
| * A visitor that will produce an HTML representation of an AST structure. |
| */ |
| -class AstWriter extends UnifyingAstVisitor { |
| - /** |
| - * The buffer on which the HTML is to be written. |
| - */ |
| - final StringBuffer buffer; |
| - |
| - /** |
| - * The current level of indentation. |
| - */ |
| - int indentLevel = 0; |
| - |
| - /** |
| - * A list containing the exceptions that were caught while attempting to write |
| - * out an AST structure. |
| - */ |
| - List<CaughtException> exceptions = <CaughtException>[]; |
| - |
| +class AstWriter extends UnifyingAstVisitor with TreeWriter { |
| /** |
| * Initialize a newly created element writer to write the HTML representation |
| * of visited nodes on the given [buffer]. |
| */ |
| - AstWriter(this.buffer); |
| + AstWriter(StringBuffer buffer) { |
| + this.buffer = buffer; |
| + } |
| @override |
| void visitNode(AstNode node) { |
| _writeNode(node); |
| + writeProperties(_computeProperties(node)); |
| indentLevel++; |
| try { |
| node.visitChildren(this); |
| @@ -109,23 +92,11 @@ class AstWriter extends UnifyingAstVisitor { |
| return buffer.toString(); |
| } |
| - void _indent([int extra = 0]) { |
| - for (int i = 0; i < indentLevel; i++) { |
| - buffer.write('┊ '); |
| - } |
| - if (extra > 0) { |
| - buffer.write('┊ '); |
| - for (int i = 1; i < extra; i++) { |
| - buffer.write(' '); |
| - } |
| - } |
| - } |
| - |
| /** |
| * Write a representation of the given [node] to the buffer. |
| */ |
| void _writeNode(AstNode node) { |
| - _indent(); |
| + indent(); |
| buffer.write(node.runtimeType); |
| buffer.write(' <span style="color:gray">['); |
| buffer.write(node.offset); |
| @@ -133,90 +104,62 @@ class AstWriter extends UnifyingAstVisitor { |
| buffer.write(node.offset + node.length - 1); |
| buffer.write(']</span>'); |
| buffer.write('<br>'); |
| - _writeProperty('name', _getName(node)); |
| + } |
| + |
| + /** |
| + * Write a representation of the properties of the given [node] to the buffer. |
| + */ |
| + Map<String, Object> _computeProperties(AstNode node) { |
| + Map<String, Object> properties = new HashMap<String, Object>(); |
| + |
| + properties['name'] = _getName(node); |
| if (node is BinaryExpression) { |
| - _writeProperty('static element', node.staticElement); |
| - _writeProperty('static type', node.staticType); |
| - _writeProperty('propagated element', node.propagatedElement); |
| - _writeProperty('propagated type', node.propagatedType); |
| + properties['static element'] =node.staticElement; |
|
scheglov
2015/02/16 21:20:29
Format before commit?
Brian Wilkerson
2015/02/16 21:41:35
Done
|
| + properties['static type'] = node.staticType; |
| + properties['propagated element'] = node.propagatedElement; |
| + properties['propagated type'] = node.propagatedType; |
| } else if (node is CompilationUnit) { |
| - _writeProperty("element", node.element); |
| + properties['element'] = node.element; |
| } else if (node is ExportDirective) { |
| - _writeProperty("element", node.element); |
| - _writeProperty("source", node.source); |
| + properties['element'] = node.element; |
| + properties['source'] = node.source; |
| } else if (node is FunctionExpressionInvocation) { |
| - _writeProperty('static element', node.staticElement); |
| - _writeProperty('static type', node.staticType); |
| - _writeProperty('propagated element', node.propagatedElement); |
| - _writeProperty('propagated type', node.propagatedType); |
| + properties['static element'] = node.staticElement; |
| + properties['static type'] = node.staticType; |
| + properties['propagated element'] = node.propagatedElement; |
| + properties['propagated type'] = node.propagatedType; |
| } else if (node is ImportDirective) { |
| - _writeProperty("element", node.element); |
| - _writeProperty("source", node.source); |
| + properties['element'] = node.element; |
| + properties['source'] = node.source; |
| } else if (node is LibraryDirective) { |
| - _writeProperty("element", node.element); |
| + properties['element'] = node.element; |
| } else if (node is PartDirective) { |
| - _writeProperty("element", node.element); |
| - _writeProperty("source", node.source); |
| + properties['element'] = node.element; |
| + properties['source'] = node.source; |
| } else if (node is PartOfDirective) { |
| - _writeProperty("element", node.element); |
| + properties['element'] = node.element; |
| } else if (node is PostfixExpression) { |
| - _writeProperty('static element', node.staticElement); |
| - _writeProperty('static type', node.staticType); |
| - _writeProperty('propagated element', node.propagatedElement); |
| - _writeProperty('propagated type', node.propagatedType); |
| + properties['static element'] = node.staticElement; |
| + properties['static type'] = node.staticType; |
| + properties['propagated element'] = node.propagatedElement; |
| + properties['propagated type'] = node.propagatedType; |
| } else if (node is PrefixExpression) { |
| - _writeProperty('static element', node.staticElement); |
| - _writeProperty('static type', node.staticType); |
| - _writeProperty('propagated element', node.propagatedElement); |
| - _writeProperty('propagated type', node.propagatedType); |
| + properties['static element'] = node.staticElement; |
| + properties['static type'] = node.staticType; |
| + properties['propagated element'] = node.propagatedElement; |
| + properties['propagated type'] = node.propagatedType; |
| } else if (node is SimpleIdentifier) { |
| - _writeProperty('static element', node.staticElement); |
| - _writeProperty('static type', node.staticType); |
| - _writeProperty('propagated element', node.propagatedElement); |
| - _writeProperty('propagated type', node.propagatedType); |
| + properties['static element'] = node.staticElement; |
| + properties['static type'] = node.staticType; |
| + properties['propagated element'] = node.propagatedElement; |
| + properties['propagated type'] = node.propagatedType; |
| } else if (node is SimpleStringLiteral) { |
| - _writeProperty("value", node.value); |
| + properties['value'] = node.value; |
| } else if (node is Expression) { |
| - _writeProperty('static type', node.staticType); |
| - _writeProperty('propagated type', node.propagatedType); |
| + properties['static type'] = node.staticType; |
| + properties['propagated type'] = node.propagatedType; |
| } |
| - } |
| - /** |
| - * Write the [value] of the property with the given [name]. |
| - */ |
| - void _writeProperty(String name, Object value) { |
| - if (value != null) { |
| - String valueString = null; |
| - try { |
| - if (value is Source) { |
| - valueString = 'Source (uri="${value.uri}", path="${value.fullName}")'; |
| - } else { |
| - valueString = value.toString(); |
| - } |
| - } catch (exception, stackTrace) { |
| - exceptions.add(new CaughtException(exception, stackTrace)); |
| - } |
| - _indent(2); |
| - buffer.write('$name = '); |
| - if (valueString == null) { |
| - buffer.write('<span style="color: #FF0000">'); |
| - buffer.write(HTML_ESCAPE.convert(value.runtimeType.toString())); |
| - buffer.write('</span>'); |
| - } else { |
| - buffer.write(HTML_ESCAPE.convert(valueString)); |
| - if (value is Element && value is! LibraryElement) { |
| - String name = value.name; |
| - if (name != null) { |
| - buffer.write(' ['); |
| - buffer.write(GetHandler.makeLink(GetHandler.INDEX_ELEMENT_BY_NAME, { |
| - 'name': name |
| - }, 'search index')); |
| - buffer.write(']'); |
| - } |
| - } |
| - } |
| - buffer.write('<br>'); |
| - } |
| + return properties; |
| } |
| } |