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

Side by Side Diff: pkg/analyzer_plugin/tool/spec/codegen_dart.dart

Issue 2664213003: Add the generator and the generated files (Closed)
Patch Set: add missed files Created 3 years, 10 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
OLDNEW
(Empty)
1 // Copyright (c) 2017, 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 import 'api.dart';
6
7 /**
8 * Visitor specialized for generating Dart code.
9 */
10 class DartCodegenVisitor extends HierarchicalApiVisitor {
11 /**
12 * Type references in the spec that are named something else in Dart.
13 */
14 static const Map<String, String> _typeRenames = const {
15 'long': 'int',
16 'object': 'Map',
17 };
18
19 DartCodegenVisitor(Api api) : super(api);
20
21 /**
22 * Convert the given [TypeDecl] to a Dart type.
23 */
24 String dartType(TypeDecl type) {
25 if (type is TypeReference) {
26 String typeName = type.typeName;
27 TypeDefinition referencedDefinition = api.types[typeName];
28 if (_typeRenames.containsKey(typeName)) {
29 return _typeRenames[typeName];
30 }
31 if (referencedDefinition == null) {
32 return typeName;
33 }
34 TypeDecl referencedType = referencedDefinition.type;
35 if (referencedType is TypeObject || referencedType is TypeEnum) {
36 return typeName;
37 }
38 return dartType(referencedType);
39 } else if (type is TypeList) {
40 return 'List<${dartType(type.itemType)}>';
41 } else if (type is TypeMap) {
42 return 'Map<${dartType(type.keyType)}, ${dartType(type.valueType)}>';
43 } else if (type is TypeUnion) {
44 return 'dynamic';
45 } else {
46 throw new Exception("Can't convert to a dart type");
47 }
48 }
49 }
OLDNEW
« no previous file with comments | « pkg/analyzer_plugin/tool/spec/check_all_test.dart ('k') | pkg/analyzer_plugin/tool/spec/codegen_dart_protocol.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698