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.element_writer; | 5 library analysis_server.src.status.element_writer; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/get_handler.dart'; | 9 import 'package:analysis_server/src/get_handler.dart'; |
| 10 import 'package:analysis_server/src/status/tree_writer.dart'; | |
| 10 import 'package:analyzer/src/generated/element.dart'; | 11 import 'package:analyzer/src/generated/element.dart'; |
| 12 import 'dart:collection'; | |
|
scheglov
2015/02/16 21:20:29
Sort members?
Brian Wilkerson
2015/02/16 21:41:35
Done
| |
| 11 | 13 |
| 12 /** | 14 /** |
| 13 * A visitor that will produce an HTML representation of an element structure. | 15 * A visitor that will produce an HTML representation of an element structure. |
| 14 */ | 16 */ |
| 15 class ElementWriter extends GeneralizingElementVisitor { | 17 class ElementWriter extends GeneralizingElementVisitor with TreeWriter { |
| 16 /** | |
| 17 * The buffer on which the HTML is to be written. | |
| 18 */ | |
| 19 final StringBuffer buffer; | |
| 20 | |
| 21 /** | |
| 22 * The current level of indentation. | |
| 23 */ | |
| 24 int indentLevel = 0; | |
| 25 | |
| 26 /** | 18 /** |
| 27 * Initialize a newly created element writer to write the HTML representation | 19 * Initialize a newly created element writer to write the HTML representation |
| 28 * of visited elements on the given [buffer]. | 20 * of visited elements on the given [buffer]. |
| 29 */ | 21 */ |
| 30 ElementWriter(this.buffer); | 22 ElementWriter(StringBuffer buffer) { |
| 23 this.buffer = buffer; | |
| 24 } | |
| 31 | 25 |
| 32 @override | 26 @override |
| 33 void visitElement(Element element) { | 27 void visitElement(Element element) { |
| 34 for (int i = 0; i < indentLevel; i++) { | 28 _writeElement(element); |
| 35 buffer.write('┊ '); | 29 writeProperties(_computeProperties(element)); |
| 30 indentLevel++; | |
| 31 try { | |
| 32 element.visitChildren(this); | |
| 33 } finally { | |
| 34 indentLevel--; | |
| 36 } | 35 } |
| 36 } | |
| 37 | |
| 38 /** | |
| 39 * Write a representation of the given [node] to the buffer. | |
| 40 */ | |
| 41 void _writeElement(Element element) { | |
| 42 indent(); | |
| 37 if (element.isSynthetic) { | 43 if (element.isSynthetic) { |
| 38 buffer.write('<i>'); | 44 buffer.write('<i>'); |
| 39 } | 45 } |
| 40 buffer.write(HTML_ESCAPE.convert(element.toString())); | 46 buffer.write(HTML_ESCAPE.convert(element.toString())); |
| 41 if (element.isSynthetic) { | 47 if (element.isSynthetic) { |
| 42 buffer.write('</i>'); | 48 buffer.write('</i>'); |
| 43 } | 49 } |
| 44 buffer.write(' <span style="color:gray">('); | 50 buffer.write(' <span style="color:gray">('); |
| 45 buffer.write(element.runtimeType); | 51 buffer.write(element.runtimeType); |
| 46 buffer.write(')</span>'); | 52 buffer.write(')</span>'); |
| 47 if (element is! LibraryElement) { | 53 if (element is! LibraryElement) { |
| 48 String name = element.name; | 54 String name = element.name; |
| 49 if (name != null) { | 55 if (name != null) { |
| 50 buffer.write(' ['); | 56 buffer.write(' ['); |
| 51 buffer.write(GetHandler.makeLink(GetHandler.INDEX_ELEMENT_BY_NAME, { | 57 buffer.write(GetHandler.makeLink(GetHandler.INDEX_ELEMENT_BY_NAME, { |
| 52 'name': name | 58 'name': name |
| 53 }, 'search index')); | 59 }, 'search index')); |
| 54 buffer.write(']'); | 60 buffer.write(']'); |
| 55 } | 61 } |
| 56 } | 62 } |
| 57 buffer.write('<br>'); | 63 buffer.write('<br>'); |
| 58 indentLevel++; | 64 } |
| 59 try { | 65 |
| 60 element.visitChildren(this); | 66 /** |
| 61 } finally { | 67 * Write a representation of the properties of the given [node] to the buffer. |
| 62 indentLevel--; | 68 */ |
| 69 Map<String, Object> _computeProperties(Element element) { | |
| 70 Map<String, Object> properties = new HashMap<String, Object>(); | |
| 71 | |
| 72 properties['isDeprecated'] = element.isDeprecated; | |
| 73 properties['isOverride'] = element.isOverride; | |
| 74 properties['metadata'] = element.metadata; | |
| 75 properties['nameOffset'] = element.nameOffset; | |
| 76 if (element is ClassElement) { | |
| 77 properties['hasNonFinalField'] = element.hasNonFinalField; | |
| 78 properties['hasReferenceToSuper'] = element.hasReferenceToSuper; | |
| 79 properties['hasStaticMember'] = element.hasStaticMember; | |
| 80 properties['interfaces'] = element.interfaces; | |
| 81 properties['isAbstract'] = element.isAbstract; | |
| 82 properties['isEnum'] = element.isEnum; | |
| 83 properties['isOrInheritsProxy'] = element.isOrInheritsProxy; | |
| 84 properties['isProxy'] = element.isProxy; | |
| 85 properties['isTypedef'] = element.isTypedef; | |
| 86 properties['isValidMixin'] = element.isValidMixin; | |
| 87 properties['mixins'] = element.mixins; | |
| 88 properties['supertype'] = element.supertype; | |
| 89 properties['type'] = element.type; | |
| 63 } | 90 } |
| 91 if (element is CompilationUnitElement) { | |
| 92 properties['isEnumConstant'] = element.hasLoadLibraryFunction; | |
| 93 properties['source'] = element.source; | |
| 94 } | |
| 95 if (element is ConstFieldElementImpl) { | |
| 96 properties['evaluationResult'] = element.evaluationResult; | |
| 97 } | |
| 98 if (element is ConstLocalVariableElementImpl) { | |
| 99 properties['evaluationResult'] = element.evaluationResult; | |
| 100 } | |
| 101 if (element is ConstTopLevelVariableElementImpl) { | |
| 102 properties['evaluationResult'] = element.evaluationResult; | |
| 103 } | |
| 104 if (element is ConstructorElement) { | |
| 105 properties['isConst'] = element.isConst; | |
| 106 properties['isDefaultConstructor'] = element.isDefaultConstructor; | |
| 107 properties['isFactory'] = element.isFactory; | |
| 108 properties['redirectedConstructor'] = element.redirectedConstructor; | |
| 109 } | |
| 110 if (element is ExecutableElement) { | |
| 111 properties['isAsynchronous'] = element.isAsynchronous; | |
| 112 properties['isGenerator'] = element.isGenerator; | |
| 113 properties['isOperator'] = element.isOperator; | |
| 114 properties['isStatic'] = element.isStatic; | |
| 115 properties['isSynchronous'] = element.isSynchronous; | |
| 116 properties['returnType'] = element.returnType; | |
| 117 properties['type'] = element.type; | |
| 118 } | |
| 119 if (element is ExportElement) { | |
| 120 properties['combinators'] = element.combinators; | |
| 121 properties['library'] = element.library; | |
| 122 } | |
| 123 if (element is FieldElement) { | |
| 124 properties['isEnumConstant'] = element.isEnumConstant; | |
| 125 } | |
| 126 if (element is FieldFormalParameterElement) { | |
| 127 properties['field'] = element.field; | |
| 128 } | |
| 129 if (element is FunctionTypeAliasElement) { | |
| 130 properties['returnType'] = element.returnType; | |
| 131 properties['type'] = element.type; | |
| 132 } | |
| 133 if (element is ImportElement) { | |
| 134 properties['combinators'] = element.combinators; | |
| 135 properties['library'] = element.library; | |
| 136 } | |
| 137 if (element is LibraryElement) { | |
| 138 properties['definingCompilationUnit'] = element.definingCompilationUnit; | |
| 139 properties['entryPoint'] = element.entryPoint; | |
| 140 properties['hasExtUri'] = element.hasExtUri; | |
| 141 properties['hasLoadLibraryFunction'] = element.hasLoadLibraryFunction; | |
| 142 properties['isBrowserApplication'] = element.isBrowserApplication; | |
| 143 } | |
| 144 if (element is LocalElement) { | |
| 145 properties['visibleRange'] = element.visibleRange; | |
| 146 } | |
| 147 if (element is MethodElement) { | |
| 148 properties['isAbstract'] = element.isAbstract; | |
| 149 } | |
| 150 if (element is ParameterElement) { | |
| 151 properties['defaultValueCode'] = element.defaultValueCode; | |
| 152 properties['isInitializingFormal'] = element.isInitializingFormal; | |
| 153 properties['parameterKind'] = element.parameterKind; | |
| 154 } | |
| 155 if (element is PropertyAccessorElement) { | |
| 156 properties['isAbstract'] = element.isAbstract; | |
| 157 properties['isGetter'] = element.isGetter; | |
| 158 properties['isSetter'] = element.isSetter; | |
| 159 } | |
| 160 if (element is PropertyInducingElement) { | |
| 161 properties['isStatic'] = element.isStatic; | |
| 162 properties['propagatedType'] = element.propagatedType; | |
| 163 } | |
| 164 if (element is TypeParameterElement) { | |
| 165 properties['bound'] = element.bound; | |
| 166 } | |
| 167 if (element is UriReferencedElement) { | |
| 168 properties['uri'] = element.uri; | |
| 169 } | |
| 170 if (element is VariableElement) { | |
| 171 properties['isConst'] = element.isConst; | |
| 172 properties['isFinal'] = element.isFinal; | |
| 173 properties['type'] = element.type; | |
| 174 } | |
| 175 | |
| 176 return properties; | |
| 64 } | 177 } |
| 65 } | 178 } |
| OLD | NEW |