Skip to content

Commit 5e7bb77

Browse files
Use real generic syntax instead of comment-based. (#75)
Also, update pubspec to support v2 dev SDKs.
1 parent 1b29bbf commit 5e7bb77

13 files changed

+82
-125
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.5.5
2+
3+
* Use real generic syntax instead of comment-based.
4+
* Support v2 dev SDKs.
5+
16
## 0.5.4
27

38
* Unknown enum values are ignored when parsing JSON, instead of throwing an

lib/src/protobuf/builder_info.dart

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
part of protobuf;
66

7-
/**
8-
* Per-message type setup.
9-
*/
7+
/// Per-message type setup.
108
class BuilderInfo {
119
final String messageName;
1210
final Map<int, FieldInfo> fieldInfo = new Map<int, FieldInfo>();
@@ -18,22 +16,17 @@ class BuilderInfo {
1816

1917
BuilderInfo(this.messageName);
2018

21-
void add/*<T>*/(
22-
int tagNumber,
23-
String name,
24-
int fieldType,
25-
dynamic defaultOrMaker,
26-
CreateBuilderFunc subBuilder,
27-
ValueOfFunc valueOf) {
19+
void add<T>(int tagNumber, String name, int fieldType, dynamic defaultOrMaker,
20+
CreateBuilderFunc subBuilder, ValueOfFunc valueOf) {
2821
var index = fieldInfo.length;
29-
addField(new FieldInfo/*<T>*/(name, tagNumber, index, fieldType,
30-
defaultOrMaker, subBuilder, valueOf));
22+
addField(new FieldInfo<T>(name, tagNumber, index, fieldType, defaultOrMaker,
23+
subBuilder, valueOf));
3124
}
3225

33-
void addRepeated/*<T>*/(int tagNumber, String name, int fieldType,
26+
void addRepeated<T>(int tagNumber, String name, int fieldType,
3427
CheckFunc check, CreateBuilderFunc subBuilder, ValueOfFunc valueOf) {
3528
var index = fieldInfo.length;
36-
addField(new FieldInfo/*<T>*/ .repeated(
29+
addField(new FieldInfo<T>.repeated(
3730
name, tagNumber, index, fieldType, check, subBuilder, valueOf));
3831
}
3932

@@ -43,39 +36,39 @@ class BuilderInfo {
4336
byName[fi.name] = fi;
4437
}
4538

46-
void a/*<T>*/(int tagNumber, String name, int fieldType,
39+
void a<T>(int tagNumber, String name, int fieldType,
4740
[dynamic defaultOrMaker,
4841
CreateBuilderFunc subBuilder,
4942
ValueOfFunc valueOf]) {
50-
add/*<T>*/(tagNumber, name, fieldType, defaultOrMaker, subBuilder, valueOf);
43+
add<T>(tagNumber, name, fieldType, defaultOrMaker, subBuilder, valueOf);
5144
}
5245

5346
// Enum.
54-
void e/*<T>*/(int tagNumber, String name, int fieldType,
55-
dynamic defaultOrMaker, ValueOfFunc valueOf) {
56-
add/*<T>*/(tagNumber, name, fieldType, defaultOrMaker, null, valueOf);
47+
void e<T>(int tagNumber, String name, int fieldType, dynamic defaultOrMaker,
48+
ValueOfFunc valueOf) {
49+
add<T>(tagNumber, name, fieldType, defaultOrMaker, null, valueOf);
5750
}
5851

5952
// Repeated message.
6053
// TODO(skybrian): migrate to pp() and remove.
61-
void m/*<T>*/(int tagNumber, String name, CreateBuilderFunc subBuilder,
54+
void m<T>(int tagNumber, String name, CreateBuilderFunc subBuilder,
6255
MakeDefaultFunc makeDefault) {
63-
add/*<T>*/(tagNumber, name, PbFieldType._REPEATED_MESSAGE, makeDefault,
56+
add<T>(tagNumber, name, PbFieldType._REPEATED_MESSAGE, makeDefault,
6457
subBuilder, null);
6558
}
6659

6760
// Repeated, not a message, group, or enum.
68-
void p/*<T>*/(int tagNumber, String name, int fieldType) {
61+
void p<T>(int tagNumber, String name, int fieldType) {
6962
assert(!_isGroupOrMessage(fieldType) && !_isEnum(fieldType));
70-
addRepeated/*<T>*/(
63+
addRepeated<T>(
7164
tagNumber, name, fieldType, getCheckFunction(fieldType), null, null);
7265
}
7366

7467
// Repeated message, group, or enum.
75-
void pp/*<T>*/(int tagNumber, String name, int fieldType, CheckFunc check,
68+
void pp<T>(int tagNumber, String name, int fieldType, CheckFunc check,
7669
[CreateBuilderFunc subBuilder, ValueOfFunc valueOf]) {
7770
assert(_isGroupOrMessage(fieldType) || _isEnum(fieldType));
78-
addRepeated/*<T>*/(tagNumber, name, fieldType, check, subBuilder, valueOf);
71+
addRepeated<T>(tagNumber, name, fieldType, check, subBuilder, valueOf);
7972
}
8073

8174
bool containsTagNumber(int tagNumber) => fieldInfo.containsKey(tagNumber);

lib/src/protobuf/extension.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
part of protobuf;
66

7-
/**
8-
* An object representing an extension field.
9-
*/
7+
/// An object representing an extension field.
108
class Extension<T> extends FieldInfo<T> {
119
final String extendee;
1210

lib/src/protobuf/extension_field_set.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ class _ExtensionFieldSet {
3838
///
3939
/// If it doesn't exist, creates the list and saves the extension.
4040
/// Suitable for public API and decoders.
41-
List/*<T>*/ _ensureRepeatedField/*<T>*/(Extension/*<T>*/ fi) {
41+
List<T> _ensureRepeatedField<T>(Extension<T> fi) {
4242
assert(fi.isRepeated);
4343
assert(fi.extendee == _parent._messageName);
4444

4545
var list = _values[fi.tagNumber];
46-
if (list != null) return list as List/*<T>*/;
46+
if (list != null) return list as List<T>;
4747

4848
// Add info and create list.
4949
_validateInfo(fi);

lib/src/protobuf/extension_registry.dart

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,23 @@
44

55
part of protobuf;
66

7-
/**
8-
* A collection of [Extension] objects, organized by the message type they
9-
* extend.
10-
*/
7+
/// A collection of [Extension] objects, organized by the message type they
8+
/// extend.
119
class ExtensionRegistry {
1210
final Map<String, Map<int, Extension>> _extensions =
1311
<String, Map<int, Extension>>{};
1412

1513
static const ExtensionRegistry EMPTY = const _EmptyExtensionRegistry();
1614

17-
/**
18-
* Store an extension in the registry.
19-
*/
15+
/// Stores an [extension] in the registry.
2016
void add(Extension extension) {
2117
var map = _extensions.putIfAbsent(
2218
extension.extendee, () => new Map<int, Extension>());
2319
map[extension.tagNumber] = extension;
2420
}
2521

26-
/**
27-
* Retrieve an extension from the registry that adds the given tag
28-
* number to the given message type.
29-
*/
22+
/// Retrieves an extension from the registry that adds tag number [tagNumber]
23+
/// to the [messageName] message type.
3024
Extension getExtension(String messageName, int tagNumber) {
3125
var map = _extensions[messageName];
3226
if (map != null) {
@@ -39,7 +33,7 @@ class ExtensionRegistry {
3933
class _EmptyExtensionRegistry implements ExtensionRegistry {
4034
const _EmptyExtensionRegistry();
4135

42-
// needed to quite missing member warning
36+
// Needed to quiet missing member warning.
4337
get _extensions => null;
4438

4539
void add(Extension extension) {

lib/src/protobuf/field_info.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
part of protobuf;
66

7-
/**
8-
* An object representing a protobuf message field.
9-
*/
7+
/// An object representing a protobuf message field.
108
class FieldInfo<T> {
119
final String name;
1210
final int tagNumber;
@@ -127,7 +125,7 @@ class FieldInfo<T> {
127125
/// be overridden by a mixin.
128126
List<T> _createRepeatedField(GeneratedMessage m) {
129127
assert(isRepeated);
130-
return m.createRepeatedField/*<T>*/(tagNumber, this);
128+
return m.createRepeatedField<T>(tagNumber, this);
131129
}
132130

133131
String toString() => name;

lib/src/protobuf/field_set.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,14 @@ class _FieldSet {
210210
/// Creates and stores the repeated field if it doesn't exist.
211211
/// If it's an extension and the list doesn't exist, validates and stores it.
212212
/// Suitable for decoders.
213-
List/*<T>*/ _ensureRepeatedField/*<T>*/(FieldInfo/*<T>*/ fi) {
213+
List<T> _ensureRepeatedField<T>(FieldInfo<T> fi) {
214214
assert(!_isReadOnly);
215215
assert(fi.isRepeated);
216216
if (fi.index == null) {
217217
return _ensureExtensions()._ensureRepeatedField(fi);
218218
}
219219
var value = _getFieldOrNull(fi);
220-
if (value != null) return value as List/*<T>*/;
220+
if (value != null) return value as List<T>;
221221

222222
var newValue = fi._createRepeatedField(_message);
223223
_setNonExtensionFieldUnchecked(fi, newValue);
@@ -235,12 +235,12 @@ class _FieldSet {
235235
// Generated method implementations
236236

237237
/// The implementation of a generated getter.
238-
/*=T*/ _$get/*<T>*/(int index, int tagNumber, /*=T*/ defaultValue) {
238+
T _$get<T>(int index, int tagNumber, T defaultValue) {
239239
assert(_nonExtensionInfo(tagNumber).index == index);
240240
var value = _values[index];
241-
if (value != null) return value as dynamic/*=T*/;
241+
if (value != null) return value as T;
242242
if (defaultValue != null) return defaultValue;
243-
return _getDefault(_nonExtensionInfo(tagNumber)) as dynamic/*=T*/;
243+
return _getDefault(_nonExtensionInfo(tagNumber)) as T;
244244
}
245245

246246
/// The implementation of a generated has method.

lib/src/protobuf/generated_message.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ abstract class GeneratedMessage {
221221
/// that the protobuf can be encoded correctly, the returned List must
222222
/// validate all items added to it. This can most easily be done
223223
/// using the FieldInfo.check function.
224-
List/*<T>*/ createRepeatedField/*<T>*/(int tagNumber, FieldInfo/*<T>*/ fi) {
225-
return new PbList/*<T>*/(check: fi.check);
224+
List<T> createRepeatedField<T>(int tagNumber, FieldInfo<T> fi) {
225+
return new PbList<T>(check: fi.check);
226226
}
227227

228228
/// Returns the value of a field, ignoring any defaults.
@@ -279,8 +279,8 @@ abstract class GeneratedMessage {
279279
void setField(int tagNumber, value) => _fieldSet._setField(tagNumber, value);
280280

281281
/// For generated code only.
282-
/*=T*/ $_get/*<T>*/(int index, int tagNumber, /*=T*/ defaultValue) =>
283-
_fieldSet._$get/*<T>*/(index, tagNumber, defaultValue);
282+
T $_get<T>(int index, int tagNumber, T defaultValue) =>
283+
_fieldSet._$get<T>(index, tagNumber, defaultValue);
284284

285285
/// For generated code only.
286286
bool $_has(int index, int tagNumber) => _fieldSet._$has(index, tagNumber);

lib/src/protobuf/pb_list.dart

Lines changed: 32 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -37,120 +37,91 @@ class PbList<E> extends Object with ListMixin<E> implements List<E> {
3737
return hash;
3838
}
3939

40-
/**
41-
* Returns an [Iterator] for the list.
42-
*/
40+
/// Returns an [Iterator] for the list.
4341
Iterator<E> get iterator => _wrappedList.iterator;
4442

45-
/**
46-
* Returns a new lazy [Iterable] with elements that are created by calling `f`
47-
* on each element of this `PbList` in iteration order.
48-
*/
49-
Iterable/*<T>*/ map/*<T>*/(/*=T*/ f(E e)) => _wrappedList.map/*<T>*/(f);
43+
/// Returns a new lazy [Iterable] with elements that are created by calling
44+
/// `f` on each element of this `PbList` in iteration order.
45+
Iterable<T> map<T>(T f(E e)) => _wrappedList.map<T>(f);
5046

51-
/**
52-
* Applies the function [f] to each element of this list in iteration order.
53-
*/
47+
/// Applies the function [f] to each element of this list in iteration order.
5448
void forEach(void f(E element)) {
5549
_wrappedList.forEach(f);
5650
}
5751

58-
/**
59-
* Returns the element at the given [index] in the list or throws
60-
* an [IndexOutOfRangeException] if [index] is out of bounds.
61-
*/
52+
/// Returns the element at the given [index] in the list or throws an
53+
/// [IndexOutOfRangeException] if [index] is out of bounds.
6254
E operator [](int index) => _wrappedList[index];
6355

64-
/**
65-
* Sets the entry at the given [index] in the list to [value].
66-
* Throws an [IndexOutOfRangeException] if [index] is out of bounds.
67-
*/
56+
/// Sets the entry at the given [index] in the list to [value].
57+
/// Throws an [IndexOutOfRangeException] if [index] is out of bounds.
6858
void operator []=(int index, E value) {
6959
_validate(value);
7060
_wrappedList[index] = value;
7161
}
7262

73-
/**
74-
* Unsupported -- violated non-null constraint imposed by protobufs.
75-
*
76-
* Changes the length of the list. If [newLength] is greater than
77-
* the current [length], entries are initialized to [:null:]. Throws
78-
* an [UnsupportedError] if the list is not extendable.
79-
*/
63+
/// Unsupported -- violated non-null constraint imposed by protobufs.
64+
///
65+
/// Changes the length of the list. If [newLength] is greater than the current
66+
/// [length], entries are initialized to [:null:]. Throws an
67+
/// [UnsupportedError] if the list is not extendable.
8068
void set length(int newLength) {
8169
if (newLength > length) {
8270
throw new ArgumentError('Extending protobuf lists is not supported');
8371
}
8472
_wrappedList.length = newLength;
8573
}
8674

87-
/**
88-
* Adds [value] at the end of the list, extending the length by
89-
* one. Throws an [UnsupportedError] if the list is not
90-
* extendable.
91-
*/
75+
/// Adds [value] at the end of the list, extending the length by one.
76+
/// Throws an [UnsupportedError] if the list is not extendable.
9277
void add(E value) {
9378
_validate(value);
9479
_wrappedList.add(value);
9580
}
9681

97-
/**
98-
* Appends all elements of the [collection] to the end of list.
99-
* Extends the length of the list by the length of [collection].
100-
* Throws an [UnsupportedError] if the list is not
101-
* extendable.
102-
*/
82+
/// Appends all elements of the [collection] to the end of list.
83+
/// Extends the length of the list by the length of [collection].
84+
/// Throws an [UnsupportedError] if the list is not extendable.
10385
void addAll(Iterable<E> collection) {
10486
collection.forEach(_validate);
10587
_wrappedList.addAll(collection);
10688
}
10789

108-
/**
109-
* Copies [:end - start:] elements of the [from] array, starting
110-
* from [skipCount], into [:this:], starting at [start].
111-
* Throws an [UnsupportedError] if the list is
112-
* not extendable.
113-
*/
90+
/// Copies [:end - start:] elements of the [from] array, starting from
91+
/// [skipCount], into [:this:], starting at [start].
92+
/// Throws an [UnsupportedError] if the list is not extendable.
11493
void setRange(int start, int end, Iterable<E> from, [int skipCount = 0]) {
11594
// NOTE: In case `take()` returns less than `end - start` elements, the
11695
// _wrappedList will fail with a `StateError`.
11796
from.skip(skipCount).take(end - start).forEach(_validate);
11897
_wrappedList.setRange(start, end, from, skipCount);
11998
}
12099

121-
/**
122-
* Inserts a new element in the list.
123-
* The element must be valid (and not nullable) for the PbList type.
124-
*/
100+
/// Inserts a new element in the list.
101+
/// The element must be valid (and not nullable) for the PbList type.
125102
void insert(int index, E element) {
126103
_validate(element);
127104
_wrappedList.insert(index, element);
128105
}
129106

130-
/**
131-
* Inserts all elements of [iterable] at position [index] in the list.
132-
*
133-
* Elements in [iterable] must be valid and not nullable for the PbList type.
134-
*/
107+
/// Inserts all elements of [iterable] at position [index] in the list.
108+
///
109+
/// Elements in [iterable] must be valid and not nullable for the PbList type.
135110
void insertAll(int index, Iterable<E> iterable) {
136111
iterable.forEach(_validate);
137112
_wrappedList.insertAll(index, iterable);
138113
}
139114

140-
/**
141-
* Overwrites elements of `this` with elements of [iterable] starting at
142-
* position [index] in the list.
143-
*
144-
* Elements in [iterable] must be valid and not nullable for the PbList type.
145-
*/
115+
/// Overwrites elements of `this` with elements of [iterable] starting at
116+
/// position [index] in the list.
117+
///
118+
/// Elements in [iterable] must be valid and not nullable for the PbList type.
146119
void setAll(int index, Iterable<E> iterable) {
147120
iterable.forEach(_validate);
148121
_wrappedList.setAll(index, iterable);
149122
}
150123

151-
/**
152-
* Returns the number of elements in this collection.
153-
*/
124+
/// Returns the number of elements in this collection.
154125
int get length => _wrappedList.length;
155126

156127
void _validate(E val) {

0 commit comments

Comments
 (0)