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