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..3f9a2fe4d326cb626c588d22003ad1e57a57b8fd 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,18 @@ 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 sortMembers = false; |
+ |
+ bool ignoreImports = false; |
+ |
+ ScopeInformationVisitor(this.compiler, this.currentElement, this.position); |
String get indentation => ' ' * indentationLevel; |
@@ -584,7 +559,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 +570,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 +585,7 @@ class ScopeInformationVisitor extends ElementVisitor/* <void> */ { |
}, |
serializeMembers: () { |
isFirst = true; |
- localScope(e).values.forEach(forEach); |
+ sortElements(localScope(e).values).forEach(forEach); |
}); |
} |
@@ -631,6 +606,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 +634,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 +657,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 +717,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; |
@@ -790,6 +766,24 @@ class ScopeInformationVisitor extends ElementVisitor/* <void> */ { |
buffer.write('\n'); |
indented.write('}'); |
} |
+ |
+ List<Element> localMembersSorted(ScopeContainerElement element) { |
+ List<Element> result = <Element>[]; |
+ element.forEachLocalMember((Element member) { |
+ result.add(member); |
+ }); |
+ return sortElements(result); |
+ } |
+ |
+ List<Element> sortElements(Iterable<Element> elements) { |
+ List<Element> result = new List<Element>.from(elements); |
+ if (sortMembers) { |
+ result.sort((Element a, Element b) => a.name.compareTo(b.name)); |
+ } else { |
+ throw "Not sorting result"; |
+ } |
+ return result; |
+ } |
} |
modelx.ScopeX localScope(modelx.LibraryElementX element) => element.localScope; |
@@ -797,9 +791,3 @@ modelx.ScopeX localScope(modelx.LibraryElementX element) => element.localScope; |
modelx.ImportScope importScope(modelx.LibraryElementX element) { |
return element.importScope; |
} |
- |
-class PoiTask extends CompilerTask { |
- PoiTask(Compiler compiler) : super(compiler); |
- |
- String get name => 'POI'; |
-} |