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

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

Issue 538253002: Use primitive int/boolean where possible in the Java client. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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_java.dart
diff --git a/pkg/analysis_server/tool/spec/codegen_java.dart b/pkg/analysis_server/tool/spec/codegen_java.dart
index 97f4df07c4844672341f1500d048a6b0a17df881..061a7377f6209f332b60e788800cc8d46f6ae3d9 100644
--- a/pkg/analysis_server/tool/spec/codegen_java.dart
+++ b/pkg/analysis_server/tool/spec/codegen_java.dart
@@ -33,8 +33,8 @@ class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator {
static const Map<String, String> _typeRenames = const {
// TODO (jwren) in some situations we want to use Boolean/Integer while
// other situations we want to use boolean/int...
- 'bool': 'Boolean',
- 'int': 'Integer',
+ 'bool': 'boolean',
+ 'int': 'int',
'FilePath': 'String',
'DebugContextId': 'String',
'object': 'Object',
@@ -137,17 +137,30 @@ class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator {
}
/**
+ * Return a Java type for the given [TypeObjectField].
+ */
+ String javaFieldType(TypeObjectField field) {
+ return javaType(field.type, field.optional);
+ }
+
+ /**
* Convert the given [TypeDecl] to a Java type.
*/
- String javaType(TypeDecl type) {
+ String javaType(TypeDecl type, [bool optional = false]) {
if (type is TypeReference) {
TypeReference resolvedType = resolveTypeReferenceChain(type);
String typeName = resolvedType.typeName;
if (_typeRenames.containsKey(typeName)) {
- return _typeRenames[typeName];
- } else {
- return typeName;
+ typeName = _typeRenames[typeName];
+ if (optional) {
+ if (typeName == 'boolean') {
+ typeName = 'Boolean';
+ } else if (typeName == 'int') {
+ typeName = 'Integer';
+ }
+ }
}
+ return typeName;
} else if (type is TypeList) {
if (isPrimitive(type.itemType)) {
return '${javaType(type.itemType)}[]';
@@ -169,7 +182,7 @@ class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator {
bool isPrimitive(TypeDecl type) {
if (type is TypeReference) {
String typeStr = javaType(type);
- return typeStr == 'Integer' || typeStr == 'boolean';
+ return typeStr == 'int' || typeStr == 'boolean';
}
return false;
}
@@ -187,7 +200,7 @@ class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator {
}
return false;
}
-
+
/**
* Return true iff the passed [TypeDecl] will be represented as Object in Java.
*/

Powered by Google App Engine
This is Rietveld 408576698