Chromium Code Reviews| 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 e534c40e47e822777882c5951b8e3dbf3b84b107..39d771d798466af694b9a766a8a497e6de8db223 100644 |
| --- a/pkg/analysis_server/tool/spec/codegen_java.dart |
| +++ b/pkg/analysis_server/tool/spec/codegen_java.dart |
| @@ -34,6 +34,7 @@ class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator { |
| 'FilePath': 'String', |
| 'DebugContextId': 'String', |
| 'object': 'Object', |
| + 'Override': 'OverrideMember', |
| }; |
| /** |
| @@ -46,6 +47,20 @@ class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator { |
| toHtmlVisitor = new ToHtmlVisitor(api); |
| /** |
| + * Create a private field, using [callback] to create its contents. |
| + */ |
| + void privateField(String fieldName, void callback()) { |
| + _state.privateFields[fieldName] = collectCode(callback); |
| + } |
| + |
| + /** |
| + * Create a constructor, using [callback] to create its contents. |
| + */ |
| + void constructor(String name, void callback()) { |
| + _state.constructors[name] = collectCode(callback); |
| + } |
| + |
| + /** |
| * Create a private method, using [callback] to create its contents. |
| */ |
| void privateMethod(String methodName, void callback()) { |
| @@ -72,6 +87,21 @@ class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator { |
| callback(); |
| writeln('$header {'); |
| indent(() { |
| + // fields |
| + List<String> allFields = _valuesSortedByKey(_state.privateFields).toList(); |
| + for (String field in allFields) { |
| + writeln(); |
| + write(field); |
| + } |
| + |
| + // constructors |
| + List<String> allConstructors = _valuesSortedByKey(_state.constructors).toList(); |
| + for (String constructor in allConstructors) { |
| + writeln(); |
| + write(constructor); |
| + } |
| + |
| + // methods |
| List<String> allMethods = _valuesSortedByKey(_state.publicMethods).toList(); |
| allMethods.addAll(_valuesSortedByKey(_state.privateMethods)); |
| for (String method in allMethods) { |
| @@ -98,7 +128,11 @@ class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator { |
| return typeName; |
| } |
| } else if (type is TypeList) { |
| - return 'List<${javaType(type.itemType)}>'; |
| + if (isPrimitive(type.itemType)) { |
| + return '${javaType(type.itemType)}[]'; |
| + } else { |
| + return 'List<${javaType(type.itemType)}>'; |
| + } |
| } else if (type is TypeMap) { |
| return 'Map<${javaType(type.keyType)}, ${javaType(type.valueType)}>'; |
| } else if (type is TypeUnion) { |
| @@ -109,6 +143,38 @@ class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator { |
| } |
| /** |
| + * Return true iff the passed [TypeDecl] will represent a primitive Java type. |
| + */ |
| + bool isPrimitive(TypeDecl type) { |
| + if (type is TypeReference) { |
| + String typeStr = javaType(type); |
| + return typeStr == 'int' || typeStr == 'boolean'; |
| + } |
| + return false; |
| + } |
| + |
| + /** |
| + * Return true iff the passed [TypeDecl] will represent an array in Java. |
|
Paul Berry
2014/08/13 21:39:06
Funky indentation here.
jwren
2014/08/13 22:29:15
Fixed. This is me fussing with the Dart Editor :)
|
| + */ |
| + bool isList(TypeDecl type) { |
| + return type is TypeList && !isPrimitive(type.itemType); |
| + } |
| + |
| + /** |
| + * Return true iff the passed [TypeDecl] will represent an array in Java. |
| + */ |
| + bool isArray(TypeDecl type) { |
| + return type is TypeList && isPrimitive(type.itemType); |
| + } |
| + |
| + /** |
| + * Return true iff the passed [TypeDecl] will represent a Map in type. |
| + */ |
| + bool isMap(TypeDecl type) { |
| + return type is TypeMap; |
| + } |
| + |
| + /** |
| * Return a suitable representation of [name] as the name of a Java variable. |
| */ |
| String javaName(String name) { |
| @@ -150,6 +216,16 @@ class _CodegenJavaState { |
| * Temporary storage for private methods. |
| */ |
| Map<String, String> privateMethods = <String, String>{}; |
| + |
| + /** |
| + * Temporary storage for private fields. |
|
Paul Berry
2014/08/13 21:39:06
And here
jwren
2014/08/13 22:29:15
Done.
|
| + */ |
| + Map<String, String> privateFields = <String, String>{}; |
| + |
| + /** |
| + * Temporary storage for constructors. |
|
Paul Berry
2014/08/13 21:39:06
And here
jwren
2014/08/13 22:29:15
Done.
|
| + */ |
| + Map<String, String> constructors = <String, String>{}; |
| } |
| /** |