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

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

Issue 621383002: Change integration test send...() methods to use structured objects. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reintroduce type checking of server responses Created 6 years, 2 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/analysis_server/tool/spec/codegen_dart.dart
diff --git a/pkg/analysis_server/tool/spec/codegen_dart.dart b/pkg/analysis_server/tool/spec/codegen_dart.dart
new file mode 100644
index 0000000000000000000000000000000000000000..efa1d380b64245ecb5123b7575d900a350f02f49
--- /dev/null
+++ b/pkg/analysis_server/tool/spec/codegen_dart.dart
@@ -0,0 +1,51 @@
+// 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.
+
+library codegen.dart;
+
+import 'api.dart';
+
+/**
+ * Visitor specialized for generating Dart code.
+ */
+class DartCodegenVisitor extends HierarchicalApiVisitor {
+ /**
+ * Type references in the spec that are named something else in Dart.
+ */
+ static const Map<String, String> _typeRenames = const {
+ 'long': 'int',
+ 'object': 'Map',
+ };
+
+ DartCodegenVisitor(Api api) : super(api);
+
+ /**
+ * Convert the given [TypeDecl] to a Dart type.
+ */
+ String dartType(TypeDecl type) {
+ if (type is TypeReference) {
+ String typeName = type.typeName;
+ TypeDefinition referencedDefinition = api.types[typeName];
+ if (_typeRenames.containsKey(typeName)) {
+ return _typeRenames[typeName];
+ }
+ if (referencedDefinition == null) {
+ return typeName;
+ }
+ TypeDecl referencedType = referencedDefinition.type;
+ if (referencedType is TypeObject || referencedType is TypeEnum) {
+ return typeName;
+ }
+ return dartType(referencedType);
+ } else if (type is TypeList) {
+ return 'List<${dartType(type.itemType)}>';
+ } else if (type is TypeMap) {
+ return 'Map<${dartType(type.keyType)}, ${dartType(type.valueType)}>';
+ } else if (type is TypeUnion) {
+ return 'dynamic';
+ } else {
+ throw new Exception("Can't convert to a dart type");
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698