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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library codegen.dart;
6
7 import 'api.dart';
8
9 /**
10 * Visitor specialized for generating Dart code.
11 */
12 class DartCodegenVisitor extends HierarchicalApiVisitor {
13 /**
14 * Type references in the spec that are named something else in Dart.
15 */
16 static const Map<String, String> _typeRenames = const {
17 'long': 'int',
18 'object': 'Map',
19 };
20
21 DartCodegenVisitor(Api api) : super(api);
22
23 /**
24 * Convert the given [TypeDecl] to a Dart type.
25 */
26 String dartType(TypeDecl type) {
27 if (type is TypeReference) {
28 String typeName = type.typeName;
29 TypeDefinition referencedDefinition = api.types[typeName];
30 if (_typeRenames.containsKey(typeName)) {
31 return _typeRenames[typeName];
32 }
33 if (referencedDefinition == null) {
34 return typeName;
35 }
36 TypeDecl referencedType = referencedDefinition.type;
37 if (referencedType is TypeObject || referencedType is TypeEnum) {
38 return typeName;
39 }
40 return dartType(referencedType);
41 } else if (type is TypeList) {
42 return 'List<${dartType(type.itemType)}>';
43 } else if (type is TypeMap) {
44 return 'Map<${dartType(type.keyType)}, ${dartType(type.valueType)}>';
45 } else if (type is TypeUnion) {
46 return 'dynamic';
47 } else {
48 throw new Exception("Can't convert to a dart type");
49 }
50 }
51 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698