Index: pkg/analysis_server/tool/spec/implied_types.dart |
diff --git a/pkg/analysis_server/tool/spec/implied_types.dart b/pkg/analysis_server/tool/spec/implied_types.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a79c245f8e7d2c5b0cf004be0303b2b0267f1dfd |
--- /dev/null |
+++ b/pkg/analysis_server/tool/spec/implied_types.dart |
@@ -0,0 +1,67 @@ |
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
+// 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. |
+ |
+/** |
+ * Code for enumerating the set of types implied by the API. |
+ */ |
+library html.tools; |
+ |
+import 'api.dart'; |
+import 'codegen_tools.dart'; |
+ |
+class ImpliedType { |
+ final String camelName; |
+ final String humanReadableName; |
+ final TypeDecl type; |
+ |
+ ImpliedType(this.camelName, this.humanReadableName, this.type); |
+} |
+ |
+Map<String, ImpliedType> computeImpliedTypes(Api api) { |
+ _ImpliedTypesVisitor visitor = new _ImpliedTypesVisitor(api); |
+ visitor.visitApi(); |
+ return visitor.impliedTypes; |
+} |
+ |
+class _ImpliedTypesVisitor extends HierarchicalApiVisitor { |
+ Map<String, ImpliedType> impliedTypes = <String, ImpliedType> {}; |
+ |
+ _ImpliedTypesVisitor(Api api) : super(api); |
+ |
+ void storeType(String name, String nameSuffix, TypeDecl type) { |
+ String humanReadableName = name; |
+ List<String> camelNameParts = name.split('.'); |
+ if (nameSuffix != null) { |
+ humanReadableName += ' $nameSuffix'; |
+ camelNameParts.add(nameSuffix); |
+ } |
+ String camelName = camelJoin(camelNameParts); |
+ impliedTypes[camelName] = new ImpliedType(camelName, humanReadableName, type |
+ ); |
+ } |
+ |
+ @override |
+ visitNotification(Notification notification) { |
+ storeType(notification.longEvent, 'params', notification.params); |
+ } |
+ |
+ @override |
+ visitRequest(Request request) { |
+ storeType(request.longMethod, 'params', request.params); |
+ storeType(request.longMethod, 'result', request.result); |
+ } |
+ |
+ @override |
+ visitRefactoring(Refactoring refactoring) { |
+ String camelKind = camelJoin(refactoring.kind.toLowerCase().split('_')); |
+ storeType(camelKind, 'feedback', refactoring.feedback); |
+ storeType(camelKind, 'options', refactoring.options); |
+ } |
+ |
+ @override |
+ visitTypeDefinition(TypeDefinition typeDefinition) { |
+ storeType(typeDefinition.name, null, typeDefinition.type); |
+ } |
+ |
+} |