mirror of
https://github.com/flutter/packages.git
synced 2025-07-04 09:38:17 +08:00
[pigeon] revert 3b5ae0070738103a80bb9ac12440dd69d598ad2c (#2987)
* start * Class file transfer and skeleton comments * relocate generator classes and update imports * merge main and changelog update * update openSink to openWriteSink * Revert "[pigeon] Relocates generator classes and updates imports (#2985)" This reverts commit 3b5ae0070738103a80bb9ac12440dd69d598ad2c.
This commit is contained in:
@ -1,7 +1,3 @@
|
||||
## 4.2.15
|
||||
|
||||
* Relocates generator classes.
|
||||
|
||||
## 4.2.14
|
||||
|
||||
* [c++] Fixes reply sending non EncodableValue wrapped lists.
|
||||
|
@ -2,14 +2,10 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'ast.dart';
|
||||
import 'functional.dart';
|
||||
import 'generator.dart';
|
||||
import 'generator_tools.dart';
|
||||
import 'pigeon_lib.dart' show Error, PigeonOptions, lineReader, openSink;
|
||||
import 'pigeon_lib.dart' show Error;
|
||||
|
||||
/// General comment opening token.
|
||||
const String _commentPrefix = '//';
|
||||
@ -68,54 +64,6 @@ class CppOptions {
|
||||
}
|
||||
}
|
||||
|
||||
/// A [Generator] that generates C++ header code.
|
||||
class CppHeaderGenerator implements Generator {
|
||||
/// Constructor for [CppHeaderGenerator].
|
||||
const CppHeaderGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
final CppOptions cppOptions = options.cppOptions ?? const CppOptions();
|
||||
final CppOptions cppOptionsWithHeader = cppOptions.merge(CppOptions(
|
||||
copyrightHeader: options.copyrightHeader != null
|
||||
? lineReader(options.copyrightHeader!)
|
||||
: null));
|
||||
generateCppHeader(path.basenameWithoutExtension(options.cppHeaderOut!),
|
||||
cppOptionsWithHeader, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) =>
|
||||
openSink(options.cppHeaderOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) =>
|
||||
validateCpp(options.cppOptions!, root);
|
||||
}
|
||||
|
||||
/// A [Generator] that generates C++ source code.
|
||||
class CppSourceGenerator implements Generator {
|
||||
/// Constructor for [CppSourceGenerator].
|
||||
const CppSourceGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
final CppOptions cppOptions = options.cppOptions ?? const CppOptions();
|
||||
final CppOptions cppOptionsWithHeader = cppOptions.merge(CppOptions(
|
||||
copyrightHeader: options.copyrightHeader != null
|
||||
? lineReader(options.copyrightHeader!)
|
||||
: null));
|
||||
generateCppSource(cppOptionsWithHeader, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) =>
|
||||
openSink(options.cppSourceOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) => <Error>[];
|
||||
}
|
||||
|
||||
String _getCodecSerializerName(Api api) => '${api.name}CodecSerializer';
|
||||
|
||||
const String _pointerPrefix = 'pointer';
|
||||
|
@ -2,16 +2,14 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io' show Directory, File, FileSystemEntity, IOSink;
|
||||
import 'dart:io' show Directory, File, FileSystemEntity;
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:yaml/yaml.dart' as yaml;
|
||||
|
||||
import 'ast.dart';
|
||||
import 'functional.dart';
|
||||
import 'generator.dart';
|
||||
import 'generator_tools.dart';
|
||||
import 'pigeon_lib.dart' show Error, PigeonOptions, lineReader, openSink;
|
||||
|
||||
/// Documentation comment open symbol.
|
||||
const String _docCommentPrefix = '///';
|
||||
@ -67,64 +65,6 @@ String _escapeForDartSingleQuotedString(String raw) {
|
||||
/// Calculates the name of the codec class that will be generated for [api].
|
||||
String _getCodecName(Api api) => '_${api.name}Codec';
|
||||
|
||||
/// A [Generator] that generates Dart source code.
|
||||
class DartGenerator implements Generator {
|
||||
/// Constructor for [DartGenerator].
|
||||
const DartGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
final DartOptions dartOptionsWithHeader = _dartOptionsWithCopyrightHeader(
|
||||
options.dartOptions, options.copyrightHeader);
|
||||
generateDart(dartOptionsWithHeader, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) => openSink(options.dartOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) => <Error>[];
|
||||
}
|
||||
|
||||
DartOptions _dartOptionsWithCopyrightHeader(
|
||||
DartOptions? dartOptions, String? copyrightHeader) {
|
||||
dartOptions = dartOptions ?? const DartOptions();
|
||||
return dartOptions.merge(DartOptions(
|
||||
copyrightHeader:
|
||||
copyrightHeader != null ? lineReader(copyrightHeader) : null));
|
||||
}
|
||||
|
||||
/// A [Generator] that generates Dart test source code.
|
||||
class DartTestGenerator implements Generator {
|
||||
/// Constructor for [DartTestGenerator].
|
||||
const DartTestGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
final DartOptions dartOptionsWithHeader = _dartOptionsWithCopyrightHeader(
|
||||
options.dartOptions, options.copyrightHeader);
|
||||
generateTestDart(
|
||||
dartOptionsWithHeader,
|
||||
root,
|
||||
sink,
|
||||
dartOutPath: options.dartOut!,
|
||||
testOutPath: options.dartTestOut!,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) {
|
||||
if (options.dartTestOut != null) {
|
||||
return openSink(options.dartTestOut);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) => <Error>[];
|
||||
}
|
||||
|
||||
/// Writes the codec that will be used by [api].
|
||||
/// Example:
|
||||
///
|
||||
|
@ -1,26 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'ast.dart';
|
||||
import 'pigeon_lib.dart' show Error, PigeonOptions;
|
||||
|
||||
/// A generator that will write code to a sink based on the contents of [PigeonOptions].
|
||||
abstract class Generator {
|
||||
/// Constructor for Generator.
|
||||
Generator();
|
||||
|
||||
/// Returns an [IOSink] instance to be written to if the [Generator] should
|
||||
/// generate. If it returns `null`, the [Generator] will be skipped.
|
||||
IOSink? shouldGenerate(PigeonOptions options);
|
||||
|
||||
/// Write the generated code described in [root] to [sink] using the
|
||||
/// [options].
|
||||
void generate(StringSink sink, PigeonOptions options, Root root);
|
||||
|
||||
/// Generates errors that would only be appropriate for this [Generator]. For
|
||||
/// example, maybe a certain feature isn't implemented in a [Generator] yet.
|
||||
List<Error> validate(PigeonOptions options, Root root);
|
||||
}
|
@ -9,7 +9,7 @@ import 'dart:mirrors';
|
||||
import 'ast.dart';
|
||||
|
||||
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
||||
const String pigeonVersion = '4.2.15';
|
||||
const String pigeonVersion = '4.2.14';
|
||||
|
||||
/// Read all the content from [stdin] to a String.
|
||||
String readStdin() {
|
||||
|
@ -2,16 +2,10 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'ast.dart';
|
||||
import 'functional.dart';
|
||||
import 'generator.dart';
|
||||
import 'generator_tools.dart';
|
||||
import 'pigeon_lib.dart'
|
||||
show Error, PigeonOptions, TaskQueueType, lineReader, openSink;
|
||||
import 'pigeon_lib.dart' show TaskQueueType;
|
||||
|
||||
/// Documentation open symbol.
|
||||
const String _docCommentPrefix = '/**';
|
||||
@ -90,30 +84,6 @@ class JavaOptions {
|
||||
}
|
||||
}
|
||||
|
||||
/// A [Generator] that generates Java source code.
|
||||
class JavaGenerator implements Generator {
|
||||
/// Constructor for [JavaGenerator].
|
||||
const JavaGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
JavaOptions javaOptions = options.javaOptions ?? const JavaOptions();
|
||||
javaOptions = javaOptions.merge(JavaOptions(
|
||||
className: javaOptions.className ??
|
||||
path.basenameWithoutExtension(options.javaOut!),
|
||||
copyrightHeader: options.copyrightHeader != null
|
||||
? lineReader(options.copyrightHeader!)
|
||||
: null));
|
||||
generateJava(javaOptions, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) => openSink(options.javaOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) => <Error>[];
|
||||
}
|
||||
|
||||
/// Calculates the name of the codec that will be generated for [api].
|
||||
String _getCodecName(Api api) => '${api.name}Codec';
|
||||
|
||||
|
@ -2,14 +2,10 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'ast.dart';
|
||||
import 'functional.dart';
|
||||
import 'generator.dart';
|
||||
import 'generator_tools.dart';
|
||||
import 'pigeon_lib.dart'
|
||||
show Error, PigeonOptions, TaskQueueType, lineReader, openSink;
|
||||
import 'pigeon_lib.dart' show TaskQueueType;
|
||||
|
||||
/// Documentation open symbol.
|
||||
const String _docCommentPrefix = '/**';
|
||||
@ -68,29 +64,6 @@ class KotlinOptions {
|
||||
}
|
||||
}
|
||||
|
||||
/// A [Generator] that generates Kotlin source code.
|
||||
class KotlinGenerator implements Generator {
|
||||
/// Constructor for [KotlinGenerator].
|
||||
const KotlinGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
KotlinOptions kotlinOptions =
|
||||
options.kotlinOptions ?? const KotlinOptions();
|
||||
kotlinOptions = kotlinOptions.merge(KotlinOptions(
|
||||
copyrightHeader: options.copyrightHeader != null
|
||||
? lineReader(options.copyrightHeader!)
|
||||
: null));
|
||||
generateKotlin(kotlinOptions, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) => openSink(options.kotlinOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) => <Error>[];
|
||||
}
|
||||
|
||||
/// Calculates the name of the codec that will be generated for [api].
|
||||
String _getCodecName(Api api) => '${api.name}Codec';
|
||||
|
||||
|
@ -2,14 +2,10 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'ast.dart';
|
||||
import 'functional.dart';
|
||||
import 'generator.dart';
|
||||
import 'generator_tools.dart';
|
||||
import 'pigeon_lib.dart'
|
||||
show Error, PigeonOptions, TaskQueueType, lineReader, openSink;
|
||||
import 'pigeon_lib.dart' show Error, TaskQueueType;
|
||||
|
||||
/// Documentation comment open symbol.
|
||||
const String _docCommentPrefix = '///';
|
||||
@ -67,53 +63,6 @@ class ObjcOptions {
|
||||
}
|
||||
}
|
||||
|
||||
/// A [Generator] that generates Objective-C header code.
|
||||
class ObjcHeaderGenerator implements Generator {
|
||||
/// Constructor for [ObjcHeaderGenerator].
|
||||
const ObjcHeaderGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
final ObjcOptions objcOptions = options.objcOptions ?? const ObjcOptions();
|
||||
final ObjcOptions objcOptionsWithHeader = objcOptions.merge(ObjcOptions(
|
||||
copyrightHeader: options.copyrightHeader != null
|
||||
? lineReader(options.copyrightHeader!)
|
||||
: null));
|
||||
generateObjcHeader(objcOptionsWithHeader, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) =>
|
||||
openSink(options.objcHeaderOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) =>
|
||||
validateObjc(options.objcOptions!, root);
|
||||
}
|
||||
|
||||
/// A [Generator] that generates Objective-C source code.
|
||||
class ObjcSourceGenerator implements Generator {
|
||||
/// Constructor for [ObjcSourceGenerator].
|
||||
const ObjcSourceGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
final ObjcOptions objcOptions = options.objcOptions ?? const ObjcOptions();
|
||||
final ObjcOptions objcOptionsWithHeader = objcOptions.merge(ObjcOptions(
|
||||
copyrightHeader: options.copyrightHeader != null
|
||||
? lineReader(options.copyrightHeader!)
|
||||
: null));
|
||||
generateObjcSource(objcOptionsWithHeader, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) =>
|
||||
openSink(options.objcSourceOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) => <Error>[];
|
||||
}
|
||||
|
||||
/// Calculates the ObjC class name, possibly prefixed.
|
||||
String _className(String? prefix, String className) {
|
||||
if (prefix != null) {
|
||||
|
@ -27,7 +27,6 @@ import 'ast.dart';
|
||||
import 'ast_generator.dart';
|
||||
import 'cpp_generator.dart';
|
||||
import 'dart_generator.dart';
|
||||
import 'generator.dart';
|
||||
import 'generator_tools.dart';
|
||||
import 'generator_tools.dart' as generator_tools;
|
||||
import 'java_generator.dart';
|
||||
@ -332,8 +331,7 @@ class ParseResults {
|
||||
final Map<String, Object>? pigeonOptions;
|
||||
}
|
||||
|
||||
/// Reads file line by line.
|
||||
Iterable<String> lineReader(String path) sync* {
|
||||
Iterable<String> _lineReader(String path) sync* {
|
||||
final String contents = File(path).readAsStringSync();
|
||||
const LineSplitter lineSplitter = LineSplitter();
|
||||
final List<String> lines = lineSplitter.convert(contents);
|
||||
@ -342,8 +340,7 @@ Iterable<String> lineReader(String path) sync* {
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates IOSink.
|
||||
IOSink? openSink(String? output) {
|
||||
IOSink? _openSink(String? output) {
|
||||
if (output == null) {
|
||||
return null;
|
||||
}
|
||||
@ -358,6 +355,29 @@ IOSink? openSink(String? output) {
|
||||
return sink;
|
||||
}
|
||||
|
||||
/// A generator that will write code to a sink based on the contents of [PigeonOptions].
|
||||
abstract class Generator {
|
||||
/// Returns an [IOSink] instance to be written to if the [Generator] should
|
||||
/// generate. If it returns `null`, the [Generator] will be skipped.
|
||||
IOSink? shouldGenerate(PigeonOptions options);
|
||||
|
||||
/// Write the generated code described in [root] to [sink] using the
|
||||
/// [options].
|
||||
void generate(StringSink sink, PigeonOptions options, Root root);
|
||||
|
||||
/// Generates errors that would only be appropriate for this [Generator]. For
|
||||
/// example, maybe a certain feature isn't implemented in a [Generator] yet.
|
||||
List<Error> validate(PigeonOptions options, Root root);
|
||||
}
|
||||
|
||||
DartOptions _dartOptionsWithCopyrightHeader(
|
||||
DartOptions? dartOptions, String? copyrightHeader) {
|
||||
dartOptions = dartOptions ?? const DartOptions();
|
||||
return dartOptions.merge(DartOptions(
|
||||
copyrightHeader:
|
||||
copyrightHeader != null ? _lineReader(copyrightHeader) : null));
|
||||
}
|
||||
|
||||
/// A [Generator] that generates the AST.
|
||||
class AstGenerator implements Generator {
|
||||
/// Constructor for [AstGenerator].
|
||||
@ -369,7 +389,221 @@ class AstGenerator implements Generator {
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) => openSink(options.astOut);
|
||||
IOSink? shouldGenerate(PigeonOptions options) => _openSink(options.astOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) => <Error>[];
|
||||
}
|
||||
|
||||
/// A [Generator] that generates Dart source code.
|
||||
class DartGenerator implements Generator {
|
||||
/// Constructor for [DartGenerator].
|
||||
const DartGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
final DartOptions dartOptionsWithHeader = _dartOptionsWithCopyrightHeader(
|
||||
options.dartOptions, options.copyrightHeader);
|
||||
generateDart(dartOptionsWithHeader, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) => _openSink(options.dartOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) => <Error>[];
|
||||
}
|
||||
|
||||
/// A [Generator] that generates Dart test source code.
|
||||
class DartTestGenerator implements Generator {
|
||||
/// Constructor for [DartTestGenerator].
|
||||
const DartTestGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
final DartOptions dartOptionsWithHeader = _dartOptionsWithCopyrightHeader(
|
||||
options.dartOptions, options.copyrightHeader);
|
||||
generateTestDart(
|
||||
dartOptionsWithHeader,
|
||||
root,
|
||||
sink,
|
||||
dartOutPath: options.dartOut!,
|
||||
testOutPath: options.dartTestOut!,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) {
|
||||
if (options.dartTestOut != null) {
|
||||
return _openSink(options.dartTestOut);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) => <Error>[];
|
||||
}
|
||||
|
||||
/// A [Generator] that generates Objective-C header code.
|
||||
class ObjcHeaderGenerator implements Generator {
|
||||
/// Constructor for [ObjcHeaderGenerator].
|
||||
const ObjcHeaderGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
final ObjcOptions objcOptions = options.objcOptions ?? const ObjcOptions();
|
||||
final ObjcOptions objcOptionsWithHeader = objcOptions.merge(ObjcOptions(
|
||||
copyrightHeader: options.copyrightHeader != null
|
||||
? _lineReader(options.copyrightHeader!)
|
||||
: null));
|
||||
generateObjcHeader(objcOptionsWithHeader, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) =>
|
||||
_openSink(options.objcHeaderOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) =>
|
||||
validateObjc(options.objcOptions!, root);
|
||||
}
|
||||
|
||||
/// A [Generator] that generates Objective-C source code.
|
||||
class ObjcSourceGenerator implements Generator {
|
||||
/// Constructor for [ObjcSourceGenerator].
|
||||
const ObjcSourceGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
final ObjcOptions objcOptions = options.objcOptions ?? const ObjcOptions();
|
||||
final ObjcOptions objcOptionsWithHeader = objcOptions.merge(ObjcOptions(
|
||||
copyrightHeader: options.copyrightHeader != null
|
||||
? _lineReader(options.copyrightHeader!)
|
||||
: null));
|
||||
generateObjcSource(objcOptionsWithHeader, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) =>
|
||||
_openSink(options.objcSourceOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) => <Error>[];
|
||||
}
|
||||
|
||||
/// A [Generator] that generates Java source code.
|
||||
class JavaGenerator implements Generator {
|
||||
/// Constructor for [JavaGenerator].
|
||||
const JavaGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
JavaOptions javaOptions = options.javaOptions ?? const JavaOptions();
|
||||
javaOptions = javaOptions.merge(JavaOptions(
|
||||
className: javaOptions.className ??
|
||||
path.basenameWithoutExtension(options.javaOut!),
|
||||
copyrightHeader: options.copyrightHeader != null
|
||||
? _lineReader(options.copyrightHeader!)
|
||||
: null));
|
||||
generateJava(javaOptions, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) => _openSink(options.javaOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) => <Error>[];
|
||||
}
|
||||
|
||||
/// A [Generator] that generates Swift source code.
|
||||
class SwiftGenerator implements Generator {
|
||||
/// Constructor for [SwiftGenerator].
|
||||
const SwiftGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
SwiftOptions swiftOptions = options.swiftOptions ?? const SwiftOptions();
|
||||
swiftOptions = swiftOptions.merge(SwiftOptions(
|
||||
copyrightHeader: options.copyrightHeader != null
|
||||
? _lineReader(options.copyrightHeader!)
|
||||
: null));
|
||||
generateSwift(swiftOptions, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) => _openSink(options.swiftOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) => <Error>[];
|
||||
}
|
||||
|
||||
/// A [Generator] that generates C++ header code.
|
||||
class CppHeaderGenerator implements Generator {
|
||||
/// Constructor for [CppHeaderGenerator].
|
||||
const CppHeaderGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
final CppOptions cppOptions = options.cppOptions ?? const CppOptions();
|
||||
final CppOptions cppOptionsWithHeader = cppOptions.merge(CppOptions(
|
||||
copyrightHeader: options.copyrightHeader != null
|
||||
? _lineReader(options.copyrightHeader!)
|
||||
: null));
|
||||
generateCppHeader(path.basenameWithoutExtension(options.cppHeaderOut!),
|
||||
cppOptionsWithHeader, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) =>
|
||||
_openSink(options.cppHeaderOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) =>
|
||||
validateCpp(options.cppOptions!, root);
|
||||
}
|
||||
|
||||
/// A [Generator] that generates C++ source code.
|
||||
class CppSourceGenerator implements Generator {
|
||||
/// Constructor for [CppSourceGenerator].
|
||||
const CppSourceGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
final CppOptions cppOptions = options.cppOptions ?? const CppOptions();
|
||||
final CppOptions cppOptionsWithHeader = cppOptions.merge(CppOptions(
|
||||
copyrightHeader: options.copyrightHeader != null
|
||||
? _lineReader(options.copyrightHeader!)
|
||||
: null));
|
||||
generateCppSource(cppOptionsWithHeader, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) =>
|
||||
_openSink(options.cppSourceOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) => <Error>[];
|
||||
}
|
||||
|
||||
/// A [Generator] that generates Kotlin source code.
|
||||
class KotlinGenerator implements Generator {
|
||||
/// Constructor for [KotlinGenerator].
|
||||
const KotlinGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
KotlinOptions kotlinOptions =
|
||||
options.kotlinOptions ?? const KotlinOptions();
|
||||
kotlinOptions = kotlinOptions.merge(KotlinOptions(
|
||||
copyrightHeader: options.copyrightHeader != null
|
||||
? _lineReader(options.copyrightHeader!)
|
||||
: null));
|
||||
generateKotlin(kotlinOptions, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) => _openSink(options.kotlinOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) => <Error>[];
|
||||
|
@ -2,13 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'ast.dart';
|
||||
import 'functional.dart';
|
||||
import 'generator.dart';
|
||||
import 'generator_tools.dart';
|
||||
import 'pigeon_lib.dart' show Error, PigeonOptions, lineReader, openSink;
|
||||
|
||||
/// Documentation comment open symbol.
|
||||
const String _docCommentPrefix = '///';
|
||||
@ -51,28 +47,6 @@ class SwiftOptions {
|
||||
}
|
||||
}
|
||||
|
||||
/// A [Generator] that generates Swift source code.
|
||||
class SwiftGenerator implements Generator {
|
||||
/// Constructor for [SwiftGenerator].
|
||||
const SwiftGenerator();
|
||||
|
||||
@override
|
||||
void generate(StringSink sink, PigeonOptions options, Root root) {
|
||||
SwiftOptions swiftOptions = options.swiftOptions ?? const SwiftOptions();
|
||||
swiftOptions = swiftOptions.merge(SwiftOptions(
|
||||
copyrightHeader: options.copyrightHeader != null
|
||||
? lineReader(options.copyrightHeader!)
|
||||
: null));
|
||||
generateSwift(swiftOptions, root, sink);
|
||||
}
|
||||
|
||||
@override
|
||||
IOSink? shouldGenerate(PigeonOptions options) => openSink(options.swiftOut);
|
||||
|
||||
@override
|
||||
List<Error> validate(PigeonOptions options, Root root) => <Error>[];
|
||||
}
|
||||
|
||||
/// Calculates the name of the codec that will be generated for [api].
|
||||
String _getCodecName(Api api) => '${api.name}Codec';
|
||||
|
||||
|
@ -2,7 +2,7 @@ name: pigeon
|
||||
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
|
||||
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
|
||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
|
||||
version: 4.2.15 # This must match the version in lib/generator_tools.dart
|
||||
version: 4.2.14 # This must match the version in lib/generator_tools.dart
|
||||
|
||||
environment:
|
||||
sdk: ">=2.12.0 <3.0.0"
|
||||
|
@ -6,13 +6,7 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:pigeon/ast.dart';
|
||||
import 'package:pigeon/cpp_generator.dart';
|
||||
import 'package:pigeon/dart_generator.dart';
|
||||
import 'package:pigeon/generator.dart';
|
||||
import 'package:pigeon/java_generator.dart';
|
||||
import 'package:pigeon/objc_generator.dart';
|
||||
import 'package:pigeon/pigeon_lib.dart';
|
||||
import 'package:pigeon/swift_generator.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
class _ValidatorGenerator implements Generator {
|
||||
|
Reference in New Issue
Block a user