Skip to content

Commit d29fec2

Browse files
a14nsigurdm
authored andcommitted
Use $async as prefix for dart:async (flutter#131)
1 parent 7cf88a9 commit d29fec2

11 files changed

+49
-37
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
## 0.10.5
2+
3+
* Generated files now import `dart:async` with a prefix to prevent name
4+
collisions.
5+
16
## 0.10.4
27

3-
* Change the fully qualfiied message name of generated messages to use
8+
* Change the fully qualified message name of generated messages to use
49
`BuilderInfo.qualifiedMessageName`.
510
Requires package:protobuf version 0.10.4 or newer.
611

lib/client_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ClientApiGenerator {
3333
var inputType = service._getDartClassName(m.inputType);
3434
var outputType = service._getDartClassName(m.outputType);
3535
out.addBlock(
36-
'Future<$outputType> $methodName('
36+
'\$async.Future<$outputType> $methodName('
3737
'$_protobufImportPrefix.ClientContext ctx, $inputType request) {',
3838
'}', () {
3939
out.println('var emptyResponse = new $outputType();');

lib/file_generator.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class FileGenerator extends ProtobufContainer {
239239
// We only add the dart:async import if there are generic client API
240240
// generators for services in the FileDescriptorProto.
241241
if (clientApiGenerators.isNotEmpty) {
242-
out.println("import 'dart:async';");
242+
out.println(r"import 'dart:async' as $async;");
243243
}
244244

245245
// Make sure any other symbols in dart:core don't cause name conflicts with
@@ -393,8 +393,8 @@ class FileGenerator extends ProtobufContainer {
393393
_writeHeading(out);
394394

395395
if (serviceGenerators.isNotEmpty) {
396-
out.println('''
397-
import 'dart:async';
396+
out.println(r'''
397+
import 'dart:async' as $async;
398398
399399
import 'package:protobuf/protobuf.dart';
400400
''');
@@ -434,8 +434,8 @@ import 'package:protobuf/protobuf.dart';
434434
var out = new IndentingWriter();
435435
_writeHeading(out);
436436

437-
out.println('''
438-
import 'dart:async';
437+
out.println(r'''
438+
import 'dart:async' as $async;
439439
440440
import 'package:grpc/grpc.dart';
441441
''');

lib/grpc_generator.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,14 @@ class _GrpcMethod {
187187
final requestType = service._getDartClassName(method.inputType);
188188
final responseType = service._getDartClassName(method.outputType);
189189

190-
final argumentType = clientStreaming ? 'Stream<$requestType>' : requestType;
190+
final argumentType =
191+
clientStreaming ? '\$async.Stream<$requestType>' : requestType;
191192
final clientReturnType = serverStreaming
192193
? 'ResponseStream<$responseType>'
193194
: 'ResponseFuture<$responseType>';
194-
final serverReturnType =
195-
serverStreaming ? 'Stream<$responseType>' : 'Future<$responseType>';
195+
final serverReturnType = serverStreaming
196+
? '\$async.Stream<$responseType>'
197+
: '\$async.Future<$responseType>';
196198

197199
return new _GrpcMethod._(
198200
grpcName,
@@ -221,8 +223,9 @@ class _GrpcMethod {
221223
out.addBlock(
222224
'$_clientReturnType $_dartName($_argumentType request, {CallOptions options}) {',
223225
'}', () {
224-
final requestStream =
225-
_clientStreaming ? 'request' : 'new Stream.fromIterable([request])';
226+
final requestStream = _clientStreaming
227+
? 'request'
228+
: r'new $async.Stream.fromIterable([request])';
226229
out.println(
227230
'final call = \$createCall(_\$$_dartName, $requestStream, options: options);');
228231
if (_serverStreaming) {
@@ -249,7 +252,7 @@ class _GrpcMethod {
249252
if (_clientStreaming) return;
250253

251254
out.addBlock(
252-
'$_serverReturnType ${_dartName}_Pre(ServiceCall call, Future request) async${_serverStreaming ? '*' : ''} {',
255+
'$_serverReturnType ${_dartName}_Pre(ServiceCall call, \$async.Future request) async${_serverStreaming ? '*' : ''} {',
253256
'}', () {
254257
if (_serverStreaming) {
255258
out.println(

lib/service_generator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class ServiceGenerator {
132132
var inputClass = _getDartClassName(m.inputType);
133133
var outputClass = _getDartClassName(m.outputType);
134134

135-
out.println('Future<$outputClass> $methodName('
135+
out.println('\$async.Future<$outputClass> $methodName('
136136
'ServerContext ctx, $inputClass request);');
137137
}
138138

@@ -159,7 +159,7 @@ class ServiceGenerator {
159159

160160
void _generateDispatchMethod(out) {
161161
out.addBlock(
162-
'Future<GeneratedMessage> handleCall(ServerContext ctx, '
162+
r'$async.Future<GeneratedMessage> handleCall(ServerContext ctx, '
163163
'String method, GeneratedMessage request) {',
164164
'}', () {
165165
out.addBlock("switch (method) {", "}", () {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: protoc_plugin
2-
version: 0.10.5-dev
2+
version: 0.10.5
33
author: Dart Team <[email protected]>
44
description: Protoc compiler plugin to generate Dart code
55
homepage: https://github.com/dart-lang/dart-protoc-plugin

test/goldens/client

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ class TestApi {
22
$pb.RpcClient _client;
33
TestApi(this._client);
44

5-
Future<SomeReply> aMethod($pb.ClientContext ctx, SomeRequest request) {
5+
$async.Future<SomeReply> aMethod($pb.ClientContext ctx, SomeRequest request) {
66
var emptyResponse = new SomeReply();
77
return _client.invoke<SomeReply>(ctx, 'Test', 'AMethod', request, emptyResponse);
88
}
9-
Future<$0.AnotherReply> anotherMethod($pb.ClientContext ctx, $0.EmptyMessage request) {
9+
$async.Future<$0.AnotherReply> anotherMethod($pb.ClientContext ctx, $0.EmptyMessage request) {
1010
var emptyResponse = new $0.AnotherReply();
1111
return _client.invoke<$0.AnotherReply>(ctx, 'Test', 'AnotherMethod', request, emptyResponse);
1212
}

test/goldens/grpc_service.pbgrpc

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
///
55
// ignore_for_file: non_constant_identifier_names,library_prefixes,unused_import
66

7-
import 'dart:async';
7+
import 'dart:async' as $async;
88

99
import 'package:grpc/grpc.dart';
1010

@@ -33,25 +33,25 @@ class TestClient extends Client {
3333
: super(channel, options: options);
3434

3535
ResponseFuture<Output> unary(Input request, {CallOptions options}) {
36-
final call = $createCall(_$unary, new Stream.fromIterable([request]),
36+
final call = $createCall(_$unary, new $async.Stream.fromIterable([request]),
3737
options: options);
3838
return new ResponseFuture(call);
3939
}
4040

41-
ResponseFuture<Output> clientStreaming(Stream<Input> request,
41+
ResponseFuture<Output> clientStreaming($async.Stream<Input> request,
4242
{CallOptions options}) {
4343
final call = $createCall(_$clientStreaming, request, options: options);
4444
return new ResponseFuture(call);
4545
}
4646

4747
ResponseStream<Output> serverStreaming(Input request, {CallOptions options}) {
4848
final call = $createCall(
49-
_$serverStreaming, new Stream.fromIterable([request]),
49+
_$serverStreaming, new $async.Stream.fromIterable([request]),
5050
options: options);
5151
return new ResponseStream(call);
5252
}
5353

54-
ResponseStream<Output> bidirectional(Stream<Input> request,
54+
ResponseStream<Output> bidirectional($async.Stream<Input> request,
5555
{CallOptions options}) {
5656
final call = $createCall(_$bidirectional, request, options: options);
5757
return new ResponseStream(call);
@@ -92,16 +92,20 @@ abstract class TestServiceBase extends Service {
9292
(Output value) => value.writeToBuffer()));
9393
}
9494

95-
Future<Output> unary_Pre(ServiceCall call, Future request) async {
95+
$async.Future<Output> unary_Pre(
96+
ServiceCall call, $async.Future request) async {
9697
return unary(call, await request);
9798
}
9899

99-
Stream<Output> serverStreaming_Pre(ServiceCall call, Future request) async* {
100+
$async.Stream<Output> serverStreaming_Pre(
101+
ServiceCall call, $async.Future request) async* {
100102
yield* serverStreaming(call, (await request) as Input);
101103
}
102104

103-
Future<Output> unary(ServiceCall call, Input request);
104-
Future<Output> clientStreaming(ServiceCall call, Stream<Input> request);
105-
Stream<Output> serverStreaming(ServiceCall call, Input request);
106-
Stream<Output> bidirectional(ServiceCall call, Stream<Input> request);
105+
$async.Future<Output> unary(ServiceCall call, Input request);
106+
$async.Future<Output> clientStreaming(
107+
ServiceCall call, $async.Stream<Input> request);
108+
$async.Stream<Output> serverStreaming(ServiceCall call, Input request);
109+
$async.Stream<Output> bidirectional(
110+
ServiceCall call, $async.Stream<Input> request);
107111
}

test/goldens/service.pb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
///
55
// ignore_for_file: non_constant_identifier_names,library_prefixes,unused_import
66

7-
import 'dart:async';
7+
import 'dart:async' as $async;
88
// ignore: UNUSED_SHOWN_NAME
99
import 'dart:core' show int, bool, double, String, List, override;
1010

@@ -34,7 +34,7 @@ class TestApi {
3434
$pb.RpcClient _client;
3535
TestApi(this._client);
3636

37-
Future<Empty> ping($pb.ClientContext ctx, Empty request) {
37+
$async.Future<Empty> ping($pb.ClientContext ctx, Empty request) {
3838
var emptyResponse = new Empty();
3939
return _client.invoke<Empty>(ctx, 'Test', 'Ping', request, emptyResponse);
4040
}

test/goldens/service.pbserver

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
///
55
// ignore_for_file: non_constant_identifier_names,library_prefixes,unused_import
66

7-
import 'dart:async';
7+
import 'dart:async' as $async;
88

99
import 'package:protobuf/protobuf.dart';
1010

@@ -14,7 +14,7 @@ import 'test.pbjson.dart';
1414
export 'test.pb.dart';
1515

1616
abstract class TestServiceBase extends GeneratedService {
17-
Future<Empty> ping(ServerContext ctx, Empty request);
17+
$async.Future<Empty> ping(ServerContext ctx, Empty request);
1818

1919
GeneratedMessage createRequest(String method) {
2020
switch (method) {
@@ -23,7 +23,7 @@ abstract class TestServiceBase extends GeneratedService {
2323
}
2424
}
2525

26-
Future<GeneratedMessage> handleCall(ServerContext ctx, String method, GeneratedMessage request) {
26+
$async.Future<GeneratedMessage> handleCall(ServerContext ctx, String method, GeneratedMessage request) {
2727
switch (method) {
2828
case 'Ping': return this.ping(ctx, request);
2929
default: throw new ArgumentError('Unknown method: $method');

0 commit comments

Comments
 (0)