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

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

Issue 725143004: Format and sort analyzer and analysis_server packages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 bec7dd64eb1099ff228398389326b398dcc5bdb4..a8d92002b4ae69e3630208d6987c60560d53c023 100644
--- a/pkg/analysis_server/tool/spec/codegen_java.dart
+++ b/pkg/analysis_server/tool/spec/codegen_java.dart
@@ -8,17 +8,37 @@
library CodegenJava;
import 'package:html5lib/dom.dart' as dom;
+
import 'api.dart';
import 'codegen_tools.dart';
import 'from_html.dart';
import 'to_html.dart';
/**
+ * Create a [GeneratedFile] that creates Java code and outputs it to [path].
+ * [path] uses Posix-style path separators regardless of the OS.
+ */
+GeneratedFile javaGeneratedFile(String path, CodegenJavaVisitor
+ createVisitor(Api api)) {
+ return new GeneratedFile(path, () {
+ CodegenJavaVisitor visitor = createVisitor(readApi());
+ return visitor.collectCode(visitor.visitApi);
+ });
+}
+
+/**
+ * Iterate through the values in [map] in the order of increasing keys.
+ */
+Iterable<String> _valuesSortedByKey(Map<String, String> map) {
+ List<String> keys = map.keys.toList();
+ keys.sort();
+ return keys.map((String key) => map[key]);
+}
+
+/**
* Common code for all Java code generation.
*/
class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator {
- _CodegenJavaState _state;
-
/**
* Variable names which must be changed in order to avoid conflict with
* reserved words in Java.
@@ -40,6 +60,8 @@ class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator {
'Override': 'OverrideMember',
};
+ _CodegenJavaState _state;
+
/**
* Visitor used to produce doc comments.
*/
@@ -50,89 +72,71 @@ class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator {
toHtmlVisitor = new ToHtmlVisitor(api);
/**
- * Convenience method for subclasses for calling docComment.
+ * Create a constructor, using [callback] to create its contents.
*/
- void javadocComment(List<dom.Node> docs) {
- docComment(docs, width: 99, javadocStyle: true);
+ void constructor(String name, void callback()) {
+ _state.constructors[name] = collectCode(callback);
}
/**
- * Create a public field, using [callback] to create its contents.
+ * Return true iff the passed [TypeDecl] will represent an array in Java.
*/
- void publicField(String fieldName, void callback()) {
- _state.publicFields[fieldName] = collectCode(callback);
+ bool isArray(TypeDecl type) {
+ return type is TypeList && isPrimitive(type.itemType);
}
/**
- * Create a private field, using [callback] to create its contents.
+ * Return true iff the passed [TypeDecl] is a type declared in the spec_input.
*/
- void privateField(String fieldName, void callback()) {
- _state.privateFields[fieldName] = collectCode(callback);
+ bool isDeclaredInSpec(TypeDecl type) {
+// TypeReference resolvedType = super.resolveTypeReferenceChain(type);
+// if(resolvedType is TypeObject) {
+// return truye;
+// }
+ if (type is TypeReference) {
+ return api.types.containsKey(type.typeName) && javaType(type) != 'String';
+ }
+ return false;
}
/**
- * Create a constructor, using [callback] to create its contents.
+ * Return true iff the passed [TypeDecl] will represent an array in Java.
*/
- void constructor(String name, void callback()) {
- _state.constructors[name] = collectCode(callback);
+ bool isList(TypeDecl type) {
+ return type is TypeList && !isPrimitive(type.itemType);
}
/**
- * Create a private method, using [callback] to create its contents.
+ * Return true iff the passed [TypeDecl] will represent a Map in type.
*/
- void privateMethod(String methodName, void callback()) {
- _state.privateMethods[methodName] = collectCode(callback);
+ bool isMap(TypeDecl type) {
+ return type is TypeMap;
}
/**
- * Create a public method, using [callback] to create its contents.
+ * Return true iff the passed [TypeDecl] will be represented as Object in Java.
*/
- void publicMethod(String methodName, void callback()) {
- _state.publicMethods[methodName] = collectCode(callback);
+ bool isObject(TypeDecl type) {
+ String typeStr = javaType(type);
+ return typeStr == 'Object';
}
/**
- * Execute [callback], collecting any methods that are output using
- * [privateMethod] or [publicMethod], and insert the class (with methods
- * sorted). [header] is the part of the class declaration before the
- * opening brace.
+ * Return true iff the passed [TypeDecl] will represent a primitive Java type.
*/
- void makeClass(String header, void callback()) {
- _CodegenJavaState oldState = _state;
- try {
- _state = new _CodegenJavaState();
- callback();
- writeln('$header {');
- indent(() {
- // fields
- List<String> allFields = _state.publicFields.values.toList();
- allFields.addAll(_state.privateFields.values.toList());
- for (String field in allFields) {
- writeln();
- write(field);
- }
-
- // constructors
- List<String> allConstructors = _state.constructors.values.toList();
- for (String constructor in allConstructors) {
- writeln();
- write(constructor);
- }
-
- // methods (ordered by method name)
- List<String> allMethods =
- _valuesSortedByKey(_state.publicMethods).toList();
- allMethods.addAll(_valuesSortedByKey(_state.privateMethods));
- for (String method in allMethods) {
- writeln();
- write(method);
- }
- writeln();
- });
- writeln('}');
- } finally {
- _state = oldState;
+ bool isPrimitive(TypeDecl type) {
+ if (type is TypeReference) {
+ String typeStr = javaType(type);
+ return typeStr == 'boolean' || typeStr == 'int' || typeStr == 'long';
}
+ return false;
+ }
+
+ /**
+ * Convenience method for subclasses for calling docComment.
+ */
+ void javadocComment(List<dom.Node> docs) {
+ docComment(docs, width: 99, javadocStyle: true);
}
/**
@@ -143,6 +147,16 @@ class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator {
}
/**
+ * Return a suitable representation of [name] as the name of a Java variable.
+ */
+ String javaName(String name) {
+ if (_variableRenames.containsKey(name)) {
+ return _variableRenames[name];
+ }
+ return name;
+ }
+
+ /**
* Convert the given [TypeDecl] to a Java type.
*/
String javaType(TypeDecl type, [bool optional = false]) {
@@ -176,67 +190,75 @@ class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator {
}
/**
- * Return true iff the passed [TypeDecl] will represent a primitive Java type.
+ * Execute [callback], collecting any methods that are output using
+ * [privateMethod] or [publicMethod], and insert the class (with methods
+ * sorted). [header] is the part of the class declaration before the
+ * opening brace.
*/
- bool isPrimitive(TypeDecl type) {
- if (type is TypeReference) {
- String typeStr = javaType(type);
- return typeStr == 'boolean' || typeStr == 'int' || typeStr == 'long';
- }
- return false;
- }
+ void makeClass(String header, void callback()) {
+ _CodegenJavaState oldState = _state;
+ try {
+ _state = new _CodegenJavaState();
+ callback();
+ writeln('$header {');
+ indent(() {
+ // fields
+ List<String> allFields = _state.publicFields.values.toList();
+ allFields.addAll(_state.privateFields.values.toList());
+ for (String field in allFields) {
+ writeln();
+ write(field);
+ }
- /**
- * Return true iff the passed [TypeDecl] is a type declared in the spec_input.
- */
- bool isDeclaredInSpec(TypeDecl type) {
-// TypeReference resolvedType = super.resolveTypeReferenceChain(type);
-// if(resolvedType is TypeObject) {
-// return truye;
-// }
- if (type is TypeReference) {
- return api.types.containsKey(type.typeName) && javaType(type) != 'String';
- }
- return false;
- }
+ // constructors
+ List<String> allConstructors = _state.constructors.values.toList();
+ for (String constructor in allConstructors) {
+ writeln();
+ write(constructor);
+ }
- /**
- * Return true iff the passed [TypeDecl] will be represented as Object in Java.
- */
- bool isObject(TypeDecl type) {
- String typeStr = javaType(type);
- return typeStr == 'Object';
+ // methods (ordered by method name)
+ List<String> allMethods =
+ _valuesSortedByKey(_state.publicMethods).toList();
+ allMethods.addAll(_valuesSortedByKey(_state.privateMethods));
+ for (String method in allMethods) {
+ writeln();
+ write(method);
+ }
+ writeln();
+ });
+ writeln('}');
+ } finally {
+ _state = oldState;
+ }
}
/**
- * Return true iff the passed [TypeDecl] will represent an array in Java.
+ * Create a private field, using [callback] to create its contents.
*/
- bool isList(TypeDecl type) {
- return type is TypeList && !isPrimitive(type.itemType);
+ void privateField(String fieldName, void callback()) {
+ _state.privateFields[fieldName] = collectCode(callback);
}
/**
- * Return true iff the passed [TypeDecl] will represent an array in Java.
+ * Create a private method, using [callback] to create its contents.
*/
- bool isArray(TypeDecl type) {
- return type is TypeList && isPrimitive(type.itemType);
+ void privateMethod(String methodName, void callback()) {
+ _state.privateMethods[methodName] = collectCode(callback);
}
/**
- * Return true iff the passed [TypeDecl] will represent a Map in type.
+ * Create a public field, using [callback] to create its contents.
*/
- bool isMap(TypeDecl type) {
- return type is TypeMap;
+ void publicField(String fieldName, void callback()) {
+ _state.publicFields[fieldName] = collectCode(callback);
}
/**
- * Return a suitable representation of [name] as the name of a Java variable.
+ * Create a public method, using [callback] to create its contents.
*/
- String javaName(String name) {
- if (_variableRenames.containsKey(name)) {
- return _variableRenames[name];
- }
- return name;
+ void publicMethod(String methodName, void callback()) {
+ _state.publicMethods[methodName] = collectCode(callback);
}
@override
@@ -250,15 +272,6 @@ class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator {
}
/**
- * Iterate through the values in [map] in the order of increasing keys.
- */
-Iterable<String> _valuesSortedByKey(Map<String, String> map) {
- List<String> keys = map.keys.toList();
- keys.sort();
- return keys.map((String key) => map[key]);
-}
-
-/**
* State used by [CodegenJavaVisitor].
*/
class _CodegenJavaState {
@@ -287,15 +300,3 @@ class _CodegenJavaState {
*/
Map<String, String> constructors = <String, String>{};
}
-
-/**
- * Create a [GeneratedFile] that creates Java code and outputs it to [path].
- * [path] uses Posix-style path separators regardless of the OS.
- */
-GeneratedFile javaGeneratedFile(String path, CodegenJavaVisitor
- createVisitor(Api api)) {
- return new GeneratedFile(path, () {
- CodegenJavaVisitor visitor = createVisitor(readApi());
- return visitor.collectCode(visitor.visitApi);
- });
-}
« no previous file with comments | « pkg/analysis_server/tool/spec/codegen_inttest_methods.dart ('k') | pkg/analysis_server/tool/spec/codegen_java_types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698