Chromium Code Reviews| Index: dart/site/try/poi/poi.dart |
| diff --git a/dart/site/try/poi/poi.dart b/dart/site/try/poi/poi.dart |
| index af038c0442c8ab6f2aa2aa988338ece64da61029..62ed6508a4aea8e43afdf6437d0e29c8f4101b5a 100644 |
| --- a/dart/site/try/poi/poi.dart |
| +++ b/dart/site/try/poi/poi.dart |
| @@ -312,12 +312,13 @@ class ScriptOnlyFilter implements QueueFilter { |
| class ScopeInformationVisitor extends ElementVisitor/* <void> */ { |
|
Johnni Winther
2014/07/18 10:33:07
Comments are generally needed in the class.
ahe
2014/08/12 13:53:47
Good idea. I've added documentation and comments.
|
| // TODO(ahe): Include function parameters and local variables. |
| - final Element element; |
| + final Element currentElement; |
| final int position; |
| final StringBuffer buffer = new StringBuffer(); |
| int indentationLevel = 0; |
| + ClassElement currentClass; |
| - ScopeInformationVisitor(this.element, this.position); |
| + ScopeInformationVisitor(this.currentElement, this.position); |
| String get indentation => ' ' * indentationLevel; |
| @@ -329,23 +330,91 @@ class ScopeInformationVisitor extends ElementVisitor/* <void> */ { |
| void visitLibraryElement(LibraryElement e) { |
| bool isFirst = true; |
| + forEach(Element member) { |
| + if (!isFirst) { |
| + buffer.write(','); |
| + } |
| + buffer.write('\n'); |
| + indented; |
| + serialize(member); |
| + isFirst = false; |
| + } |
| serialize( |
| - e, omitEnclosing: true, |
| + e, omitEnclosing: currentClass == null, |
| name: e.getLibraryName(), |
| + serializeEnclosing: () { |
| + isFirst = true; |
| + buffer.write('{\n'); |
| + indentationLevel++; |
| + indented.write('"kind": "imports",\n'); |
| + indented.write('"members": ['); |
| + indentationLevel++; |
| + e.importScope.importScope.values.forEach(forEach); |
| + indentationLevel--; |
| + buffer.write('\n'); |
| + indented.write('],\n'); |
| + indented.write('"enclosing": '); |
| + serializeClassSide( |
| + currentClass.superclass, isStatic: false, includeSuper: true); |
| + buffer.write('\n'); |
| + indentationLevel--; |
| + indented.write('}'); |
| + }, |
| serializeMembers: () { |
| - // TODO(ahe): Include imported elements in libraries. |
| - e.forEachLocalMember((Element member) { |
| - if (!isFirst) { |
| - buffer.write(','); |
| - } |
| - buffer.write('\n'); |
| - indented; |
| - serialize(member); |
| - isFirst = false; |
| - }); |
| + isFirst = true; |
| + e.localScope.values.forEach(forEach); |
| }); |
| } |
| + void visitClassElement(ClassElement e) { |
| + currentClass = e; |
| + serializeClassSide(e, isStatic: true); |
| + } |
| + |
| + void serializeClassSide( |
| + ClassElement e, |
| + {bool isStatic: false, |
| + bool omitEnclosing: false, |
| + bool includeSuper: false}) { |
| + bool isFirst = true; |
| + String name = e.name; |
| + var serializeEnclosing; |
| + if (isStatic) { |
| + serializeEnclosing = () { |
| + serializeClassSide(e, isStatic: false, omitEnclosing: omitEnclosing); |
| + }; |
| + } else { |
| + name = "this($name)"; |
| + } |
| + if (includeSuper) { |
| + assert(!omitEnclosing && !isStatic); |
| + if (e.superclass == null) { |
| + omitEnclosing = true; |
| + } else { |
| + serializeEnclosing = () { |
| + serializeClassSide( |
| + e.superclass, isStatic: false, omitEnclosing: false, |
| + includeSuper: true); |
| + }; |
| + } |
| + } |
| + serialize( |
| + e, omitEnclosing: omitEnclosing, serializeEnclosing: serializeEnclosing, |
| + name: name, serializeMembers: () { |
| + // TODO(ahe): Include inherited members in classes. |
| + e.forEachLocalMember((Element member) { |
| + if (member.isStatic != isStatic) return; |
| + if (!isFirst) { |
| + buffer.write(','); |
| + } |
| + buffer.write('\n'); |
| + indented; |
| + serialize(member); |
| + isFirst = false; |
| + }); |
| + }); |
| + } |
| + |
| void visitScopeContainerElement(ScopeContainerElement e) { |
| bool isFirst = true; |
| serialize(e, omitEnclosing: false, serializeMembers: () { |
| @@ -370,6 +439,7 @@ class ScopeInformationVisitor extends ElementVisitor/* <void> */ { |
| Element element, |
| {bool omitEnclosing: true, |
| void serializeMembers(), |
| + void serializeEnclosing(), |
| String name}) { |
| DartType type; |
| int category = element.kind.category; |
| @@ -383,10 +453,12 @@ class ScopeInformationVisitor extends ElementVisitor/* <void> */ { |
| } |
| buffer.write('{\n'); |
| indentationLevel++; |
| - indented |
| - ..write('"name": "') |
| - ..write(name) |
| - ..write('",\n'); |
| + if (name != '') { |
| + indented |
| + ..write('"name": "') |
| + ..write(name) |
| + ..write('",\n'); |
| + } |
| indented |
| ..write('"kind": "') |
| ..write(element.kind) |
| @@ -410,7 +482,11 @@ class ScopeInformationVisitor extends ElementVisitor/* <void> */ { |
| if (!omitEnclosing) { |
| buffer.write(',\n'); |
| indented.write('"enclosing": '); |
| - element.enclosingElement.accept(this); |
| + if (serializeEnclosing != null) { |
| + serializeEnclosing(); |
| + } else { |
| + element.enclosingElement.accept(this); |
| + } |
| } |
| indentationLevel--; |
| buffer.write('\n'); |