fb2d1171e5
Modifies `GeneratedDirectory.outputDirPath` and `GeneratedFile.outputPath` to be relative to the SDK's `pkg` directory rather than relative to the containing package. Accordingly, modifies the `GeneratedContent` methods `check`, `checkAll`, `generate`, `generateAll`, `output`, as well as the `DirectoryContentsComputer` and `FileContentsComputer` callbacks, so that their first parameter is the path to the `pkg` directory rather than the path to the containing package. Also modifies the `readApi` functions in `pkg/analysis_server` and `pkg/analyzer_plugin` to accept a path to the `pkg` directory rather than a path to the containing package, since these functions are called by code generation callbacks. These changes should make code generation logic easier to reason about. They also will make it easier to move the outputs of code generation from one package to another, which will pave the way for some follow-up work in which I intend to start sharing error message representations belonging to `pkg/analyzer`, `pkg/front_end`, and `pkg/_fe_analyzer_shared`. Change-Id: Ia9b369b16f2df931c8a472f91400f2c5a0b8be9d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438480 Reviewed-by: Samuel Rawlins <srawlins@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
194 lines
5.5 KiB
Dart
194 lines
5.5 KiB
Dart
// 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;
|
|
|
|
import 'package:analyzer_utilities/tools.dart';
|
|
|
|
import 'api.dart';
|
|
import 'codegen_java.dart';
|
|
|
|
final GeneratedFile target = javaGeneratedFile(
|
|
'analysis_server/tool/spec/generated/java/AnalysisServer.java',
|
|
(Api api) => CodegenAnalysisServer(api),
|
|
);
|
|
|
|
class CodegenAnalysisServer extends CodegenJavaVisitor {
|
|
CodegenAnalysisServer(super.api);
|
|
|
|
@override
|
|
void visitApi() {
|
|
outputHeader(javaStyle: true);
|
|
writeln('package com.google.dart.server.generated;');
|
|
writeln();
|
|
writeln('import com.google.dart.server.*;');
|
|
writeln('import org.dartlang.analysis.server.protocol.*;');
|
|
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 AnalysisServer', () {
|
|
//
|
|
// addAnalysisServerListener(..)
|
|
//
|
|
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);',
|
|
);
|
|
});
|
|
|
|
//
|
|
// removeAnalysisServerListener(..)
|
|
//
|
|
publicMethod('removeAnalysisServerListener', () {
|
|
writeln('''/**
|
|
* Remove the given listener from the list of listeners that will receive notification when new
|
|
* analysis results become available.
|
|
*
|
|
* @param listener the listener to be removed
|
|
*/''');
|
|
writeln(
|
|
'public void removeAnalysisServerListener(AnalysisServerListener listener);',
|
|
);
|
|
});
|
|
|
|
//
|
|
// addRequestListener(..)
|
|
//
|
|
publicMethod('addRequestListener', () {
|
|
writeln('''/**
|
|
* Add the given listener to the list of listeners that will receive notification when
|
|
* requests are made by an analysis server client.
|
|
*
|
|
* @param listener the listener to be added
|
|
*/''');
|
|
writeln('public void addRequestListener(RequestListener listener);');
|
|
});
|
|
|
|
//
|
|
// removeRequestListener(..)
|
|
//
|
|
publicMethod('removeRequestListener', () {
|
|
writeln('''/**
|
|
* Remove the given listener from the list of listeners that will receive notification when
|
|
* requests are made by an analysis server client.
|
|
*
|
|
* @param listener the listener to be removed
|
|
*/''');
|
|
writeln('public void removeRequestListener(RequestListener listener);');
|
|
});
|
|
|
|
//
|
|
// addResponseListener(..)
|
|
//
|
|
publicMethod('addResponseListener', () {
|
|
writeln('''/**
|
|
* Add the given listener to the list of listeners that will receive notification when
|
|
* responses are received by an analysis server client.
|
|
*
|
|
* @param listener the listener to be added
|
|
*/''');
|
|
writeln('public void addResponseListener(ResponseListener listener);');
|
|
});
|
|
|
|
//
|
|
// removeResponseListener(..)
|
|
//
|
|
publicMethod('removeResponseListener', () {
|
|
writeln('''/**
|
|
* Remove the given listener from the list of listeners that will receive notification when
|
|
* responses are received by an analysis server client.
|
|
*
|
|
* @param listener the listener to be removed
|
|
*/''');
|
|
writeln(
|
|
'public void removeResponseListener(ResponseListener listener);',
|
|
);
|
|
});
|
|
|
|
//
|
|
// addStatusListener(..)
|
|
//
|
|
publicMethod('addStatusListener', () {
|
|
writeln('''/**
|
|
* Add the given listener to the list of listeners that will receive notification when the server
|
|
* is not active
|
|
*
|
|
* @param listener the listener to be added
|
|
*/''');
|
|
writeln(
|
|
'public void addStatusListener(AnalysisServerStatusListener listener);',
|
|
);
|
|
});
|
|
|
|
//
|
|
// isSocketOpen()
|
|
//
|
|
publicMethod('isSocketOpen', () {
|
|
writeln('''/**
|
|
* Return {@code true} if the socket is open.
|
|
*/''');
|
|
writeln('public boolean isSocketOpen();');
|
|
});
|
|
|
|
//
|
|
// start(..)
|
|
//
|
|
publicMethod('start', () {
|
|
writeln('''/**
|
|
* Start the analysis server.
|
|
*/''');
|
|
writeln('public void start() throws Exception;');
|
|
});
|
|
super.visitApi();
|
|
});
|
|
}
|
|
|
|
@override
|
|
void visitRequest(Request request) {
|
|
var methodName = '${request.domainName}_${request.method}';
|
|
publicMethod(methodName, () {
|
|
docComment(
|
|
toHtmlVisitor.collectHtml(() {
|
|
toHtmlVisitor.write('{@code ${request.longMethod}}');
|
|
toHtmlVisitor.translateHtml(request.html);
|
|
toHtmlVisitor.javadocParams(request.params);
|
|
if (request.deprecated) {
|
|
toHtmlVisitor.p(() => toHtmlVisitor.write('@deprecated'));
|
|
}
|
|
}),
|
|
);
|
|
write('public void $methodName(');
|
|
var arguments = <String>[];
|
|
|
|
var params = request.params;
|
|
if (params != null) {
|
|
for (var field in params.fields) {
|
|
arguments.add('${javaType(field.type)} ${javaName(field.name)}');
|
|
}
|
|
}
|
|
|
|
if (request.result != null) {
|
|
arguments.add('${consumerName(request)} consumer');
|
|
}
|
|
|
|
write(arguments.join(', '));
|
|
writeln(');');
|
|
});
|
|
}
|
|
}
|