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

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

Issue 2664213003: Add the generator and the generated files (Closed)
Patch Set: add missed files Created 3 years, 11 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/analyzer_plugin/tool/spec/generate_files ('k') | pkg/analyzer_plugin/tool/spec/plugin_spec.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer_plugin/tool/spec/implied_types.dart
diff --git a/pkg/analyzer_plugin/tool/spec/implied_types.dart b/pkg/analyzer_plugin/tool/spec/implied_types.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e7086fe0ea792a2e8f2f331d2cd36346721ec845
--- /dev/null
+++ b/pkg/analyzer_plugin/tool/spec/implied_types.dart
@@ -0,0 +1,89 @@
+// Copyright (c) 2017, 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.
+ */
+import 'package:analyzer/src/codegen/tools.dart';
+
+import 'api.dart';
+
+Map<String, ImpliedType> computeImpliedTypes(Api api) {
+ _ImpliedTypesVisitor visitor = new _ImpliedTypesVisitor(api);
+ visitor.visitApi();
+ return visitor.impliedTypes;
+}
+
+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;
+
+ /**
+ * API node from which this type was inferred.
+ */
+ final ApiNode apiNode;
+
+ ImpliedType(this.camelName, this.humanReadableName, this.type, this.kind,
+ this.apiNode);
+}
+
+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,
+ ApiNode apiNode) {
+ 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, apiNode);
+ }
+
+ @override
+ visitNotification(Notification notification) {
+ storeType(notification.longEvent, 'params', notification.params,
+ 'notificationParams', notification);
+ }
+
+ @override
+ visitRefactoring(Refactoring refactoring) {
+ String camelKind = camelJoin(refactoring.kind.toLowerCase().split('_'));
+ storeType(camelKind, 'feedback', refactoring.feedback,
+ 'refactoringFeedback', refactoring);
+ storeType(camelKind, 'options', refactoring.options, 'refactoringOptions',
+ refactoring);
+ }
+
+ @override
+ visitRequest(Request request) {
+ storeType(
+ request.longMethod, 'params', request.params, 'requestParams', request);
+ storeType(
+ request.longMethod, 'result', request.result, 'requestResult', request);
+ }
+
+ @override
+ visitTypeDefinition(TypeDefinition typeDefinition) {
+ storeType(typeDefinition.name, null, typeDefinition.type, 'typeDefinition',
+ typeDefinition);
+ }
+}
« no previous file with comments | « pkg/analyzer_plugin/tool/spec/generate_files ('k') | pkg/analyzer_plugin/tool/spec/plugin_spec.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698