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

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

Issue 2880443006: Generate common types into a separate library (Closed)
Patch Set: add missed files Created 3 years, 7 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
Index: pkg/analyzer_plugin/tool/spec/codegen_protocol_common.dart
diff --git a/pkg/analyzer_plugin/tool/spec/codegen_protocol_common.dart b/pkg/analyzer_plugin/tool/spec/codegen_protocol_common.dart
new file mode 100644
index 0000000000000000000000000000000000000000..08bfb70f06242217929b4a6659627ca5c0c735f8
--- /dev/null
+++ b/pkg/analyzer_plugin/tool/spec/codegen_protocol_common.dart
@@ -0,0 +1,53 @@
+// 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.
+
+import 'package:analyzer/src/codegen/tools.dart';
+import 'package:front_end/src/codegen/tools.dart';
+import 'package:path/path.dart' as path;
+
+import 'api.dart';
+import 'codegen_dart_protocol.dart';
+import 'from_html.dart';
+import 'implied_types.dart';
+
+final GeneratedFile target =
+ new GeneratedFile('lib/protocol/protocol_common.dart', (String pkgPath) {
+ CodegenCommonVisitor visitor =
+ new CodegenCommonVisitor(path.basename(pkgPath), readApi(pkgPath));
+ return visitor.collectCode(visitor.visitApi);
+});
+
+/**
+ * A visitor that produces Dart code defining the common types associated with
+ * the API.
+ */
+class CodegenCommonVisitor extends CodegenProtocolVisitor {
+ /**
+ * Initialize a newly created visitor to generate code in the package with the
+ * given [packageName] corresponding to the types in the given [api] that are
+ * common to multiple protocols.
+ */
+ CodegenCommonVisitor(String packageName, Api api) : super(packageName, api);
+
+ @override
+ void emitImports() {
+ writeln("import 'dart:convert' hide JsonDecoder;");
+ writeln();
+ writeln("import 'package:analyzer/src/generated/utilities_general.dart';");
+ writeln("import 'package:$packageName/protocol/protocol.dart';");
+ writeln(
+ "import 'package:$packageName/src/protocol/protocol_internal.dart';");
+ }
+
+ @override
+ List<ImpliedType> getClassesToEmit() {
+ List<ImpliedType> types = impliedTypes.values.where((ImpliedType type) {
+ ApiNode node = type.apiNode;
+ return node is TypeDefinition && node.isExternal;
+ }).toList();
+ types.sort((first, second) =>
+ capitalize(first.camelName).compareTo(capitalize(second.camelName)));
+ return types;
+ }
+}
« no previous file with comments | « pkg/analyzer_plugin/tool/spec/codegen_inttest_methods.dart ('k') | pkg/analyzer_plugin/tool/spec/from_html.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698