Index: dart/site/try/poi/scope_information_visitor.dart |
diff --git a/dart/site/try/poi/poi.dart b/dart/site/try/poi/scope_information_visitor.dart |
similarity index 94% |
copy from dart/site/try/poi/poi.dart |
copy to dart/site/try/poi/scope_information_visitor.dart |
index 0261ba5584fd39fa79b24a3f391446f1ad6060d9..7f89de573589d7194f51bda2a0a0453c0f0e8055 100644 |
--- a/dart/site/try/poi/poi.dart |
+++ b/dart/site/try/poi/scope_information_visitor.dart |
@@ -2,38 +2,20 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
-library trydart.poi; |
+library trydart.poi.scope_information_visitor; |
-import 'dart:async' show |
- Completer, |
- Future; |
- |
-import 'dart:io' as io; |
- |
-import 'dart:convert' show |
- UTF8; |
- |
-import 'package:dart2js_incremental/dart2js_incremental.dart' show |
- reuseCompiler; |
- |
-import 'package:dart2js_incremental/library_updater.dart' show |
- LibraryUpdater; |
- |
-import 'package:compiler/src/source_file_provider.dart' show |
- FormattingDiagnosticHandler; |
- |
-import 'package:compiler/compiler.dart' as api; |
+import 'package:compiler/src/elements/modelx.dart' as modelx; |
-import 'package:compiler/src/dart2jslib.dart' show |
- Compiler, |
- CompilerTask, |
- Enqueuer, |
- QueueFilter, |
- WorkItem; |
+import 'package:compiler/src/elements/modelx.dart' show |
+ CompilationUnitElementX, |
+ FieldElementX; |
import 'package:compiler/src/elements/visitor.dart' show |
ElementVisitor; |
+import 'package:compiler/src/dart2jslib.dart' show |
+ Compiler; |
+ |
import 'package:compiler/src/elements/elements.dart' show |
AbstractFieldElement, |
ClassElement, |
@@ -44,24 +26,10 @@ import 'package:compiler/src/elements/elements.dart' show |
LibraryElement, |
ScopeContainerElement; |
-import 'package:compiler/src/elements/modelx.dart' as modelx; |
- |
-import 'package:compiler/src/elements/modelx.dart' show |
- DeclarationSite; |
- |
import 'package:compiler/src/dart_types.dart' show |
DartType; |
-import 'package:compiler/src/scanner/scannerlib.dart' show |
- EOF_TOKEN, |
- IDENTIFIER_TOKEN, |
- KEYWORD_TOKEN, |
- PartialClassElement, |
- PartialElement, |
- Token; |
- |
-import 'package:compiler/src/js/js.dart' show |
- js; |
+/****************** IGNORE THIS ONLY FOR SMALL DIFF **************************** |
/// Enabled by the option --enable-dart-mind. Controls if this program should |
/// be querying Dart Mind. |
@@ -545,6 +513,8 @@ class ScriptOnlyFilter implements QueueFilter { |
} |
} |
+*******************************************************************************/ |
+ |
/** |
* Serializes scope information about an element. This is accomplished by |
* calling the [serialize] method on each element. Some elements need special |
@@ -553,13 +523,16 @@ class ScriptOnlyFilter implements QueueFilter { |
class ScopeInformationVisitor extends ElementVisitor/* <void> */ { |
// TODO(ahe): Include function parameters and local variables. |
+ final Compiler compiler; |
final Element currentElement; |
final int position; |
final StringBuffer buffer = new StringBuffer(); |
int indentationLevel = 0; |
ClassElement currentClass; |
- ScopeInformationVisitor(this.currentElement, this.position); |
+ bool ignoreImports = false; |
+ |
+ ScopeInformationVisitor(this.compiler, this.currentElement, this.position); |
String get indentation => ' ' * indentationLevel; |
@@ -584,7 +557,7 @@ class ScopeInformationVisitor extends ElementVisitor/* <void> */ { |
e, |
// TODO(ahe): We omit the import scope if there is no current |
// class. That's wrong. |
- omitEnclosing: currentClass == null, |
+ omitEnclosing: ignoreImports || currentClass == null, |
name: e.getLibraryName(), |
serializeEnclosing: () { |
// The enclosing scope of a library is a scope which contains all the |
@@ -595,7 +568,7 @@ class ScopeInformationVisitor extends ElementVisitor/* <void> */ { |
indented.write('"kind": "imports",\n'); |
indented.write('"members": ['); |
indentationLevel++; |
- importScope(e).importScope.values.forEach(forEach); |
+ sortElements(importScope(e).importScope.values).forEach(forEach); |
indentationLevel--; |
buffer.write('\n'); |
indented.write('],\n'); |
@@ -610,7 +583,7 @@ class ScopeInformationVisitor extends ElementVisitor/* <void> */ { |
}, |
serializeMembers: () { |
isFirst = true; |
- localScope(e).values.forEach(forEach); |
+ sortElements(localScope(e).values).forEach(forEach); |
}); |
} |
@@ -631,6 +604,7 @@ class ScopeInformationVisitor extends ElementVisitor/* <void> */ { |
{bool isStatic: false, |
bool omitEnclosing: false, |
bool includeSuper: false}) { |
+ e.ensureResolved(compiler); |
bool isFirst = true; |
var serializeEnclosing; |
String kind; |
@@ -658,7 +632,7 @@ class ScopeInformationVisitor extends ElementVisitor/* <void> */ { |
serialize( |
e, omitEnclosing: omitEnclosing, serializeEnclosing: serializeEnclosing, |
kind: kind, serializeMembers: () { |
- e.forEachLocalMember((Element member) { |
+ localMembersSorted(e).forEach((Element member) { |
// Filter out members that don't belong to this "side". |
if (member.isConstructor) { |
// In dart2js, some constructors aren't static, but that isn't |
@@ -681,7 +655,7 @@ class ScopeInformationVisitor extends ElementVisitor/* <void> */ { |
void visitScopeContainerElement(ScopeContainerElement e) { |
bool isFirst = true; |
serialize(e, omitEnclosing: false, serializeMembers: () { |
- e.forEachLocalMember((Element member) { |
+ localMembersSorted(e).forEach((Element member) { |
if (!isFirst) { |
buffer.write(','); |
} |
@@ -741,7 +715,7 @@ class ScopeInformationVisitor extends ElementVisitor/* <void> */ { |
if (category == ElementCategory.FUNCTION || |
category == ElementCategory.VARIABLE || |
element.isConstructor) { |
- type = element.computeType(cachedCompiler); |
+ type = element.computeType(compiler); |
} |
if (name == null) { |
name = element.name; |
@@ -798,8 +772,15 @@ modelx.ImportScope importScope(modelx.LibraryElementX element) { |
return element.importScope; |
} |
-class PoiTask extends CompilerTask { |
- PoiTask(Compiler compiler) : super(compiler); |
+List<Element> localMembersSorted(ScopeContainerElement element) { |
+ List<Element> result = <Element>[]; |
+ element.forEachLocalMember((Element member) { |
+ result.add(member); |
+ }); |
+ return sortElements(result); |
+} |
- String get name => 'POI'; |
+List<Element> sortElements(Iterable<Element> elements) { |
+ return new List<Element>.from(elements) |
+ ..sort((Element a, Element b) => a.name.compareTo(b.name)); |
} |