blob: a636b5bc053f0a101a25c74bd0cad4c2214d071c [file] [log] [blame]
// 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/src/codegen/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 target(bool responseRequiresRequestTime) =>
new GeneratedFile('lib/protocol/protocol_common.dart',
(String pkgPath) async {
CodegenCommonVisitor visitor = new CodegenCommonVisitor(
return visitor.collectCode(visitor.visitApi);
* A visitor that produces Dart code defining the common types associated with
* the API.
class CodegenCommonVisitor extends CodegenProtocolVisitor {
* 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.
String packageName, bool responseRequiresRequestTime, Api api)
: super(packageName, responseRequiresRequestTime, api);
void emitImports() {
writeln("import 'dart:convert' hide JsonDecoder;");
writeln("import 'package:analyzer/src/generated/utilities_general.dart';");
writeln("import 'package:$packageName/protocol/protocol.dart';");
"import 'package:$packageName/src/protocol/protocol_internal.dart';");
List<ImpliedType> getClassesToEmit() {
List<ImpliedType> types = impliedTypes.values.where((ImpliedType type) {
ApiNode node = type.apiNode;
return node is TypeDefinition && node.isExternal;
types.sort((first, second) =>
return types;