3b0b1bd863
Changes: ``` > git log --format="%C(auto) %h %s" 8d5f750..b044aca https://dart.googlesource.com/lints.git/+/b044aca add several rules to core and recommended (150) https://dart.googlesource.com/lints.git/+/81100a2 fix a dangling table link (146) ``` Diff: https://dart.googlesource.com/lints.git/+/8d5f7500024320654adb1e799e49fc10c5304ae7..b044acab9f6669b3d8e781923a8ff86877801177/ Change-Id: I031333ade99af700a7009b14a36d3aadba12fc94 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/327321 Reviewed-by: Nicholas Shahan <nshahan@google.com> Commit-Queue: Devon Carew <devoncarew@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com>
68 lines
2.5 KiB
Dart
68 lines
2.5 KiB
Dart
// Copyright (c) 2017, 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.
|
|
|
|
import 'package:analyzer_utilities/tools.dart';
|
|
import 'package:path/path.dart' as path;
|
|
|
|
import 'api.dart';
|
|
import 'codegen_dart_protocol.dart';
|
|
import 'from_html.dart';
|
|
import 'implied_types.dart';
|
|
|
|
GeneratedFile clientTarget(bool responseRequiresRequestTime) => GeneratedFile(
|
|
'../analysis_server_client/lib/src/protocol/protocol_common.dart',
|
|
(String pkgPath) async {
|
|
var visitor = CodegenCommonVisitor(
|
|
path.basename(pkgPath), responseRequiresRequestTime, readApi(pkgPath),
|
|
forClient: true);
|
|
return visitor.collectCode(visitor.visitApi);
|
|
});
|
|
|
|
GeneratedFile pluginTarget(bool responseRequiresRequestTime) =>
|
|
GeneratedFile('lib/protocol/protocol_common.dart', (String pkgPath) async {
|
|
var visitor = CodegenCommonVisitor(path.basename(pkgPath),
|
|
responseRequiresRequestTime, readApi(pkgPath));
|
|
return visitor.collectCode(visitor.visitApi);
|
|
});
|
|
|
|
/// A visitor that produces Dart code defining the common types associated with
|
|
/// the API.
|
|
class CodegenCommonVisitor extends CodegenProtocolVisitor {
|
|
final bool forClient;
|
|
|
|
/// Initialize a newly created visitor to generate code in the package with
|
|
/// the given [packageName] corresponding to the types in the given [api] that
|
|
/// are common to multiple protocols.
|
|
CodegenCommonVisitor(
|
|
super.packageName, super.responseRequiresRequestTime, super.api,
|
|
{this.forClient = false});
|
|
|
|
@override
|
|
void emitImports() {
|
|
writeln("import 'dart:convert' hide JsonDecoder;");
|
|
writeln();
|
|
if (forClient) {
|
|
writeln(
|
|
"import 'package:analysis_server_client/src/protocol/protocol_base.dart';");
|
|
writeln(
|
|
"import 'package:analysis_server_client/src/protocol/protocol_internal.dart';");
|
|
} else {
|
|
writeln("import 'package:$packageName/protocol/protocol.dart';");
|
|
writeln(
|
|
"import 'package:$packageName/src/protocol/protocol_internal.dart';");
|
|
}
|
|
}
|
|
|
|
@override
|
|
List<ImpliedType> getClassesToEmit() {
|
|
var types = impliedTypes.values.where((ImpliedType type) {
|
|
var node = type.apiNode;
|
|
return node is TypeDefinition && node.isExternal;
|
|
}).toList();
|
|
types.sort((first, second) =>
|
|
capitalize(first.camelName).compareTo(capitalize(second.camelName)));
|
|
return types;
|
|
}
|
|
}
|