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

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

Issue 2879273002: Make server use the common protocol classes (Closed)
Patch Set: 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
« no previous file with comments | « pkg/analysis_server/tool/spec/api.dart ('k') | pkg/analysis_server/tool/spec/codegen_inttest_methods.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
diff --git a/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart b/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
index 941b881d85a43f48d50728e83811fb96be7382cb..4a422424fdcd024b526c2296edf537067b9cd9ef 100644
--- a/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
+++ b/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
@@ -119,12 +119,9 @@ class CodegenProtocolVisitor extends DartCodegenVisitor with CodeGenerator {
}
/**
- * Translate each type implied by the API to a class.
+ * Translate each of the given [types] implied by the API to a class.
*/
- void emitClasses() {
- List<ImpliedType> types = impliedTypes.values.toList();
- types.sort((first, second) =>
- capitalize(first.camelName).compareTo(capitalize(second.camelName)));
+ void emitClasses(List<ImpliedType> types) {
for (ImpliedType impliedType in types) {
TypeDecl type = impliedType.type;
String dartTypeName = capitalize(impliedType.camelName);
@@ -395,6 +392,20 @@ class CodegenProtocolVisitor extends DartCodegenVisitor with CodeGenerator {
writeln('}');
}
+ 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';");
+ for (String uri in api.types.importUris) {
+ write("import '");
+ write(uri);
+ writeln("';");
+ }
+ }
+
/**
* Emit the class to encapsulate an object type.
*/
@@ -1052,6 +1063,19 @@ class CodegenProtocolVisitor extends DartCodegenVisitor with CodeGenerator {
}
/**
+ * Return a list of the classes to be emitted.
+ */
+ 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;
+ }
+
+ /**
* True if the constructor argument for the given field should be optional.
*/
bool isOptionalConstructorArg(String className, TypeObjectField field) {
@@ -1131,13 +1155,8 @@ class CodegenProtocolVisitor extends DartCodegenVisitor with CodeGenerator {
visitApi() {
outputHeader(year: '2017');
writeln();
- 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';");
- emitClasses();
+ emitImports();
+ emitClasses(getClassesToEmit());
}
}
« no previous file with comments | « pkg/analysis_server/tool/spec/api.dart ('k') | pkg/analysis_server/tool/spec/codegen_inttest_methods.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698