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

Side by Side Diff: pkg/analysis_server/tool/spec/codegen_java.dart

Issue 452313004: Cleanup in CodegenJavaVisitor.javaType(...), no functional change. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: missed change in the docs Created 6 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * Tools for Java code generation. 6 * Tools for Java code generation.
7 */ 7 */
8 library CodegenJava; 8 library CodegenJava;
9 9
10 import 'dart:io'; 10 import 'dart:io';
(...skipping 10 matching lines...) Expand all
21 21
22 /** 22 /**
23 * Variable names which must be changed in order to avoid conflict with 23 * Variable names which must be changed in order to avoid conflict with
24 * reserved words in Java. 24 * reserved words in Java.
25 */ 25 */
26 static const Map<String, String> _variableRenames = const { 26 static const Map<String, String> _variableRenames = const {
27 'default': 'defaultSdk' 27 'default': 'defaultSdk'
28 }; 28 };
29 29
30 /** 30 /**
31 * Type references in the spec that are named something else in Java.
32 */
33 static const Map<String, String> _typeRenames = const {
34 'bool': 'boolean',
35 'FilePath': 'String',
36 'DebugContextId': 'String',
37 'object': 'Object',
38 };
39
40 /**
31 * Visitor used to produce doc comments. 41 * Visitor used to produce doc comments.
32 */ 42 */
33 final ToHtmlVisitor toHtmlVisitor; 43 final ToHtmlVisitor toHtmlVisitor;
34 44
35 CodegenJavaVisitor(Api api) 45 CodegenJavaVisitor(Api api)
36 : super(api), 46 : super(api),
37 toHtmlVisitor = new ToHtmlVisitor(api); 47 toHtmlVisitor = new ToHtmlVisitor(api);
38 48
39 /** 49 /**
40 * Create a private method, using [callback] to create its contents. 50 * Create a private method, using [callback] to create its contents.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 _state = oldState; 85 _state = oldState;
76 } 86 }
77 } 87 }
78 88
79 /** 89 /**
80 * Convert the given [TypeDecl] to a Java type. 90 * Convert the given [TypeDecl] to a Java type.
81 */ 91 */
82 String javaType(TypeDecl type) { 92 String javaType(TypeDecl type) {
83 if (type is TypeReference) { 93 if (type is TypeReference) {
84 TypeReference resolvedType = resolveTypeReferenceChain(type); 94 TypeReference resolvedType = resolveTypeReferenceChain(type);
85 switch (resolvedType.typeName) { 95 String typeName = resolvedType.typeName;
86 // TODO(jwren) make this into a type type renames map, like _variableRen ames 96 if (_typeRenames.containsKey(typeName)) {
87 case 'bool': 97 return _typeRenames[typeName];
88 return 'boolean'; 98 } else {
89 case 'FilePath': 99 return typeName;
90 return 'String';
91 case 'DebugContextId':
92 return 'String';
93 case 'object':
94 return 'Object';
95 default:
96 return resolvedType.typeName;
97 } 100 }
98 } else if (type is TypeList) { 101 } else if (type is TypeList) {
99 return 'List<${javaType(type.itemType)}>'; 102 return 'List<${javaType(type.itemType)}>';
100 } else if (type is TypeMap) { 103 } else if (type is TypeMap) {
101 return 'Map<${javaType(type.keyType)}, ${javaType(type.valueType)}>'; 104 return 'Map<${javaType(type.keyType)}, ${javaType(type.valueType)}>';
102 } else { 105 } else {
103 throw new Exception("Can't make type buildable"); 106 throw new Exception("Can't make type buildable");
104 } 107 }
105 } 108 }
106 109
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 152 }
150 153
151 /** 154 /**
152 * Use [visitor] to create Java code and output it to [path]. 155 * Use [visitor] to create Java code and output it to [path].
153 */ 156 */
154 void createJavaCode(String path, CodegenJavaVisitor visitor) { 157 void createJavaCode(String path, CodegenJavaVisitor visitor) {
155 String code = visitor.collectCode(visitor.visitApi); 158 String code = visitor.collectCode(visitor.visitApi);
156 File outputFile = new File(path); 159 File outputFile = new File(path);
157 outputFile.writeAsStringSync(code); 160 outputFile.writeAsStringSync(code);
158 } 161 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698