Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Unified Diff: pkg/analysis_server/tool/spec/implied_types.dart

Issue 479043002: Code generate Dart classes representing the analysis server API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove accidental comment change Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/tool/spec/generate_all.dart ('k') | pkg/analysis_server/tool/spec/spec_input.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e37c0b4dc14cefa2f9262905742cfe50e2c1ce95
--- /dev/null
+++ b/pkg/analysis_server/tool/spec/implied_types.dart
@@ -0,0 +1,77 @@
+// 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;
+
+ /**
+ * Kind of implied type this is. One of:
+ * - 'requestParams'
+ * - 'requestResult'
+ * - 'notificationParams'
+ * - 'refactoringFeedback'
+ * - 'refactoringOptions'
+ * - 'typeDefinition'
+ */
+ final String kind;
+
+ ImpliedType(this.camelName, this.humanReadableName, this.type, this.kind);
+}
+
+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 kind) {
+ 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, kind);
+ }
+
+ @override
+ visitNotification(Notification notification) {
+ storeType(notification.longEvent, 'params', notification.params, 'notificationParams');
+ }
+
+ @override
+ visitRequest(Request request) {
+ storeType(request.longMethod, 'params', request.params, 'requestParams');
+ storeType(request.longMethod, 'result', request.result, 'requestResult');
+ }
+
+ @override
+ visitRefactoring(Refactoring refactoring) {
+ String camelKind = camelJoin(refactoring.kind.toLowerCase().split('_'));
+ storeType(camelKind, 'feedback', refactoring.feedback, 'refactoringFeedback');
+ storeType(camelKind, 'options', refactoring.options, 'refactoringOptions');
+ }
+
+ @override
+ visitTypeDefinition(TypeDefinition typeDefinition) {
+ storeType(typeDefinition.name, null, typeDefinition.type, 'typeDefinition');
+ }
+
+}
« no previous file with comments | « pkg/analysis_server/tool/spec/generate_all.dart ('k') | pkg/analysis_server/tool/spec/spec_input.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698