08b4f49249
To reduce the headache associated with adding parameters to VM service APIs, VmServiceInterface has been removed from package:vm_service and pulled into its own dedicated package:vm_service_interface. This will help reduce the need for major version bumps of package:vm_service, which requires manual version bumps through >8 packages in order to make the latest version available to flutter_tools and DevTools. This separation of the VmService client from the interface will reduce the frequency of major version bumps to `package:vm_service` as adding optional parameters to existing APIs would cause implementers of the interface to break. package:vm_service continues to expose a copy of the contents of package:vm_service_interface to avoid breaking google3 rolls until package:dwds can migrate to package:vm_service_interface. package:vm_service will not be published until this copy is removed. This change also includes: - some code cleanup and modernization to both the code generator and generated code - >=3.0.0 SDK version requirement to allow for new language features Change-Id: Ib1859c1b4e153fef7ee1f91e67e881bbf42652c2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330500 Reviewed-by: Derek Xu <derekx@google.com> Reviewed-by: Devon Carew <devoncarew@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com>
107 lines
3.2 KiB
Dart
107 lines
3.2 KiB
Dart
// Copyright (c) 2015, 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.
|
|
|
|
/// A library to generate Dart source code.
|
|
library src_gen_dart;
|
|
|
|
import '../common/src_gen_common.dart';
|
|
|
|
/// A class used to generate Dart source code. This class facilitates writing out
|
|
/// dartdoc comments, automatically manages indent by counting curly braces, and
|
|
/// automatically wraps doc comments on 80 char column boundaries.
|
|
class DartGenerator {
|
|
static const defaultColumnBoundary = 80;
|
|
|
|
final int colBoundary;
|
|
final String interfaceName;
|
|
|
|
String _indent = '';
|
|
final StringBuffer _buf = StringBuffer();
|
|
|
|
bool _previousWasEol = false;
|
|
|
|
DartGenerator({
|
|
required this.interfaceName,
|
|
this.colBoundary = defaultColumnBoundary,
|
|
});
|
|
|
|
/// Write out the given dartdoc text, wrapping lines as necessary to flow
|
|
/// along the column boundary.
|
|
void writeDocs(String docs) {
|
|
docs = docs
|
|
.replaceAll('[RPC error] code', 'RPC error code')
|
|
.replaceAll('[RPC error]', '[RPCError]')
|
|
.replaceAll('[SnapshotGraph]', '[HeapSnapshotGraph]')
|
|
.replaceAllMapped(RegExp(r'\[([gs]et[a-zA-Z]+)\]'), (match) {
|
|
return '[$interfaceName.${match[1]}]';
|
|
});
|
|
|
|
docs = wrap(docs.trim(), colBoundary - _indent.length - 4);
|
|
// docs = docs.replaceAll('*/', '/');
|
|
// docs = docs.replaceAll('/*', r'/\*');
|
|
|
|
docs.split('\n').forEach((line) => _writeln('/// $line'.trimRight()));
|
|
|
|
// if (!docs.contains('\n') && preferSingle) {
|
|
// _writeln("/// ${docs}", true);
|
|
// } else {
|
|
// _writeln("/**", true);
|
|
// _writeln(" * ${docs.replaceAll("\n", "\n * ")}", true);
|
|
// _writeln(" */", true);
|
|
// }
|
|
}
|
|
|
|
/// Write out the given Dart statement and terminate it with an eol. If the
|
|
/// statement will overflow the column boundary, attempt to wrap it at
|
|
/// reasonable places.
|
|
void writeStatement(String str) {
|
|
if (_indent.length + str.length > colBoundary) {
|
|
// Split the line on the first '('. Currently, we don't do anything
|
|
// fancier then that. This takes the edge off the long lines.
|
|
int index = str.indexOf('(');
|
|
|
|
if (index == -1) {
|
|
writeln(str);
|
|
} else {
|
|
writeln(str.substring(0, index + 1));
|
|
writeln(' ${str.substring(index + 1)}');
|
|
}
|
|
} else {
|
|
writeln(str);
|
|
}
|
|
}
|
|
|
|
void writeln([String str = '']) => _write('$str\n');
|
|
|
|
void write(String str) => _write(str);
|
|
|
|
void out(String str) => _buf.write(str);
|
|
|
|
void _writeln([String str = '', bool ignoreCurlies = false]) =>
|
|
_write('$str\n', ignoreCurlies);
|
|
|
|
void _write(String str, [bool ignoreCurlies = false]) {
|
|
for (final int rune in str.runes) {
|
|
if (!ignoreCurlies) {
|
|
if (rune == $leftCurly) {
|
|
_indent = '$_indent ';
|
|
} else if (rune == $rightCurly && _indent.length >= 2) {
|
|
_indent = _indent.substring(2);
|
|
}
|
|
}
|
|
|
|
if (_previousWasEol && rune != $eol) {
|
|
_buf.write(_indent);
|
|
}
|
|
|
|
_buf.write(String.fromCharCode(rune));
|
|
|
|
_previousWasEol = rune == $eol;
|
|
}
|
|
}
|
|
|
|
@override
|
|
String toString() => _buf.toString();
|
|
}
|