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

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

Issue 463163002: Initial cut at generating the AnalysisServer.java interface. Currently this generates a commented o… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: review 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/tool/spec/codegen_analysis_server.dart
diff --git a/pkg/analysis_server/tool/spec/codegen_analysis_server.dart b/pkg/analysis_server/tool/spec/codegen_analysis_server.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1a7229756be3588c47bc81587b442b0a17580b09
--- /dev/null
+++ b/pkg/analysis_server/tool/spec/codegen_analysis_server.dart
@@ -0,0 +1,102 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/**
+ * Code generation for the file "AnalysisServer.java".
+ */
+library CodegenAnalysisServer;
Brian Wilkerson 2014/08/12 17:58:02 Perhaps "server.generator.java"? (They're usually
jwren 2014/08/12 18:23:08 Done.
+
+import 'api.dart';
+import 'codegen_java.dart';
+import 'codegen_tools.dart';
+import 'from_html.dart';
+
+class CodegenAnalysisServer extends CodegenJavaVisitor {
+ CodegenAnalysisServer(Api api) : super(api);
+
+ @override
+ void visitApi() {
+ outputHeader(javaStyle: true);
+ writeln('package com.google.dart.server;');
+ writeln();
+ writeln('import java.util.List;');
+ writeln('import java.util.Map;');
+ writeln();
+ writeln('''/**
+ * The interface {@code AnalysisServer} defines the behavior of objects that interface to an
+ * analysis server.
+ *
+ * @coverage dart.server
+ */''');
+ makeClass('public interface AnalysisServer2', () {
+ publicMethod('addAnalysisServerListener', () {
+ writeln('''/**
+ * Add the given listener to the list of listeners that will receive notification when new
+ * analysis results become available.
+ *
+ * @param listener the listener to be added
+ */''');
+ writeln('public void addAnalysisServerListener(AnalysisServerListener listener);');
+ writeln('''/**
+ * Start the analysis server.
+ *
+ * @param millisToRestart the number of milliseconds to wait for an unresponsive server before
+ * restarting it, or zero if the server should not be restarted.
+ */''');
+ writeln('public void start(long millisToRestart) throws Exception;');
+ });
+ super.visitApi();
+ });
+ }
+
+ @override
+ void visitRequest(Request request) {
+ String methodName;
+ switch (request.longMethod) {
Paul Berry 2014/08/12 18:04:01 Maybe drop this do-nothing switch statement? (I t
jwren 2014/08/12 18:23:08 Done.
+ default:
+ methodName = request.method;
+ }
+ publicMethod(methodName, () {
+ docComment(toHtmlVisitor.collectHtml(() {
+ toHtmlVisitor.write('{@code ${request.longMethod }}');
+ toHtmlVisitor.translateHtml(request.html);
+ toHtmlVisitor.javadocParams(request.params);
+ }), width: 99, javadocStyle: true);
+ write('// public void $methodName(');
+ if (request.params != null) {
Paul Berry 2014/08/12 18:04:02 Rather than do all the bookkeeping about commas, c
jwren 2014/08/12 18:23:08 I looked for join, but didn't find it... this is m
+ int i = 0;
+ int length = request.params.fields.length;
+ for (TypeObjectField field in request.params.fields) {
+ write('${javaType(field.type)} ${javaName(field.name)}');
+ if (++i < length) {
+ write(', ');
+ }
+ }
+ }
+ if (request.result != null) {
+ // if we had parameters, put a comma after them, otherwise, don't
+ if (request.params != null) {
+ write(', ');
+ }
+ // write out the consumer name
+ write('${consumerName(request)} consumer');
+ }
+ writeln(');');
+ });
+ }
+
+ /**
+ * Get the name of the consumer class for responses to this request.
+ */
+ String consumerName(Request request) {
+ return camelJoin([request.method, 'consumer'], capitalize: true);
+ }
+}
+
+/**
+ * Translate spec_input.html into AnalysisServer.java.
+ */
+main() {
+ createJavaCode('../../../../editor/tools/plugins/com.google.dart.server/src/com/google/dart/server/AnalysisServer2.java', new CodegenAnalysisServer(readApi()));
+}

Powered by Google App Engine
This is Rietveld 408576698